mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -55,9 +55,9 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
|
||||
|
||||
constructor(private contentMetadataService: ContentMetadataService,
|
||||
private cardViewUpdateService: CardViewUpdateService,
|
||||
private nodesApi: NodesApiService,
|
||||
private nodesApiService: NodesApiService,
|
||||
private logService: LogService,
|
||||
private apiService: AlfrescoApiService) {}
|
||||
private alfrescoApiService: AlfrescoApiService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.cardViewUpdateService.itemUpdated$
|
||||
@@ -66,7 +66,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
|
||||
(node) => {
|
||||
this.nodeHasBeenUpdated = true;
|
||||
this.node = node;
|
||||
this.apiService.nodeUpdated.next(node);
|
||||
this.alfrescoApiService.nodeUpdated.next(node);
|
||||
},
|
||||
error => this.logService.error(error)
|
||||
);
|
||||
@@ -84,6 +84,6 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
|
||||
}
|
||||
|
||||
private saveNode({ changed: nodeBody }): Observable<MinimalNodeEntryEntity> {
|
||||
return this.nodesApi.updateNode(this.node.id, nodeBody);
|
||||
return this.nodesApiService.updateNode(this.node.id, nodeBody);
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,12 @@
|
||||
"DOWNLOAD": "Download",
|
||||
"UPLOAD": {
|
||||
"TITLE": "Upload new version",
|
||||
"TOOLTIP": "Restriction: you must upload a file with the same name to create a new version of it"
|
||||
"TOOLTIP": "Restriction: you must upload a file with the same name to create a new version of it",
|
||||
"MAJOR": "major changes (2.0)",
|
||||
"MINOR": "minor changes (1.1)",
|
||||
"COMMENT": "Leave a comment",
|
||||
"ADD": "Add New Version",
|
||||
"CANCEL": "Cancel"
|
||||
}
|
||||
},
|
||||
"CONFIRM_DELETE": {
|
||||
@@ -241,12 +246,12 @@
|
||||
}
|
||||
},
|
||||
"PERMISSION_MANAGER": {
|
||||
"PERMISSION_DISPLAY": {
|
||||
"INHERITED" : "Inherited",
|
||||
"AUTHORITY_ID" : "Authority ID",
|
||||
"ROLE": "Role",
|
||||
"LOCALLY_SET" : "Locally set",
|
||||
"NO_PERMISSIONS" : "No permissions"
|
||||
}
|
||||
"PERMISSION_DISPLAY": {
|
||||
"INHERITED": "Inherited",
|
||||
"AUTHORITY_ID": "Authority ID",
|
||||
"ROLE": "Role",
|
||||
"LOCALLY_SET": "Locally set",
|
||||
"NO_PERMISSIONS": "No permissions"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,268 @@
|
||||
/*!
|
||||
* @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 } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslationService, UploadService, setupTestBed, CoreModule, FileModel } from '@alfresco/adf-core';
|
||||
import { UploadBase } from './upload-base';
|
||||
import { TranslationMock } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-upload-button-test',
|
||||
template: 'test componente';
|
||||
})
|
||||
|
||||
export class UploadTestComponent extends UploadBase {
|
||||
|
||||
constructor(protected uploadService: UploadService,
|
||||
protected translationService: TranslationService) {
|
||||
super(uploadService, translationService);
|
||||
}
|
||||
}
|
||||
|
||||
describe('UploadBase', () => {
|
||||
|
||||
let component: UploadTestComponent;
|
||||
let fixture: ComponentFixture<UploadTestComponent>;
|
||||
let uploadService: UploadService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
NoopAnimationsModule,
|
||||
CoreModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
UploadTestComponent
|
||||
],
|
||||
providers: [
|
||||
UploadService,
|
||||
{ provide: TranslationService, useClass: TranslationMock }
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UploadTestComponent);
|
||||
uploadService = TestBed.get(UploadService);
|
||||
|
||||
spyOn(FileModel.prototype, 'generateId').and.returnValue('test');
|
||||
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
describe('filesize', () => {
|
||||
|
||||
const files: File[] = [
|
||||
<File> { name: 'bigFile.png', size: 1000 },
|
||||
<File> { name: 'smallFile.png', size: 10 }
|
||||
];
|
||||
|
||||
let addToQueueSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
addToQueueSpy = spyOn(uploadService, 'addToQueue');
|
||||
});
|
||||
|
||||
it('should filter out file, which are too big if max file size is set', () => {
|
||||
component.maxFilesSize = 100;
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
const filesCalledWith = addToQueueSpy.calls.mostRecent().args;
|
||||
expect(filesCalledWith.length).toBe(1);
|
||||
expect(filesCalledWith[0].name).toBe('smallFile.png');
|
||||
});
|
||||
|
||||
it('should filter out all files if maxFilesSize is 0', () => {
|
||||
component.maxFilesSize = 0;
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
expect(addToQueueSpy.calls.mostRecent()).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should allow file of 0 size when the max file size is set to 0', () => {
|
||||
const zeroFiles: File[] = [
|
||||
<File> { name: 'zeroFile.png', size: 0 }
|
||||
];
|
||||
component.maxFilesSize = 0;
|
||||
|
||||
component.uploadFiles(zeroFiles);
|
||||
|
||||
expect(addToQueueSpy.calls.mostRecent()).toBeDefined();
|
||||
});
|
||||
|
||||
it('should filter out all files if maxFilesSize is <0', () => {
|
||||
component.maxFilesSize = -2;
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
expect(addToQueueSpy.calls.mostRecent()).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should output an error when you try to upload a file too big', (done) => {
|
||||
component.maxFilesSize = 100;
|
||||
|
||||
component.error.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
component.uploadFiles(files);
|
||||
});
|
||||
|
||||
it('should not filter out files if max file size is not set', () => {
|
||||
component.maxFilesSize = null;
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
const filesCalledWith = addToQueueSpy.calls.mostRecent().args;
|
||||
expect(filesCalledWith.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('uploadFiles', () => {
|
||||
|
||||
const files: File[] = [
|
||||
<File> { name: 'phobos.jpg' },
|
||||
<File> { name: 'deimos.png' },
|
||||
<File> { name: 'ganymede.bmp' }
|
||||
];
|
||||
|
||||
let addToQueueSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
addToQueueSpy = spyOn(uploadService, 'addToQueue');
|
||||
});
|
||||
|
||||
it('should filter out file, which is not part of the acceptedFilesType', () => {
|
||||
component.acceptedFilesType = '.jpg';
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
const filesCalledWith = addToQueueSpy.calls.mostRecent().args;
|
||||
expect(filesCalledWith.length).toBe(1, 'Files should contain only one element');
|
||||
expect(filesCalledWith[0].name).toBe('phobos.jpg', 'png file should be filtered out');
|
||||
});
|
||||
|
||||
it('should filter out files, which are not part of the acceptedFilesType', () => {
|
||||
component.acceptedFilesType = '.jpg,.png';
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
const filesCalledWith = addToQueueSpy.calls.mostRecent().args;
|
||||
expect(filesCalledWith.length).toBe(2, 'Files should contain two elements');
|
||||
expect(filesCalledWith[0].name).toBe('phobos.jpg');
|
||||
expect(filesCalledWith[1].name).toBe('deimos.png');
|
||||
});
|
||||
|
||||
it('should not filter out anything if acceptedFilesType is wildcard', () => {
|
||||
component.acceptedFilesType = '*';
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
const filesCalledWith = addToQueueSpy.calls.mostRecent().args;
|
||||
expect(filesCalledWith.length).toBe(3, 'Files should contain all elements');
|
||||
expect(filesCalledWith[0].name).toBe('phobos.jpg');
|
||||
expect(filesCalledWith[1].name).toBe('deimos.png');
|
||||
expect(filesCalledWith[2].name).toBe('ganymede.bmp');
|
||||
});
|
||||
|
||||
it('should not add any file to que if everything is filtered out', () => {
|
||||
component.acceptedFilesType = 'doc';
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
expect(addToQueueSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Comments', () => {
|
||||
|
||||
let addToQueueSpy;
|
||||
|
||||
const files: File[] = [
|
||||
<File> { name: 'phobos.jpg' }
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
addToQueueSpy = spyOn(uploadService, 'addToQueue');
|
||||
});
|
||||
|
||||
it('should add the comment in the uploaded files', () => {
|
||||
component.comment = 'example-comment';
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
expect(addToQueueSpy).toHaveBeenCalledWith(new FileModel(files[0], {
|
||||
comment: 'example-comment'
|
||||
newVersion: false,
|
||||
majorVersion: false,
|
||||
parentId: '-root-',
|
||||
path: ''
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Versions', () => {
|
||||
|
||||
let addToQueueSpy;
|
||||
|
||||
const files: File[] = [
|
||||
<File> { name: 'phobos.jpg' }
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
addToQueueSpy = spyOn(uploadService, 'addToQueue');
|
||||
});
|
||||
|
||||
it('should be a mahor version upload if majorVersion is true', () => {
|
||||
component.majorVersion = true;
|
||||
component.versioning = true;
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
expect(addToQueueSpy).toHaveBeenCalledWith(new FileModel(files[0], {
|
||||
comment: undefined,
|
||||
newVersion: true,
|
||||
majorVersion: true,
|
||||
parentId: '-root-',
|
||||
path: ''
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not be a mahor version upload if majorVersion is false', () => {
|
||||
component.majorVersion = false;
|
||||
component.versioning = true;
|
||||
|
||||
component.uploadFiles(files);
|
||||
|
||||
expect(addToQueueSpy).toHaveBeenCalledWith(new FileModel(files[0], {
|
||||
comment: undefined,
|
||||
newVersion: true,
|
||||
majorVersion: false,
|
||||
parentId: '-root-',
|
||||
path: ''
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
@@ -15,16 +15,98 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { FileModel } from '@alfresco/adf-core';
|
||||
import { Input } from '@angular/core';
|
||||
import { FileModel, FileInfo } from '@alfresco/adf-core';
|
||||
import { EventEmitter, Input, Output } from '@angular/core';
|
||||
import { UploadService, TranslationService } from '@alfresco/adf-core';
|
||||
|
||||
export abstract class UploadBase {
|
||||
|
||||
/** Sets a limit on the maximum size (in bytes) of a file to be uploaded.
|
||||
* Has no effect if undefined.
|
||||
*/
|
||||
@Input()
|
||||
maxFilesSize: number;
|
||||
|
||||
/** The ID of the root. Use the nodeId for
|
||||
* Content Services or the taskId/processId for Process Services.
|
||||
*/
|
||||
@Input()
|
||||
rootFolderId: string = '-root-';
|
||||
|
||||
/** Toggles component disabled state (if there is no node permission checking). */
|
||||
@Input()
|
||||
disabled: boolean = false;
|
||||
|
||||
/** Filter for accepted file types. */
|
||||
@Input()
|
||||
acceptedFilesType: string = '*';
|
||||
|
||||
constructor() {}
|
||||
/** Toggles versioning. */
|
||||
@Input()
|
||||
versioning: boolean = false;
|
||||
|
||||
/** majorVersion boolean field to true to indicate a major version should be created. */
|
||||
@Input()
|
||||
majorVersion: boolean = false;
|
||||
|
||||
/** When you overwrite existing content, you can use the comment field to add a version comment that appears in the version history */
|
||||
@Input()
|
||||
comment: string;
|
||||
|
||||
/** Emitted when the file is uploaded successfully. */
|
||||
@Output()
|
||||
success = new EventEmitter();
|
||||
|
||||
/** @deprecated 2.4.0 */
|
||||
/** Emitted when a folder is created. */
|
||||
@Output()
|
||||
createFolder = new EventEmitter();
|
||||
|
||||
/** Emitted when an error occurs. */
|
||||
@Output()
|
||||
error = new EventEmitter();
|
||||
|
||||
constructor(protected uploadService: UploadService,
|
||||
protected translationService: TranslationService) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a list of file in the specified path
|
||||
* @param files
|
||||
* @param path
|
||||
*/
|
||||
uploadFiles(files: File[]): void {
|
||||
const filteredFiles: FileModel[] = files
|
||||
.map<FileModel>((file: File) => {
|
||||
return this.createFileModel(file, this.rootFolderId, (file.webkitRelativePath || '').replace(/\/[^\/]*$/, ''));
|
||||
});
|
||||
|
||||
this.uploadQueue(filteredFiles);
|
||||
}
|
||||
|
||||
uploadFilesInfo(files: FileInfo[]): void {
|
||||
const filteredFiles: FileModel[] = files
|
||||
.map<FileModel>((fileInfo: FileInfo) => {
|
||||
return this.createFileModel(fileInfo.file, this.rootFolderId, fileInfo.relativeFolder);
|
||||
});
|
||||
|
||||
this.uploadQueue(filteredFiles);
|
||||
}
|
||||
|
||||
private uploadQueue(files: FileModel[]) {
|
||||
let filteredFiles = files
|
||||
.filter(this.isFileAcceptable.bind(this))
|
||||
.filter(this.isFileSizeAcceptable.bind(this));
|
||||
|
||||
if (filteredFiles.length > 0) {
|
||||
this.uploadService.addToQueue(...filteredFiles);
|
||||
this.uploadService.uploadFilesInTheQueue(this.success);
|
||||
this.uploadService.fileUploadError.subscribe((error) => {
|
||||
this.error.emit(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given file is allowed by the extension filters
|
||||
*
|
||||
@@ -45,4 +127,56 @@ export abstract class UploadBase {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates FileModel from File
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
protected createFileModel(file: File, parentId: string, path: string): FileModel {
|
||||
return new FileModel(file, {
|
||||
comment: this.comment,
|
||||
majorVersion: this.majorVersion,
|
||||
newVersion: this.versioning,
|
||||
parentId: parentId,
|
||||
path: path
|
||||
});
|
||||
}
|
||||
|
||||
protected isFileSizeAllowed(file: FileModel) {
|
||||
let isFileSizeAllowed = true;
|
||||
if (this.isMaxFileSizeDefined()) {
|
||||
isFileSizeAllowed = this.isFileSizeCorrect(file);
|
||||
}
|
||||
|
||||
return isFileSizeAllowed;
|
||||
}
|
||||
|
||||
protected isMaxFileSizeDefined() {
|
||||
return this.maxFilesSize !== undefined && this.maxFilesSize !== null;
|
||||
}
|
||||
|
||||
protected isFileSizeCorrect(file: FileModel) {
|
||||
return this.maxFilesSize >= 0 && file.size <= this.maxFilesSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.translationService.get('FILE_UPLOAD.MESSAGES.EXCEED_MAX_FILE_SIZE', { fileName: file.name }).subscribe((message: string) => {
|
||||
this.error.emit(message);
|
||||
});
|
||||
}
|
||||
|
||||
return acceptableSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -16,23 +16,17 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
EXTENDIBLE_COMPONENT,
|
||||
FileInfo,
|
||||
FileModel,
|
||||
FileUtils,
|
||||
NodePermissionSubject,
|
||||
NotificationService,
|
||||
TranslationService,
|
||||
UploadService
|
||||
EXTENDIBLE_COMPONENT, FileInfo, FileModel, FileUtils, NodePermissionSubject,
|
||||
NotificationService, TranslationService, UploadService, ContentService, PermissionsEnum
|
||||
} from '@alfresco/adf-core';
|
||||
import { Component, EventEmitter, forwardRef, Input, Output, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, forwardRef, Input, ViewEncapsulation } from '@angular/core';
|
||||
import { UploadBase } from './base-upload/upload-base';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-upload-drag-area',
|
||||
templateUrl: './upload-drag-area.component.html',
|
||||
styleUrls: ['./upload-drag-area.component.css'],
|
||||
host: {'class': 'adf-upload-drag-area'},
|
||||
host: { 'class': 'adf-upload-drag-area' },
|
||||
viewProviders: [
|
||||
{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadDragAreaComponent) }
|
||||
],
|
||||
@@ -40,32 +34,17 @@ import { UploadBase } from './base-upload/upload-base';
|
||||
})
|
||||
export class UploadDragAreaComponent extends UploadBase implements NodePermissionSubject {
|
||||
|
||||
/** Toggle component disabled state. */
|
||||
/** @deprecaretd 2.4.0 use rootFolderId ID of parent folder node. */
|
||||
@Input()
|
||||
disabled: boolean = false;
|
||||
set parentId(nodeId: string) {
|
||||
this.rootFolderId = nodeId;
|
||||
}
|
||||
|
||||
/** When false, renames the file using an integer suffix if there is a name clash.
|
||||
* Set to true to indicate that a major version should be created instead.
|
||||
*/
|
||||
@Input()
|
||||
versioning: boolean = false;
|
||||
|
||||
/** ID of parent folder node. */
|
||||
@Input()
|
||||
parentId: string;
|
||||
|
||||
/** Emitted when the file is uploaded. */
|
||||
@Output()
|
||||
success = new EventEmitter();
|
||||
|
||||
/** Raised when the file upload goes in error. */
|
||||
@Output()
|
||||
error = new EventEmitter();
|
||||
|
||||
constructor(private uploadService: UploadService,
|
||||
private translateService: TranslationService,
|
||||
private notificationService: NotificationService) {
|
||||
super();
|
||||
constructor(protected uploadService: UploadService,
|
||||
protected translationService: TranslationService,
|
||||
private notificationService: NotificationService,
|
||||
private contentService: ContentService) {
|
||||
super(uploadService, translationService);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,12 +54,7 @@ export class UploadDragAreaComponent extends UploadBase implements NodePermissio
|
||||
*/
|
||||
onFilesDropped(files: File[]): void {
|
||||
if (!this.disabled && files.length) {
|
||||
const fileModels = files.map(file => new FileModel(file, {
|
||||
newVersion: this.versioning,
|
||||
path: '/',
|
||||
parentId: this.parentId
|
||||
})).filter(this.isFileAcceptable.bind(this));
|
||||
this.addNodeInUploadQueue(fileModels);
|
||||
this.uploadFiles(files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,14 +66,9 @@ export class UploadDragAreaComponent extends UploadBase implements NodePermissio
|
||||
onFilesEntityDropped(item: any): void {
|
||||
if (!this.disabled) {
|
||||
item.file((file: File) => {
|
||||
const fileModel = new FileModel(file, {
|
||||
newVersion: this.versioning,
|
||||
parentId: this.parentId,
|
||||
path: item.fullPath.replace(item.name, '')
|
||||
});
|
||||
if (this.isFileAcceptable(fileModel)) {
|
||||
this.addNodeInUploadQueue([fileModel]);
|
||||
}
|
||||
// const fileModel = this.createFileModel(file, this.rootFolderId, item.fullPath.replace(item.name, ''));
|
||||
|
||||
this.uploadFiles([file]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -111,29 +80,12 @@ export class UploadDragAreaComponent extends UploadBase implements NodePermissio
|
||||
*/
|
||||
onFolderEntityDropped(folder: any): void {
|
||||
if (!this.disabled && folder.isDirectory) {
|
||||
FileUtils.flattern(folder).then(entries => {
|
||||
let files = entries.map(entry => {
|
||||
return new FileModel(entry.file, {
|
||||
newVersion: this.versioning,
|
||||
parentId: this.parentId,
|
||||
path: entry.relativeFolder
|
||||
});
|
||||
}).filter(this.isFileAcceptable.bind(this));
|
||||
this.addNodeInUploadQueue(files);
|
||||
FileUtils.flattern(folder).then(filesInfo => {
|
||||
this.uploadFilesInfo(filesInfo);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private addNodeInUploadQueue(files: FileModel[]) {
|
||||
if (files.length) {
|
||||
this.uploadService.addToQueue(...files);
|
||||
this.uploadService.uploadFilesInTheQueue(this.success);
|
||||
this.uploadService.fileUploadError.subscribe((error) => {
|
||||
this.error.emit(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show undo notification bar.
|
||||
*
|
||||
@@ -141,8 +93,8 @@ export class UploadDragAreaComponent extends UploadBase implements NodePermissio
|
||||
*/
|
||||
showUndoNotificationBar(latestFilesAdded: FileModel[]) {
|
||||
let messageTranslate: any, actionTranslate: any;
|
||||
messageTranslate = this.translateService.get('FILE_UPLOAD.MESSAGES.PROGRESS');
|
||||
actionTranslate = this.translateService.get('FILE_UPLOAD.ACTION.UNDO');
|
||||
messageTranslate = this.translationService.get('FILE_UPLOAD.MESSAGES.PROGRESS');
|
||||
actionTranslate = this.translationService.get('FILE_UPLOAD.ACTION.UNDO');
|
||||
|
||||
this.notificationService.openSnackMessageAction(messageTranslate.value, actionTranslate.value, 3000).onAction().subscribe(() => {
|
||||
this.uploadService.cancelUpload(...latestFilesAdded);
|
||||
@@ -162,35 +114,13 @@ export class UploadDragAreaComponent extends UploadBase implements NodePermissio
|
||||
onUploadFiles(event: CustomEvent) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
let isAllowed: boolean = this.hasCreatePermission(event.detail.data.obj.entry);
|
||||
let isAllowed: boolean = this.contentService.hasPermission(event.detail.data.obj.entry, PermissionsEnum.CREATE);
|
||||
if (isAllowed) {
|
||||
let files: FileInfo[] = event.detail.files;
|
||||
if (files && files.length > 0) {
|
||||
let parentId = this.parentId;
|
||||
if (event.detail.data && event.detail.data.obj.entry.isFolder) {
|
||||
parentId = event.detail.data.obj.entry.id || this.parentId;
|
||||
}
|
||||
const fileModels = files.map(fileInfo => new FileModel(fileInfo.file, {
|
||||
newVersion: this.versioning,
|
||||
path: fileInfo.relativeFolder,
|
||||
parentId: parentId
|
||||
})).filter(this.isFileAcceptable.bind(this));
|
||||
this.addNodeInUploadQueue(fileModels);
|
||||
let fileInfo: FileInfo[] = event.detail.files;
|
||||
if (fileInfo && fileInfo.length > 0) {
|
||||
this.uploadFilesInfo(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if "create" permission is present on the given node
|
||||
*
|
||||
* @param node
|
||||
*/
|
||||
private hasCreatePermission(node: any): boolean {
|
||||
let isPermitted = false;
|
||||
if (node && node['allowableOperations']) {
|
||||
let permFound = node['allowableOperations'].find(element => element === 'create');
|
||||
isPermitted = permFound ? true : false;
|
||||
}
|
||||
return isPermitted;
|
||||
}
|
||||
}
|
||||
|
@@ -39,18 +39,19 @@ export class UploadVersionButtonComponent extends UploadButtonComponent implemen
|
||||
super.ngOnChanges(changes);
|
||||
|
||||
if (changes['acceptedFilesType']) {
|
||||
const message = this.translateService.instant('FILE_UPLOAD.VERSION.MESSAGES.NO_ACCEPTED_FILE_TYPES');
|
||||
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 {
|
||||
const fileModel = super.createFileModel(file);
|
||||
const fileModel = super.createFileModel(file, this.rootFolderId, (file.webkitRelativePath || '').replace(/\/[^\/]*$/, ''));
|
||||
|
||||
fileModel.options.newVersionBaseName = this.node.name;
|
||||
|
||||
if (!this.isFileAcceptable(fileModel)) {
|
||||
const message = this.translateService.instant('FILE_UPLOAD.VERSION.MESSAGES.INCOMPATIBLE_VERSION');
|
||||
const message = this.translationService.instant('FILE_UPLOAD.VERSION.MESSAGES.INCOMPATIBLE_VERSION');
|
||||
this.error.emit(message);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<mat-list class="adf-version-list" *ngIf="!isLoading; else loading_template">
|
||||
<mat-list-item *ngFor="let version of versions">
|
||||
<mat-list-item *ngFor="let version of versions; let idx = index">
|
||||
<mat-icon mat-list-icon>insert_drive_file</mat-icon>
|
||||
<h4 mat-line class="adf-version-list-item-name">{{version.entry.name}}</h4>
|
||||
<p mat-line>
|
||||
@@ -8,30 +8,39 @@
|
||||
</p>
|
||||
<p mat-line class="adf-version-list-item-comment" *ngIf="showComments">{{version.entry.versionComment}}</p>
|
||||
|
||||
<mat-menu #versionMenu="matMenu" yPosition="below" xPosition="before">
|
||||
<button *ngIf="canUpdate()"
|
||||
mat-menu-item
|
||||
(click)="restore(version.entry.id)">
|
||||
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}
|
||||
</button>
|
||||
<button *ngIf="allowDownload"
|
||||
mat-menu-item
|
||||
(click)="downloadVersion(version.entry.id)">
|
||||
{{ 'ADF_VERSION_LIST.ACTIONS.DOWNLOAD' | translate }}
|
||||
</button>
|
||||
<button *ngIf="canUpdate()"
|
||||
(click)="deleteVersion(version.entry.id)"
|
||||
mat-menu-item>
|
||||
{{ 'ADF_VERSION_LIST.ACTIONS.DELETE' | translate }}
|
||||
</button>
|
||||
</mat-menu>
|
||||
<div *ngIf="showActions">
|
||||
<mat-menu [id]="'adf-version-list-action-menu-'+idx"
|
||||
#versionMenu="matMenu" yPosition="below" xPosition="before">
|
||||
<button
|
||||
[id]="'adf-version-list-action-restore-'+idx"
|
||||
[disabled]="!canUpdate()"
|
||||
mat-menu-item
|
||||
(click)="restore(version.entry.id)">
|
||||
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}
|
||||
</button>
|
||||
<button *ngIf="allowDownload"
|
||||
[id]="'adf-version-list-action-download-'+idx"
|
||||
mat-menu-item
|
||||
(click)="downloadVersion(version.entry.id)">
|
||||
{{ 'ADF_VERSION_LIST.ACTIONS.DOWNLOAD' | translate }}
|
||||
</button>
|
||||
<button
|
||||
[disabled]="!canDelete()"
|
||||
[id]="'adf-version-list-action-delete-'+idx"
|
||||
(click)="deleteVersion(version.entry.id)"
|
||||
mat-menu-item>
|
||||
{{ 'ADF_VERSION_LIST.ACTIONS.DELETE' | translate }}
|
||||
</button>
|
||||
</mat-menu>
|
||||
|
||||
<button mat-icon-button [matMenuTriggerFor]="versionMenu">
|
||||
<mat-icon>more_vert</mat-icon>
|
||||
</button>
|
||||
<button mat-icon-button [matMenuTriggerFor]="versionMenu" [id]="'adf-version-list-action-menu-button-'+idx">
|
||||
<mat-icon>more_vert</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</mat-list-item>
|
||||
</mat-list>
|
||||
|
||||
<ng-template #loading_template>
|
||||
<mat-progress-bar data-automation-id="version-history-loading-bar" mode="indeterminate" color="accent"></mat-progress-bar>
|
||||
<mat-progress-bar data-automation-id="version-history-loading-bar" mode="indeterminate"
|
||||
color="accent"></mat-progress-bar>
|
||||
</ng-template>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
.adf-version-list {
|
||||
.mat-list-item {
|
||||
.mat-list-item-content {
|
||||
border-bottom:1px solid #d8d8d8;
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,7 @@ import { VersionListComponent } from './version-list.component';
|
||||
import { AlfrescoApiService, setupTestBed, CoreModule, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
describe('VersionListComponent', () => {
|
||||
let component: VersionListComponent;
|
||||
@@ -34,7 +35,8 @@ describe('VersionListComponent', () => {
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
CoreModule.forRoot()
|
||||
CoreModule.forRoot(),
|
||||
NoopAnimationsModule
|
||||
],
|
||||
declarations: [
|
||||
VersionListComponent
|
||||
@@ -56,7 +58,7 @@ describe('VersionListComponent', () => {
|
||||
dialog = TestBed.get(MatDialog);
|
||||
|
||||
component = fixture.componentInstance;
|
||||
component.node = { id: nodeId, allowableOperations: [ 'update' ] };
|
||||
component.node = { id: nodeId, allowableOperations: ['update'] };
|
||||
|
||||
spyOn(component, 'downloadContent').and.stub();
|
||||
});
|
||||
@@ -117,7 +119,7 @@ describe('VersionListComponent', () => {
|
||||
|
||||
it('should use loading bar', () => {
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
|
||||
.callFake(() => Promise.resolve({ list: { entries: []}}));
|
||||
.callFake(() => Promise.resolve({ list: { entries: [] } }));
|
||||
|
||||
let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
|
||||
expect(loadingProgressBar).toBeNull();
|
||||
@@ -131,7 +133,7 @@ describe('VersionListComponent', () => {
|
||||
|
||||
it('should load the versions for a given id', () => {
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
|
||||
.callFake(() => Promise.resolve({ list: { entries: []}}));
|
||||
.callFake(() => Promise.resolve({ list: { entries: [] } }));
|
||||
|
||||
component.ngOnChanges();
|
||||
fixture.detectChanges();
|
||||
@@ -142,11 +144,15 @@ describe('VersionListComponent', () => {
|
||||
it('should show the versions after loading', (done) => {
|
||||
fixture.detectChanges();
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => {
|
||||
return Promise.resolve({ list: { entries: [
|
||||
{
|
||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
||||
return Promise.resolve({
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
||||
}
|
||||
]
|
||||
}
|
||||
]}});
|
||||
});
|
||||
});
|
||||
|
||||
component.ngOnChanges();
|
||||
@@ -193,8 +199,14 @@ describe('VersionListComponent', () => {
|
||||
});
|
||||
|
||||
it('should be able to download a version', () => {
|
||||
const versionEntry = { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }};
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve({ list: { entries: [ versionEntry ] }}));
|
||||
const versionEntry = {
|
||||
entry: {
|
||||
name: 'test-file-name',
|
||||
id: '1.0',
|
||||
versionComment: 'test-version-comment'
|
||||
}
|
||||
};
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve({ list: { entries: [versionEntry] } }));
|
||||
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('the/download/url');
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -204,9 +216,15 @@ describe('VersionListComponent', () => {
|
||||
});
|
||||
|
||||
it('should NOT be able to download a version if configured so', () => {
|
||||
const versionEntry = { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }};
|
||||
const versionEntry = {
|
||||
entry: {
|
||||
name: 'test-file-name',
|
||||
id: '1.0',
|
||||
versionComment: 'test-version-comment'
|
||||
}
|
||||
};
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
|
||||
.callFake(() => Promise.resolve({ list: { entries: [ versionEntry ] }}));
|
||||
.callFake(() => Promise.resolve({ list: { entries: [versionEntry] } }));
|
||||
const spyOnDownload = spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.stub();
|
||||
|
||||
component.allowDownload = false;
|
||||
@@ -240,20 +258,20 @@ describe('VersionListComponent', () => {
|
||||
it('should load the versions for a given id', () => {
|
||||
fixture.detectChanges();
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
|
||||
.callFake(() => Promise.resolve({ list: { entries: []}}));
|
||||
.callFake(() => Promise.resolve({ list: { entries: [] } }));
|
||||
const spyOnRevertVersion = spyOn(alfrescoApiService.versionsApi, 'revertVersion').and
|
||||
.callFake(() => Promise.resolve(
|
||||
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }}));
|
||||
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } }));
|
||||
|
||||
component.restore(versionId);
|
||||
|
||||
expect(spyOnRevertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: ''});
|
||||
expect(spyOnRevertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: '' });
|
||||
});
|
||||
|
||||
it('should reload the version list after a version restore', (done) => {
|
||||
fixture.detectChanges();
|
||||
const spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
|
||||
.callFake(() => Promise.resolve({ list: { entries: []}}));
|
||||
.callFake(() => Promise.resolve({ list: { entries: [] } }));
|
||||
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
|
||||
|
||||
component.restore(versionId);
|
||||
@@ -264,4 +282,149 @@ describe('VersionListComponent', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Actions buttons', () => {
|
||||
|
||||
describe('showActions', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
component.node = { id: nodeId };
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => {
|
||||
return Promise.resolve({
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
component.ngOnChanges();
|
||||
});
|
||||
|
||||
it('should show Actions if showActions is true', (done) => {
|
||||
component.showActions = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
|
||||
|
||||
expect(menuButton).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide Actions if showActions is false', (done) => {
|
||||
component.showActions = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
|
||||
|
||||
expect(menuButton).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('disabled', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
component.node = { id: nodeId };
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => {
|
||||
return Promise.resolve({
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
component.ngOnChanges();
|
||||
});
|
||||
|
||||
it('should disable delete action if is not allowed', (done) => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
|
||||
menuButton.nativeElement.click();
|
||||
|
||||
let deleteButton = fixture.debugElement.query(By.css('#adf-version-list-action-delete-0'));
|
||||
|
||||
expect(deleteButton.nativeElement.disabled).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should disable restore action if is not allowed', (done) => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
|
||||
menuButton.nativeElement.click();
|
||||
|
||||
let restoreButton = fixture.debugElement.query(By.css('#adf-version-list-action-restore-0'));
|
||||
|
||||
expect(restoreButton.nativeElement.disabled).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('enabled', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
component.node = { id: nodeId, allowableOperations: ['update', 'delete'] };
|
||||
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => {
|
||||
return Promise.resolve({
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
component.ngOnChanges();
|
||||
});
|
||||
|
||||
it('should enable delete action if is allowed', (done) => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
|
||||
menuButton.nativeElement.click();
|
||||
|
||||
let deleteButton = fixture.debugElement.query(By.css('#adf-version-list-action-delete-0'));
|
||||
|
||||
expect(deleteButton.nativeElement.disabled).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should enable restore action if is allowed', (done) => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
|
||||
menuButton.nativeElement.click();
|
||||
|
||||
let restoreButton = fixture.debugElement.query(By.css('#adf-version-list-action-restore-0'));
|
||||
|
||||
expect(restoreButton.nativeElement.disabled).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { AlfrescoApiService, ContentService } from '@alfresco/adf-core';
|
||||
import { Component, Input, OnChanges, ViewEncapsulation, ElementRef } from '@angular/core';
|
||||
import { VersionsApi, MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
import { VersionsApi, MinimalNodeEntryEntity, VersionEntry } from 'alfresco-js-api';
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
|
||||
|
||||
@@ -33,7 +33,7 @@ import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
|
||||
export class VersionListComponent implements OnChanges {
|
||||
|
||||
private versionsApi: VersionsApi;
|
||||
versions: any = [];
|
||||
versions: VersionEntry[] = [];
|
||||
isLoading = true;
|
||||
|
||||
/** @deprecated in 2.3.0 */
|
||||
@@ -43,6 +43,7 @@ export class VersionListComponent implements OnChanges {
|
||||
@Input()
|
||||
node: MinimalNodeEntryEntity;
|
||||
|
||||
/** show/hide comments */
|
||||
@Input()
|
||||
showComments = true;
|
||||
|
||||
@@ -50,11 +51,14 @@ export class VersionListComponent implements OnChanges {
|
||||
@Input()
|
||||
allowDownload = true;
|
||||
|
||||
constructor(
|
||||
private alfrescoApi: AlfrescoApiService,
|
||||
private contentService: ContentService,
|
||||
private dialog: MatDialog,
|
||||
private el: ElementRef) {
|
||||
/** show/hide version actions */
|
||||
@Input()
|
||||
showActions = true;
|
||||
|
||||
constructor(private alfrescoApi: AlfrescoApiService,
|
||||
private contentService: ContentService,
|
||||
private dialog: MatDialog,
|
||||
private el: ElementRef) {
|
||||
this.versionsApi = this.alfrescoApi.versionsApi;
|
||||
}
|
||||
|
||||
@@ -66,10 +70,14 @@ export class VersionListComponent implements OnChanges {
|
||||
return this.contentService.hasPermission(this.node, 'update');
|
||||
}
|
||||
|
||||
canDelete(): boolean {
|
||||
return this.contentService.hasPermission(this.node, 'delete');
|
||||
}
|
||||
|
||||
restore(versionId) {
|
||||
if (this.canUpdate()) {
|
||||
this.versionsApi
|
||||
.revertVersion(this.node.id, versionId, { majorVersion: true, comment: ''})
|
||||
.revertVersion(this.node.id, versionId, { majorVersion: true, comment: '' })
|
||||
.then(() => this.onVersionRestored());
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,39 @@
|
||||
<div class="adf-new-version-uploader-container" fxLayout="row" fxLayoutAlign="end center">
|
||||
<adf-version-upload
|
||||
[node]="node"
|
||||
(success)="onUploadSuccess($event)"
|
||||
(error)="uploadError.emit($event)">
|
||||
</adf-version-upload>
|
||||
</div>
|
||||
<div class="adf-version-list-container">
|
||||
<adf-version-list
|
||||
#versionList
|
||||
[node]="node"
|
||||
[allowDownload]="allowDownload"
|
||||
[showComments]="showComments">
|
||||
</adf-version-list>
|
||||
<div class="adf-new-version-container">
|
||||
<div class="adf-new-version-uploader-container" fxLayout="row" fxLayoutAlign="end center" [@uploadToggle]="uploadState">
|
||||
<table class="adf-version-upload">
|
||||
<tr>
|
||||
<td>
|
||||
<adf-version-upload
|
||||
id="adf-version-upload-button"
|
||||
[node]="node"
|
||||
(success)="onUploadSuccess($event)"
|
||||
(cancel)="onUploadCancel()"
|
||||
(error)="uploadError.emit($event)">
|
||||
</adf-version-upload>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="adf-version-list-container">
|
||||
<div class="adf-version-list-table">
|
||||
<div>
|
||||
<button mat-raised-button
|
||||
id="adf-show-version-upload-button"
|
||||
(click)="toggleNewVersion()" color="primary"
|
||||
*ngIf="uploadState ==='close'">{{
|
||||
'ADF_VERSION_LIST.ACTIONS.UPLOAD.ADD'|
|
||||
translate }}
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<adf-version-list
|
||||
#versionList
|
||||
[node]="node"
|
||||
[allowDownload]="allowDownload"
|
||||
[showComments]="showComments">
|
||||
</adf-version-list>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1,8 +1,40 @@
|
||||
.adf-button.upload-new-version {
|
||||
box-shadow: none;
|
||||
width: 100%;
|
||||
height: 175px;
|
||||
float: left;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.adf-new-version-uploader-container {
|
||||
border-bottom:1px solid #d8d8d8;
|
||||
border-bottom: 1px solid #d8d8d8;
|
||||
padding: 16px 0;
|
||||
}
|
||||
width: 100%;
|
||||
height: 0%;
|
||||
|
||||
float: left;
|
||||
position: relative;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.adf-new-version-container {
|
||||
height: 800px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.adf-version-list-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.adf-version-upload-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.adf-version-list {
|
||||
width: 100% !important;
|
||||
float: left !important;
|
||||
}
|
||||
|
||||
.adf-new-version-uploader-container {
|
||||
float: left !important;
|
||||
}
|
||||
|
@@ -22,11 +22,13 @@ import { AlfrescoApiService, setupTestBed, CoreModule, AlfrescoApiServiceMock }
|
||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
import { VersionManagerComponent } from './version-manager.component';
|
||||
import { VersionListComponent } from './version-list.component';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
describe('VersionManagerComponent', () => {
|
||||
let component: VersionManagerComponent;
|
||||
let fixture: ComponentFixture<VersionManagerComponent>;
|
||||
let spyOnListVersionHistory: jasmine.Spy;
|
||||
let alfrescoApiService: AlfrescoApiService;
|
||||
|
||||
const expectedComment = 'test-version-comment';
|
||||
const node: MinimalNodeEntryEntity = {
|
||||
@@ -44,7 +46,8 @@ describe('VersionManagerComponent', () => {
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
CoreModule.forRoot()
|
||||
CoreModule.forRoot(),
|
||||
NoopAnimationsModule
|
||||
],
|
||||
declarations: [
|
||||
VersionManagerComponent,
|
||||
@@ -61,7 +64,7 @@ describe('VersionManagerComponent', () => {
|
||||
component = fixture.componentInstance;
|
||||
component.node = node;
|
||||
|
||||
const alfrescoApiService = TestBed.get(AlfrescoApiService);
|
||||
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
||||
spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
|
||||
.callFake(() => Promise.resolve({ list: { entries: [ versionEntry ] }}));
|
||||
});
|
||||
@@ -94,7 +97,7 @@ describe('VersionManagerComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should emit success event upon successful upload of a new version', () => {
|
||||
it('should emit success event upon successful upload of a new version', async(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const emittedData = { value: { entry: node }};
|
||||
@@ -102,5 +105,35 @@ describe('VersionManagerComponent', () => {
|
||||
expect(event).toBe(emittedData);
|
||||
});
|
||||
component.onUploadSuccess(emittedData);
|
||||
}));
|
||||
|
||||
it('should emit nodeUpdated event upon successful upload of a new version', (done) => {
|
||||
fixture.detectChanges();
|
||||
alfrescoApiService.nodeUpdated.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
const emittedData = { value: { entry: node }};
|
||||
component.onUploadSuccess(emittedData);
|
||||
});
|
||||
|
||||
describe('Animation', () => {
|
||||
|
||||
it('should upload button be hide by default', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.uploadState).toEqual('close');
|
||||
});
|
||||
|
||||
it('should upload button be visible after click on add new version button', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
let showUploadButton = fixture.debugElement.query(By.css('#adf-show-version-upload-button'));
|
||||
|
||||
showUploadButton.nativeElement.click();
|
||||
|
||||
expect(component.uploadState).toEqual('open');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -18,12 +18,27 @@
|
||||
import { Component, Input, ViewEncapsulation, ViewChild, Output, EventEmitter } from '@angular/core';
|
||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
import { VersionListComponent } from './version-list.component';
|
||||
import { AppConfigService, ContentService } from '@alfresco/adf-core';
|
||||
import { AppConfigService, ContentService, AlfrescoApiService } from '@alfresco/adf-core';
|
||||
import { trigger, state, style, animate, transition } from '@angular/animations';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-version-manager',
|
||||
templateUrl: './version-manager.component.html',
|
||||
styleUrls: ['./version-manager.component.scss'],
|
||||
animations: [
|
||||
trigger('uploadToggle', [
|
||||
state('open', style({ height: '175px', opacity: 1, visibility: 'visible' })),
|
||||
state('close', style({ height: '0%', opacity: 0, visibility: 'hidden' })),
|
||||
transition('open => close', [
|
||||
style({ visibility: 'hidden' }),
|
||||
animate('0.4s cubic-bezier(0.25, 0.8, 0.25, 1)')
|
||||
]),
|
||||
transition('close => open', [
|
||||
style({ visibility: 'visible' }),
|
||||
animate('0.4s cubic-bezier(0.25, 0.8, 0.25, 1)')
|
||||
])
|
||||
])
|
||||
],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class VersionManagerComponent {
|
||||
@@ -46,16 +61,28 @@ export class VersionManagerComponent {
|
||||
@ViewChild('versionList')
|
||||
versionListComponent: VersionListComponent;
|
||||
|
||||
constructor(
|
||||
config: AppConfigService,
|
||||
private contentService: ContentService) {
|
||||
uploadState: string = 'close';
|
||||
|
||||
constructor(config: AppConfigService,
|
||||
private contentService: ContentService,
|
||||
private alfrescoApiService: AlfrescoApiService) {
|
||||
this.showComments = config.get('adf-version-manager.allowComments', true);
|
||||
this.allowDownload = config.get('adf-version-manager.allowDownload', true);
|
||||
}
|
||||
|
||||
onUploadSuccess(event): void {
|
||||
onUploadSuccess(event) {
|
||||
this.alfrescoApiService.nodeUpdated.next(event.value.entry);
|
||||
this.versionListComponent.loadVersionHistory();
|
||||
this.uploadSuccess.emit(event);
|
||||
this.uploadState = 'close';
|
||||
}
|
||||
|
||||
onUploadCancel() {
|
||||
this.uploadState = 'close';
|
||||
}
|
||||
|
||||
toggleNewVersion() {
|
||||
this.uploadState = this.uploadState === 'open' ? 'close' : 'open';
|
||||
}
|
||||
|
||||
canUpdate(): boolean {
|
||||
|
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
@@ -30,12 +31,14 @@ import { UploadModule } from '../upload/upload.module';
|
||||
CommonModule,
|
||||
MaterialModule,
|
||||
TranslateModule,
|
||||
UploadModule
|
||||
UploadModule,
|
||||
FormsModule
|
||||
],
|
||||
exports: [
|
||||
VersionUploadComponent,
|
||||
VersionManagerComponent,
|
||||
VersionListComponent
|
||||
VersionListComponent,
|
||||
FormsModule
|
||||
],
|
||||
declarations: [
|
||||
VersionUploadComponent,
|
||||
|
@@ -1,12 +1,37 @@
|
||||
<adf-upload-version-button
|
||||
data-automation-id="adf-new-version-file-upload"
|
||||
class="adf-new-version-file-upload"
|
||||
staticTitle="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.TITLE' | translate }}"
|
||||
[node]="node"
|
||||
[disabled]="!canUpload()"
|
||||
[rootFolderId]="node.parentId"
|
||||
tooltip="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.TOOLTIP' | translate }}"
|
||||
[versioning]="true"
|
||||
(success)="success.emit($event)"
|
||||
(error)="error.emit($event)">
|
||||
</adf-upload-version-button>
|
||||
<div class="adf-new-version-max-width">
|
||||
<mat-radio-group class="adf-new-version-radio-group" [(ngModel)]="semanticVersion">
|
||||
<mat-radio-button class="adf-new-version-radio-button" [value]="'minor'">{{
|
||||
'ADF_VERSION_LIST.ACTIONS.UPLOAD.MINOR' |
|
||||
translate }}
|
||||
</mat-radio-button>
|
||||
<mat-radio-button class="adf-new-version-radio-button" [value]="'major'">{{
|
||||
'ADF_VERSION_LIST.ACTIONS.UPLOAD.MAJOR' |
|
||||
translate }}
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
<mat-form-field class="adf-new-version-max-width">
|
||||
<input matInput [(ngModel)]="comment"
|
||||
placeholder="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.COMMENT' | translate }}">
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<button mat-raised-button (click)="cancelUpload()" class="adf-cancel-button">{{
|
||||
'ADF_VERSION_LIST.ACTIONS.UPLOAD.CANCEL'| translate }}
|
||||
</button>
|
||||
<adf-upload-version-button
|
||||
data-automation-id="adf-new-version-file-upload"
|
||||
class="adf-new-version-file-upload"
|
||||
staticTitle="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.TITLE' | translate }}"
|
||||
[node]="node"
|
||||
[disabled]="!canUpload()"
|
||||
[rootFolderId]="node.parentId"
|
||||
tooltip="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.TOOLTIP' | translate }}"
|
||||
[comment]="comment"
|
||||
[versioning]="true"
|
||||
[majorVersion]="isMajorVersion()"
|
||||
(success)="success.emit($event)"
|
||||
(error)="error.emit($event)">
|
||||
</adf-upload-version-button>
|
||||
</div>
|
||||
|
||||
|
@@ -0,0 +1,22 @@
|
||||
.adf-new-version-radio-group {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.adf-new-version-radio-button {
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.adf-cancel-button {
|
||||
margin-left: 20px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.adf-new-version-file-upload {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.adf-new-version-max-width {
|
||||
width: 100%;
|
||||
float: right;
|
||||
}
|
@@ -22,11 +22,16 @@ import { ContentService } from '@alfresco/adf-core';
|
||||
@Component({
|
||||
selector: 'adf-version-upload',
|
||||
templateUrl: './version-upload.component.html',
|
||||
styleUrls: ['./version-upload.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { 'class': 'adf-version-upload' }
|
||||
})
|
||||
export class VersionUploadComponent {
|
||||
|
||||
semanticVersion: string = 'minor';
|
||||
comment: string;
|
||||
uploadVersion: boolean = false;
|
||||
|
||||
@Input()
|
||||
node: MinimalNodeEntryEntity;
|
||||
|
||||
@@ -36,6 +41,9 @@ export class VersionUploadComponent {
|
||||
@Output()
|
||||
error = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
cancel = new EventEmitter();
|
||||
|
||||
constructor(private contentService: ContentService) {
|
||||
}
|
||||
|
||||
@@ -43,4 +51,12 @@ export class VersionUploadComponent {
|
||||
return this.contentService.hasPermission(this.node, 'update');
|
||||
}
|
||||
|
||||
isMajorVersion(): boolean {
|
||||
return this.semanticVersion === 'minor' ? false : true;
|
||||
}
|
||||
|
||||
cancelUpload() {
|
||||
this.cancel.emit();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user