From 0f47ead3d5f380e039067c754886dd80c07a5c64 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Sun, 2 Feb 2020 12:02:56 -0600 Subject: [PATCH 1/6] env files --- .env.example | 16 +++ .gitignore | 263 ++++++++++++++++++++++---------------------- gulpfile.js | 21 ++-- package-lock.json | 5 + package.json | 1 + src/js/qmHelpers.js | 8 +- 6 files changed, 171 insertions(+), 143 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000..2ac9b2f537 --- /dev/null +++ b/.env.example @@ -0,0 +1,16 @@ +# Copy me to .env and never commit publicly. .env should be in .gitignore file to prevent this +ANALYTICS_PROVIDER= +ANALYTICS_TRACKING_ID= +APP_DEBUG=true +APP_ENV=local +APP_HOST_NAME= +APP_LOG_LEVEL=INFO +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY="" +BUGSNAG_API_KEY= +GITHUB_ACCESS_TOKEN= +HEROKU_API_KEY= +# Get QUANTIMODO_ACCESS_TOKEN @ https://app.quantimo.do/api/v2/account +QUANTIMODO_ACCESS_TOKEN= +# Get QUANTIMODO_CLIENT_ID @ https://builder.quantimo.do +QUANTIMODO_CLIENT_ID= diff --git a/.gitignore b/.gitignore index 214760030d..95d7ee4f57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,131 +1,132 @@ -# Specifies intentionally untracked files to ignore when using Git -# http://git-scm.com/docs/gitignore -!/fastlane/ -!/src/ -!/src/your_quantimodo_client_id_here.private_config.json -*.app.dSYM.zip -*.ipa -*.keystore -*.mobileprovision -.idea/ -!.idea/runConfigurations/* -!.idea/dictionaries/* -!.idea/modules/* -!.idea/inspectionProfiles/* -.vagrant/ -.vs/ -/android-armv7-debug/ -/android-armv7-release/ -/android-x86-release/ -/bin/ -/bld/ -/build/ -/config.xml -/fastlane/* -/hooks/generate_resources_fix_xcode_and_fastlane_beta.sh -/platforms/ -/resources -android-sdk-linux/ -android-sdk_r24.2-linux.tgz -build.json -dev-credentials.json -dropbox -gradle-2.14.1-bin.zip -my-bot/ -node_modules/ -npm-debug.log -plugins/ -QM-Ionic-Build.jsproj -QM-Ionic-Build.sln -QM-Ionic.jsproj -QM-Ionic.jsproj.user -QM-Ionic.sln -resources-shared/screenshots/3.5/ -resources-shared/screenshots/4.0/ -resources-shared/screenshots/4.7/ -resources-shared/screenshots/5.5/ -scripts/certs/apple.cer -scripts/certs/dist.cer -scripts/certs/dist.p12 -supply_json_key_for_google_play.json -src/configuration-index.html -src/configuration/ -#*.css -src/data/*.json -src/img/CS6.zip -src/img/icons/* -!src/img/icons/.gitkeep - -!src/chrome_extension/* -src/js/configuration-app.js -src/lib/ -src/manifest.json - -# Visual Studio Recommended Folder Exclusions -platforms -bld -bin -.vs - -# Visual Studio Recommended File Exclusions -plugins/android.json -plugins/windows.json -plugins/wp8.json -plugins/ios.json -plugins/remote_ios.json -changeList.json -*.suo -*.jsproj.user -Ionic\.jsproj -Ionic\.sln -composer.phar -packages/ -npm-debug.log* -src/scripts/ -src/index.html -src/custom-lib/quantimodo/ -.DS_Store -.io-config.json -src/data/units\.json -ghostinspector\.json -ngrok* -gradlew -gradlew.bat -local.properties -gradle/ -success -www/* -!/www/gitkeep -/src/qm-amazon/ -dist/ -.chcplogin - -cordova-hcp.json -.chcpenv - -src/default.config.json - -src/chcp\.json - -src/chcp\.manifest - -chcpbuild\.options -*.pkey -*.pem -*.p12 - -yarn-error\.log -\.publish -*.private_config.json -GoogleService-Info.plist -google-services.json -!/src/css/study.css -src/data/qmStaticData.js -src/data/apiai/ -/lastCommitBuilt -src/data/commits/ -tmp/ -sh.exe.stackdump -.vscode/launch.json -src/css/app.css -src/css/app.min.css +# Specifies intentionally untracked files to ignore when using Git +# http://git-scm.com/docs/gitignore +!/fastlane/ +!/src/ +!/src/your_quantimodo_client_id_here.private_config.json +*.app.dSYM.zip +*.ipa +*.keystore +*.mobileprovision +.idea/ +!.idea/runConfigurations/* +!.idea/dictionaries/* +!.idea/modules/* +!.idea/inspectionProfiles/* +.vagrant/ +.vs/ +/android-armv7-debug/ +/android-armv7-release/ +/android-x86-release/ +/bin/ +/bld/ +/build/ +/config.xml +/fastlane/* +/hooks/generate_resources_fix_xcode_and_fastlane_beta.sh +/platforms/ +/resources +android-sdk-linux/ +android-sdk_r24.2-linux.tgz +build.json +dev-credentials.json +dropbox +gradle-2.14.1-bin.zip +my-bot/ +node_modules/ +npm-debug.log +plugins/ +QM-Ionic-Build.jsproj +QM-Ionic-Build.sln +QM-Ionic.jsproj +QM-Ionic.jsproj.user +QM-Ionic.sln +resources-shared/screenshots/3.5/ +resources-shared/screenshots/4.0/ +resources-shared/screenshots/4.7/ +resources-shared/screenshots/5.5/ +scripts/certs/apple.cer +scripts/certs/dist.cer +scripts/certs/dist.p12 +supply_json_key_for_google_play.json +src/configuration-index.html +src/configuration/ +#*.css +src/data/*.json +src/img/CS6.zip +src/img/icons/* +!src/img/icons/.gitkeep + +!src/chrome_extension/* +src/js/configuration-app.js +src/lib/ +src/manifest.json + +# Visual Studio Recommended Folder Exclusions +platforms +bld +bin +.vs + +# Visual Studio Recommended File Exclusions +plugins/android.json +plugins/windows.json +plugins/wp8.json +plugins/ios.json +plugins/remote_ios.json +changeList.json +*.suo +*.jsproj.user +Ionic\.jsproj +Ionic\.sln +composer.phar +packages/ +npm-debug.log* +src/scripts/ +src/index.html +src/custom-lib/quantimodo/ +.DS_Store +.io-config.json +src/data/units\.json +ghostinspector\.json +ngrok* +gradlew +gradlew.bat +local.properties +gradle/ +success +www/* +!/www/gitkeep +/src/qm-amazon/ +dist/ +.chcplogin + +cordova-hcp.json +.chcpenv + +src/default.config.json + +src/chcp\.json + +src/chcp\.manifest + +chcpbuild\.options +*.pkey +*.pem +*.p12 + +yarn-error\.log +\.publish +*.private_config.json +GoogleService-Info.plist +google-services.json +!/src/css/study.css +src/data/qmStaticData.js +src/data/apiai/ +/lastCommitBuilt +src/data/commits/ +tmp/ +sh.exe.stackdump +.vscode/launch.json +src/css/app.css +src/css/app.min.css +.env diff --git a/gulpfile.js b/gulpfile.js index 9b92fc50c0..ad056b32d8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,5 @@ /* eslint-disable no-process-env */ +var dotenv = require('dotenv').config({path: './.env'}); var QUANTIMODO_CLIENT_ID = process.env.QUANTIMODO_CLIENT_ID || process.env.CLIENT_ID; var devCredentials; var androidArm7DebugApkName = 'android-armv7-debug'; @@ -203,7 +204,7 @@ var qmLog = { if(process.env.QUANTIMODO_CLIENT_SECRET){message = message.replace(process.env.QUANTIMODO_CLIENT_SECRET, 'HIDDEN');} if(AWS_SECRET_ACCESS_KEY){message = message.replace(AWS_SECRET_ACCESS_KEY, 'HIDDEN');} if(process.env.ENCRYPTION_SECRET){message = message.replace(process.env.ENCRYPTION_SECRET, 'HIDDEN');} - if(process.env.QUANTIMODO_ACCESS_TOKEN){message = message.replace(process.env.QUANTIMODO_ACCESS_TOKEN, 'HIDDEN');} + if(qmGulp.getQMAccessToken()){message = message.replace(qmGulp.getQMAccessToken(), 'HIDDEN');} message = qmLog.obfuscateString(message); return message; }, @@ -758,6 +759,12 @@ var qmGulp = { /** @namespace qm.getAppSettings().appStatus.buildStatus */ qmGulp.getBuildStatus()[convertFilePathToPropertyName(filePath)] = "READY"; return uploadToS3(filePath); + }, + getQMAccessToken: function() { + if(process.env.QUANTIMODO_ACCESS_TOKEN){return process.env.QUANTIMODO_ACCESS_TOKEN;} + qmLog.info("Please add QUANTIMODO_ACCESS_TOKEN to .env file in root of project! "+ + "Your token can be obtained at "+qmGulp.getAppHostName() + "/api/v2/account"); + return null; } }; qmGulp.buildInfoHelper.setVersionNumbers(); @@ -765,7 +772,7 @@ var Quantimodo = require('quantimodo'); /** @namespace Quantimodo.ApiClient */ var defaultClient = Quantimodo.ApiClient.instance; var quantimodo_oauth2 = defaultClient.authentications.quantimodo_oauth2; -quantimodo_oauth2.accessToken = process.env.QUANTIMODO_ACCESS_TOKEN; +quantimodo_oauth2.accessToken = qmGulp.getQMAccessToken(); console.log("process.platform is " + process.platform + " and process.env.OS is " + process.env.OS); qmGit.outputCommitMessageAndBranch(); function setClientId(callback) { @@ -1131,11 +1138,9 @@ function getRequestOptions(path) { headers: {'User-Agent': 'Request-Promise', 'Content-Type': 'application/json'}, json: true // Automatically parses the JSON string in the response }; - if(process.env.QUANTIMODO_ACCESS_TOKEN){ - options.qs.access_token = process.env.QUANTIMODO_ACCESS_TOKEN; + if(qmGulp.getQMAccessToken()){ + options.qs.access_token = qmGulp.getQMAccessToken(); qmLog.info("Using QUANTIMODO_ACCESS_TOKEN: " + options.qs.access_token.substring(0,4)+'...'); - } else { - qmLog.error("Please add your QUANTIMODO_ACCESS_TOKEN environmental variable from " + qmGulp.getAppHostName() + "/api/v2/account"); } return options; } @@ -1197,7 +1202,7 @@ function downloadEncryptedFile(url, outputFileName) { var decryptedFilename = getFileNameFromUrl(url).replace('.enc', ''); var downloadUrl = qmGulp.getAppHostName() + '/api/v2/download?client_id=' + QUANTIMODO_CLIENT_ID + '&filename=' + encodeURIComponent(url); qmLog.info("Downloading " + downloadUrl + ' to ' + decryptedFilename); - return request(downloadUrl + '&accessToken=' + process.env.QUANTIMODO_ACCESS_TOKEN, defaultRequestOptions) + return request(downloadUrl + '&accessToken=' + qmGulp.getQMAccessToken(), defaultRequestOptions) .pipe(fs.createWriteStream(outputFileName)); } function unzipFile(pathToZipFile, pathToOutputFolder) { @@ -4062,4 +4067,4 @@ gulp.task('lint_report_github', function () { .pipe(eslint()) .pipe(github(qmGulp.getGithubOptions())) // Comment issues in github PR! .pipe(github.failThisTask()); // Fail this task when jscs/jshint/eslint issues found. -}); \ No newline at end of file +}); diff --git a/package-lock.json b/package-lock.json index 414ec78b73..77056e2565 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2140,6 +2140,11 @@ "is-obj": "^1.0.0" } }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "duplexer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", diff --git a/package.json b/package.json index 30f1e63024..55a7ac8aa5 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "cordova-plugin-compat": "1.2.0", "cordova-plugin-drawoverapps": "git+https://github.com/mikepsinn/cordova-plugin-drawoverapps.git#37813e845f8309edc339d847b0ea653032b8f748", "cordova-plugin-googleplus": "8.2.1", + "dotenv": "^8.2.0", "es6-promise-plugin": "4.2.2", "event-stream": "4.0.1", "express": "4.17.1", diff --git a/src/js/qmHelpers.js b/src/js/qmHelpers.js index eed3c9c0b6..cbe6165aa9 100644 --- a/src/js/qmHelpers.js +++ b/src/js/qmHelpers.js @@ -2089,7 +2089,7 @@ var qm = { } }, filterConnectorsByName: function(name, connectors){ - let c = connectors.find(function(connector){ + var c = connectors.find(function(connector){ return connector.name === name.toLowerCase(); }); if(!c){ @@ -2102,7 +2102,7 @@ var qm = { getConnectorByName: function(connectorName, successHandler, errorHandler){ if(!successHandler){ var connectors = qm.connectorHelper.getConnectorsFromLocalStorage(); - let c = qm.connectorHelper.filterConnectorsByName(connectorName, connectors); + var c = qm.connectorHelper.filterConnectorsByName(connectorName, connectors); return c; } qm.connectorHelper.getConnectorsFromLocalStorageOrApi(function(connectors){ @@ -2113,7 +2113,7 @@ var qm = { } return; } - let c = qm.connectorHelper.filterConnectorsByName(connectorName, connectors); + var c = qm.connectorHelper.filterConnectorsByName(connectorName, connectors); if(c){ successHandler(c); }else{ @@ -2136,7 +2136,7 @@ var qm = { }); } qm.connectorHelper.getConnectorsFromLocalStorageOrApi(function(connectors){ - let c = connectors.find(function(connector){ + var c = connectors.find(function(connector){ return connector.id === connectorId; }); successHandler(c); From a0788fefe9805bc674fa34bcf21a59bb6c0974b8 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Sun, 2 Feb 2020 12:19:18 -0600 Subject: [PATCH 2/6] catch dotenv errors --- gulpfile.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index ad056b32d8..184483d41d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,9 @@ /* eslint-disable no-process-env */ -var dotenv = require('dotenv').config({path: './.env'}); +try { + var dotenv = require('dotenv').config({path: './.env'}); +} catch (e) { + console.error(e); +} var QUANTIMODO_CLIENT_ID = process.env.QUANTIMODO_CLIENT_ID || process.env.CLIENT_ID; var devCredentials; var androidArm7DebugApkName = 'android-armv7-debug'; From af09e76a3822cc09d8cdd1fc923a5a55c4078028 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Sun, 2 Feb 2020 12:34:49 -0600 Subject: [PATCH 3/6] Sometimes localStorage is null apparently? --- src/js/qmLogger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/qmLogger.js b/src/js/qmLogger.js index ab2fc8b324..c8cca7157c 100644 --- a/src/js/qmLogger.js +++ b/src/js/qmLogger.js @@ -81,7 +81,7 @@ var qmLog = { if(qmLog.logLevel){ return qmLog.logLevel; } - if(typeof localStorage !== "undefined"){ + if(typeof localStorage !== "undefined" && localStorage){ // Sometimes localStorage is null apparently? qmLog.logLevel = localStorage.getItem(qmLog.qm.items.logLevel); // Can't use qmLog.qm.storage because of recursion issue } if(qmLog.logLevel){ From fdeb644c1c424100ce6bee8f533bfbee95c475d0 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Sun, 2 Feb 2020 12:40:50 -0600 Subject: [PATCH 4/6] Make sure stored values are valid --- src/js/qmHelpers.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/js/qmHelpers.js b/src/js/qmHelpers.js index cbe6165aa9..f253daaf17 100644 --- a/src/js/qmHelpers.js +++ b/src/js/qmHelpers.js @@ -3529,7 +3529,7 @@ var qm = { return study; }, setItem: function(key, value){ - if(!qm.storage.valueIsValid(value)){ + if(!qm.storage.valueIsValid(value, key)){ return false; } qm.storage.setGlobal(key, value); @@ -3975,7 +3975,7 @@ var qm = { }) }, setItem: function(key, value, successHandler, errorHandler){ - if(!qm.storage.valueIsValid(value)){ + if(!qm.storage.valueIsValid(value, key)){ return false; } value = JSON.parse(JSON.stringify(value)); // Failed to execute 'put' on 'IDBObjectStore': could not be cloned. @@ -3994,7 +3994,7 @@ var qm = { } return; } - if(!qm.storage.valueIsValid(value)){ + if(!qm.storage.valueIsValid(value, key)){ return false; } if(qm.pouch.enabled){ @@ -7168,13 +7168,13 @@ var qm = { }, }, storage: { - valueIsValid: function(value){ + valueIsValid: function(value, key){ if(typeof value === "undefined"){ - qm.qmLog.error("value provided to qm.storage.setItem is undefined!"); + qm.qmLog.error(key+ " value provided to qm.storage.setItem is undefined!"); return false; } if(value === "null"){ - qm.qmLog.error("null string provided to qm.storage.setItem!"); + qm.qmLog.error("null string provided to qm.storage.setItem for "+key); return false; } return true; @@ -7346,7 +7346,7 @@ var qm = { return qm.storage.getItem(qm.api.getLocalStorageNameForRequest(type, route)); }, setItem: function(key, value){ - if(!qm.storage.valueIsValid(value)){ + if(!qm.storage.valueIsValid(value, key)){ return false; } var globalValue = qm.storage.getGlobal(key); From 8efcd20f373758ed9ab18c05118c2bda6216d19c Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Sun, 2 Feb 2020 12:51:44 -0600 Subject: [PATCH 5/6] secrets/.env --- .gitignore | 4 +++- gulpfile.js | 2 +- .env.example => secrets/.env.example | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) rename .env.example => secrets/.env.example (76%) diff --git a/.gitignore b/.gitignore index 95d7ee4f57..8be47051ba 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,6 @@ sh.exe.stackdump .vscode/launch.json src/css/app.css src/css/app.min.css -.env + +secrets/* +!/secrets/.env.example diff --git a/gulpfile.js b/gulpfile.js index 184483d41d..f62e0a2bc5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,6 @@ /* eslint-disable no-process-env */ try { - var dotenv = require('dotenv').config({path: './.env'}); + var dotenv = require('dotenv').config({path: './secrets/.env'}); } catch (e) { console.error(e); } diff --git a/.env.example b/secrets/.env.example similarity index 76% rename from .env.example rename to secrets/.env.example index 2ac9b2f537..d9ce23857e 100644 --- a/.env.example +++ b/secrets/.env.example @@ -1,4 +1,4 @@ -# Copy me to .env and never commit publicly. .env should be in .gitignore file to prevent this +# Copy me to /secrets/.env and never commit publicly. /secrets folder should be in .gitignore file to prevent this ANALYTICS_PROVIDER= ANALYTICS_TRACKING_ID= APP_DEBUG=true From be99bdd62c61c421d3618e4d63c5c3f566a40563 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Sun, 17 May 2020 20:01:52 -0500 Subject: [PATCH 6/6] addNotificationsToScope --- src/js/controllers/remindersInboxCtrl.js | 137 ++++++++++++--------- src/templates/items/notification-item.html | 18 ++- 2 files changed, 97 insertions(+), 58 deletions(-) diff --git a/src/js/controllers/remindersInboxCtrl.js b/src/js/controllers/remindersInboxCtrl.js index 28ae2dcfd8..ca61f94832 100644 --- a/src/js/controllers/remindersInboxCtrl.js +++ b/src/js/controllers/remindersInboxCtrl.js @@ -1,14 +1,14 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", "$stateParams", "$rootScope", "$filter", - "$ionicPlatform", "$ionicActionSheet", "$timeout", "qmService", "qmLogService", - function($scope, $state, $stateParams, $rootScope, $filter, $ionicPlatform, $ionicActionSheet, $timeout, qmService, - qmLogService){ + "$ionicPlatform", "$ionicActionSheet", "$timeout", "qmService", + function($scope, $state, $stateParams, $rootScope, $filter, $ionicPlatform, $ionicActionSheet, $timeout, qmService){ if(!$rootScope.appSettings){ qmService.rootScope.setProperty('appSettings', window.qm.getAppSettings()); } $scope.controller_name = "RemindersInboxCtrl"; - qmLogService.debug('Loading ' + $scope.controller_name); + qmLog.debug('Loading ' + $scope.controller_name); qmService.navBar.setFilterBarSearchIcon(false); $scope.state = { + maximumNotificationsToDisplay: 20, showMeasurementBox: false, selectedReminder: false, reminderDefaultValue: "", @@ -38,7 +38,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", //createWordCloudFromNotes(); $scope.$on('$ionicView.beforeEnter', function(e){ if (document.title !== $scope.state.title) {document.title = $scope.state.title;} - qmLogService.info('RemindersInboxCtrl beforeEnter: ' + window.location.href); + qmLog.info('RemindersInboxCtrl beforeEnter: ' + window.location.href); $scope.state.loading = true; if(qmService.login.sendToLoginIfNecessaryAndComeBack("beforeEnter in " + $state.current.name)){ return; @@ -51,7 +51,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", // setPageTitle(); // Setting title beforeEnter doesn't fix cutoff on Android }); $scope.$on('$ionicView.enter', function(e){ - qmLogService.info('RemindersInboxCtrl enter: ' + window.location.href); + qmLog.info('RemindersInboxCtrl enter: ' + window.location.href); $scope.defaultHelpCards = qmService.setupHelpCards($rootScope.appSettings); readHelpCards(); getTrackingReminderNotifications(); @@ -63,7 +63,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", }); $scope.stateParams = $stateParams; qmService.actionSheet.setDefaultActionSheet(function(){ - $scope.refreshTrackingReminderNotifications(3); + $scope.refreshTrackingReminderNotifications(); }, getVariableCategoryName(), 'Clear All Notifications', function(){ @@ -80,7 +80,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", qmService.splash.hideSplashScreen(); }); $scope.$on('$ionicView.afterEnter', function(){ - qmLogService.info('RemindersInboxCtrl afterEnter: ' + window.location.href); + qmLog.info('RemindersInboxCtrl afterEnter: ' + window.location.href); setPageTitle(); // Setting title afterEnter doesn't fix cutoff on Android if(needToRefresh()){ $scope.refreshTrackingReminderNotifications(); @@ -123,7 +123,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", }, 30 * 60 * 1000); } $scope.$on('$ionicView.afterLeave', function(){ - qmLogService.debug('RemindersInboxCtrl afterLeave', null); + qmLog.debug('RemindersInboxCtrl afterLeave', null); $rootScope.hideHomeButton = false; $rootScope.hideBackButton = false; }); @@ -153,14 +153,14 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", return false; } if($event && $scope.state.lastButtonPressTimeStamp > $event.timeStamp - 3000 && $scope.state.lastClientX === $event.clientX && $scope.state.lastClientY === $event.clientY){ - qmLogService.debug('This event is probably a ghost click so not registering.', null, $event); + qmLog.debug('This event is probably a ghost click so not registering.', null, $event); return true; }else{ if(!$event){ - qmLogService.error('No event provided to isGhostClick!'); + qmLog.error('No event provided to isGhostClick!'); return false; } - qmLogService.debug('This Track event is not a ghost click so registering.', null, $event); + qmLog.debug('This Track event is not a ghost click so registering.', null, $event); $scope.state.lastButtonPressTimeStamp = $event.timeStamp; $scope.state.lastClientX = $event.clientX; $scope.state.lastClientY = $event.clientY; @@ -190,20 +190,6 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", qm.notifications.trackNotification(trackingReminderNotification); refreshIfRunningOutOfNotifications(); }; - function getWeekdayCharts(){ - if(false && !$scope.weekdayChartConfig){ - qmService.syncPrimaryOutcomeVariableMeasurements(60 * 60); - qmService.getWeekdayChartConfigForPrimaryOutcome($scope.state.primaryOutcomeMeasurements, qm.getPrimaryOutcomeVariable()) - .then(function(chartConfig){ - $scope.weekdayChartConfig = chartConfig; - }); - } - if(!$scope.state.variableObject || !$scope.state.variableObject.charts){ - qmService.getVariableWithCharts(qm.getPrimaryOutcomeVariable().name, false, function(variableObject){ - $scope.state.variableObject = variableObject; - }); - } - } function getFavorites(){ if(!$scope.state.favoritesArray){ qmService.storage.getFavorites(getVariableCategoryName()) @@ -215,17 +201,17 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", var getFallbackInboxContentIfNecessary = function(){ if(!$scope.state.numberOfDisplayedNotifications){ if(getVariableCategoryName()){ - qmLogService.info('Falling back to getTrackingReminderNotificationsFromApi request for category ' + getVariableCategoryName()); - qmService.refreshTrackingReminderNotifications(3, { + qmLog.info('Falling back to getTrackingReminderNotificationsFromApi request for category ' + getVariableCategoryName()); + qmService.refreshTrackingReminderNotifications({ variableCategoryName: getVariableCategoryName(), onlyPast: true }, function(response){ - qmLogService.info('getTrackingReminderNotificationsFromApi response for ' + getVariableCategoryName() + ': ' + JSON.stringify(response)); - $scope.filteredTrackingReminderNotifications = qmService.groupTrackingReminderNotificationsByDateRange(response.data); + qmLog.info('getTrackingReminderNotificationsFromApi response for ' + getVariableCategoryName() + + ': ' + JSON.stringify(response)); + addNotificationsToScope(response.data) }); } getFavorites(); - getWeekdayCharts(); getDiscoveries(); } }; @@ -274,7 +260,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", qm.notifications.trackNotification(body, trackAll); refreshIfRunningOutOfNotifications(); }; - function trackAll(trackingReminderNotification, modifiedReminderValue, ev){ + $scope.trackAll = function(trackingReminderNotification, modifiedReminderValue, ev){ trackingReminderNotification.modifiedValue = modifiedReminderValue; var lastAction = 'Recorded ' + modifiedReminderValue + ' ' + trackingReminderNotification.unitAbbreviatedName; qm.notifications.lastAction = qm.stringHelper.formatValueUnitDisplayText(lastAction) + ' for all '+trackingReminderNotification.variableName; @@ -288,7 +274,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", var textContent = "Do you want to record " + qm.stringHelper.formatValueUnitDisplayText(modifiedReminderValue + " " + trackingReminderNotification.unitAbbreviatedName) + " for all remaining past " + trackingReminderNotification.variableName + " reminder notifications?"; function yesCallback(ev){ - trackAll(trackingReminderNotification, modifiedReminderValue, ev); + $scope.trackAll(trackingReminderNotification, modifiedReminderValue, ev); } function noCallback(){ } @@ -326,19 +312,32 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", $scope.words = response; }); } - var getFilteredTrackingReminderNotificationsFromLocalStorage = function(){ - var trackingReminderNotifications = qm.storage.getTrackingReminderNotifications(getVariableCategoryName(), 20); - for(var i = 0; i < trackingReminderNotifications.length; i++){ - trackingReminderNotifications[i].showZeroButton = shouldWeShowZeroButton(trackingReminderNotifications[i]); + function logNotificationDividers(dividers) { + if(!dividers){ + qmLog.info("No notification dividers!") + return; + } + qmLog.debug('Just added ' + dividers.length +' notification dividers to $scope.notificationDividers. \n' + + 'state.numberOfDisplayedNotifications is '+$scope.state.numberOfDisplayedNotifications); + if(typeof dividers.forEach !== "function"){ + qmLog.error("typeof dividers.forEach !== \"function\"") + return; } - qmLogService.debug('Just got ' + trackingReminderNotifications.length + ' trackingReminderNotifications from local storage'); - $scope.state.numberOfDisplayedNotifications = trackingReminderNotifications.length; - //if($scope.state.numberOfDisplayedNotifications){hideInboxLoader();} // TODO: Why was did we only do this if we had notifications? It loads forever if category inbox has no notifications + dividers.forEach(function (divider) { + qmLog.debug('Notification Divider '+divider.name); + divider.trackingReminderNotifications.forEach(function (notification) { + qmLog.debug("notification title: " + notification.title); + }) + }) + } + var getFilteredTrackingReminderNotificationsFromLocalStorage = function(){ + var notifications = qm.storage.getTrackingReminderNotifications(getVariableCategoryName(), + $scope.state.maximumNotificationsToDisplay); + qmLog.debug('Just got ' + notifications.length + ' trackingReminderNotifications from local storage'); if($state.current.name === "app.remindersInboxCompact"){ - $scope.trackingReminderNotifications = trackingReminderNotifications; + $scope.trackingReminderNotifications = notifications; }else{ - $scope.filteredTrackingReminderNotifications = qmService.groupTrackingReminderNotificationsByDateRange(trackingReminderNotifications); - qmLogService.debug('Just added ' + trackingReminderNotifications.length + ' to $scope.filteredTrackingReminderNotifications'); + addNotificationsToScope(notifications) } hideInboxLoader(); }; @@ -348,28 +347,51 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", $scope.state.loading = false; qmService.hideLoader(); }; + function addNotificationsToScope(trackingReminderNotifications) { + for(var i = 0; i < trackingReminderNotifications.length; i++){ + var n = trackingReminderNotifications[i] + n.showZeroButton = shouldWeShowZeroButton(trackingReminderNotifications[i]); + n.trackAllActions.forEach(function (a) { + if(a.callback === "skipAction"){ + a.valueUnit = "Skip" + a.longTitle = "Skip all remaining un-tracked past notifications" + a.titleHtml = "

