diff --git a/frontend/app/components/work-packages/work-package-cache.service.ts b/frontend/app/components/work-packages/work-package-cache.service.ts index 4120321113..0b03e76994 100644 --- a/frontend/app/components/work-packages/work-package-cache.service.ts +++ b/frontend/app/components/work-packages/work-package-cache.service.ts @@ -86,14 +86,19 @@ export class WorkPackageCacheService { return this.$q.when(workPackage); } - return workPackage.save() + const deferred = this.$q.defer(); + workPackage.save() .then(() => { this.wpNotificationsService.showSave(workPackage); this.$rootScope.$emit('workPackagesRefreshInBackground'); + deferred.resolve(workPackage); }) .catch((error) => { this.wpNotificationsService.handleErrorResponse(error, workPackage); + deferred.reject(error); }); + + return deferred.promise; } loadWorkPackage(workPackageId: number, forceUpdate = false): State { diff --git a/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts b/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts index c25b3e478d..bf3db77f18 100644 --- a/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts +++ b/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts @@ -33,7 +33,7 @@ export class TimelineCellRenderer { /** * Restore the original date, if any was set. */ - public onCancel(wp:WorkPackageResourceInterface, dates:CellDateMovement) { + public onCancel(wp:WorkPackageResourceInterface) { wp.restoreFromPristine('startDate'); wp.restoreFromPristine('dueDate'); } diff --git a/frontend/app/components/wp-table/timeline/cell-renderer/timeline-milestone-cell-renderer.ts b/frontend/app/components/wp-table/timeline/cell-renderer/timeline-milestone-cell-renderer.ts index d145753736..d8ed54241a 100644 --- a/frontend/app/components/wp-table/timeline/cell-renderer/timeline-milestone-cell-renderer.ts +++ b/frontend/app/components/wp-table/timeline/cell-renderer/timeline-milestone-cell-renderer.ts @@ -28,7 +28,7 @@ export class TimelineMilestoneCellRenderer extends TimelineCellRenderer { /** * Restore the original date, if any was set. */ - public onCancel(wp: WorkPackageResourceInterface, dates:CellMilestoneMovement) { + public onCancel(wp: WorkPackageResourceInterface) { wp.restoreFromPristine('date'); } diff --git a/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts b/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts index 5bf16eb3a3..c2594896d3 100644 --- a/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts +++ b/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts @@ -106,13 +106,6 @@ export function registerWorkPackageMouseHandler(this: void, return; } - if (cancelled) { - renderer.onCancel(renderInfo.workPackage, dateStates); - } else { - // Persist the changes - wpCacheService.saveIfChanged(renderInfo.workPackage); - } - jBody.off("mousemove", mouseMoveFn); jBody.off("keyup", keyPressFn); jQuery(".hascontextmenu").css("cursor", "context-menu"); @@ -123,9 +116,20 @@ export function registerWorkPackageMouseHandler(this: void, startX = null; dateStates = {}; - workPackageTimeline.refreshView(); + if (cancelled) { + renderer.onCancel(renderInfo.workPackage); + return workPackageTimeline.refreshView(); + } + // Persist the changes + wpCacheService.saveIfChanged(renderInfo.workPackage) + .catch(() => { + // Reset the changes on error + renderer.onCancel(renderInfo.workPackage); + }) + .finally(() => { + workPackageTimeline.refreshView(); + }); } - }