Implement updateAttachments() method

pull/4781/head
Alex Dik 8 years ago
parent c4c44b5104
commit 55da4fb065
  1. 21
      frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts
  2. 8
      frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts
  3. 3
      frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.test.ts
  4. 13
      frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.ts

@ -61,8 +61,9 @@ describe('WorkPackageResource service', () => {
}); });
$httpBackend.flush(); $httpBackend.flush();
}; };
const expectWpCacheUpdateWith = (...urls) => { const testWpCacheUpdateWith = (prepare, ...urls) => {
beforeEach(() => { beforeEach(() => {
prepare();
expectUncachedRequests(urls); expectUncachedRequests(urls);
}); });
@ -91,21 +92,21 @@ describe('WorkPackageResource service', () => {
}); });
describe('when updating multiple linked resource', () => { describe('when updating multiple linked resource', () => {
var linkNames = ['activities', 'attachments']; testWpCacheUpdateWith(() => {
workPackage.updateLinkedResources('activities', 'attachments');
beforeEach(() => { }, 'activities', 'attachments');
workPackage.updateLinkedResources(...linkNames);
});
expectWpCacheUpdateWith(...linkNames);
}); });
describe('when updating the activities', () => { describe('when updating the activities', () => {
beforeEach(() => { testWpCacheUpdateWith(() => {
workPackage.updateActivities(); workPackage.updateActivities();
}, 'activities');
}); });
expectWpCacheUpdateWith('activities'); describe('when updating the attachments', () => {
testWpCacheUpdateWith(() => {
workPackage.updateAttachments();
}, 'activities', 'attachments');
}); });
}); });
}); });

@ -371,6 +371,14 @@ export class WorkPackageResource extends HalResource {
this.updateLinkedResources('activities'); 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. * Assign values from the form for a newly created work package resource.
* @param form * @param form

@ -51,7 +51,8 @@ describe('wp-attachments.directive', () => {
$unload: angular.noop, $unload: angular.noop,
href: '/api/v3/work_packages/1/activities', href: '/api/v3/work_packages/1/activities',
}, },
updateLinkedResources: () => null updateLinkedResources: () => null,
updateAttachments: () => null
}; };
beforeEach(angular.mock.module('openproject')); beforeEach(angular.mock.module('openproject'));

@ -110,7 +110,7 @@ export class WorkPackageAttachmentsController {
// Reload the work package after attachments are uploaded to // Reload the work package after attachments are uploaded to
// provide the correct links, in e.g., the description // provide the correct links, in e.g., the description
this.wpCacheService.loadWorkPackage(<number> wp.id, true); this.wpCacheService.loadWorkPackage(<number> wp.id, true);
}) });
}); });
} }
@ -125,7 +125,7 @@ export class WorkPackageAttachmentsController {
if (this.files.length > 0) { if (this.files.length > 0) {
this.wpAttachments.upload(this.workPackage, this.files).then(() => { this.wpAttachments.upload(this.workPackage, this.files).then(() => {
this.files = []; this.files = [];
this.attachmentsChanged(); this.workPackage.updateAttachments();
}); });
} }
}; };
@ -146,7 +146,7 @@ export class WorkPackageAttachmentsController {
if (!this.workPackage.isNew) { if (!this.workPackage.isNew) {
if (file._type === 'Attachment') { if (file._type === 'Attachment') {
file.delete() file.delete()
.then(() => this.attachmentsChanged()) .then(() => this.workPackage.updateAttachments())
.catch(error => { .catch(error => {
this.wpNotificationsService.handleErrorResponse(error, this.workPackage); this.wpNotificationsService.handleErrorResponse(error, this.workPackage);
}); });
@ -176,13 +176,6 @@ export class WorkPackageAttachmentsController {
this.filterFiles(files); this.filterFiles(files);
this.upload(); 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 { function wpAttachmentsDirective():ng.IDirective {

Loading…
Cancel
Save