diff --git a/www/i18n/en.json b/www/i18n/en.json index 236092a74e..d765f5fa71 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -370,16 +370,16 @@ "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_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_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", "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 2895863280..7902d6fdc5 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,14 +36,10 @@ 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; + vm.isReadonlyExcludeUntil = false; let isUpdated = false; vm.data = {}; const account = accountService.getDefault(); @@ -51,10 +49,13 @@ $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}T00:00:00`); + vm.isReadonlyExcludeUntil = true; } + 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; @@ -112,11 +113,11 @@ 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) { - 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 @@ -126,6 +127,61 @@ isUpdated = true; } + // yyyy-mm-dd + const filterDate = (date) => $filter('date')(date, 'yyyy-MM-dd'); + + const filterTime = (date) => $filter('date')(date, 'HH:mm'); + + 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 dateAfterWeeks = date.setDate(date.getDate() + weeks * 7); + return { + limit: `${filterDate(dateAfterWeeks)}T${exactTime}`, + text : `${filterDate(dateAfterWeeks)} 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 dateAfterYears = new Date(date.setDate(date.getDate() + years * 365)).getTime(); + return filterDate(dateAfterYears); + } + + const getCurrentDateTime = (startingDate) => { + const date = _.clone(startingDate); + const now = new Date(date).getTime(); + return filterDateTime(now); + } + + const calculateDateLimits = (startingDate = new Date()) => { + vm.minTimeoutUntil = getCurrentDateTime(startingDate); + // calculating the min date for 'timeout until' + // (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) + 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) => { vm.hasError = false; vm.accountLimits = limits; @@ -140,8 +196,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..9be227d825 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,17 @@

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" + ng-readonly="vm.isReadonlyExcludeUntil" + />
{{ '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} }} @@ -466,7 +471,8 @@

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: } }