Skip to content

Commit 41b83f0

Browse files
authored
Merge branch 'develop' into feature/setHideDefaultValueField
2 parents 1d151b9 + a9bedf1 commit 41b83f0

15 files changed

+447
-520
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ before_install:
4646
- bundle install
4747
- bundle update
4848
- export LANG=en_US.UTF-8
49-
- nvm install 8
49+
- nvm install 10
5050
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; brew install yarn ios-sim
5151
ios-deploy imagemagick; fi
5252
- npm install -g cordova ionic gulp bower cordova-hot-code-push-cli cordova-res

src/js/controllers/appCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ angular.module('starter')// Parent Controller - This controller runs before ever
1414
});
1515
$scope.$on('$ionicView.afterEnter', function(e){
1616
qmLog.debug($scope.controller_name + ".afterEnter so posting queued notifications if any");
17-
qm.notifications.post();
17+
qmService.syncNotificationsIfQueued();
1818
qmService.refreshUserUsingAccessTokenInUrlIfNecessary();
1919
$rootScope.setMicAndSpeechEnabled(qm.mic.getMicEnabled());
2020
qm.chatButton.setZohoChatButtonZIndex();

src/js/controllers/measurementAddCtrl.js

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
99
showVariableCategorySelector: false,
1010
showUnits: false,
1111
unitCategories: [],
12-
variableCategoryName: getVariableCategoryName(),
13-
variableCategoryObject: getVariableCategory(),
14-
helpText: getVariableCategory().helpText,
1512
unitAbbreviatedName: '',
1613
measurement: {},
1714
searchedUnits: [],
@@ -30,6 +27,16 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
3027
qmService.navBar.showNavigationMenuIfHideUrlParamNotSet();
3128
qmService.rootScope.setProperty('bloodPressure', {systolicValue: null, diastolicValue: null, show: false});
3229
$scope.state.title = 'Record a Measurement';
30+
setupMeasurement();
31+
var cat = getVariableCategory();
32+
if(cat){setupVariableCategory(cat);}
33+
});
34+
$scope.$on('$ionicView.enter', function(e){
35+
qmLogService.debug('$ionicView.enter ' + $state.current.name);
36+
qmService.hideLoader();
37+
qmLog.info("$ionicView.enter $scope.state.measurement is ", $scope.state.measurement);
38+
});
39+
function setupMeasurement() {
3340
$scope.state.selectedDate = moment();
3441
$scope.state.units = qm.unitHelper.getNonAdvancedUnits();
3542
var reminderFromUrl = qm.urlHelper.getParam('trackingReminderObject', window.location.href, true);
@@ -39,33 +46,34 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
3946
var v = $stateParams.variableObject;
4047
var n = $stateParams.reminderNotification;
4148
var id = qm.urlHelper.getParam('measurementId', location.href, true);
42-
if(tr){
49+
if (tr) {
4350
setupTrackingByReminder(tr);
44-
}else if(m){
51+
} else if (m) {
4552
setupTrackingByMeasurement(m);
46-
}else if(measurementFromUrl){
53+
} else if (measurementFromUrl) {
4754
setupTrackingByMeasurement(JSON.parse(measurementFromUrl));
48-
}else if(v){
55+
} else if (v) {
4956
setupFromVariable(v);
50-
}else if(reminderFromUrl){
57+
} else if (reminderFromUrl) {
5158
setupTrackingByReminder(JSON.parse(reminderFromUrl));
52-
}else if(n){
59+
} else if (n) {
5360
setupTrackingByReminder(n);
54-
}else if(id){
55-
setMeasurementVariablesByMeasurementId(id).then(function(){
56-
if(!$scope.state.measurementIsSetup){$scope.goBack();}
61+
} else if (id) {
62+
setMeasurementVariablesByMeasurementId(id).then(function () {
63+
if (!$scope.state.measurementIsSetup) {
64+
$scope.goBack();
65+
}
5766
});
58-
}else if($stateParams.variableName){
67+
} else if ($stateParams.variableName) {
5968
setupFromVariableName($stateParams.variableName);
6069
}
61-
if(!$scope.state.measurementIsSetup){setupFromUrlParameters();}
62-
if(!$scope.state.measurementIsSetup){setupFromVariable(qm.getPrimaryOutcomeVariable());}
63-
});
64-
$scope.$on('$ionicView.enter', function(e){
65-
qmLogService.debug('$ionicView.enter ' + $state.current.name);
66-
qmService.hideLoader();
67-
qmLog.info("$ionicView.enter $scope.state.measurement is ", $scope.state.measurement);
68-
});
70+
if (!$scope.state.measurementIsSetup) {
71+
setupFromUrlParameters();
72+
}
73+
if (!$scope.state.measurementIsSetup) {
74+
setupFromVariable(qm.getPrimaryOutcomeVariable());
75+
}
76+
}
6977
var trackBloodPressure = function(){
7078
if(!$rootScope.bloodPressure.diastolicValue || !$rootScope.bloodPressure.systolicValue){
7179
qmService.validationFailure('Please enter both values for blood pressure.', $scope.state.measurement);
@@ -142,16 +150,20 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
142150
}
143151
};
144152
$scope.variableCategorySelectorChange = function(variableCategoryName){
145-
var cat = qmService.getVariableCategoryInfo(variableCategoryName);
153+
var cat = qm.variableCategoryHelper.findVariableCategory(variableCategoryName);
146154
setupUnit(cat.defaultUnitAbbreviatedName);
147155
$scope.state.defaultValuePlaceholderText = 'Enter a value';
148156
$scope.state.defaultValueLabel = 'Value';
149157
setupVariableCategory(variableCategoryName);
150158
};
151159
var setupVariableCategory = function(variableCategoryName){
160+
var cat = getVariableCategory(variableCategoryName);
152161
qmLogService.debug($state.current.name + ': ' + 'variableCategoryName is ' + variableCategoryName);
153-
$scope.state.measurement.variableCategoryName = variableCategoryName;
154-
var cat = getVariableCategory();
162+
if($scope.state.measurement){
163+
$scope.state.measurement.variableCategoryName = cat.name;
164+
}
165+
$scope.state.variableCategoryObject = cat;
166+
$scope.state.helpText = cat.helpText;
155167
$scope.state.title = "Add Measurement";
156168
$scope.state.measurementSynonymSingularLowercase = cat.measurementSynonymSingularLowercase;
157169
if(cat.defaultValueLabel){$scope.state.defaultValueLabel = cat.defaultValueLabel;}
@@ -183,8 +195,9 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
183195
$scope.state.measurement.unitAbbreviatedName = unitAbbreviatedName;
184196
$scope.state.measurement = qm.unitHelper.updateAllUnitPropertiesOnObject(unitAbbreviatedName, $scope.state.measurement);
185197
qmLog.info("Setting $scope.state.measurement to ", $scope.state.measurement);
198+
qm.unitHelper.setInputType($scope.state.measurement);
199+
$scope.state.units = qm.unitHelper.getUnitArrayContaining(unitAbbreviatedName);
186200
}
187-
setupValueFieldType(unitAbbreviatedName, valence);
188201
}
189202
$scope.selectPrimaryOutcomeVariableValue = function($event, newValue){
190203
// remove any previous primary outcome variables if present
@@ -245,7 +258,7 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
245258
if(v.unitAbbreviatedName){
246259
setupUnit(v.unitAbbreviatedName, v.valence);
247260
}else if(v.variableCategoryName){
248-
var category = qmService.getVariableCategoryInfo(v.variableCategoryName);
261+
var category = qm.variableCategoryHelper.findVariableCategory(v);
249262
setupUnit(category.defaultUnitAbbreviatedName, v.valence);
250263
}
251264
var m = qm.measurements.newMeasurement(v);
@@ -297,15 +310,6 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
297310
measurement: $stateParams.measurement
298311
});
299312
};
300-
function setupValueFieldType(unitAbbreviatedName, valence, variableName){
301-
$scope.state.units = qm.unitHelper.getUnitArrayContaining(unitAbbreviatedName);
302-
//if($scope.state.measurement.inputType){return;} Why is this here? It prevents updating when we change a unit! :(
303-
if(!unitAbbreviatedName){
304-
qmLogService.error('No unitAbbreviatedName provided to setupValueFieldType');
305-
return false;
306-
}
307-
$scope.state.measurement.inputType = qm.unitHelper.getInputType(unitAbbreviatedName, valence, variableName);
308-
}
309313
function setVariableObjectFromMeasurement(){
310314
$scope.state.variableObject = {
311315
unitAbbreviatedName: $scope.state.measurement.unitAbbreviatedName,
@@ -398,18 +402,20 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
398402
hideSheet();
399403
}, 20000);
400404
});
401-
function getVariableCategoryName(object){
402-
var name;
403-
if(object && object.variableCategoryName){name = object.variableCategoryName;}
404-
if(!name && $scope.state && $scope.state.measurement && $scope.state.measurement.variableCategoryName){
405-
name = $scope.state.measurement.variableCategoryName;
406-
}
407-
if(!name){name = $stateParams.variableCategoryName;}
408-
if(!name){name = qm.urlHelper.getParam('variableCategoryName');}
409-
if(!name && $stateParams.variableObject){name = $stateParams.variableObject.variableCategoryName;}
410-
return name;
405+
function getVariableCategoryName(obj){
406+
var cat = getVariableCategory(obj);
407+
if(!cat){return null;}
408+
return cat.name;
411409
}
412-
function getVariableCategory(){
413-
return qmService.getVariableCategoryInfo(getVariableCategoryName());
410+
function getVariableCategory(obj){
411+
var cat;
412+
if(obj){cat = qm.variableCategoryHelper.findVariableCategory(obj);}
413+
if(!cat && $scope.state){cat = qm.variableCategoryHelper.findVariableCategory($scope.state);}
414+
if(!cat){cat = qm.variableCategoryHelper.findVariableCategory($stateParams);}
415+
if(!cat){
416+
qmLog.debug("No variable category name from getVariableCategory")
417+
return null;
418+
}
419+
return cat;
414420
}
415421
}]);

