[ADF-2563] Improve versioning functionality (#3335)

* change input with textarea

* update file version use now the update content API

* provide way to test read only mode version list

* fix test

* test fix
This commit is contained in:
Eugenio Romano
2018-05-17 11:35:42 +01:00
committed by GitHub
parent 9772b2308a
commit 9e3a4aa49f
12 changed files with 58 additions and 52 deletions

View File

@@ -25,7 +25,6 @@ export interface FileUploadOptions {
comment?: string;
newVersion?: boolean;
majorVersion?: boolean;
newVersionBaseName?: string;
parentId?: string;
path?: string;
nodeType?: string;
@@ -43,20 +42,19 @@ export enum FileUploadStatus {
}
export class FileModel {
readonly id: string;
readonly name: string;
readonly size: number;
readonly file: File;
id: string;
status: FileUploadStatus = FileUploadStatus.Pending;
progress: FileUploadProgress;
options: FileUploadOptions;
data: any;
constructor(file: File, options?: FileUploadOptions) {
constructor(file: File, options?: FileUploadOptions, id?: string) {
this.file = file;
this.id = this.generateId();
this.id = id;
this.name = file.name;
this.size = file.size;
this.data = null;
@@ -72,13 +70,6 @@ export class FileModel {
}, options);
}
generateId(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
get extension(): string {
return this.name.slice((Math.max(0, this.name.lastIndexOf('.')) || Infinity) + 1);
}

View File

@@ -161,18 +161,16 @@ describe('UploadService', () => {
expect(jasmine.Ajax.requests.mostRecent().params.has('majorVersion')).toBe(false);
});
it('If newVersionBaseName is set, name should be a param', () => {
it('If newVersion is set, name should be a param', () => {
let emitter = new EventEmitter();
const filesFake = new FileModel(<File> { name: 'fake-name', size: 10 }, {
newVersion: true,
newVersionBaseName: 'name-under-test'
newVersion: true
});
service.addToQueue(filesFake);
service.uploadFilesInTheQueue(emitter);
expect(jasmine.Ajax.requests.mostRecent().params.has('name')).toBe(true);
expect(jasmine.Ajax.requests.mostRecent().params.get('name')).toBe('name-under-test');
});
it('should use custom root folder ID given to the service', (done) => {

View File

@@ -52,9 +52,8 @@ export class UploadService {
fileUploadDeleted: Subject<FileUploadDeleteEvent> = new Subject<FileUploadDeleteEvent>();
fileDeleted: Subject<string> = new Subject<string>();
constructor(
protected apiService: AlfrescoApiService,
appConfigService: AppConfigService) {
constructor(protected apiService: AlfrescoApiService,
appConfigService: AppConfigService) {
this.excludedFileList = <String[]> appConfigService.get('files.excluded');
}
@@ -164,25 +163,32 @@ export class UploadService {
opts.overwrite = true;
opts.majorVersion = file.options.majorVersion;
opts.comment = file.options.comment;
opts.name = file.name;
} else {
opts.autoRename = true;
}
if (file.options.newVersionBaseName) {
opts.name = file.options.newVersionBaseName;
}
if (file.options.nodeType) {
opts.nodeType = file.options.nodeType;
}
return this.apiService.getInstance().upload.uploadFile(
file.file,
file.options.path,
file.options.parentId,
null,
opts
);
if (file.id) {
return this.apiService.getInstance().upload.updateFile(
file.file,
file.options.path,
file.id,
file.file,
opts
);
} else {
return this.apiService.getInstance().upload.uploadFile(
file.file,
file.options.path,
file.options.parentId,
null,
opts
);
}
}
private beginUpload(file: FileModel, /* @deprecated */emitter: EventEmitter<any>): any {