mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-08-07 17:48:54 +00:00
[ADF-610] Upload button and DnD area should not upload hidden files and folders (#1908)
[ADF-610] upload cleanup - more strongly typing - api improvements * Upload cleanup and api improvements - remove old unused settings (formFields variable) - individual options for uploaded files (i.e. versioning) - upload button and drag-and-drop area now set individual settings for file versioning * exclude hidden files from upload
This commit is contained in:
committed by
Eugenio Romano
parent
2e1649e1da
commit
9bb7d90670
@@ -50,10 +50,7 @@ describe('FileUploadingDialogComponent', () => {
|
||||
beforeEach(() => {
|
||||
window['componentHandler'] = null;
|
||||
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
const fileFake = new File([''], 'fake-name');
|
||||
file = new FileModel(fileFake);
|
||||
|
||||
fixture = TestBed.createComponent(FileUploadingDialogComponent);
|
||||
@@ -80,7 +77,7 @@ describe('FileUploadingDialogComponent', () => {
|
||||
});
|
||||
|
||||
it('should render dialog box with css class show when an element is added to Observer', () => {
|
||||
uploadService.addToQueue([<File> { name: 'file' }]);
|
||||
uploadService.addToQueue(new FileModel(<File> { name: 'file' }));
|
||||
component.filesUploadingList = [file];
|
||||
|
||||
fixture.detectChanges();
|
||||
|
@@ -127,8 +127,6 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
if (rootFolderId && rootFolderId.currentValue) {
|
||||
this.checkPermission();
|
||||
}
|
||||
let formFields = this.createFormFields();
|
||||
this.uploadService.setOptions(formFields, this.versioning);
|
||||
}
|
||||
|
||||
isButtonDisabled(): boolean {
|
||||
@@ -186,7 +184,7 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
this.onError.emit({value: errorMessagePlaceholder});
|
||||
let errorMessage = this.formatString(errorMessagePlaceholder, [directoryName]);
|
||||
if (errorMessage) {
|
||||
this._showErrorNotificationBar(errorMessage);
|
||||
this.showErrorNotificationBar(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,12 +202,13 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
* @param path
|
||||
* @param files
|
||||
*/
|
||||
uploadFiles(path: string, files: any[]) {
|
||||
uploadFiles(path: string, files: File[]): void {
|
||||
if (files.length) {
|
||||
let latestFilesAdded = this.uploadService.addToQueue(files);
|
||||
const latestFilesAdded = files.map(f => new FileModel(f, { newVersion: this.versioning }));
|
||||
this.uploadService.addToQueue(...latestFilesAdded);
|
||||
this.uploadService.uploadFilesInTheQueue(this.rootFolderId, path, this.onSuccess);
|
||||
if (this.showNotificationBar) {
|
||||
this._showUndoNotificationBar(latestFilesAdded);
|
||||
this.showUndoNotificationBar(latestFilesAdded);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,8 +219,8 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
* @param files - array of files
|
||||
* @returns {Map}
|
||||
*/
|
||||
private convertIntoHashMap(files: any[]) {
|
||||
let directoryMap = new Map<string, Object[]>();
|
||||
private convertIntoHashMap(files: File[]): Map<string, File[]> {
|
||||
let directoryMap = new Map<string, File[]>();
|
||||
for (let file of files) {
|
||||
let directory = this.getDirectoryPath(file.webkitRelativePath);
|
||||
let filesSomeDir = directoryMap.get(directory) || [];
|
||||
@@ -236,7 +235,7 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
* @param directory
|
||||
* @returns {string}
|
||||
*/
|
||||
private getDirectoryPath(directory: string) {
|
||||
private getDirectoryPath(directory: string): string {
|
||||
let relativeDirPath = '';
|
||||
let dirPath = directory.split('/');
|
||||
if (dirPath.length > 1) {
|
||||
@@ -251,7 +250,7 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
* @param directory
|
||||
* @returns {string}
|
||||
*/
|
||||
private getDirectoryName(directory: string) {
|
||||
private getDirectoryName(directory: string): string {
|
||||
let dirPath = directory.split('/');
|
||||
if (dirPath.length > 1) {
|
||||
return dirPath.pop();
|
||||
@@ -265,7 +264,7 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
*
|
||||
* @param {FileModel[]} latestFilesAdded - files in the upload queue enriched with status flag and xhr object.
|
||||
*/
|
||||
private _showUndoNotificationBar(latestFilesAdded: FileModel[]) {
|
||||
private showUndoNotificationBar(latestFilesAdded: FileModel[]): void {
|
||||
let messageTranslate: any, actionTranslate: any;
|
||||
messageTranslate = this.translateService.get('FILE_UPLOAD.MESSAGES.PROGRESS');
|
||||
actionTranslate = this.translateService.get('FILE_UPLOAD.ACTION.UNDO');
|
||||
@@ -295,7 +294,7 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
* @param Error message
|
||||
* @private
|
||||
*/
|
||||
private _showErrorNotificationBar(errorMessage: string) {
|
||||
private showErrorNotificationBar(errorMessage: string): void {
|
||||
this.notificationService.openSnackMessage(errorMessage, 3000);
|
||||
}
|
||||
|
||||
@@ -305,7 +304,7 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
* @param keys - array of value
|
||||
* @returns {string} - The message without placeholder
|
||||
*/
|
||||
private formatString(message: string, keys: any []) {
|
||||
private formatString(message: string, keys: any []): string {
|
||||
let i = keys.length;
|
||||
while (i--) {
|
||||
message = message.replace(new RegExp('\\{' + i + '\\}', 'gm'), keys[i]);
|
||||
@@ -313,14 +312,6 @@ export class UploadButtonComponent implements OnInit, OnChanges {
|
||||
return message;
|
||||
}
|
||||
|
||||
private createFormFields(): any {
|
||||
return {
|
||||
formFields: {
|
||||
overwrite: true
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
checkPermission() {
|
||||
if (this.rootFolderId) {
|
||||
this.uploadService.getFolderNode(this.rootFolderId).subscribe(
|
||||
|
@@ -22,6 +22,7 @@ import { AlfrescoTranslationService, CoreModule, LogService, LogServiceMock, Not
|
||||
import { UploadDragAreaComponent } from './upload-drag-area.component';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { FileModel } from '../models/file.model';
|
||||
|
||||
describe('UploadDragAreaComponent', () => {
|
||||
|
||||
@@ -73,11 +74,12 @@ describe('UploadDragAreaComponent', () => {
|
||||
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
fixture.detectChanges();
|
||||
let fileFake = <File> {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
const file = <File> {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
let fileFake = new FileModel(file);
|
||||
let filesList = [fileFake];
|
||||
|
||||
component.onFilesDropped(filesList);
|
||||
expect(uploadService.addToQueue).toHaveBeenCalledWith(filesList);
|
||||
expect(uploadService.addToQueue).toHaveBeenCalledWith(fileFake);
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith('-root-', '/root-fake-/sites-fake/folder-fake', null);
|
||||
});
|
||||
|
||||
@@ -89,7 +91,7 @@ describe('UploadDragAreaComponent', () => {
|
||||
component.showUndoNotificationBar = jasmine.createSpy('_showUndoNotificationBar');
|
||||
|
||||
fixture.detectChanges();
|
||||
let fileFake = <File> {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
let fileFake = new FileModel(<File> {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'});
|
||||
let filesList = [fileFake];
|
||||
|
||||
component.onFilesDropped(filesList);
|
||||
|
@@ -66,11 +66,6 @@ export class UploadDragAreaComponent {
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes) {
|
||||
let formFields = this.createFormFields();
|
||||
this.uploadService.setOptions(formFields, this.versioning);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles 'upload-files' events raised by child components.
|
||||
* @param e DOM event
|
||||
@@ -79,13 +74,14 @@ export class UploadDragAreaComponent {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
let files = e.detail.files;
|
||||
let files: File[] = e.detail.files;
|
||||
if (files && files.length > 0) {
|
||||
const fileModels = files.map(f => new FileModel(f, { newVersion: this.versioning }));
|
||||
if (e.detail.data.obj.entry.isFolder) {
|
||||
let id = e.detail.data.obj.entry.id;
|
||||
this.onFilesDropped(files, id, '/');
|
||||
this.onFilesDropped(fileModels, id, '/');
|
||||
} else {
|
||||
this.onFilesDropped(files);
|
||||
this.onFilesDropped(fileModels);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,9 +91,9 @@ export class UploadDragAreaComponent {
|
||||
*
|
||||
* @param {File[]} files - files dropped in the drag area.
|
||||
*/
|
||||
onFilesDropped(files: File[], rootId?: string, directory?: string): void {
|
||||
onFilesDropped(files: FileModel[], rootId?: string, directory?: string): void {
|
||||
if (files.length) {
|
||||
this.uploadService.addToQueue(files);
|
||||
this.uploadService.addToQueue(...files);
|
||||
this.uploadService.uploadFilesInTheQueue(rootId || this.rootFolderId, directory || this.currentFolderPath, this.onSuccess);
|
||||
let latestFilesAdded = this.uploadService.getQueue();
|
||||
if (this.showNotificationBar) {
|
||||
@@ -111,8 +107,9 @@ export class UploadDragAreaComponent {
|
||||
* @param item - FileEntity
|
||||
*/
|
||||
onFilesEntityDropped(item: any): void {
|
||||
item.file((file: any) => {
|
||||
this.uploadService.addToQueue([file]);
|
||||
item.file((file: File) => {
|
||||
const fileModel = new FileModel(file, { newVersion: this.versioning });
|
||||
this.uploadService.addToQueue(fileModel);
|
||||
let path = item.fullPath.replace(item.name, '');
|
||||
let filePath = this.currentFolderPath + path;
|
||||
this.uploadService.uploadFilesInTheQueue(this.rootFolderId, filePath, this.onSuccess);
|
||||
@@ -228,12 +225,4 @@ export class UploadDragAreaComponent {
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
private createFormFields(): any {
|
||||
return {
|
||||
formFields: {
|
||||
overwrite: true
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user