Skip to content

Commit 78744e3

Browse files
authored
Merge branch 'develop' into feature/getVariableCategoryName
2 parents 5965da4 + b3b33d3 commit 78744e3

File tree

7 files changed

+67
-189
lines changed

7 files changed

+67
-189
lines changed

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.syncTrackingReminderNotifications();
1818
qmService.refreshUserUsingAccessTokenInUrlIfNecessary();
1919
$rootScope.setMicAndSpeechEnabled(qm.mic.getMicEnabled());
2020
qm.chatButton.setZohoChatButtonZIndex();

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.syncTrackingReminderNotifications();
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/popup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function updateQuestion(variableName){
243243
qmLog.error("Asking " + questionText + "!", "qmPopup.trackingReminderNotification is: " + JSON.stringify(qmPopup.trackingReminderNotification),
244244
{trackingReminderNotification: qmPopup.trackingReminderNotification});
245245
}
246-
if (qmPopup.trackingReminderNotification.valence === "positive" ||
246+
if (qmPopup.trackingReminderNotification.valence === "positive" ||
247247
qmPopup.trackingReminderNotification.valence === "negative") {
248248
numericRatingButtons().style.display = "none";
249249
faceRatingButtons().style.display = "block";
@@ -312,7 +312,7 @@ document.addEventListener('DOMContentLoaded', function(){
312312
}else{
313313
qmLog.pushDebug("popup addEventListener: Calling hidePopup...");
314314
hidePopup();
315-
qm.notifications.refreshNotifications(updateQuestion, qm.notifications.closePopup);
315+
qm.notifications.syncTrackingReminderNotifications(updateQuestion, qm.notifications.closePopup);
316316
}
317317
qmLog.pushDebug("popup addEventListener: calling setFaceButtonListeners...");
318318
setFaceButtonListeners();

src/js/qmHelpers.js

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5517,7 +5517,7 @@ var qm = {
55175517
refreshIfEmpty: function(successHandler, errorHandler){
55185518
if(!qm.notifications.getNumberInGlobalsOrLocalStorage()){
55195519
qm.qmLog.info('No notifications in local storage');
5520-
qm.notifications.refreshNotifications(successHandler, errorHandler);
5520+
qm.notifications.syncTrackingReminderNotifications(successHandler, errorHandler);
55215521
return true;
55225522
}
55235523
qm.qmLog.info(qm.notifications.getNumberInGlobalsOrLocalStorage() + ' notifications in local storage');
@@ -5528,7 +5528,7 @@ var qm = {
55285528
qm.qmLog.info("qm.notifications.refreshIfEmptyOrStale");
55295529
if(!qm.notifications.getNumberInGlobalsOrLocalStorage() || qm.notifications.getSecondsSinceLastNotificationsRefresh() > 3600){
55305530
qm.qmLog.info('Refreshing notifications because empty or last refresh was more than an hour ago');
5531-
qm.notifications.refreshNotifications(callback);
5531+
qm.notifications.syncTrackingReminderNotifications(callback);
55325532
}else{
55335533
qm.qmLog.info('Not refreshing notifications because last refresh was last than an hour ago and we have notifications in local storage');
55345534
if(callback){
@@ -5620,39 +5620,16 @@ var qm = {
56205620
}else{
56215621
console.info('No rating notifications for popup');
56225622
qm.notifications.getLastNotificationsRefreshTime();
5623-
qm.notifications.refreshNotifications();
5623+
qm.notifications.syncTrackingReminderNotifications();
56245624
return null;
56255625
}
56265626
},
56275627
deleteByVariableName: function(variableName){
56285628
return qm.storage.deleteByProperty(qm.items.trackingReminderNotifications, 'variableName', variableName);
56295629
},
56305630
promise: null,
5631-
refreshNotifications: function(successHandler, errorHandler, options){
5632-
var route = qm.apiPaths.trackingReminderNotificationsPast;
5633-
qm.api.getRequestUrl(route, function(url){
5634-
// Can't use QM SDK in service worker
5635-
qm.api.getViaXhrOrFetch(url, function(response){
5636-
if(!response){
5637-
qm.qmLog.error("No response from " + url);
5638-
if(errorHandler){
5639-
errorHandler("No response from " + url);
5640-
}
5641-
return;
5642-
}
5643-
if(response.status === 401){
5644-
qm.chrome.showSignInNotification();
5645-
}else{
5646-
qm.storage.setTrackingReminderNotifications(response.data);
5647-
if(successHandler){
5648-
successHandler(response.data);
5649-
}
5650-
}
5651-
})
5652-
}, options);
5653-
},
56545631
refreshAndShowPopupIfNecessary: function(notificationParams){
5655-
qm.notifications.refreshNotifications(notificationParams, function(trackingReminderNotifications){
5632+
qm.notifications.syncTrackingReminderNotifications(function(response){
56565633
var uniqueNotification = qm.notifications.getMostRecentUniqueNotificationNotInSyncQueue();
56575634
function objectLength(obj){
56585635
var result = 0;
@@ -5664,6 +5641,7 @@ var qm = {
56645641
}
56655642
return result;
56665643
}
5644+
var trackingReminderNotifications = qm.notifications.getFromGlobalsOrLocalStorage();
56675645
var numberOfWaitingNotifications = objectLength(trackingReminderNotifications);
56685646
if(uniqueNotification){
56695647
function getChromeRatingNotificationParams(trackingReminderNotification){
@@ -5769,7 +5747,7 @@ var qm = {
57695747
if(!successHandler){
57705748
return null;
57715749
}
5772-
qm.notifications.refreshNotifications(function(notifications){
5750+
qm.notifications.syncTrackingReminderNotifications(function(response){
57735751
var notification = qm.notifications.getMostRecentNotification();
57745752
if(notification){
57755753
successHandler(notification);
@@ -5781,7 +5759,7 @@ var qm = {
57815759
schedulePost: function(delayInMilliseconds){
57825760
var queue = qm.storage.getItem(qm.items.notificationsSyncQueue);
57835761
if(queue && queue.length > 10){
5784-
qm.notifications.post();
5762+
qm.notifications.syncTrackingReminderNotifications();
57855763
return;
57865764
}
57875765
if(!delayInMilliseconds){
@@ -5797,7 +5775,7 @@ var qm = {
57975775
}
57985776
setTimeout(function(){
57995777
qm.qmLog.info("Notifications sync countdown completed. Syncing now... ");
5800-
qm.notifications.post();
5778+
qm.notifications.syncTrackingReminderNotifications();
58015779
}, delayInMilliseconds);
58025780
}else{
58035781
if(!qm.platform.isMobile()){ // Better performance
@@ -5826,8 +5804,8 @@ var qm = {
58265804
qm.notifications.deleteByVariableName(n.variableName);
58275805
qm.notifications.addToSyncQueue(n);
58285806
},
5829-
post: function(successHandler, errorHandler){
5830-
qm.qmLog.debug("Called postNotifications...");
5807+
syncTrackingReminderNotifications: function(successHandler, errorHandler){
5808+
qm.qmLog.debug("Called syncTrackingReminderNotifications...");
58315809
var notifications = qm.storage.getItem(qm.items.notificationsSyncQueue);
58325810
qm.storage.removeItem(qm.items.notificationsSyncQueue);
58335811
qm.storage.removeItem(qm.items.trackingReminderNotificationSyncScheduled);
@@ -5851,21 +5829,29 @@ var qm = {
58515829
})
58525830
qm.api.postToQuantiModo(body, 'v3/trackingReminderNotifications',
58535831
function(response){
5854-
var measurements = response.measurements;
5855-
if(!measurements && response.data){measurements = response.data.measurements;}
5832+
if(!response){
5833+
var err = "No response from postToQuantiModo(body, 'v3/trackingReminderNotifications";
5834+
if(errorHandler){
5835+
errorHandler(err);
5836+
return;
5837+
} else {
5838+
throw err;
5839+
}
5840+
}
5841+
var measurements = response.measurements || response.data.measurements;
58565842
if(measurements){qm.measurements.addMeasurementsToMemory(measurements);}
5843+
var trackingReminderNotifications = response.trackingReminderNotifications || response.data.trackingReminderNotifications;
5844+
if(trackingReminderNotifications){qm.storage.setTrackingReminderNotifications(notifications);}
58575845
if(successHandler){successHandler(response);}
58585846
}, function(response){
5859-
if(!response.success){
5860-
qm.qmLog.error(response.message)
5861-
var newNotificationsSyncQueue = qm.storage.getItem(qm.items.notificationsSyncQueue);
5862-
if(newNotificationsSyncQueue){notifications = notifications.concat(newNotificationsSyncQueue);}
5863-
qm.storage.setItem(qm.items.notificationsSyncQueue, notifications);
5864-
if(errorHandler){errorHandler(response.message || response.error);}
5865-
} else{ // This happens when the error is a message saying the notification was already deleted
5866-
// so we don't want to put notifications back in queue
5867-
qm.qmLog.warn(response.message)
5868-
}
5847+
qm.qmLog.error(response.message)
5848+
// This happens when the error is a message saying the notification was already deleted
5849+
// so we don't want to put notifications back in queue
5850+
// Don't return to queue or we cause an infinite loop if we get a no changes error
5851+
// var newNotificationsSyncQueue = qm.storage.getItem(qm.items.notificationsSyncQueue);
5852+
// if(newNotificationsSyncQueue){notifications = notifications.concat(newNotificationsSyncQueue);}
5853+
// qm.storage.setItem(qm.items.notificationsSyncQueue, notifications);
5854+
if(errorHandler){errorHandler(response.message || response.error);}
58695855
});
58705856
},
58715857
skip: function(trackingReminderNotification){
@@ -9519,6 +9505,7 @@ var qm = {
95199505
}
95209506
},
95219507
userVariables: {
9508+
defaultLimit: 20,
95229509
updateLatestMeasurementTime: function(variableName, lastValue){
95239510
qm.storage.getUserVariableByName(variableName, true, lastValue);
95249511
},
@@ -9531,7 +9518,7 @@ var qm = {
95319518
params.sort = '-latestMeasurementTime';
95329519
}
95339520
if(!params.limit){
9534-
params.limit = 50;
9521+
params.limit = qm.userVariables.defaultLimit;
95359522
}
95369523
params = qm.api.addGlobalParams(params);
95379524
var cacheKey = 'getUserVariablesFromApi';

0 commit comments

Comments
 (0)