Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dexw 2439 shutdown service #1798

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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 @@ -248,6 +250,10 @@
return false;
}

_setShutdownService() {
shutdownService.run();
}

/**
* @private
*/
Expand Down Expand Up @@ -399,6 +405,7 @@
});

balanceWatcher.change.once(this._onBalanceChange, this);
this._setShutdownService();
});
}

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

Expand Down
63 changes: 63 additions & 0 deletions src/modules/app/services/ShutdownService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
(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() {
createPoll(this, this._getDates, this._handleDates, 1000);
}

/**
* @return {*}
* @private
*/
_getDates() {
return configService.get('SHUTDOWN_NOTIFICATION_TIMERS');
}

/**
* @param {[{ start: string, end: ?string, action: string }]} timers
* @private
*/
_handleDates(timers) {

Choose a reason for hiding this comment

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

Так все-таки dates или timers?

const now = Date.now();
timers.forEach(timer => {

Choose a reason for hiding this comment

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

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

Copy link
Member

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

Choose a reason for hiding this comment

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

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

}
});
}


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
*/
34 changes: 34 additions & 0 deletions src/modules/utils/modals/ModalManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

state.signals.changeRouterStateStart.on(this.closeModals, this);
user.logoutSignal.on(this.closeModals, this);
window._mm = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Choose a reason for hiding this comment

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

это из моей ветки доехало. там wip

}

/**
Expand Down Expand Up @@ -755,6 +756,39 @@
return this._getModal(tsUtils.merge({}, DEFAULT_OPTIONS, options, { contentUrl, controller }));
}

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

Choose a reason for hiding this comment

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

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

Copy link
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
Member

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
Contributor

Choose a reason for hiding this comment

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

what?

Copy link
Member

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.