From a3d77131c2a723d27712bf54b66a925d829e6b74 Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Mon, 12 Aug 2019 15:27:58 -0400 Subject: [PATCH 1/6] Fix self exclusion time and date fields --- .../self-exclusion.controller.js | 46 ++++++++++++++++--- .../self-exclusion.template.html | 6 +-- www/js/share/services/websocket.service.js | 14 ++++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/www/js/pages/self-exclusion/self-exclusion.controller.js b/www/js/pages/self-exclusion/self-exclusion.controller.js index 2895863280..9f0d36527f 100644 --- a/www/js/pages/self-exclusion/self-exclusion.controller.js +++ b/www/js/pages/self-exclusion/self-exclusion.controller.js @@ -12,6 +12,7 @@ SelfExclusion.$inject = [ "$scope", "$state", + "$filter", "$translate", "$ionicScrollDelegate", "alertService", @@ -23,6 +24,7 @@ function SelfExclusion( $scope, $state, + $filter, $translate, $ionicScrollDelegate, alertService, @@ -34,11 +36,6 @@ vm.hasError = false; vm.validation = validationService; vm.fractionalDigits = vm.validation.fractionalDigits; - const today = new Date(); - vm.minDate = today.toISOString().slice(0, 10); - vm.minDateTime = today.toISOString(); - vm.nextSixWeeks = new Date(today.getTime() + 7 * 6 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); - vm.nextSixMonths = new Date(today.getTime() + 30 * 6 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); vm.disableUpdateButton = true; vm.isDataLoaded = false; vm.disableForZeroValues = false; @@ -126,6 +123,31 @@ isUpdated = true; } + // yyyy-mm-dd + const filterDate = (date) => { + const year = $filter('date')(date, 'yyyy', 'UTC'); + const month = $filter('date')(date, 'MM', 'UTC'); + const day = $filter('date')(date, 'dd', 'UTC'); + return `${year}-${month}-${day}`; + } + + const calculateDateLimits = (startingDate = new Date()) => { + vm.minDateTime = startingDate.toISOString(); + startingDate.setDate(startingDate.getDate() + 1); + // calculating the min date for 'timeout until' + // (6 weeks after tomorrow in format yyyy-mm-dd in UTC) + const tomorrow = _.clone(startingDate); + vm.minDate = `${tomorrow.toISOString().slice(0, 10)}T00:00:00`; + const dateAfterSixWeeks = tomorrow.setDate(tomorrow.getDate() + 41); + vm.nextSixWeeks = filterDate(dateAfterSixWeeks); + vm.nextSixWeeksDateTime = `${vm.nextSixWeeks}T23:59:59` + + // calculating the min date for 'exclude until' + // (6 month after tomorrow in format yyyy-mm-dd in UTC) + const dateAfterSixMonths = new Date(startingDate.setMonth(startingDate.getMonth() + 6)).getTime(); + vm.nextSixMonths = filterDate(dateAfterSixMonths); + }; + $scope.$on('get_limits', (e, limits) => { vm.hasError = false; vm.accountLimits = limits; @@ -140,8 +162,20 @@ $state.go('contact'); }; - const init = () => getLimits(); + $scope.$on('time:success', (e, time) => { + const startingDate = new Date(time * 1000); + calculateDateLimits(startingDate); + }); + + $scope.$on('time:error', () => { + calculateDateLimits(); + }); + const init = () => { + websocketService.sendRequestFor.serverTime(); + getLimits(); + }; + init(); } diff --git a/www/js/pages/self-exclusion/self-exclusion.template.html b/www/js/pages/self-exclusion/self-exclusion.template.html index 04a53d55be..1b46da4844 100644 --- a/www/js/pages/self-exclusion/self-exclusion.template.html +++ b/www/js/pages/self-exclusion/self-exclusion.template.html @@ -411,10 +411,10 @@

+ ng-max="vm.nextSixWeeksDateTime"/>
{{ 'self-exclusion.time_out_hint' | translate }}
diff --git a/www/js/share/services/websocket.service.js b/www/js/share/services/websocket.service.js index b423606574..e9c22b6586 100644 --- a/www/js/share/services/websocket.service.js +++ b/www/js/share/services/websocket.service.js @@ -566,6 +566,13 @@ angular set_account_currency: currency }; + sendMessage(data); + }, + serverTime() { + const data = { + time: 1, + }; + sendMessage(data); } }; @@ -911,6 +918,13 @@ angular $rootScope.$broadcast("set_account_currency:error", message.error); } break; + case "time": + if (message.time) { + $rootScope.$broadcast("time:success", message.time); + } else if (message.error) { + $rootScope.$broadcast("time:error", message.error); + } + break; default: } } From 15f72b185e8bd067519c5f0136869e711e0b4f0a Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Tue, 13 Aug 2019 10:01:31 -0400 Subject: [PATCH 2/6] refactor --- www/i18n/en.json | 4 +- .../self-exclusion.controller.js | 77 ++++++++++++++----- .../self-exclusion.template.html | 18 +++-- 3 files changed, 72 insertions(+), 27 deletions(-) diff --git a/www/i18n/en.json b/www/i18n/en.json index 236092a74e..e28a06527a 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -378,8 +378,8 @@ "enter_valid_value": "Please enter a value with up to {{fractionalDigits}} decimal places and max length of {{max}}", "valid_range_hint": "Please enter a number between 0 and {{max}}", "date_is_not_valid": "Exclude time must be after today", - "date_can_not_be_greater_than": "Exclude time cannot be greater than {{max}}", - "date_can_not_less_than": "Exclude time cannot be less than {{max}}", + "date_can_not_be_greater_than": "Exclude time cannot be after {{max}}", + "date_can_not_less_than": "Exclude time cannot be before {{min}} and after {{max}}", "save_prompt": "Content saved successfully", "session_timeout_warning":"Your session duration limit will end in 10 seconds.", "success": "Success", diff --git a/www/js/pages/self-exclusion/self-exclusion.controller.js b/www/js/pages/self-exclusion/self-exclusion.controller.js index 9f0d36527f..50f94dfe92 100644 --- a/www/js/pages/self-exclusion/self-exclusion.controller.js +++ b/www/js/pages/self-exclusion/self-exclusion.controller.js @@ -48,10 +48,12 @@ $scope.$on("get-self-exclusion", (e, response) => { $scope.$applyAsync(() => { - vm.data = _.clone(response); - if (vm.data.exclude_until) { - vm.data.exclude_until = new Date(vm.data.exclude_until); + const data = _.clone(response); + if (data.exclude_until) { + data.exclude_until = new Date(data.exclude_until); } + if (data.timeout_until) data.timeout_until = new Date(data.timeout_until * 1000); + vm.data = data; vm.limits = _.clone(response); vm.disableUpdateButton = false; vm.isDataLoaded = true; @@ -109,7 +111,7 @@ const data = _.clone(vm.data); if (data.timeout_until) { - data.timeout_until = new Date(data.timeout_until).getTime() / 1000; + data.timeout_until = Math.floor(new Date(data.timeout_until).getTime() / 1000); } if (data.exclude_until) { @@ -125,27 +127,66 @@ // yyyy-mm-dd const filterDate = (date) => { - const year = $filter('date')(date, 'yyyy', 'UTC'); - const month = $filter('date')(date, 'MM', 'UTC'); - const day = $filter('date')(date, 'dd', 'UTC'); + const year = $filter('date')(date, 'yyyy'); + const month = $filter('date')(date, 'MM'); + const day = $filter('date')(date, 'dd'); return `${year}-${month}-${day}`; } + const filterTime = (date) => { + const hour = $filter('date')(date, 'HH'); + const minute = $filter('date')(date, 'mm'); + return `${hour}:${minute}`; + } + + const filterDateTime = (date) => { + const filteredDate = filterDate(date); + const filteredTime = filterTime(date); + return `${filteredDate}T${filteredTime}`; + } + + const addWeeks = (startingDate, weeks) => { + const date = _.clone(startingDate); + const exactTime = filterTime(date); + const dateAfterSixWeeks = date.setDate(date.getDate() + weeks * 7); + return { + limit: `${filterDate(dateAfterSixWeeks)}T${exactTime}`, + text : `${filterDate(dateAfterSixWeeks)} at ${exactTime}` + }; + } + + const addMonth = (startingDate, month) => { + const date = _.clone(startingDate); + date.setDate(date.getDate() + 1); + const dateAfterMonths = new Date(date.setMonth(date.getMonth() + month)).getTime(); + return filterDate(dateAfterMonths); + } + + const addYears = (startingDate, years) => { + const date = _.clone(startingDate); + const dateAfterFiveMonth = new Date(date.setDate(date.getDate() + years * 365)).getTime(); + return filterDate(dateAfterFiveMonth); + } + + const getCurrentDateTime = (startingDate) => { + const date = _.clone(startingDate); + const now = new Date(date).getTime(); + return filterDateTime(now); + } + const calculateDateLimits = (startingDate = new Date()) => { - vm.minDateTime = startingDate.toISOString(); - startingDate.setDate(startingDate.getDate() + 1); + vm.minTimeoutUntil = getCurrentDateTime(startingDate); // calculating the min date for 'timeout until' - // (6 weeks after tomorrow in format yyyy-mm-dd in UTC) - const tomorrow = _.clone(startingDate); - vm.minDate = `${tomorrow.toISOString().slice(0, 10)}T00:00:00`; - const dateAfterSixWeeks = tomorrow.setDate(tomorrow.getDate() + 41); - vm.nextSixWeeks = filterDate(dateAfterSixWeeks); - vm.nextSixWeeksDateTime = `${vm.nextSixWeeks}T23:59:59` + // (6 weeks after tomorrow in format yyyy-mm-dd) + vm.maxTimeoutUntil = addWeeks(startingDate, 6); // calculating the min date for 'exclude until' - // (6 month after tomorrow in format yyyy-mm-dd in UTC) - const dateAfterSixMonths = new Date(startingDate.setMonth(startingDate.getMonth() + 6)).getTime(); - vm.nextSixMonths = filterDate(dateAfterSixMonths); + // (6 month after tomorrow in format yyyy-mm-dd) + vm.minExcludeUntil = addMonth(startingDate, 6); + // calculating the max date for 'exclude until' + // we add 5 * 365 = 1825 days instead of years to be exactly like API + // otherwise it will have more days considering leap years + vm.maxExcludeUntil = addYears(startingDate, 5); }; $scope.$on('get_limits', (e, limits) => { diff --git a/www/js/pages/self-exclusion/self-exclusion.template.html b/www/js/pages/self-exclusion/self-exclusion.template.html index 1b46da4844..3805afb421 100644 --- a/www/js/pages/self-exclusion/self-exclusion.template.html +++ b/www/js/pages/self-exclusion/self-exclusion.template.html @@ -411,10 +411,10 @@

+ min="{{ vm.minTimeoutUntil }}" + max="{{ vm.maxTimeoutUntil['limit'] }}" + ng-min="vm.minTimeoutUntil" + ng-max="vm.maxTimeoutUntil['limit']"/>
{{ 'self-exclusion.time_out_hint' | translate }}
@@ -422,7 +422,7 @@

{{ 'self-exclusion.date_is_not_valid' | translate }} - {{ 'self-exclusion.date_can_not_be_greater_than' | translate:{max: vm.nextSixWeeks} }} + {{ 'self-exclusion.date_can_not_be_greater_than' | translate:{max: vm.maxTimeoutUntil['text']} }} @@ -444,12 +444,16 @@

type="date" ng-model="vm.data.exclude_until" maxlength="10" - min="{{ vm.nextSixMonths }}"/> + min="{{ vm.minExcludeUntil }}" + max="{{ vm.maxExcludeUntil }}" + ng-min="vm.minExcludeUntil" + ng-max="vm.maxExcludeUntil" + />
{{ 'self-exclusion.exclude_me_hint' | translate }}
- {{ 'self-exclusion.date_can_not_less_than' | translate : {max: vm.nextSixMonths} }} + {{ 'self-exclusion.date_can_not_less_than' | translate : {min: vm.minExcludeUntil, max: vm.maxExcludeUntil} }} From 0c7907b5ab5975e07cf8252148cbebd9365f175e Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Wed, 14 Aug 2019 13:39:46 -0400 Subject: [PATCH 3/6] fixes to self exclusion --- www/i18n/en.json | 6 ++--- .../self-exclusion.controller.js | 23 ++++++++----------- .../self-exclusion.template.html | 4 +++- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/www/i18n/en.json b/www/i18n/en.json index e28a06527a..d765f5fa71 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -370,14 +370,14 @@ "session_duration_limit_in_minutes": "Session duration limit, in minutes", "session_duration_hint": "You will be automatically logged out after such time.", "time_out_until": "Time out until", - "time_out_hint": "Please enter date in the format MM/DD/YYYY HH:mm (local time). ", + "time_out_hint": "Please enter date in the format DD/MM/YYYY HH:mm (local time). ", "exclude_me_from_the_website_until": "Exclude me from the website until", - "exclude_me_hint": "Please enter date in the format MM/DD/YYYY.", + "exclude_me_hint": "Please enter date in the format DD/MM/YYYY.", "update_settings": "Update Settings", "please_enter_an_integer_value": "Please enter an integer value with max length of {{max}}", "enter_valid_value": "Please enter a value with up to {{fractionalDigits}} decimal places and max length of {{max}}", "valid_range_hint": "Please enter a number between 0 and {{max}}", - "date_is_not_valid": "Exclude time must be after today", + "date_is_not_valid": "Time out cannot be in the past.", "date_can_not_be_greater_than": "Exclude time cannot be after {{max}}", "date_can_not_less_than": "Exclude time cannot be before {{min}} and after {{max}}", "save_prompt": "Content saved successfully", diff --git a/www/js/pages/self-exclusion/self-exclusion.controller.js b/www/js/pages/self-exclusion/self-exclusion.controller.js index 50f94dfe92..6066f74873 100644 --- a/www/js/pages/self-exclusion/self-exclusion.controller.js +++ b/www/js/pages/self-exclusion/self-exclusion.controller.js @@ -39,6 +39,7 @@ vm.disableUpdateButton = true; vm.isDataLoaded = false; vm.disableForZeroValues = false; + vm.isReadonlyExcludeUntil = false; let isUpdated = false; vm.data = {}; const account = accountService.getDefault(); @@ -50,7 +51,8 @@ $scope.$applyAsync(() => { const data = _.clone(response); if (data.exclude_until) { - data.exclude_until = new Date(data.exclude_until); + data.exclude_until = new Date(`${data.exclude_until}T00:00:00`); + vm.isReadonlyExcludeUntil = true; } if (data.timeout_until) data.timeout_until = new Date(data.timeout_until * 1000); vm.data = data; @@ -127,16 +129,11 @@ // yyyy-mm-dd const filterDate = (date) => { - const year = $filter('date')(date, 'yyyy'); - const month = $filter('date')(date, 'MM'); - const day = $filter('date')(date, 'dd'); - return `${year}-${month}-${day}`; + return $filter('date')(date, 'yyyy-MM-dd'); } const filterTime = (date) => { - const hour = $filter('date')(date, 'HH'); - const minute = $filter('date')(date, 'mm'); - return `${hour}:${minute}`; + return $filter('date')(date, 'HH:mm'); } const filterDateTime = (date) => { @@ -148,10 +145,10 @@ const addWeeks = (startingDate, weeks) => { const date = _.clone(startingDate); const exactTime = filterTime(date); - const dateAfterSixWeeks = date.setDate(date.getDate() + weeks * 7); + const dateAfterWeeks = date.setDate(date.getDate() + weeks * 7); return { - limit: `${filterDate(dateAfterSixWeeks)}T${exactTime}`, - text : `${filterDate(dateAfterSixWeeks)} at ${exactTime}` + limit: `${filterDate(dateAfterWeeks)}T${exactTime}`, + text : `${filterDate(dateAfterWeeks)} at ${exactTime}` }; } @@ -164,8 +161,8 @@ const addYears = (startingDate, years) => { const date = _.clone(startingDate); - const dateAfterFiveMonth = new Date(date.setDate(date.getDate() + years * 365)).getTime(); - return filterDate(dateAfterFiveMonth); + const dateAfterYears = new Date(date.setDate(date.getDate() + years * 365)).getTime(); + return filterDate(dateAfterYears); } const getCurrentDateTime = (startingDate) => { diff --git a/www/js/pages/self-exclusion/self-exclusion.template.html b/www/js/pages/self-exclusion/self-exclusion.template.html index 3805afb421..8e6a93958a 100644 --- a/www/js/pages/self-exclusion/self-exclusion.template.html +++ b/www/js/pages/self-exclusion/self-exclusion.template.html @@ -448,6 +448,7 @@

max="{{ vm.maxExcludeUntil }}" ng-min="vm.minExcludeUntil" ng-max="vm.maxExcludeUntil" + ng-readonly="vm.isReadonlyExcludeUntil" />
{{ 'self-exclusion.exclude_me_hint' | translate }}
@@ -470,7 +471,8 @@

From 4c074836a4741bba8efb904da15a7b24cb262b2a Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Thu, 15 Aug 2019 09:17:15 -0400 Subject: [PATCH 4/6] fix eslint --- www/js/pages/self-exclusion/self-exclusion.controller.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/www/js/pages/self-exclusion/self-exclusion.controller.js b/www/js/pages/self-exclusion/self-exclusion.controller.js index 6066f74873..4f3ad4f888 100644 --- a/www/js/pages/self-exclusion/self-exclusion.controller.js +++ b/www/js/pages/self-exclusion/self-exclusion.controller.js @@ -128,13 +128,9 @@ } // yyyy-mm-dd - const filterDate = (date) => { - return $filter('date')(date, 'yyyy-MM-dd'); - } + const filterDate = (date) => $filter('date')(date, 'yyyy-MM-dd'); - const filterTime = (date) => { - return $filter('date')(date, 'HH:mm'); - } + const filterTime = (date) => $filter('date')(date, 'HH:mm'); const filterDateTime = (date) => { const filteredDate = filterDate(date); From c2677111587fa0463933815a1620e9e99babca3f Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Fri, 16 Aug 2019 10:28:36 -0400 Subject: [PATCH 5/6] not validate exclude until when user has set it already --- www/js/pages/self-exclusion/self-exclusion.template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/js/pages/self-exclusion/self-exclusion.template.html b/www/js/pages/self-exclusion/self-exclusion.template.html index 8e6a93958a..9be227d825 100644 --- a/www/js/pages/self-exclusion/self-exclusion.template.html +++ b/www/js/pages/self-exclusion/self-exclusion.template.html @@ -452,7 +452,7 @@

/>
{{ 'self-exclusion.exclude_me_hint' | translate }}
- + {{ 'self-exclusion.date_can_not_less_than' | translate : {min: vm.minExcludeUntil, max: vm.maxExcludeUntil} }} From 0c5f4a806ef74ad187110f31fb0a7b23bf8d9736 Mon Sep 17 00:00:00 2001 From: nazaninreihani Date: Fri, 16 Aug 2019 10:48:38 -0400 Subject: [PATCH 6/6] fix exclude until error and make it show the correct time user selected --- www/js/pages/self-exclusion/self-exclusion.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/js/pages/self-exclusion/self-exclusion.controller.js b/www/js/pages/self-exclusion/self-exclusion.controller.js index 4f3ad4f888..7902d6fdc5 100644 --- a/www/js/pages/self-exclusion/self-exclusion.controller.js +++ b/www/js/pages/self-exclusion/self-exclusion.controller.js @@ -117,7 +117,7 @@ } if (data.exclude_until) { - data.exclude_until = data.exclude_until.toISOString().slice(0, 10); + data.exclude_until = filterDate(new Date(data.exclude_until).getTime()); } // Convert all numbers to string for supporting number with more than 15 digits