2017-10-30 12:38:01 +03:00
|
|
|
import Service, {inject as service} from '@ember/service';
|
2018-01-09 17:23:36 +03:00
|
|
|
import {get, set} from '@ember/object';
|
|
|
|
import {htmlSafe} from '@ember/string';
|
2016-06-30 17:45:02 +03:00
|
|
|
|
|
|
|
export default Service.extend({
|
2018-01-09 17:23:36 +03:00
|
|
|
notifications: service(),
|
|
|
|
|
2016-06-30 17:45:02 +03:00
|
|
|
isRequired: false,
|
2018-01-09 17:23:36 +03:00
|
|
|
message: '',
|
2016-06-30 17:45:02 +03:00
|
|
|
|
2018-01-09 17:23:36 +03:00
|
|
|
// called when notifications are fetched during app boot for notifications
|
|
|
|
// where the `location` is not 'top' and `custom` is false
|
|
|
|
handleUpgradeNotification(notification) {
|
|
|
|
let message = get(notification, 'message');
|
|
|
|
set(this, 'message', htmlSafe(message));
|
|
|
|
},
|
2016-06-30 17:45:02 +03:00
|
|
|
|
2018-01-09 17:23:36 +03:00
|
|
|
// called when a MaintenanceError is encountered
|
2016-07-08 16:54:36 +03:00
|
|
|
maintenanceAlert() {
|
2018-01-09 17:23:36 +03:00
|
|
|
get(this, 'notifications').showAlert(
|
2016-07-08 16:54:36 +03:00
|
|
|
'Sorry, Ghost is currently undergoing maintenance, please wait a moment then try again.',
|
|
|
|
{type: 'error', key: 'api-error.under-maintenance'}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2018-01-09 17:23:36 +03:00
|
|
|
// called when a VersionMismatchError is encountered
|
2016-06-30 17:45:02 +03:00
|
|
|
requireUpgrade() {
|
2018-01-09 17:23:36 +03:00
|
|
|
set(this, 'isRequired', true);
|
|
|
|
get(this, 'notifications').showAlert(
|
2016-06-30 17:45:02 +03:00
|
|
|
'Ghost has been upgraded, please copy any unsaved data and refresh the page to continue.',
|
|
|
|
{type: 'error', key: 'api-error.upgrade-required'}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|