[ADF-2563] Upload new version information dialog (#3235)

* add majorVersion param
move common part in base class

* refactor upload queue

* fix after refactoring

* add comment functionality in versioning
add minor and major option in versioning
add animation in versioning
add new functionality in demo shell

* add animation test

* add missing properties test and base upload class

* fix reload after new version upload [ADF-2582]

* update documentation

* update doc and fix minor style issues

* fix tslint error

* change cachebuster

* ADF-2672 version manager disable buttons

* [ADF-2649] hide show actions in version list

* fix tests
This commit is contained in:
Eugenio Romano
2018-04-26 14:57:55 +01:00
committed by GitHub
parent b2b3625929
commit 8872706eab
37 changed files with 17315 additions and 449 deletions

View File

@@ -15,11 +15,14 @@
* limitations under the License.
*/
import { ContentService, EXTENDIBLE_COMPONENT, FileModel, FileUtils,
LogService, NodePermissionSubject, TranslationService, UploadService
import {
ContentService, EXTENDIBLE_COMPONENT, FileUtils,
LogService, NodePermissionSubject, TranslationService, UploadService, PermissionsEnum
} from '@alfresco/adf-core';
import { Component, EventEmitter, forwardRef, Input,
OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
import {
Component, EventEmitter, forwardRef, Input,
OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation
} from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { PermissionModel } from '../../document-list/models/permissions.model';
import 'rxjs/add/observable/throw';
@@ -36,10 +39,6 @@ import { UploadBase } from './base-upload/upload-base';
})
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodePermissionSubject {
/** Toggles component disabled state (if there is no node permission checking). */
@Input()
disabled: boolean = false;
/** Allows/disallows upload folders (only for Chrome). */
@Input()
uploadFolders: boolean = false;
@@ -48,16 +47,6 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
@Input()
multipleFiles: boolean = false;
/** Toggles versioning. */
@Input()
versioning: boolean = false;
/** Sets a limit on the maximum size (in bytes) of a file to be uploaded.
* Has no effect if undefined.
*/
@Input()
maxFilesSize: number;
/** Defines the text of the upload button. */
@Input()
staticTitle: string;
@@ -66,25 +55,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
@Input()
tooltip: string = null;
/** The ID of the root. Use the nodeId for
* Content Services or the taskId/processId for Process Services.
*/
@Input()
rootFolderId: string = '-root-';
/** Emitted when the file is uploaded successfully. */
@Output()
success = new EventEmitter();
/** Emitted when an error occurs. */
@Output()
error = new EventEmitter();
/** Emitted when a folder is created. */
@Output()
createFolder = new EventEmitter();
/** Emitted when delete permission is missing. */
/** Emitted when create permission is missing. */
@Output()
permissionEvent: EventEmitter<PermissionModel> = new EventEmitter<PermissionModel>();
@@ -92,12 +63,11 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
private permissionValue: Subject<boolean> = new Subject<boolean>();
constructor(private uploadService: UploadService,
constructor(protected uploadService: UploadService,
private contentService: ContentService,
protected translateService: TranslationService,
protected logService: LogService
) {
super();
protected translationService: TranslationService,
protected logService: LogService) {
super(uploadService, translationService);
}
ngOnInit() {
@@ -123,7 +93,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
if (this.hasPermission) {
this.uploadFiles(files);
} else {
this.permissionEvent.emit(new PermissionModel({type: 'content', action: 'upload', permission: 'create'}));
this.permissionEvent.emit(new PermissionModel({ type: 'content', action: 'upload', permission: 'create' }));
}
// reset the value of the input file
$event.target.value = '';
@@ -134,73 +104,12 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
let files: File[] = FileUtils.toFileArray($event.currentTarget.files);
this.uploadFiles(files);
} else {
this.permissionEvent.emit(new PermissionModel({type: 'content', action: 'upload', permission: 'create'}));
this.permissionEvent.emit(new PermissionModel({ type: 'content', action: 'upload', permission: 'create' }));
}
// reset the value of the input file
$event.target.value = '';
}
/**
* Upload a list of file in the specified path
* @param files
* @param path
*/
uploadFiles(files: File[]): void {
const latestFilesAdded: FileModel[] = files
.map<FileModel>(this.createFileModel.bind(this))
.filter(this.isFileAcceptable.bind(this))
.filter(this.isFileSizeAcceptable.bind(this));
if (latestFilesAdded.length > 0) {
this.uploadService.addToQueue(...latestFilesAdded);
this.uploadService.uploadFilesInTheQueue(this.success);
}
}
/**
* Creates FileModel from File
*
* @param file
*/
protected createFileModel(file: File): FileModel {
return new FileModel(file, {
newVersion: this.versioning,
parentId: this.rootFolderId,
path: (file.webkitRelativePath || '').replace(/\/[^\/]*$/, '')
});
}
/**
* Checks if the given file is an acceptable size
*
* @param file FileModel
*/
private isFileSizeAcceptable(file: FileModel): boolean {
let acceptableSize = true;
if (this.isFileSizeAllowed(file)) {
acceptableSize = false;
this.translateService.get('FILE_UPLOAD.MESSAGES.EXCEED_MAX_FILE_SIZE', {fileName: file.name}).subscribe((message: string) => {
this.error.emit(message);
});
}
return acceptableSize;
}
private isFileSizeAllowed(file: FileModel) {
return this.isMaxFileSizeDefined() && this.isFileSizeCorrect(file);
}
private isMaxFileSizeDefined() {
return this.maxFilesSize !== undefined && this.maxFilesSize !== null;
}
private isFileSizeCorrect(file: FileModel) {
return this.maxFilesSize < 0 || file.size > this.maxFilesSize;
}
checkPermission() {
if (this.rootFolderId) {
let opts: any = {
@@ -209,16 +118,9 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
};
this.contentService.getNode(this.rootFolderId, opts).subscribe(
res => this.permissionValue.next(this.hasCreatePermission(res.entry)),
res => this.permissionValue.next(this.contentService.hasPermission(res.entry, PermissionsEnum.CREATE)),
error => this.error.emit(error)
);
}
}
private hasCreatePermission(node: any): boolean {
if (node && node.allowableOperations) {
return node.allowableOperations.find(permission => permission === 'create') ? true : false;
}
return false;
}
}