Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACA-45] Drag and Drop a New Version #5710

Merged
merged 20 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
de1fd28
added a new input: file
ursedaniel May 18, 2020
265cd03
unit test - having singleFile option and a file as input, the type of…
ursedaniel May 18, 2020
54eff80
added a click event for the upload button and also handle if having a…
ursedaniel May 18, 2020
7bd8bbb
handling allowed for upload also for 'update' permissions over a drop…
ursedaniel May 18, 2020
85b2431
unit tests for handling dropping a file over another
ursedaniel May 18, 2020
5be088e
added a new input (file type)
ursedaniel May 18, 2020
74daa97
passing a file to adf-version-upload component
ursedaniel May 18, 2020
fd07b23
new input as file and toggle new version if having that as input + un…
ursedaniel May 18, 2020
2c40f44
added new input as file for new version
ursedaniel May 18, 2020
e2c75c7
added new input to allow dropping a file over another to update it's …
ursedaniel May 18, 2020
48a9197
added a new variable for handling dropping a file over another one an…
ursedaniel May 18, 2020
8ad133e
pass a new dropped file to the dialog
ursedaniel May 18, 2020
2a8b9dc
new message
ursedaniel May 18, 2020
7522aef
new method to allow isDropTarget for a file instead only to folders.
ursedaniel May 18, 2020
bbcf9f0
new emitter for updating a file's version
ursedaniel May 18, 2020
aeb9b7e
allows updating a file's version by dropping another file over it.
ursedaniel May 18, 2020
2a874ed
refactor allowDropFiles
eromano May 18, 2020
1099ed1
update docs for drag&drop file into another file
ursedaniel May 18, 2020
cca69eb
update for drag&drop a file over another file functionality
ursedaniel May 18, 2020
6999e86
made the allowDropFiles checking optional for isDropTarget property, …
ursedaniel May 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions demo-shell/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"MULTISELECT_CHECKBOXES": "Multiselect (with checkboxes)",
"THUMBNAILS": "Enable Thumbnails",
"ALLOW_DROP_FILES": "Enable Drop Files in a folder",
"ALLOW_DROP_FILE_VERSION": "Enable Drop File in a file to change version",
"MULTIPLE_FILE_UPLOAD": "Multiple File Upload",
"FOLDER_UPLOAD": "Folder upload",
"CUSTOM_FILTER": "Custom extensions filter",
Expand Down
11 changes: 10 additions & 1 deletion demo-shell/src/app/components/files/files.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
[versioning]="versioning"
[adf-check-allowable-operation]="'create'"
[adf-nodes]="disableDragArea ? getCurrentDocumentListNode() : []"
(beginUpload)="onBeginUpload($event)">
(beginUpload)="onBeginUpload($event)"
(updateFileVersion)="onUploadNewVersion($event)">
<div *ngIf="errorMessage" class="app-error-message">
<button (click)="resetError()" mat-icon-button>
<mat-icon>highlight_off</mat-icon>
Expand Down Expand Up @@ -226,6 +227,7 @@
[contextMenuActions]="true"
[contentActions]="true"
[allowDropFiles]="allowDropFiles"
[allowDropFileVersion]="allowDropFileVersion"
[selectionMode]="selectionMode"
[multiselect]="multiselect"
[display]="displayMode"
Expand Down Expand Up @@ -571,6 +573,13 @@ <h1>You don't have permissions</h1>
</mat-slide-toggle>
</section>

<section>
<mat-slide-toggle id="adf-document-list-enable-drop-file-version" [color]="'primary'" [(ngModel)]="allowDropFileVersion"
(click)="toggleAllowDropFileVersion()">
{{'DOCUMENT_LIST.ALLOW_DROP_FILE_VERSION' | translate}}
</mat-slide-toggle>
</section>

<section>
<mat-slide-toggle id="adf-version-upload-switch" [color]="'primary'" [(ngModel)]="versioning">
{{'DOCUMENT_LIST.ENABLE_VERSIONING' | translate}}
Expand Down
36 changes: 31 additions & 5 deletions demo-shell/src/app/components/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
showViewer = false;
showVersions = false;
allowDropFiles = true;
allowDropFileVersion = true;
displayMode = DisplayMode.List;
includeFields = ['isFavorite', 'isLocked', 'aspectNames'];

