-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathShutdownService.js
More file actions
69 lines (56 loc) · 1.88 KB
/
ShutdownService.js
File metadata and controls
69 lines (56 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function () {
'use strict';
/**
* @param {Base} Base
* @param {IPollCreate} createPoll
* @param {ConfigService} configService
* @param {ModalManager} modalManager
* @return {ShutdownService}
*/
const factory = function (Base, createPoll, configService, modalManager) {
class ShutdownService extends Base {
/**
* @private
*/
_timeOutTimerId;
/**
* @public
*/
run() {
this._handleTimers(this._getTimers());
window.clearTimeout(this._timeOutTimerId);
this._timeOutTimerId = setTimeout(() => this.run(), 1000);
}
/**
* @return {*}
* @private
*/
_getTimers() {
return configService.get('SHUTDOWN_NOTIFICATION_TIMERS') || [];
}
/**
* @param {[{ start: string, end: ?string, action: string }]} timers
* @private
*/
_handleTimers(timers) {
const now = Date.now();
timers.forEach(timer => {
const start = new Date(timer.start).getTime();
const end = timer.end ? new Date(timer.end).getTime() : Date.now();
if (now >= start && now <= end) {
if (!sessionStorage.getItem(timer.action)) {
sessionStorage.setItem(timer.action, 'true');
modalManager[timer.action]();
}
}
});
}
}
return new ShutdownService();
};
factory.$inject = ['Base', 'createPoll', 'configService', 'modalManager'];
angular.module('app').factory('shutdownService', factory);
})();
/**
* @name ShutdownService
*/