Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
7 changes: 6 additions & 1 deletion mocks/waves-client-config/master/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,10 @@
"GATEWAYS_SOON": [
"5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz"
],
"DEXW_LOCKED": false
"DEXW_LOCKED": false,
"SHUTDOWN_NOTIFICATION_TIMERS": [
{ "start": "2019-12-01T15:00:00+03:00", "end": "2019-12-01T15:01:00+03:00", "action": "showShutdownFirstModal" },
{ "start": "2019-12-02T08:00:00+03:00", "end": "2019-12-02T08:01:00+03:00", "action": "showShutdownSecondModal" },
{ "start": "2019-12-02T10:00:00+03:00", "action": "showShutdownLastModal" }
]
}
10 changes: 9 additions & 1 deletion src/modules/app/initialize/AppRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
* @param {ModalRouter} ModalRouter
* @param {ConfigService} configService
* @param {INotification} userNotification
* @param {ShutdownService} shutdownService
* @return {AppRun}
*/
// eslint-disable-next-line max-params
Expand All @@ -97,7 +98,8 @@
multiAccount,
ModalRouter,
configService,
userNotification
userNotification,
shutdownService
) {

const phone = WavesApp.device.phone();
Expand Down Expand Up @@ -158,6 +160,7 @@
this._initializeLogin();
this._initializeOutLinks();
this._openMigrationModal();
this._setShutdownService();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нам точно нужен метод? можно же сразу shutdownService.run();


if (WavesApp.isDesktop()) {
window.listenMainProcessEvent((type, url) => {
Expand Down Expand Up @@ -248,6 +251,10 @@
return false;
}

_setShutdownService() {
shutdownService.run();
}

/**
* @private
*/
Expand Down Expand Up @@ -809,6 +816,7 @@
'ModalRouter',
'configService',
'userNotification',
'shutdownService',
'whatsNew'
];

Expand Down
74 changes: 74 additions & 0 deletions src/modules/app/services/ShutdownService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(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 {

/**
* @public
*/
run() {
let timeOutTimerId;
const tick = () => {
this._handleTimers(this._getTimers());
if (timeOutTimerId) {
window.clearInterval(timeOutTimerId);
}
timeOutTimerId = setTimeout(() => tick(), 1000);
};

tick();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишний перенос.

}

/**
* @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 => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что будет если configService еще не прогрузил конфиг из сети?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Такого не может быть

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]();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лишние переносы

}
});
}


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут тоже

}

return new ShutdownService();
};

factory.$inject = ['Base', 'createPoll', 'configService', 'modalManager'];

angular.module('app').factory('shutdownService', factory);
})();

/**
* @name ShutdownService
*/
33 changes: 33 additions & 0 deletions src/modules/utils/modals/ModalManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,39 @@
return this._getModal(tsUtils.merge({}, DEFAULT_OPTIONS, options, { contentUrl, controller }));
}

showShutdownFirstModal() {
localStorage.setItem('shutdownFirstShown', true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем локал сторадж?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это Виктор исправит в своей ветке

return this._getModal({
id: 'shutdownFirstModal',
templateUrl: 'modules/utils/modals/shutdownFirst/shutdownFirst.html',
controller: 'ShutdownFirstCtrl',
clickOutsideToClose: false,
escapeToClose: false
});
}

showShutdownSecondModal() {
localStorage.setItem('shutdownSecondShown', true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично

return this._getModal({
id: 'shutdownSecondModal',
templateUrl: 'modules/utils/modals/shutdownSecond/shutdownSecond.html',
controller: 'ShutdownSecondCtrl',
clickOutsideToClose: false,
escapeToClose: false
});
}

showShutdownLastModal() {
return this._getModal({
id: 'shutdownLastModal',
templateUrl: 'modules/utils/modals/shutdownLast/shutdownLast.html',
controller: 'ShutdownLastCtrl',
clickOutsideToClose: false,
escapeToClose: false
});
}


/**
* @param {IModalOptions} options
* @return {$q.resolve}
Expand Down
8 changes: 8 additions & 0 deletions src/modules/utils/modals/shutdownFirst/shutdownFirst.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<md-dialog w-i18n-ns="app.utils" aria-label="modal">
<md-dialog-content>
<w-button class="submit long big" on-click="$ctrl.confirm()">
<span>modal day before</span>
<!-- <span w-i18n="modal.termsAccept.body.ok"></span> -->
</w-button>
</md-dialog-content>
</md-dialog>
20 changes: 20 additions & 0 deletions src/modules/utils/modals/shutdownFirst/shutdownFirst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function () {
'use strict';

const controller = function (Base, $mdDialog) {

class ShutdownFirstCtrl extends Base {

confirm() {
$mdDialog.hide();
}

}

return new ShutdownFirstCtrl();
};

controller.$inject = ['Base', '$mdDialog'];

angular.module('app.utils').controller('ShutdownFirstCtrl', controller);
})();
Empty file.
8 changes: 8 additions & 0 deletions src/modules/utils/modals/shutdownLast/shutdownLast.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<md-dialog w-i18n-ns="app.utils" aria-label="modal">
<md-dialog-content>
<w-button class="submit long big" on-click="$ctrl.confirm()">
<span>modal hour x</span>
<!-- <span w-i18n="modal.termsAccept.body.ok"></span> -->
</w-button>
</md-dialog-content>
</md-dialog>
21 changes: 21 additions & 0 deletions src/modules/utils/modals/shutdownLast/shutdownLast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function () {
'use strict';

const controller = function (Base, $mdDialog) {

class ShutdownLastCtrl extends Base {

confirm() {
window.history.go(0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

location.reload();

$mdDialog.hide();
}

}

return new ShutdownLastCtrl();
};

controller.$inject = ['Base', '$mdDialog'];

angular.module('app.utils').controller('ShutdownLastCtrl', controller);
})();
Empty file.
8 changes: 8 additions & 0 deletions src/modules/utils/modals/shutdownSecond/shutdownSecond.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<md-dialog w-i18n-ns="app.utils" aria-label="modal">
<md-dialog-content>
<w-button class="submit long big" on-click="$ctrl.confirm()">
<span>modal hour before</span>
<!-- <span w-i18n="modal.termsAccept.body.ok"></span> -->
</w-button>
</md-dialog-content>
</md-dialog>
20 changes: 20 additions & 0 deletions src/modules/utils/modals/shutdownSecond/shutdownSecond.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function () {
'use strict';

const controller = function (Base, $mdDialog) {

class ShutdownSecondCtrl extends Base {

confirm() {
$mdDialog.hide();
}

}

return new ShutdownSecondCtrl();
};

controller.$inject = ['Base', '$mdDialog'];

angular.module('app.utils').controller('ShutdownSecondCtrl', controller);
})();
Empty file.