Skip to content

Commit

Permalink
Merge branch 'develop' into feature/getVariableCategoryName
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepsinn authored Sep 22, 2020
2 parents 5965da4 + b3b33d3 commit 78744e3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 189 deletions.
2 changes: 1 addition & 1 deletion src/js/controllers/appCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ angular.module('starter')// Parent Controller - This controller runs before ever
});
$scope.$on('$ionicView.afterEnter', function(e){
qmLog.debug($scope.controller_name + ".afterEnter so posting queued notifications if any");
qm.notifications.post();
qmService.syncTrackingReminderNotifications();
qmService.refreshUserUsingAccessTokenInUrlIfNecessary();
$rootScope.setMicAndSpeechEnabled(qm.mic.getMicEnabled());
qm.chatButton.setZohoChatButtonZIndex();
Expand Down
45 changes: 9 additions & 36 deletions src/js/controllers/remindersInboxCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
});
$scope.stateParams = $stateParams;
qmService.actionSheet.setDefaultActionSheet(function(){
$scope.refreshTrackingReminderNotifications();
$scope.syncTrackingReminderNotifications();
}, getVariableCategoryName());
qmService.splash.hideSplashScreen();
});
$scope.$on('$ionicView.afterEnter', function(){
qmLog.info('RemindersInboxCtrl afterEnter: ' + window.location.href);
setPageTitle(); // Setting title afterEnter doesn't fix cutoff on Android
if(needToRefresh()){
$scope.refreshTrackingReminderNotifications();
$scope.syncTrackingReminderNotifications();
}
if($rootScope.platform.isWeb){
qm.webNotifications.registerServiceWorker();
Expand All @@ -77,7 +77,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
});
$scope.$on('$ionicView.beforeLeave', function(){
qmLog.debug('RemindersInboxCtrl beforeLeave');
qm.notifications.post();
qmService.syncTrackingReminderNotifications();
});
$scope.$on('$ionicView.afterLeave', function(){
qmLog.debug('RemindersInboxCtrl afterLeave');
Expand Down Expand Up @@ -105,12 +105,11 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
function autoRefresh(){
$timeout(function(){
if($state.current.name.toLowerCase().indexOf('inbox') !== -1){
$scope.refreshTrackingReminderNotifications();
$scope.syncTrackingReminderNotifications();
autoRefresh();
}
}, 30 * 60 * 1000);
}

var setPageTitle = function(){
if(getVariableCategoryName() === 'Treatments'){
$scope.state.title = 'Overdue Meds';
Expand Down Expand Up @@ -148,7 +147,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
if(qm.notifications.getNumberInGlobalsOrLocalStorage(cat)){
getTrackingReminderNotifications();
}else{
$scope.refreshTrackingReminderNotifications();
$scope.syncTrackingReminderNotifications();
}
}
}
Expand Down Expand Up @@ -178,17 +177,6 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
});
}
}
function refreshNotificationsForCategory(cat) {
qmLog.info('Falling back to getTrackingReminderNotificationsFromApi request for category ' + cat);
qmService.refreshTrackingReminderNotifications({
variableCategoryName: cat,
onlyPast: true
}, function (response) {
qmLog.info('getTrackingReminderNotificationsFromApi response for ' + cat +
': ' + JSON.stringify(response));
addNotificationsToScope(response.data)
});
}
function getNumberOfDisplayedNotifications() {
var total = 0;
var dividers = $scope.notificationDividers;
Expand Down Expand Up @@ -232,15 +220,13 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
function getFallbackInboxContentIfNecessary(){
var num = getNumberOfDisplayedNotifications();
if(!num && !$scope.state.loading){
var cat = getVariableCategoryName();
if(cat){refreshNotificationsForCategory(cat);}
getFavorites();
getDiscoveries();
}
}
var closeWindowIfNecessary = function(){
if($state.current.name === "app.remindersInboxCompact" && !getNumberOfDisplayedNotifications()){
$scope.refreshTrackingReminderNotifications();
$scope.syncTrackingReminderNotifications();
window.close();
}
};
Expand Down Expand Up @@ -432,19 +418,6 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
logNotificationDividers($scope.notificationDividers);
})
}
var getFilteredTodayTrackingReminderNotifications = function(){
qmService.getTodayTrackingReminderNotificationsDeferred(getVariableCategoryName())
.then(function(trackingReminderNotifications){
addNotificationsToScope(trackingReminderNotifications)
getFallbackInboxContentIfNecessary();
hideInboxLoader();
}, function(error){
getFallbackInboxContentIfNecessary();
qmLog.error(error);
qmLog.error('failed to get reminder notifications!');
hideInboxLoader();
});
};
$rootScope.$on('broadcastGetTrackingReminderNotifications', function(){
qmLog.info('getTrackingReminderNotifications broadcast received..');
getFilteredTrackingReminderNotificationsFromLocalStorage();
Expand All @@ -465,16 +438,16 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state",
}
}, 10000);
};
$scope.refreshTrackingReminderNotifications = function(params){
$scope.syncTrackingReminderNotifications = function(params){
showLoader();
qmService.refreshTrackingReminderNotifications(params).then(function(){
qmService.syncTrackingReminderNotifications(params).then(function(){
getTrackingReminderNotifications();
if(!getNumberOfDisplayedNotifications()){
getFallbackInboxContentIfNecessary();
}
}, function(error){
getFallbackInboxContentIfNecessary();
qmLog.info('$scope.refreshTrackingReminderNotifications: ', error);
qmLog.info('$scope.syncTrackingReminderNotifications: ', error);
hideInboxLoader();
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function updateQuestion(variableName){
qmLog.error("Asking " + questionText + "!", "qmPopup.trackingReminderNotification is: " + JSON.stringify(qmPopup.trackingReminderNotification),
{trackingReminderNotification: qmPopup.trackingReminderNotification});
}
if (qmPopup.trackingReminderNotification.valence === "positive" ||
if (qmPopup.trackingReminderNotification.valence === "positive" ||
qmPopup.trackingReminderNotification.valence === "negative") {
numericRatingButtons().style.display = "none";
faceRatingButtons().style.display = "block";
Expand Down Expand Up @@ -312,7 +312,7 @@ document.addEventListener('DOMContentLoaded', function(){
}else{
qmLog.pushDebug("popup addEventListener: Calling hidePopup...");
hidePopup();
qm.notifications.refreshNotifications(updateQuestion, qm.notifications.closePopup);
qm.notifications.syncTrackingReminderNotifications(updateQuestion, qm.notifications.closePopup);
}
qmLog.pushDebug("popup addEventListener: calling setFaceButtonListeners...");
setFaceButtonListeners();
Expand Down
77 changes: 32 additions & 45 deletions src/js/qmHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5517,7 +5517,7 @@ var qm = {
refreshIfEmpty: function(successHandler, errorHandler){
if(!qm.notifications.getNumberInGlobalsOrLocalStorage()){
qm.qmLog.info('No notifications in local storage');
qm.notifications.refreshNotifications(successHandler, errorHandler);
qm.notifications.syncTrackingReminderNotifications(successHandler, errorHandler);
return true;
}
qm.qmLog.info(qm.notifications.getNumberInGlobalsOrLocalStorage() + ' notifications in local storage');
Expand All @@ -5528,7 +5528,7 @@ var qm = {
qm.qmLog.info("qm.notifications.refreshIfEmptyOrStale");
if(!qm.notifications.getNumberInGlobalsOrLocalStorage() || qm.notifications.getSecondsSinceLastNotificationsRefresh() > 3600){
qm.qmLog.info('Refreshing notifications because empty or last refresh was more than an hour ago');
qm.notifications.refreshNotifications(callback);
qm.notifications.syncTrackingReminderNotifications(callback);
}else{
qm.qmLog.info('Not refreshing notifications because last refresh was last than an hour ago and we have notifications in local storage');
if(callback){
Expand Down Expand Up @@ -5620,39 +5620,16 @@ var qm = {
}else{
console.info('No rating notifications for popup');
qm.notifications.getLastNotificationsRefreshTime();
qm.notifications.refreshNotifications();
qm.notifications.syncTrackingReminderNotifications();
return null;
}
},
deleteByVariableName: function(variableName){
return qm.storage.deleteByProperty(qm.items.trackingReminderNotifications, 'variableName', variableName);
},
promise: null,
refreshNotifications: function(successHandler, errorHandler, options){
var route = qm.apiPaths.trackingReminderNotificationsPast;
qm.api.getRequestUrl(route, function(url){
// Can't use QM SDK in service worker
qm.api.getViaXhrOrFetch(url, function(response){
if(!response){
qm.qmLog.error("No response from " + url);
if(errorHandler){
errorHandler("No response from " + url);
}
return;
}
if(response.status === 401){
qm.chrome.showSignInNotification();
}else{
qm.storage.setTrackingReminderNotifications(response.data);
if(successHandler){
successHandler(response.data);
}
}
})
}, options);
},
refreshAndShowPopupIfNecessary: function(notificationParams){
qm.notifications.refreshNotifications(notificationParams, function(trackingReminderNotifications){
qm.notifications.syncTrackingReminderNotifications(function(response){
var uniqueNotification = qm.notifications.getMostRecentUniqueNotificationNotInSyncQueue();
function objectLength(obj){
var result = 0;
Expand All @@ -5664,6 +5641,7 @@ var qm = {
}
return result;
}
var trackingReminderNotifications = qm.notifications.getFromGlobalsOrLocalStorage();
var numberOfWaitingNotifications = objectLength(trackingReminderNotifications);
if(uniqueNotification){
function getChromeRatingNotificationParams(trackingReminderNotification){
Expand Down Expand Up @@ -5769,7 +5747,7 @@ var qm = {
if(!successHandler){
return null;
}
qm.notifications.refreshNotifications(function(notifications){
qm.notifications.syncTrackingReminderNotifications(function(response){
var notification = qm.notifications.getMostRecentNotification();
if(notification){
successHandler(notification);
Expand All @@ -5781,7 +5759,7 @@ var qm = {
schedulePost: function(delayInMilliseconds){
var queue = qm.storage.getItem(qm.items.notificationsSyncQueue);
if(queue && queue.length > 10){
qm.notifications.post();
qm.notifications.syncTrackingReminderNotifications();
return;
}
if(!delayInMilliseconds){
Expand All @@ -5797,7 +5775,7 @@ var qm = {
}
setTimeout(function(){
qm.qmLog.info("Notifications sync countdown completed. Syncing now... ");
qm.notifications.post();
qm.notifications.syncTrackingReminderNotifications();
}, delayInMilliseconds);
}else{
if(!qm.platform.isMobile()){ // Better performance
Expand Down Expand Up @@ -5826,8 +5804,8 @@ var qm = {
qm.notifications.deleteByVariableName(n.variableName);
qm.notifications.addToSyncQueue(n);
},
post: function(successHandler, errorHandler){
qm.qmLog.debug("Called postNotifications...");
syncTrackingReminderNotifications: function(successHandler, errorHandler){
qm.qmLog.debug("Called syncTrackingReminderNotifications...");
var notifications = qm.storage.getItem(qm.items.notificationsSyncQueue);
qm.storage.removeItem(qm.items.notificationsSyncQueue);
qm.storage.removeItem(qm.items.trackingReminderNotificationSyncScheduled);
Expand All @@ -5851,21 +5829,29 @@ var qm = {
})
qm.api.postToQuantiModo(body, 'v3/trackingReminderNotifications',
function(response){
var measurements = response.measurements;
if(!measurements && response.data){measurements = response.data.measurements;}
if(!response){
var err = "No response from postToQuantiModo(body, 'v3/trackingReminderNotifications";
if(errorHandler){
errorHandler(err);
return;
} else {
throw err;
}
}
var measurements = response.measurements || response.data.measurements;
if(measurements){qm.measurements.addMeasurementsToMemory(measurements);}
var trackingReminderNotifications = response.trackingReminderNotifications || response.data.trackingReminderNotifications;
if(trackingReminderNotifications){qm.storage.setTrackingReminderNotifications(notifications);}
if(successHandler){successHandler(response);}
}, function(response){
if(!response.success){
qm.qmLog.error(response.message)
var newNotificationsSyncQueue = qm.storage.getItem(qm.items.notificationsSyncQueue);
if(newNotificationsSyncQueue){notifications = notifications.concat(newNotificationsSyncQueue);}
qm.storage.setItem(qm.items.notificationsSyncQueue, notifications);
if(errorHandler){errorHandler(response.message || response.error);}
} else{ // This happens when the error is a message saying the notification was already deleted
// so we don't want to put notifications back in queue
qm.qmLog.warn(response.message)
}
qm.qmLog.error(response.message)
// This happens when the error is a message saying the notification was already deleted
// so we don't want to put notifications back in queue
// Don't return to queue or we cause an infinite loop if we get a no changes error
// var newNotificationsSyncQueue = qm.storage.getItem(qm.items.notificationsSyncQueue);
// if(newNotificationsSyncQueue){notifications = notifications.concat(newNotificationsSyncQueue);}
// qm.storage.setItem(qm.items.notificationsSyncQueue, notifications);
if(errorHandler){errorHandler(response.message || response.error);}
});
},
skip: function(trackingReminderNotification){
Expand Down Expand Up @@ -9519,6 +9505,7 @@ var qm = {
}
},
userVariables: {
defaultLimit: 20,
updateLatestMeasurementTime: function(variableName, lastValue){
qm.storage.getUserVariableByName(variableName, true, lastValue);
},
Expand All @@ -9531,7 +9518,7 @@ var qm = {
params.sort = '-latestMeasurementTime';
}
if(!params.limit){
params.limit = 50;
params.limit = qm.userVariables.defaultLimit;
}
params = qm.api.addGlobalParams(params);
var cacheKey = 'getUserVariablesFromApi';
Expand Down
Loading

1 comment on commit 78744e3

@mikepsinn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View recording of ionic_variables_spec.js
Cypress Dashboard

ionic_variables-ionic

BUILD LOG

Please sign in to comment.