Skip All

" + } else{ + a.valueUnit = a.title.replace(" for all", ""); + a.longTitle = "Record "+a.valueUnit + " for all remaining un-tracked past notifications" + a.titleHtml = "

"+a.valueUnit+"

"+"

for all

" + } + }) + } + var dividers = qmService.groupTrackingReminderNotificationsByDateRange(trackingReminderNotifications) + $scope.safeApply(function () { // For som reason these are not visible to Ghost Inspector sometimes + $scope.notificationDividers = dividers; + $scope.state.numberOfDisplayedNotifications = trackingReminderNotifications.length; + $scope.state.showTrackAllButtons = trackingReminderNotifications.length >= $scope.state.maximumNotificationsToDisplay; + logNotificationDividers($scope.notificationDividers); + }) + } var getFilteredTodayTrackingReminderNotifications = function(){ qmService.getTodayTrackingReminderNotificationsDeferred(getVariableCategoryName()) .then(function(trackingReminderNotifications){ - $scope.state.numberOfDisplayedNotifications = trackingReminderNotifications.length; - $scope.filteredTrackingReminderNotifications = qmService.groupTrackingReminderNotificationsByDateRange(trackingReminderNotifications); + addNotificationsToScope(trackingReminderNotifications) getFallbackInboxContentIfNecessary(); hideInboxLoader(); }, function(error){ getFallbackInboxContentIfNecessary(); - qmLogService.error(error); - qmLogService.error('failed to get reminder notifications!'); + qmLog.error(error); + qmLog.error('failed to get reminder notifications!'); hideInboxLoader(); }); }; $rootScope.$on('broadcastGetTrackingReminderNotifications', function(){ - qmLogService.info('getTrackingReminderNotifications broadcast received..'); + qmLog.info('getTrackingReminderNotifications broadcast received..'); if(!$stateParams.today){ getFilteredTrackingReminderNotificationsFromLocalStorage(); } }); var getTrackingReminderNotifications = function(){ - qmLogService.info('RemindersInboxCtrl called getTrackingReminderNotifications: ' + window.location.href); + qmLog.info('RemindersInboxCtrl called getTrackingReminderNotifications: ' + window.location.href); if($stateParams.today){ getFilteredTodayTrackingReminderNotifications(); }else{ @@ -377,7 +399,8 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", } }; function shouldWeShowZeroButton(trackingReminderNotification){ - return trackingReminderNotification.inputType === 'defaultValue' || (trackingReminderNotification.inputType === 'value' && trackingReminderNotification.defaultValue !== null); + return trackingReminderNotification.inputType === 'defaultValue' || + (trackingReminderNotification.inputType === 'value' && trackingReminderNotification.defaultValue !== null); } var showLoader = function(){ $scope.state.loading = true; @@ -387,9 +410,9 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", } }, 10000); }; - $scope.refreshTrackingReminderNotifications = function(minimumSecondsBetweenRequests){ + $scope.refreshTrackingReminderNotifications = function(params){ showLoader(); - qmService.refreshTrackingReminderNotifications(minimumSecondsBetweenRequests).then(function(){ + qmService.refreshTrackingReminderNotifications(params).then(function(){ getTrackingReminderNotifications(); if(!qm.notifications.getNumberInGlobalsOrLocalStorage(getVariableCategoryName())){ getFallbackInboxContentIfNecessary(); @@ -404,7 +427,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", }; $scope.editMeasurement = function(trackingReminderNotification){ enlargeChromePopupIfNecessary(); - //$scope.filteredTrackingReminderNotifications[dividerIndex].trackingReminderNotifications[trackingReminderNotificationIndex].hide = true; + //$scope.notificationDividers[dividerIndex].trackingReminderNotifications[trackingReminderNotificationIndex].hide = true; trackingReminderNotification.hide = true; qm.notifications.numberOfPendingNotifications--; $scope.state.numberOfDisplayedNotifications--; @@ -416,7 +439,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", }; $scope.editReminderSettingsByNotification = function(trackingReminderNotification){ enlargeChromePopupIfNecessary(); - //$scope.filteredTrackingReminderNotifications[dividerIndex].trackingReminderNotifications[trackingReminderNotificationIndex].hide = true; + //$scope.notificationDividers[dividerIndex].trackingReminderNotifications[trackingReminderNotificationIndex].hide = true; trackingReminderNotification.hide = true; qm.notifications.numberOfPendingNotifications--; $scope.state.numberOfDisplayedNotifications--; @@ -476,16 +499,16 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", destructiveText: 'Skip All ', cancelText: 'Cancel', cancel: function(){ - qmLogService.debug('CANCELLED', null); + qmLog.debug('CANCELLED', null); }, buttonClicked: function(index, button){ - qmLogService.debug('BUTTON CLICKED', null, index); + qmLog.debug('BUTTON CLICKED', null, index); if(index === 0){ qmLog.debug('clicked variable name'); return false; // Don't hide } if(typeof button.trackAllIndex !== "undefined"){ - trackAll(trackingReminderNotification, trackingReminderNotification.trackAllActions[button.trackAllIndex].modifiedValue); + $scope.trackAll(trackingReminderNotification, trackingReminderNotification.trackAllActions[button.trackAllIndex].modifiedValue); return true; // Hide sheet } if(button.state){ diff --git a/src/templates/items/notification-item.html b/src/templates/items/notification-item.html index a8f628cfba..0e3858dd6a 100644 --- a/src/templates/items/notification-item.html +++ b/src/templates/items/notification-item.html @@ -198,4 +198,20 @@

- +
+

Record same value for all remaining past notifications

+ + +   + + + +

FOR ALL REMAINING

+