updated to use new model._meta

- use model._meta to access the meta object in the delete response
- removed unused `_deleteUser` method
- move the success/failure method bodies into the main `deleteUser` task to improve readability
- added a timeout after calling `_exportDb()` so that the iframe is not removed from the DOM immediately after it's `src` value is set due to a transition away from the member screen
This commit is contained in:
Kevin Ansfield 2019-12-17 20:47:38 +00:00 committed by Daniel Lockyer
parent 7bb24df7b9
commit 9186280ac9
2 changed files with 13 additions and 17 deletions

View File

@ -8,7 +8,7 @@ import {computed} from '@ember/object';
import {isArray as isEmberArray} from '@ember/array';
import {run} from '@ember/runloop';
import {inject as service} from '@ember/service';
import {task, taskGroup} from 'ember-concurrency';
import {task, taskGroup, timeout} from 'ember-concurrency';
export default Controller.extend({
ajax: service(),
@ -331,16 +331,6 @@ export default Controller.extend({
}
},
_deleteUserSuccess() {
this.notifications.closeAlerts('user.delete');
this.store.unloadAll('post');
this.transitionToRoute('staff');
},
_deleteUserFailure() {
this.notifications.showAlert('The user could not be deleted. Please try again.', {type: 'error', key: 'user.delete.failed'});
},
_exportDb(filename) {
let exportUrl = this.get('ghostPaths.url').api('db');
let downloadURL = `${exportUrl}?filename=${filename}`;
@ -360,13 +350,19 @@ export default Controller.extend({
try {
const result = yield this.user.destroyRecord();
if (result.get('meta') && result.get('meta.filename')) {
yield this._exportDb(result.meta.filename);
if (result._meta && result._meta.filename) {
this._exportDb(result._meta.filename);
// give the iframe some time to trigger the download before
// it's removed from the dom when transitioning
yield timeout(300);
}
this._deleteUserSuccess();
} catch {
this._deleteUserFailure();
this.notifications.closeAlerts('user.delete');
this.store.unloadAll('post');
this.transitionToRoute('staff');
} catch (error) {
this.notifications.showAlert('The user could not be deleted. Please try again.', {type: 'error', key: 'user.delete.failed'});
throw error;
}
}),

View File

@ -1,4 +1,4 @@
import Model from 'ember-data/model';
import Model from '@ember-data/model';
export default Model.extend({
// this is a hack that gives us access to meta data in single resource responses