[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 58 additions and 52 deletions

View File

@ -9,7 +9,8 @@
"ADF_VERSION_MANAGER": { "ADF_VERSION_MANAGER": {
"ALLOW_DELETE": "Allow delete", "ALLOW_DELETE": "Allow delete",
"SHOW_COMMENTS" : "Show comments on versions", "SHOW_COMMENTS" : "Show comments on versions",
"ALLOW_DOWNLOAD" :"Enable version download" "ALLOW_DOWNLOAD" :"Enable version download",
"READ_ONLY" : "Read only"
} }
}, },
"title": "Welcome", "title": "Welcome",

View File

@ -1,7 +1,18 @@
<header mat-dialog-title>{{'VERSION.DIALOG.TITLE' | translate}}</header> <header mat-dialog-title>{{'VERSION.DIALOG.TITLE' | translate}}</header>
<section mat-dialog-content>
<section>
<mat-slide-toggle color="primary" [(ngModel)]="readOnly">
{{'APP.ADF_VERSION_MANAGER.READ_ONLY' | translate}}
</mat-slide-toggle>
</section>
<section mat-dialog-content *ngIf="!readOnly">
<adf-version-manager [node]="contentEntry" [allowDownload]="allowDownload" [showComments]="showComments" (uploadError)="uploadError($event)"></adf-version-manager> <adf-version-manager [node]="contentEntry" [allowDownload]="allowDownload" [showComments]="showComments" (uploadError)="uploadError($event)"></adf-version-manager>
</section> </section>
<section mat-dialog-content *ngIf="readOnly">
<adf-version-list [node]="contentEntry" [showActions]="false" ></adf-version-list>
</section>
<footer mat-dialog-actions fxLayout="row" fxLayoutAlign="end center"> <footer mat-dialog-actions fxLayout="row" fxLayoutAlign="end center">
<button mat-button (click)="close()">{{'VERSION.DIALOG.CLOSE' | translate}}</button> <button mat-button (click)="close()">{{'VERSION.DIALOG.CLOSE' | translate}}</button>
</footer> </footer>

View File

