2017-09-11 10:41:17 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2017-01-19 14:40:31 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
export default ModalComponent.extend({
|
|
|
|
|
2017-10-30 12:38:01 +03:00
|
|
|
ghostPaths: service(),
|
|
|
|
notifications: service(),
|
|
|
|
store: service(),
|
|
|
|
ajax: service(),
|
2015-11-18 13:50:48 +03:00
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
actions: {
|
|
|
|
confirm() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.deleteAll.perform();
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-18 13:50:48 +03:00
|
|
|
_deleteAll() {
|
2016-01-18 18:37:14 +03:00
|
|
|
let deleteUrl = this.get('ghostPaths.url').api('db');
|
2019-03-06 16:53:54 +03:00
|
|
|
return this.ajax.del(deleteUrl);
|
2015-11-18 13:50:48 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_unloadData() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.store.unloadAll('post');
|
|
|
|
this.store.unloadAll('tag');
|
2015-11-18 13:50:48 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_showSuccess() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.notifications.showAlert('All content deleted from database.', {type: 'success', key: 'all-content.delete.success'});
|
2015-11-18 13:50:48 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_showFailure(error) {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.notifications.showAPIError(error, {key: 'all-content.delete'});
|
2015-11-18 13:50:48 +03:00
|
|
|
},
|
|
|
|
|
2017-01-19 14:40:31 +03:00
|
|
|
deleteAll: task(function* () {
|
|
|
|
try {
|
|
|
|
yield this._deleteAll();
|
|
|
|
this._unloadData();
|
|
|
|
this._showSuccess();
|
|
|
|
} catch (error) {
|
|
|
|
this._showFailure(error);
|
|
|
|
} finally {
|
|
|
|
this.send('closeModal');
|
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
}).drop()
|
2015-11-18 13:50:48 +03:00
|
|
|
});
|