Change the type of the opFileUpload upload result

pull/4783/head
Alex Dik 8 years ago
parent f061e29a05
commit 50dc2ff2ba
  1. 4
      frontend/app/components/api/api-v3/hal-resources/attachment-collection-resource.service.ts
  2. 8
      frontend/app/components/api/op-file-upload/op-file-upload.service.test.ts
  3. 14
      frontend/app/components/api/op-file-upload/op-file-upload.service.ts

@ -31,7 +31,7 @@ import {CollectionResource} from './collection-resource.service';
import {HalResource} from './hal-resource.service'; import {HalResource} from './hal-resource.service';
import { import {
OpenProjectFileUploadService, OpenProjectFileUploadService,
UploadFile UploadFile, UploadResult
} from '../../op-file-upload/op-file-upload.service'; } from '../../op-file-upload/op-file-upload.service';
import IPromise = angular.IPromise; import IPromise = angular.IPromise;
@ -41,7 +41,7 @@ export class AttachmentCollectionResource extends CollectionResource {
/** /**
* Upload the given files to the $href property of this resource. * Upload the given files to the $href property of this resource.
*/ */
public upload(files: UploadFile[]): IPromise<any> { public upload(files: UploadFile[]): UploadResult {
return opFileUpload.upload(this.$href, files); return opFileUpload.upload(this.$href, files);
} }
} }

@ -80,8 +80,12 @@ describe('opFileUpload service', () => {
})); }));
}); });
it('should return a resolved promise', () => { it('should return a result object that contains each upload in an array', () => {
expect(result).to.eventually.be.fulfilled; expect(result.uploads).to.have.length(files.length);
});
it('should return a resolved promise that is the summary of the uploads', () => {
expect(result.upload).to.eventually.be.fulfilled;
}); });
}); });
}); });

@ -34,6 +34,11 @@ export interface UploadFile extends File {
description: string; description: string;
} }
export interface UploadResult {
uploads: IPromise<any>[];
upload: IPromise<any>;
}
export class OpenProjectFileUploadService { export class OpenProjectFileUploadService {
constructor(protected $q: IQService, constructor(protected $q: IQService,
protected Upload) { protected Upload) {
@ -42,8 +47,8 @@ export class OpenProjectFileUploadService {
/** /**
* Upload multiple files using `ngFileUpload` and return a single promise. * Upload multiple files using `ngFileUpload` and return a single promise.
*/ */
public upload(url: string, files: UploadFile[]): IPromise<any> { public upload(url: string, files: UploadFile[]): UploadResult {
return this.$q.all(_.map(files, (file: UploadFile) => this.Upload.upload({ const uploads = _.map(files, (file: UploadFile) => this.Upload.upload({
file, url, file, url,
fields: { fields: {
metadata: { metadata: {
@ -51,7 +56,10 @@ export class OpenProjectFileUploadService {
fileName: file.name, fileName: file.name,
} }
} }
}))); }));
const upload = this.$q.all(uploads);
return {uploads, upload};
} }
} }

Loading…
Cancel
Save