diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts index 95ffe948a7..47aa0f0245 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts @@ -61,8 +61,9 @@ describe('WorkPackageResource service', () => { }); $httpBackend.flush(); }; - const expectWpCacheUpdateWith = (...urls) => { + const testWpCacheUpdateWith = (prepare, ...urls) => { beforeEach(() => { + prepare(); expectUncachedRequests(urls); }); @@ -91,21 +92,21 @@ describe('WorkPackageResource service', () => { }); describe('when updating multiple linked resource', () => { - var linkNames = ['activities', 'attachments']; - - beforeEach(() => { - workPackage.updateLinkedResources(...linkNames); - }); - - expectWpCacheUpdateWith(...linkNames); + testWpCacheUpdateWith(() => { + workPackage.updateLinkedResources('activities', 'attachments'); + }, 'activities', 'attachments'); }); describe('when updating the activities', () => { - beforeEach(() => { + testWpCacheUpdateWith(() => { workPackage.updateActivities(); - }); + }, 'activities'); + }); - expectWpCacheUpdateWith('activities'); + describe('when updating the attachments', () => { + testWpCacheUpdateWith(() => { + workPackage.updateAttachments(); + }, 'activities', 'attachments'); }); }); }); diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts index 1f216f69b6..36c6f2feb9 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts @@ -371,6 +371,14 @@ export class WorkPackageResource extends HalResource { this.updateLinkedResources('activities'); } + /** + * Get updated attachments and activities from the server and inform the cache service + * about the update. + */ + public updateAttachments() { + this.updateLinkedResources('activities', 'attachments'); + } + /** * Assign values from the form for a newly created work package resource. * @param form diff --git a/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.test.ts b/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.test.ts index 98edea97d9..473f3168b1 100644 --- a/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.test.ts +++ b/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.test.ts @@ -51,7 +51,8 @@ describe('wp-attachments.directive', () => { $unload: angular.noop, href: '/api/v3/work_packages/1/activities', }, - updateLinkedResources: () => null + updateLinkedResources: () => null, + updateAttachments: () => null }; beforeEach(angular.mock.module('openproject')); diff --git a/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.ts b/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.ts index 05867e9016..ac191664f6 100644 --- a/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.ts +++ b/frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.ts @@ -110,7 +110,7 @@ export class WorkPackageAttachmentsController { // Reload the work package after attachments are uploaded to // provide the correct links, in e.g., the description this.wpCacheService.loadWorkPackage( wp.id, true); - }) + }); }); } @@ -125,7 +125,7 @@ export class WorkPackageAttachmentsController { if (this.files.length > 0) { this.wpAttachments.upload(this.workPackage, this.files).then(() => { this.files = []; - this.attachmentsChanged(); + this.workPackage.updateAttachments(); }); } }; @@ -146,7 +146,7 @@ export class WorkPackageAttachmentsController { if (!this.workPackage.isNew) { if (file._type === 'Attachment') { file.delete() - .then(() => this.attachmentsChanged()) + .then(() => this.workPackage.updateAttachments()) .catch(error => { this.wpNotificationsService.handleErrorResponse(error, this.workPackage); }); @@ -176,13 +176,6 @@ export class WorkPackageAttachmentsController { this.filterFiles(files); this.upload(); } - - /** - * Update the work package links affected by attachments: activities and attachments themselves - */ - protected attachmentsChanged() { - this.workPackage.updateLinkedResources('attachments', 'activities'); - } } function wpAttachmentsDirective():ng.IDirective {