@@ -23,8 +23,12 @@ angular.module('starter').controller('historyAllMeasurementsCtrl', ["$scope", "$
23
23
icon : "ion-calendar"
24
24
} ;
25
25
}
26
- if ( $stateParams . refresh ) { $scope . state . history = null ; }
27
- $scope . state . history = addRecentlyPostedAndQueuedMeasurements ( $scope . state . history ) ;
26
+ if ( $stateParams . refresh ) { $scope . state . history = [ ] ; }
27
+ qm . measurements . addLocalMeasurements ( $scope . state . history , getRequestParams ( ) , function ( combined ) {
28
+ $scope . safeApply ( function ( ) {
29
+ $scope . state . history = combined ;
30
+ } )
31
+ } )
28
32
$scope . state . moreDataCanBeLoaded = true ;
29
33
// Need to use rootScope here for some reason
30
34
qmService . rootScope . setProperty ( 'hideHistoryPageInstructionsCard' ,
@@ -37,26 +41,14 @@ angular.module('starter').controller('historyAllMeasurementsCtrl', ["$scope", "$
37
41
document . title = $scope . state . title = cat + ' History' ;
38
42
$scope . state . showLocationToggle = cat === "Location" ;
39
43
}
40
- if ( cat ) {
41
- setupVariableCategoryActionSheet ( ) ;
42
- }
44
+ if ( cat ) { setupVariableCategoryActionSheet ( ) ; }
43
45
getScopedVariableObject ( ) ;
44
46
if ( getVariableName ( ) ) { $scope . state . title = getVariableName ( ) + ' History' ; }
45
47
updateNavigationMenuButton ( ) ;
46
48
if ( ! $scope . state . history || ! $scope . state . history . length ) { // Otherwise it keeps add more measurements whenever we edit one
47
49
$scope . getHistory ( ) ;
48
50
}
49
51
} ) ;
50
- function addRecentlyPostedAndQueuedMeasurements ( history ) {
51
- history = history || [ ] ;
52
- var recentlyPosted = qm . measurements . getRecentlyPostedMeasurements ( getRequestParams ( ) ) ;
53
- //qm.measurements.recentlyPostedMeasurements = []; TODO: Why are we resetting recentlyPostedMeasurements?
54
- if ( recentlyPosted ) { history = qm . arrayHelper . addToOrReplaceByIdAndMoveToFront ( history , recentlyPosted ) ; }
55
- var queue = qm . measurements . getMeasurementsFromQueue ( getRequestParams ( ) ) ;
56
- if ( queue ) { history = qm . arrayHelper . addToOrReplaceByIdAndMoveToFront ( history , queue ) ; }
57
- history = qm . arrayHelper . sortByProperty ( history , $scope . state . sort )
58
- return history ;
59
- }
60
52
function updateNavigationMenuButton ( ) {
61
53
$timeout ( function ( ) {
62
54
qmService . rootScope . setShowActionSheetMenu ( function ( ) {
@@ -223,24 +215,10 @@ angular.module('starter').controller('historyAllMeasurementsCtrl', ["$scope", "$
223
215
if ( measurements . length < $scope . state . limit ) {
224
216
$scope . state . noHistory = measurements . length === 0 ;
225
217
}
226
- measurements = addRecentlyPostedAndQueuedMeasurements ( measurements ) ;
227
- measurements = qm . measurements . addInfoAndImagesToMeasurements ( measurements ) ;
228
- if ( ! qm . arrayHelper . variableIsArray ( $scope . state . history ) ) {
229
- qmLogService . error ( "$scope.state.history is not an array! $scope.state.history: " + JSON . stringify ( $scope . state . history ) ) ;
230
- $scope . state . history = measurements ;
231
- } else {
232
- if ( ! $scope . state . history ) {
233
- $scope . state . history = [ ] ;
234
- }
235
- try {
236
- $scope . state . history = $scope . state . history . concat ( measurements ) ;
237
- } catch ( error ) {
238
- qmLog . error ( error ) ;
239
- $scope . state . history = JSON . parse ( JSON . stringify ( $scope . state . history ) ) ;
240
- $scope . state . history = $scope . state . history . concat ( measurements ) ;
241
- }
242
- }
243
- hideLoader ( ) ;
218
+ qm . measurements . addLocalMeasurements ( measurements , getRequestParams ( ) , function ( combined ) {
219
+ $scope . state . history = combined ;
220
+ hideLoader ( ) ;
221
+ } )
244
222
}
245
223
function errorHandler ( error ) {
246
224
qmLogService . error ( "History update error: " , error ) ;
0 commit comments