Expand All @@ -75,9 +76,9 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
toolbarColor = 'default';

selectionModes = [
{ value: 'none', viewValue: 'None' },
{ value: 'single', viewValue: 'Single' },
{ value: 'multiple', viewValue: 'Multiple' }
{value: 'none', viewValue: 'None'},
{value: 'single', viewValue: 'Single'},
{value: 'multiple', viewValue: 'Multiple'}
];

// The identifier of a node. You can also use one of these well-known aliases: -my- | -shared- | -root-
Expand Down Expand Up @@ -240,6 +241,10 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
this.documentList.reload();
}

toggleAllowDropFileVersion() {
this.documentList.reload();
}

ngOnInit() {
if (!this.pagination) {
this.pagination = <Pagination> {
Expand Down Expand Up @@ -322,7 +327,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {

getCurrentDocumentListNode(): MinimalNodeEntity[] {
if (this.documentList.folderNode) {
return [{ entry: this.documentList.folderNode }];
return [{entry: this.documentList.folderNode}];
} else {
return [];
}
Expand Down Expand Up @@ -427,7 +432,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {

if (this.contentService.hasAllowableOperations(contentEntry, 'update')) {
this.dialog.open(VersionManagerDialogAdapterComponent, {
data: { contentEntry: contentEntry, showComments: showComments, allowDownload: allowDownload },
data: {contentEntry: contentEntry, showComments: showComments, allowDownload: allowDownload},
panelClass: 'adf-version-manager-dialog',
width: '630px'
});
Expand Down Expand Up @@ -591,6 +596,27 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
this.logService.log(event);
}

onUploadNewVersion(ev) {
ursedaniel marked this conversation as resolved.
Show resolved Hide resolved
const contentEntry = ev.detail.data.node.entry;
const showComments = this.showVersionComments;
const allowDownload = this.allowVersionDownload;
const newFileVersion = ev.detail.files[0].file;

if (this.contentService.hasAllowableOperations(contentEntry, 'update')) {
this.dialog.open(VersionManagerDialogAdapterComponent, {
data: {
contentEntry: contentEntry, showComments: showComments, allowDownload: allowDownload,
newFileVersion: newFileVersion, showComparison: true
},
panelClass: 'adf-version-manager-dialog',
width: '630px'
});
} else {
const translatedErrorMessage: any = this.translateService.instant('OPERATION.ERROR.PERMISSION');
this.openSnackMessage(translatedErrorMessage);
}
}

getFileFiltering(): string {
return this.acceptedFilesTypeShow ? this.acceptedFilesType : '*';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</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" [newFileVersion]="newFileVersion" [allowDownload]="allowDownload" [showComments]="showComments" (uploadError)="uploadError($event)"></adf-version-manager>
</section>
<section mat-dialog-content *ngIf="readOnly">
<adf-version-list [node]="contentEntry" [showActions]="false" ></adf-version-list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
export class VersionManagerDialogAdapterComponent {

public contentEntry: MinimalNodeEntryEntity;
public newFileVersion: File;

showComments = true;
allowDownload = true;
Expand All @@ -36,6 +37,7 @@ export class VersionManagerDialogAdapterComponent {
private snackBar: MatSnackBar,
private containingDialog?: MatDialogRef<VersionManagerDialogAdapterComponent>) {
this.contentEntry = data.contentEntry;
this.newFileVersion = data.hasOwnProperty('newFileVersion') ? data.newFileVersion : this.newFileVersion;
this.showComments = data.hasOwnProperty('showComments') ? data.showComments : this.showComments;
this.allowDownload = data.hasOwnProperty('allowDownload') ? data.allowDownload : this.allowDownload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[actionsPosition]="contentActionsPosition"
[multiselect]="multiselect"
[allowDropFiles]="allowDropFiles"
[allowDropFileVersion]="allowDropFileVersion"
[contextMenu]="contextMenuActions"
[rowStyle]="rowStyle"
[rowStyleClass]="rowStyleClass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
@Input()
emptyFolderImageUrl: string = './assets/images/empty_doc_lib.svg';

/**
* When true, this enables you to drop one file directly into a file
* as item in the list and then create a new version for that file.
* When false, the dropped file will be added to the
* current folder (ie, the one containing all the items shown in the list).
* See the Upload directive for further details about how the file drop is
* handled.
*/
@Input()
allowDropFileVersion: boolean = false;

/**
* When true, this enables you to drop files directly into subfolders shown
* as items in the list. When false, the dropped file will be added to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export class ShareDataRow implements DataRow {
throw new Error(ShareDataRow.ERR_OBJECT_NOT_FOUND);
}

this.isDropTarget = this.isFolderAndHasPermissionToUpload(obj);

this.isDropTarget = this.isFolderAndHasPermissionToUpload(obj) || this.isFileAndHasParentFolderPermissionToUpload(obj);
if (permissionsStyle) {
this.cssClass = this.getPermissionClass(obj);
}
Expand Down Expand Up @@ -81,6 +80,14 @@ export class ShareDataRow implements DataRow {
return this.isFolder(nodeEntry) && this.contentService.hasAllowableOperations(nodeEntry.entry, 'create');
}

isFileAndHasParentFolderPermissionToUpload(nodeEntry: NodeEntry): boolean {
return this.isFile(nodeEntry) && this.contentService.hasAllowableOperations(nodeEntry.entry, 'update');
}

isFile(nodeEntry: NodeEntry): boolean {
return nodeEntry.entry && nodeEntry.entry.isFile;
}

isFolder(nodeEntry: NodeEntry): boolean {
return nodeEntry.entry && nodeEntry.entry.isFolder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export abstract class UploadBase implements OnInit, OnDestroy {
@Output()
beginUpload = new EventEmitter<UploadFilesEvent>();

/** Emitted when dropping a file over another file to update the version. */
@Output()
updateFileVersion = new EventEmitter<CustomEvent>();

protected onDestroy$ = new Subject<boolean>();

constructor(protected uploadService: UploadService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
<input #uploadSingleFile
id="upload-single-file"
data-automation-id="upload-single-file"
type="file"
[type]="file ? 'button' : 'file'"
name="uploadFiles"
accept="{{acceptedFilesType}}"
[attr.disabled]="isButtonDisabled()"
[title]="tooltip"
(change)="onFilesAdded($event)">
(change)="onFilesAdded($event)"
(click)="onClickUploadButton()">
</button>

<!--Multiple Files Upload-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ describe('UploadButtonComponent', () => {
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
});

it('should have input type as button if receiving a file as input', () => {
component.multipleFiles = false;
component.file = new File([], 'Fake file name');
const compiled = fixture.debugElement.nativeElement;
fixture.detectChanges();
const inputButton = compiled.querySelector('#upload-single-file');
expect(inputButton.type).toBe('button');

component.file = undefined;
fixture.detectChanges();
expect(inputButton.type).toBe('file');
});

it('should disable uploadFolder button if disabled is true', () => {
component.disabled = true;
component.uploadFolders = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
@Input()
tooltip: string = null;

/** Custom added file. The upload button type will be 'button' instead of 'file' */
@Input()
file: File;

/** Emitted when create permission is missing. */
@Output()
permissionEvent: EventEmitter<PermissionModel> = new EventEmitter<PermissionModel>();
Expand Down Expand Up @@ -100,6 +104,16 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
$event.target.value = '';
}

onClickUploadButton(): void {
const files: File[] = [this.file];

if (this.hasAllowableOperations) {
this.uploadFiles(files);
} else {
this.permissionEvent.emit(new PermissionModel({ type: 'content', action: 'upload', permission: 'create' }));
}
}

onDirectoryAdded($event: any): void {
if (this.hasAllowableOperations) {
const files: File[] = FileUtils.toFileArray($event.currentTarget.files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,34 @@ describe('UploadDragAreaComponent', () => {
});
}));

it('should NOT upload the file if it is dropped on another file', () => {
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
name: 'file-fake.png',
relativeFolder: '/',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};

addToQueueSpy.and.callFake((fileList) => {
expect(fileList.name).toBe('file');
expect(fileList.options.path).toBe('pippo/');
});

const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
}
});

component.onUploadFiles(fakeCustomEvent);
});

it('should not upload a file if fileType is not in acceptedFilesType', async(() => {
component.success = null;
component.acceptedFilesType = '.pdf';
Expand Down Expand Up @@ -369,8 +397,8 @@ describe('UploadDragAreaComponent', () => {
component.onUploadFiles(fakeCustomEvent);
}));

it('should upload the file in the current folder when the target is file', async(() => {

it('should trigger updating the file version when we drop a file over another file', async(() => {
spyOn(component.updateFileVersion, 'emit');
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
Expand All @@ -396,6 +424,7 @@ describe('UploadDragAreaComponent', () => {
});

component.onUploadFiles(fakeCustomEvent);
expect(component.updateFileVersion.emit).toHaveBeenCalledWith(fakeCustomEvent);
}));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import { UploadBase } from './base-upload/upload-base';
selector: 'adf-upload-drag-area',
templateUrl: './upload-drag-area.component.html',
styleUrls: ['./upload-drag-area.component.scss'],
host: { 'class': 'adf-upload-drag-area' },
host: {'class': 'adf-upload-drag-area'},
viewProviders: [
{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadDragAreaComponent) }
{provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadDragAreaComponent)}
],
encapsulation: ViewEncapsulation.None
})
Expand Down Expand Up @@ -94,15 +94,21 @@ export class UploadDragAreaComponent extends UploadBase implements NodeAllowable
onUploadFiles(event: CustomEvent) {
event.stopPropagation();
event.preventDefault();
const isAllowed: boolean = this.contentService.hasAllowableOperations(event.detail.data.obj.entry, AllowableOperationsEnum.CREATE);
const isAllowed: boolean = this.isTargetNodeFolder(event) ?
this.contentService.hasAllowableOperations(event.detail.data.obj.entry, AllowableOperationsEnum.CREATE)
: this.contentService.hasAllowableOperations(event.detail.data.obj.entry, AllowableOperationsEnum.UPDATE);
if (isAllowed) {
const fileInfo: FileInfo[] = event.detail.files;
if (this.isTargetNodeFolder(event)) {
const destinationFolderName = event.detail.data.obj.entry.name;
fileInfo.map((file) => file.relativeFolder = destinationFolderName ? destinationFolderName.concat(file.relativeFolder) : file.relativeFolder);
}
if (fileInfo && fileInfo.length > 0) {
this.uploadFilesInfo(fileInfo);
if (!this.isTargetNodeFolder(event) && event.detail.files.length === 1) {
this.updateFileVersion.emit(event);
} else {
const fileInfo: FileInfo[] = event.detail.files;
if (this.isTargetNodeFolder(event)) {
const destinationFolderName = event.detail.data.obj.entry.name;
fileInfo.map((file) => file.relativeFolder = destinationFolderName ? destinationFolderName.concat(file.relativeFolder) : file.relativeFolder);
}
if (fileInfo && fileInfo.length > 0) {
this.uploadFilesInfo(fileInfo);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class UploadVersionButtonComponent extends UploadButtonComponent implemen
@Input()
node: Node;

/** (**Required**) The drag&dropped new file to be versioned. */
@Input()
newFileVersion: File;
ursedaniel marked this conversation as resolved.
Show resolved Hide resolved

protected createFileModel(file: File): FileModel {
const fileModel = super.createFileModel(file, this.rootFolderId, ((<any> file).webkitRelativePath || '').replace(/\/[^\/]*$/, ''), this.node.id);

Expand All @@ -47,6 +51,7 @@ export class UploadVersionButtonComponent extends UploadButtonComponent implemen
}

ngOnInit() {
this.file = this.newFileVersion;
ursedaniel marked this conversation as resolved.
Show resolved Hide resolved
super.ngOnInit();
this.checkPermission();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<adf-version-upload
id="adf-version-upload-button"
[node]="node"
[newFileVersion]="newFileVersion"
(success)="onUploadSuccess($event)"
(cancel)="onUploadCancel()"
(error)="onUploadError($event)">
Expand Down