2017-10-30 12:38:01 +03:00
|
|
|
import Service, {inject as service} from '@ember/service';
|
2022-02-03 01:11:11 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2018-01-09 17:23:36 +03:00
|
|
|
import {get, set} from '@ember/object';
|
2021-05-12 14:33:36 +03:00
|
|
|
import {htmlSafe} from '@ember/template';
|
2023-03-02 21:39:38 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2016-06-30 17:45:02 +03:00
|
|
|
|
2022-02-03 01:11:11 +03:00
|
|
|
@classic
|
|
|
|
export default class UpgradeStatusService extends Service {
|
2022-02-03 22:04:43 +03:00
|
|
|
@service notifications;
|
2018-01-09 17:23:36 +03:00
|
|
|
|
2023-03-02 21:39:38 +03:00
|
|
|
@tracked refreshRequired = false;
|
|
|
|
|
2022-02-03 01:11:11 +03:00
|
|
|
isRequired = false;
|
|
|
|
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));
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|
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() {
|
2019-03-06 16:53:54 +03:00
|
|
|
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'}
|
|
|
|
);
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|
2016-07-08 16:54:36 +03:00
|
|
|
|
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);
|
2019-03-06 16:53:54 +03:00
|
|
|
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'}
|
|
|
|
);
|
|
|
|
}
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|