Skip to content

Commit 27002b2

Browse files
committed
Save timestamps to server
1 parent faad785 commit 27002b2

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

js/api.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ angular.module('openeis-ui.api', ['ngResource'])
120120
})
121121
.service('Files', function ($resource, $http) {
122122
var Files = this,
123-
resource = $resource(settings.API_URL + 'files/:fileId', { fileId: '@id' });
123+
resource = $resource(settings.API_URL + 'files/:fileId', { fileId: '@id' }, {
124+
update: { method: 'PATCH' },
125+
});
124126

125127
Files.get = function (fileId) {
126128
return resource.get({ fileId: fileId }).$promise;
@@ -130,6 +132,10 @@ angular.module('openeis-ui.api', ['ngResource'])
130132
return resource.query({ project: projectId }).$promise;
131133
};
132134

135+
Files.update = function (file) {
136+
return resource.update(file).$promise;
137+
};
138+
133139
Files.head = function (fileId) {
134140
return $http({
135141
method: 'GET',

js/projects.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ angular.module('openeis-ui.projects', [
109109
$scope.dataFiles[$index].cols.push(k);
110110
});
111111

112-
$scope.timestampsFile = $scope.dataFiles[$index];
112+
$scope.timestampFile = $scope.dataFiles[$index];
113113
});
114114
};
115115

116-
$scope.closeTimestampsModal = function () {
117-
delete $scope.timestampsFile;
116+
$scope.closeTimestampModal = function () {
117+
delete $scope.timestampFile;
118118
};
119119

120120
$scope.upload = function (fileInput) {
@@ -180,10 +180,10 @@ angular.module('openeis-ui.projects', [
180180
});
181181
};
182182
})
183-
.controller('TimestampsCtrl', function ($scope, Files, $http) {
183+
.controller('TimestampCtrl', function ($scope, Files, $http) {
184184
$scope.modal = { columns: {}, };
185185

186-
$scope.previewTimestamps = function () {
186+
$scope.preview = function () {
187187
$scope.selectedColumns = [];
188188

189189
angular.forEach($scope.modal.columns, function (selected, column) {
@@ -194,7 +194,7 @@ angular.module('openeis-ui.projects', [
194194

195195
$http({
196196
method: 'GET',
197-
url: settings.API_URL + 'files/' + $scope.timestampsFile.id + '/timestamps?columns=' + $scope.selectedColumns.join(','),
197+
url: settings.API_URL + 'files/' + $scope.timestampFile.id + '/timestamps?columns=' + $scope.selectedColumns.join(','),
198198
transformResponse: angular.fromJson,
199199
}).then(function (response) {
200200
$scope.modal.confirm = true;
@@ -204,10 +204,18 @@ angular.module('openeis-ui.projects', [
204204
});
205205
};
206206

207-
$scope.saveTimestamps = function () {
208-
// TODO: Save timestamp to server
209-
$scope.timestampsFile.timestamp = { columns: $scope.selectedColumns };
210-
$scope.closeTimestampsModal();
207+
$scope.save = function () {
208+
var timestamp = { columns: $scope.selectedColumns };
209+
210+
Files.update({
211+
id: $scope.timestampFile.id,
212+
timestamp: timestamp,
213+
}).then(function (file) {
214+
$scope.timestampFile.timestamp = timestamp;
215+
$scope.closeTimestampModal();
216+
}, function (rejection) {
217+
alert(angular.toJson(rejection));
218+
});
211219
};
212220
})
213221
.controller('NewDataSetCtrl', function ($scope, DataSets, SensorMaps) {

partials/file-timestamps.html renamed to partials/file-timestamp.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
<h4>{{timestampsFile.file}}</h4>
1+
<h4>{{timestampFile.file}}</h4>
22
<div ng-if="!modal.confirm">
33
<table class="table--file-preview">
44
<thead>
55
<tr>
6-
<th colspan="{{timestampsFile.cols.length}}">Select columns that comprise timestamp:</th>
6+
<th colspan="{{timestampFile.cols.length}}">Select columns that comprise timestamp:</th>
77
<tr>
8-
<th ng-repeat="col in timestampsFile.cols">
8+
<th ng-repeat="col in timestampFile.cols">
99
<input type="checkbox" ng-model="modal.columns[$index]">
1010
</th>
1111
</tr>
12-
<tr ng-if="timestampsFile.head.header.length">
13-
<th ng-repeat="header in timestampsFile.head.header"><label for="{{$index}}">{{header}}</label></th>
12+
<tr ng-if="timestampFile.head.header.length">
13+
<th ng-repeat="header in timestampFile.head.header"><label for="{{$index}}">{{header}}</label></th>
1414
</tr>
1515
</thead>
1616
<tbody>
17-
<tr ng-repeat="row in timestampsFile.head.rows">
17+
<tr ng-repeat="row in timestampFile.head.rows">
1818
<td ng-repeat="col in row track by $index">{{col}}</td>
1919
</tr>
2020
</tbody>
2121
</table>
22-
<button ng-click="previewTimestamps()">Continue</button> <button ng-click="closeTimestampsModal()">Cancel</button>
22+
<button ng-click="preview()">Continue</button> <button ng-click="closeTimestampModal()">Cancel</button>
2323
</div>
2424
<div ng-if="modal.confirm">
2525
<h5>Timestamps</h5>
@@ -38,5 +38,5 @@ <h5>Timestamps</h5>
3838
</tbody>
3939
</table>
4040
<p>Are the parsed timestamps correct?</p>
41-
<button ng-click="saveTimestamps()">Yes, save configuration</button> <button ng-click="modal.confirm = false">No, re-select columns</button>
41+
<button ng-click="save()">Yes, save configuration</button> <button ng-click="modal.confirm = false">No, re-select columns</button>
4242
</div>

partials/project.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ <h3>Data files</h3>
3333
</tr>
3434
</tbody>
3535
</table>
36-
<modal class="modal--file-timestamps" ng-if="timestampsFile">
37-
<ng-include src="'partials/file-timestamps.html'" ng-controller="TimestampsCtrl"></ng-include>
36+
<modal class="modal--file-timestamp" ng-if="timestampFile">
37+
<ng-include src="'partials/file-timestamp.html'" ng-controller="TimestampCtrl"></ng-include>
3838
</modal>
3939
</div>
4040
<div class="layout">

scss/app.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ nav {
202202
&--project {
203203
@extend %box;
204204

205-
.layout {
205+
> .layout {
206206
display: flex;
207207
margin-right: -$inuit-base-spacing-unit;
208208
}

0 commit comments

Comments
 (0)