2017-09-11 10:41:17 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {inject as injectService} 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({
|
|
|
|
|
2016-06-30 13:21:47 +03:00
|
|
|
ghostPaths: injectService(),
|
|
|
|
notifications: injectService(),
|
|
|
|
store: injectService(),
|
|
|
|
ajax: injectService(),
|
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');
|
|
|
|
return this.get('ajax').del(deleteUrl);
|
2015-11-18 13:50:48 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_unloadData() {
|
|
|
|
this.get('store').unloadAll('post');
|
|
|
|
this.get('store').unloadAll('tag');
|
|
|
|
},
|
|
|
|
|
|
|
|
_showSuccess() {
|
|
|
|
this.get('notifications').showAlert('All content deleted from database.', {type: 'success', key: 'all-content.delete.success'});
|
|
|
|
},
|
|
|
|
|
|
|
|
_showFailure(error) {
|
|
|
|
this.get('notifications').showAPIError(error, {key: 'all-content.delete'});
|
|
|
|
},
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}).drop(),
|
|
|
|
|
2015-11-18 13:50:48 +03:00
|
|
|
actions: {
|
|
|
|
confirm() {
|
2017-01-19 14:40:31 +03:00
|
|
|
this.get('deleteAll').perform();
|
2015-11-18 13:50:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|