src/js/controllers/reminderAddCtrl.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ angular.module('starter').controller('ReminderAddCtrl', ["$scope", "$state", "$s
5858
$scope.state.trackingReminder.id = $stateParams.trackingReminderId;
5959
}
6060
$scope.state.savingText = 'Save';
61-
qm.variableCategoryHelper.getVariableCategoriesFromGlobalsOrApi(function(variableCategories){
62-
$scope.state.variableCategories = variableCategories;
63-
});
61+
$scope.state.variableCategories = qm.variableCategoryHelper.getVariableCategories();
6462
qmService.navBar.showNavigationMenuIfHideUrlParamNotSet();
6563
qmService.login.sendToLoginIfNecessaryAndComeBack("beforeEnter in " + $state.current.name);
6664
$stateParams.variableCategoryName = getVariableCategoryName();
@@ -423,7 +421,7 @@ angular.module('starter').controller('ReminderAddCtrl', ["$scope", "$state", "$s
423421
setHideDefaultValueField();
424422
};
425423
$scope.variableCategorySelectorChange = function(variableCategoryName){
426-
$scope.state.variableCategoryObject = qmService.getVariableCategoryInfo(variableCategoryName);
424+
$scope.state.variableCategoryObject = qm.variableCategoryHelper.findVariableCategory(variableCategoryName);
427425
$scope.state.trackingReminder.unitAbbreviatedName = $scope.state.variableCategoryObject.defaultUnitAbbreviatedName;
428426
$scope.state.defaultValuePlaceholderText = 'Enter most common value';
429427
$scope.state.defaultValueLabel = 'Default Value';
@@ -444,7 +442,7 @@ angular.module('starter').controller('ReminderAddCtrl', ["$scope", "$state", "$s
444442
}
445443
var r = $scope.state.trackingReminder;
446444
r.variableCategoryName = variableCategoryName;
447-
$scope.state.variableCategoryObject = qmService.getVariableCategoryInfo(variableCategoryName);
445+
$scope.state.variableCategoryObject = qm.variableCategoryHelper.findVariableCategory(variableCategoryName);
448446
if(!r.unitAbbreviatedName){
449447
r.unitAbbreviatedName = $scope.state.variableCategoryObject.defaultUnitAbbreviatedName;
450448
}

src/js/controllers/remindersInboxCtrl.js

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
6060
});
6161
$scope.stateParams = $stateParams;
6262
qmService.actionSheet.setDefaultActionSheet(function(){
63-
$scope.refreshTrackingReminderNotifications();
63+
$scope.syncTrackingReminderNotifications();
6464
}, getVariableCategoryName());
6565
qmService.splash.hideSplashScreen();
6666
});
6767
$scope.$on('$ionicView.afterEnter', function(){
6868
qmLog.info('RemindersInboxCtrl afterEnter: ' + window.location.href);
6969
setPageTitle(); // Setting title afterEnter doesn't fix cutoff on Android
7070
if(needToRefresh()){
71-
$scope.refreshTrackingReminderNotifications();
71+
$scope.syncTrackingReminderNotifications();
7272
}
7373
if($rootScope.platform.isWeb){
7474
qm.webNotifications.registerServiceWorker();
@@ -77,7 +77,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
7777
});
7878
$scope.$on('$ionicView.beforeLeave', function(){
7979
qmLog.debug('RemindersInboxCtrl beforeLeave');
80-
qm.notifications.post();
80+
qmService.syncNotificationsIfQueued();
8181
});
8282
$scope.$on('$ionicView.afterLeave', function(){
8383
qmLog.debug('RemindersInboxCtrl afterLeave');
@@ -105,12 +105,11 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
105105
function autoRefresh(){
106106
$timeout(function(){
107107
if($state.current.name.toLowerCase().indexOf('inbox') !== -1){
108-
$scope.refreshTrackingReminderNotifications();
108+
$scope.syncTrackingReminderNotifications();
109109
autoRefresh();
110110
}
111111
}, 30 * 60 * 1000);
112112
}
113-
114113
var setPageTitle = function(){
115114
if(getVariableCategoryName() === 'Treatments'){
116115
$scope.state.title = 'Overdue Meds';
@@ -148,7 +147,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
148147
if(qm.notifications.getNumberInGlobalsOrLocalStorage(cat)){
149148
getTrackingReminderNotifications();
150149
}else{
151-
$scope.refreshTrackingReminderNotifications();
150+
$scope.syncTrackingReminderNotifications();
152151
}
153152
}
154153
}
@@ -178,17 +177,6 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
178177
});
179178
}
180179
}
181-
function refreshNotificationsForCategory(cat) {
182-
qmLog.info('Falling back to getTrackingReminderNotificationsFromApi request for category ' + cat);
183-
qmService.refreshTrackingReminderNotifications({
184-
variableCategoryName: cat,
185-
onlyPast: true
186-
}, function (response) {
187-
qmLog.info('getTrackingReminderNotificationsFromApi response for ' + cat +
188-
': ' + JSON.stringify(response));
189-
addNotificationsToScope(response.data)
190-
});
191-
}
192180
function getNumberOfDisplayedNotifications() {
193181
var total = 0;
194182
var dividers = $scope.notificationDividers;
@@ -232,15 +220,13 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
232220
function getFallbackInboxContentIfNecessary(){
233221
var num = getNumberOfDisplayedNotifications();
234222
if(!num && !$scope.state.loading){
235-
var cat = getVariableCategoryName();
236-
if(cat){refreshNotificationsForCategory(cat);}
237223
getFavorites();
238224
getDiscoveries();
239225
}
240226
}
241227
var closeWindowIfNecessary = function(){
242228
if($state.current.name === "app.remindersInboxCompact" && !getNumberOfDisplayedNotifications()){
243-
$scope.refreshTrackingReminderNotifications();
229+
$scope.syncTrackingReminderNotifications();
244230
window.close();
245231
}
246232
};
@@ -432,19 +418,6 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
432418
logNotificationDividers($scope.notificationDividers);
433419
})
434420
}
435-
var getFilteredTodayTrackingReminderNotifications = function(){
436-
qmService.getTodayTrackingReminderNotificationsDeferred(getVariableCategoryName())
437-
.then(function(trackingReminderNotifications){
438-
addNotificationsToScope(trackingReminderNotifications)
439-
getFallbackInboxContentIfNecessary();
440-
hideInboxLoader();
441-
}, function(error){
442-
getFallbackInboxContentIfNecessary();
443-
qmLog.error(error);
444-
qmLog.error('failed to get reminder notifications!');
445-
hideInboxLoader();
446-
});
447-
};
448421
$rootScope.$on('broadcastGetTrackingReminderNotifications', function(){
449422
qmLog.info('getTrackingReminderNotifications broadcast received..');
450423
getFilteredTrackingReminderNotificationsFromLocalStorage();
@@ -465,16 +438,16 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
465438
}
466439
}, 10000);
467440
};
468-
$scope.refreshTrackingReminderNotifications = function(params){
441+
$scope.syncTrackingReminderNotifications = function(params){
469442
showLoader();
470-
qmService.refreshTrackingReminderNotifications(params).then(function(){
443+
qmService.syncTrackingReminderNotifications(params).then(function(){
471444
getTrackingReminderNotifications();
472445
if(!getNumberOfDisplayedNotifications()){
473446
getFallbackInboxContentIfNecessary();
474447
}
475448
}, function(error){
476449
getFallbackInboxContentIfNecessary();
477-
qmLog.info('$scope.refreshTrackingReminderNotifications: ', error);
450+
qmLog.info('$scope.syncTrackingReminderNotifications: ', error);
478451
hideInboxLoader();
479452
});
480453
};

src/js/controllers/remindersManageCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ angular.module('starter').controller('RemindersManageCtrl', ["$scope", "$state",
5555
}else{
5656
$scope.state.noRemindersTitle = "Add " + cat;
5757
$scope.state.noRemindersText = "You haven't saved any " + cat.toLowerCase() + " favorites or reminders here, yet.";
58-
$scope.state.noRemindersIcon = qmService.getVariableCategoryInfo(cat).ionIcon;
58+
$scope.state.noRemindersIcon = qm.variableCategoryHelper.findVariableCategory(cat).ionIcon;
5959
$scope.stateParams.title = document.title = cat;
6060
if(!$scope.stateParams.addButtonText){
6161
$scope.stateParams.addButtonText = 'Add New ' + pluralize($filter('wordAliases')(cat), 1) + " Reminder";

0 commit comments

Comments
 (0)