Skip to content

Commit

Permalink
Should Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian FERBACH committed Apr 26, 2017
1 parent 82d4248 commit 39b4ce9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
60 changes: 32 additions & 28 deletions src/javascripts/ng-admin/Crud/delete/DeleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,40 @@ export default class DeleteController {

deleteOne($event) {
const entityName = this.entity.name();
const { $state, $translate, notification, progression } = this;
const fromState = $state.current.name;
const fromParams = $state.current.params;
let toState;
let toParams;
if (fromParams.entity === entityName &&
fromParams.id === this.entityId) {
toState = $state.get('list');
toParams = {
entity: entityName,
...$state.params,
};
}

const { $translate, notification, progression } = this;
progression.start();
return this.WriteQueries.deleteOne(this.view, this.entityId)
.then(() => this.previousStateParametersDeferred.promise)
.then(previousStateParameters => {
// if previous page was related to deleted entity, redirect to list
if(toState){
return $state.go(toState, toParams);

return this.previousStateParametersDeferred.promise
.then((previousStateParameters) => {
const fromState = 'delete';
const fromParams = previousStateParameters;
let toState;
let toParams;

// if previous page was related to deleted entity,
// redirect to list
if (fromParams.entity === entityName &&
fromParams.id === this.entityId) {
toState = this.$state.get('list');
toParams = {
entity: entityName,
...this.$state.params,
};
}
return this.back();
})
// no need to call progression.done() in case of success, as it's called by the view dislayed afterwards
.then(() => $translate('DELETE_SUCCESS'))
.then(text => notification.log(text, { addnCls: 'humane-flatty-success' }))
.catch(error => {
progression.done();
this.HttpErrorService.handleError($event, toState, toParams, fromState, fromParams, error);

return this.WriteQueries.deleteOne(this.view, this.entityId)
.then(() => {
if(toState){
return this.$state.go(toState, toParams);
}
return this.back();
})
.then(() => $translate('DELETE_SUCCESS'))
.then(text => notification.log(text, { addnCls: 'humane-flatty-success' }))
.catch(error => {
progression.done();
this.HttpErrorService.handleError($event, toState, toParams, fromState, fromParams, error);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('DeleteController', function () {
});
var $state = {
go: jasmine.createSpy('$state.go'),
get: jasmine.createSpy('$state.get'),
get: jasmine.createSpy('$state.get').and.callFake(state => state),
params: {}
};
var writeQueries = {
Expand Down

0 comments on commit 39b4ce9

Please sign in to comment.