[ADF-2368] Version manager update (#3058)

* Add auto file renaming in FE side

* Add error handling, file type restriction

* Documentation

* Fix ts-lint error

* Test the service

* Fix fdescribe...
This commit is contained in:
Popovics András
2018-03-09 23:55:24 +01:00
committed by Eugenio Romano
parent 4ee7cc0870
commit 8859d3466e
15 changed files with 150 additions and 12 deletions

View File

@@ -104,6 +104,12 @@
"UPLOAD_FILE": "Upload file",
"UPLOAD_FOLDER": "Upload folder"
},
"VERSION": {
"MESSAGES": {
"NO_ACCEPTED_FILE_TYPES": "Please note that setting of acceptedFilesType has no effect for new version upload. File type will be the same as the original file's.",
"INCOMPATIBLE_VERSION": "Only files from the same type are allowed to be uploaded as a new version."
}
},
"MESSAGES": {
"UPLOAD_CANCELED": "Upload canceled",
"UPLOAD_COMPLETED": "Uploaded {{ completed }} / {{ total }}",

View File

@@ -114,9 +114,10 @@ export class UploadButtonComponent implements OnInit, OnChanges, NodePermissionS
private permissionValue: Subject<boolean> = new Subject<boolean>();
constructor(private uploadService: UploadService,
private translateService: TranslationService,
private logService: LogService,
private apiService: AlfrescoApiService) {
private apiService: AlfrescoApiService,
protected translateService: TranslationService,
protected logService: LogService
) {
}
ngOnInit() {
@@ -181,7 +182,7 @@ export class UploadButtonComponent implements OnInit, OnChanges, NodePermissionS
*
* @param file
*/
private createFileModel(file: File): FileModel {
protected createFileModel(file: File): FileModel {
return new FileModel(file, {
newVersion: this.versioning,
parentId: this.rootFolderId,
@@ -194,7 +195,7 @@ export class UploadButtonComponent implements OnInit, OnChanges, NodePermissionS
*
* @param file FileModel
*/
private isFileAcceptable(file: FileModel): boolean {
protected isFileAcceptable(file: FileModel): boolean {
if (this.acceptedFilesType === '*') {
return true;
}

View File

@@ -0,0 +1,58 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, forwardRef, Input, OnChanges, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { UploadButtonComponent } from './upload-button.component';
import { FileModel, EXTENDIBLE_COMPONENT } from '@alfresco/adf-core';
@Component({
selector: 'adf-upload-version-button',
templateUrl: './upload-button.component.html',
styleUrls: ['./upload-button.component.scss'],
viewProviders: [
{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadVersionButtonComponent) }
],
encapsulation: ViewEncapsulation.None
})
export class UploadVersionButtonComponent extends UploadButtonComponent implements OnChanges {
@Input()
node: MinimalNodeEntryEntity;
ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
if (changes['acceptedFilesType']) {
const message = this.translateService.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 {
const fileModel = super.createFileModel(file);
fileModel.options.newVersionBaseName = this.node.name;
if (!this.isFileAcceptable(fileModel)) {
const message = this.translateService.instant('FILE_UPLOAD.VERSION.MESSAGES.INCOMPATIBLE_VERSION');
this.error.emit(message);
}
return fileModel;
}
}

View File

@@ -16,6 +16,7 @@
*/
export * from './components/upload-button.component';
export * from './components/upload-version-button.component';
export * from './components/file-uploading-dialog.component';
export * from './components/upload-drag-area.component';
export * from './components/file-uploading-list.component';

View File

@@ -24,6 +24,7 @@ import { FileUploadingDialogComponent } from './components/file-uploading-dialog
import { FileUploadingListRowComponent } from './components/file-uploading-list-row.component';
import { FileUploadingListComponent } from './components/file-uploading-list.component';
import { UploadButtonComponent } from './components/upload-button.component';
import { UploadVersionButtonComponent } from './components/upload-version-button.component';
import { UploadDragAreaComponent } from './components/upload-drag-area.component';
import { PipeModule } from '@alfresco/adf-core';
@@ -40,6 +41,7 @@ import { FileDraggableDirective } from './directives/file-draggable.directive';
FileDraggableDirective,
UploadDragAreaComponent,
UploadButtonComponent,
UploadVersionButtonComponent,
FileUploadingDialogComponent,
FileUploadingListComponent,
FileUploadingListRowComponent
@@ -48,6 +50,7 @@ import { FileDraggableDirective } from './directives/file-draggable.directive';
FileDraggableDirective,
UploadDragAreaComponent,
UploadButtonComponent,
UploadVersionButtonComponent,
FileUploadingDialogComponent,
FileUploadingListComponent,
FileUploadingListRowComponent

View File

@@ -1,10 +1,11 @@
<adf-upload-button
<adf-upload-version-button
data-automation-id="adf-new-version-file-upload"
class="adf-new-version-file-upload"
staticTitle="Upload new version"
[node]="node"
[rootFolderId]="node.parentId"
tooltip="Restriction: upload file with the same name to create a new version of it"
[versioning]="true"
(success)="onUploadSuccess($event)"
(error)="onUploadError($event)">
</adf-upload-button>
</adf-upload-version-button>