Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
90 changes: 79 additions & 11 deletions www/js/pages/self-exclusion/self-exclusion.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
SelfExclusion.$inject = [
"$scope",
"$state",
"$filter",
"$translate",
"$ionicScrollDelegate",
"alertService",
Expand All @@ -23,6 +24,7 @@
function SelfExclusion(
$scope,
$state,
$filter,
$translate,
$ionicScrollDelegate,
alertService,
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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();

}
Expand Down
24 changes: 15 additions & 9 deletions www/js/pages/self-exclusion/self-exclusion.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,18 @@ <h1 class="page-title">
<input name="time_out_until"
type="datetime-local"
ng-model="vm.data.timeout_until"
min="{{ vm.minDate }}T00:00:00"
max="{{ vm.nextSixWeeks }}T00:00:00"
ng-min="vm.minDateTime"
ng-max="vm.nextSixWeeks + 'T00:00:00'"/>
min="{{ vm.minTimeoutUntil }}"
max="{{ vm.maxTimeoutUntil['limit'] }}"
ng-min="vm.minTimeoutUntil"
ng-max="vm.maxTimeoutUntil['limit']"/>
</label>
<div class="hint"> {{ 'self-exclusion.time_out_hint' | translate }}</div>
<ng-messages for="self_exclusion_form.time_out_until.$error" role="alert" class="error">
<ng-message when="min">
{{ 'self-exclusion.date_is_not_valid' | translate }}
</ng-message>
<ng-message when="max">
{{ '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']} }}
</ng-message>
</ng-messages>
</div>
Expand All @@ -444,12 +444,17 @@ <h1 class="page-title">
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"
/>
</label>
<div class="hint"> {{ 'self-exclusion.exclude_me_hint' | translate }}</div>
<ng-messages for="self_exclusion_form.exclude_me_until.$error" role="alert" class="error">
<ng-messages for="self_exclusion_form.exclude_me_until.$error" role="alert" class="error" ng-if="!vm.isReadonlyExcludeUntil">
<ng-message when="min, max">
{{ '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} }}
</ng-message>
</ng-messages>
</div>
Expand All @@ -466,7 +471,8 @@ <h1 class="page-title">
<div class="col center">
<button class="button button-positive"
type="submit"
ng-disabled="self_exclusion_form.$invalid || vm.disableUpdateButton || vm.disableForZeroValues">
ng-disabled="self_exclusion_form.$invalid || vm.disableUpdateButton || vm.disableForZeroValues"
ng-if="!vm.isReadonlyExcludeUntil">
{{ 'self-exclusion.update_settings' | translate }}
</button>
</div>
Expand Down
14 changes: 14 additions & 0 deletions www/js/share/services/websocket.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ angular
set_account_currency: currency
};

sendMessage(data);
},
serverTime() {
const data = {
time: 1,
};

sendMessage(data);
}
};
Expand Down Expand Up @@ -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:
}
}
Expand Down