@ -30,6 +30,7 @@ export class VersionManagerDialogAdapterComponent {
showComments = true; showComments = true;
allowDownload = true; allowDownload = true;
readOnly = false;
constructor(@Inject(MAT_DIALOG_DATA) data: any, constructor(@Inject(MAT_DIALOG_DATA) data: any,
private snackBar: MatSnackBar, private snackBar: MatSnackBar,

View File

@ -31,6 +31,13 @@ Displays the version history of a node in a Version Manager component.
This component is used by the Version Manager component to This component is used by the Version Manager component to
load and displays the version history of a node. load and displays the version history of a node.
If you want show readonly version list you set this component with showActions false:
```html
<adf-version-list [node]="myNode" [showActions]="false" ></adf-version-list>
```
## See also ## See also
- [Version manager component](version-manager.component.md) - [Version manager component](version-manager.component.md)

View File

@ -59,8 +59,6 @@ describe('UploadBase', () => {
fixture = TestBed.createComponent(UploadTestComponent); fixture = TestBed.createComponent(UploadTestComponent);
uploadService = TestBed.get(UploadService); uploadService = TestBed.get(UploadService);
spyOn(FileModel.prototype, 'generateId').and.returnValue('test');
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });

View File

@ -137,7 +137,7 @@ export abstract class UploadBase {
* *
* @param file * @param file
*/ */
protected createFileModel(file: File, parentId: string, path: string): FileModel { protected createFileModel(file: File, parentId: string, path: string, id?: string): FileModel {
return new FileModel(file, { return new FileModel(file, {
comment: this.comment, comment: this.comment,
majorVersion: this.majorVersion, majorVersion: this.majorVersion,
@ -145,7 +145,7 @@ export abstract class UploadBase {
parentId: parentId, parentId: parentId,
path: path, path: path,
nodeType: this.nodeType nodeType: this.nodeType
}); }, id);
} }
protected isFileSizeAllowed(file: FileModel) { protected isFileSizeAllowed(file: FileModel) {

View File

@ -16,7 +16,7 @@
*/ */
import { PermissionsEnum } from '@alfresco/adf-core'; import { PermissionsEnum } from '@alfresco/adf-core';
import { Component, forwardRef, Input, OnChanges, SimpleChanges, ViewEncapsulation, OnInit } from '@angular/core'; import { Component, forwardRef, Input, OnChanges, ViewEncapsulation, OnInit } from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api'; import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { UploadButtonComponent } from './upload-button.component'; import { UploadButtonComponent } from './upload-button.component';
import { FileModel, EXTENDIBLE_COMPONENT } from '@alfresco/adf-core'; import { FileModel, EXTENDIBLE_COMPONENT } from '@alfresco/adf-core';
@ -36,20 +36,8 @@ export class UploadVersionButtonComponent extends UploadButtonComponent implemen
@Input() @Input()
node: MinimalNodeEntryEntity; node: MinimalNodeEntryEntity;
ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
if (changes['acceptedFilesType']) {
const message = this.translationService.instant('FILE_UPLOAD.VERSION.MESSAGES.NO_ACCEPTED_FILE_TYPES');
this.logService.error(message);
}
this.acceptedFilesType = '.' + this.node.name.split('.').pop();
}
protected createFileModel(file: File): FileModel { protected createFileModel(file: File): FileModel {
const fileModel = super.createFileModel(file, this.rootFolderId, (file.webkitRelativePath || '').replace(/\/[^\/]*$/, '')); const fileModel = super.createFileModel(file, this.rootFolderId, (file.webkitRelativePath || '').replace(/\/[^\/]*$/, ''), this.node.id);
fileModel.options.newVersionBaseName = this.node.name;
if (!this.isFileAcceptable(fileModel)) { if (!this.isFileAcceptable(fileModel)) {
const message = this.translationService.instant('FILE_UPLOAD.VERSION.MESSAGES.INCOMPATIBLE_VERSION'); const message = this.translationService.instant('FILE_UPLOAD.VERSION.MESSAGES.INCOMPATIBLE_VERSION');

View File

@ -10,8 +10,8 @@
</mat-radio-button> </mat-radio-button>
</mat-radio-group> </mat-radio-group>
<mat-form-field class="adf-new-version-max-width"> <mat-form-field class="adf-new-version-max-width">
<input matInput [(ngModel)]="comment" <textarea matInput [(ngModel)]="comment" class="adf-new-version-text-area"
placeholder="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.COMMENT' | translate }}"> placeholder="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.COMMENT' | translate }}"></textarea>
</mat-form-field> </mat-form-field>
</div> </div>

View File

@ -20,3 +20,8 @@
width: 100%; width: 100%;
float: right; float: right;
} }
.adf-new-version-text-area {
resize: none !important;
}

View File

@ -25,7 +25,6 @@ export interface FileUploadOptions {
comment?: string; comment?: string;
newVersion?: boolean; newVersion?: boolean;
majorVersion?: boolean; majorVersion?: boolean;
newVersionBaseName?: string;
parentId?: string; parentId?: string;
path?: string; path?: string;
nodeType?: string; nodeType?: string;
@ -43,20 +42,19 @@ export enum FileUploadStatus {
} }
export class FileModel { export class FileModel {
readonly id: string;
readonly name: string; readonly name: string;
readonly size: number; readonly size: number;
readonly file: File; readonly file: File;
id: string;
status: FileUploadStatus = FileUploadStatus.Pending; status: FileUploadStatus = FileUploadStatus.Pending;
progress: FileUploadProgress; progress: FileUploadProgress;
options: FileUploadOptions; options: FileUploadOptions;
data: any; data: any;
constructor(file: File, options?: FileUploadOptions) { constructor(file: File, options?: FileUploadOptions, id?: string) {
this.file = file; this.file = file;
this.id = id;
this.id = this.generateId();
this.name = file.name; this.name = file.name;
this.size = file.size; this.size = file.size;
this.data = null; this.data = null;
@ -72,13 +70,6 @@ export class FileModel {
}, options); }, 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 { get extension(): string {
return this.name.slice((Math.max(0, this.name.lastIndexOf('.')) || Infinity) + 1); 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); 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(); let emitter = new EventEmitter();
const filesFake = new FileModel(<File> { name: 'fake-name', size: 10 }, { const filesFake = new FileModel(<File> { name: 'fake-name', size: 10 }, {
newVersion: true, newVersion: true
newVersionBaseName: 'name-under-test'
}); });
service.addToQueue(filesFake); service.addToQueue(filesFake);
service.uploadFilesInTheQueue(emitter); service.uploadFilesInTheQueue(emitter);
expect(jasmine.Ajax.requests.mostRecent().params.has('name')).toBe(true); 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) => { 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>(); fileUploadDeleted: Subject<FileUploadDeleteEvent> = new Subject<FileUploadDeleteEvent>();
fileDeleted: Subject<string> = new Subject<string>(); fileDeleted: Subject<string> = new Subject<string>();
constructor( constructor(protected apiService: AlfrescoApiService,
protected apiService: AlfrescoApiService, appConfigService: AppConfigService) {
appConfigService: AppConfigService) {
this.excludedFileList = <String[]> appConfigService.get('files.excluded'); this.excludedFileList = <String[]> appConfigService.get('files.excluded');
} }
@ -164,25 +163,32 @@ export class UploadService {
opts.overwrite = true; opts.overwrite = true;
opts.majorVersion = file.options.majorVersion; opts.majorVersion = file.options.majorVersion;
opts.comment = file.options.comment; opts.comment = file.options.comment;
opts.name = file.name;
} else { } else {
opts.autoRename = true; opts.autoRename = true;
} }
if (file.options.newVersionBaseName) {
opts.name = file.options.newVersionBaseName;
}
if (file.options.nodeType) { if (file.options.nodeType) {
opts.nodeType = file.options.nodeType; opts.nodeType = file.options.nodeType;
} }
return this.apiService.getInstance().upload.uploadFile( if (file.id) {
file.file, return this.apiService.getInstance().upload.updateFile(
file.options.path, file.file,
file.options.parentId, file.options.path,
null, file.id,
opts 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 { private beginUpload(file: FileModel, /* @deprecated */emitter: EventEmitter<any>): any {