Skip to content

Commit

Permalink
[ACA-45] Drag and Drop a New Version (#5710)
Browse files Browse the repository at this point in the history
* added a new input: file

* unit test - having singleFile option and a file as input, the type of the input for uploading should be button instead of file

* added a click event for the upload button and also handle if having a file as input, the type of the input should be 'button' instead of 'file'

* handling allowed for upload also for 'update' permissions over a dropped file. also emitting a new event for updating file version if i'm dropping a single file over another file.

* unit tests for handling dropping a file over another

* added a new input (file type)

* passing a file to adf-version-upload component

* new input as file and toggle new version if having that as input + unit test

* added new input as file for new version

* added new input to allow dropping a file over another to update it's version

* added a new variable for handling dropping a file over another one and also handle a new event when we update the file version

* pass a new dropped file to the dialog

* new message

* new method to allow isDropTarget for a file instead only to folders.

* new emitter for updating a file's version

* allows updating a file's version by dropping another file over it.

* refactor allowDropFiles

* update docs for drag&drop file into another file

* update for drag&drop a file over another file functionality

* made the allowDropFiles checking optional for isDropTarget property, only checking if the value is passed to the share-data-row

Co-authored-by: Eugenio Romano <eugenio.romano@alfresco.com>
  • Loading branch information
ursedaniel and eromano committed May 20, 2020
1 parent 531d1d7 commit 4cb3a87
Show file tree
Hide file tree
Showing 28 changed files with 185 additions and 53 deletions.
2 changes: 1 addition & 1 deletion demo-shell/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"DOCUMENT_LIST": {
"MULTISELECT_CHECKBOXES": "Multiselect (with checkboxes)",
"THUMBNAILS": "Enable Thumbnails",
"ALLOW_DROP_FILES": "Enable Drop Files in a folder",
"ALLOW_DROP_FILES": "Enable Drop Files in a folder or a file",
"MULTIPLE_FILE_UPLOAD": "Multiple File Upload",
"FOLDER_UPLOAD": "Folder upload",
"CUSTOM_FILTER": "Custom extensions filter",
Expand Down
7 changes: 4 additions & 3 deletions 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 @@ -565,8 +566,8 @@ <h1>You don't have permissions</h1>
</section>

<section>
<mat-slide-toggle id="adf-document-list-enable-drop-files" [color]="'primary'" [(ngModel)]="allowDropFiles"
(click)="toggleAllowDropFiles()">
<mat-slide-toggle id="adf-document-list-enable-drop-files" [color]="'primary'" [checked]="allowDropFiles"
(change)="toggleAllowDropFiles()">
{{'DOCUMENT_LIST.ALLOW_DROP_FILES' | translate}}
</mat-slide-toggle>
</section>
Expand Down
32 changes: 27 additions & 5 deletions demo-shell/src/app/components/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,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 @@ -237,6 +237,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
}

toggleAllowDropFiles() {
this.allowDropFiles = !this.allowDropFiles;
this.documentList.reload();
}

Expand Down Expand Up @@ -322,7 +323,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 +428,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 +592,27 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
this.logService.log(event);
}

onUploadNewVersion(ev) {
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 @@ -56,7 +56,7 @@ Displays the documents from a repository.

| Name | Type | Default value | Description |
| ---- | ---- | ------------- | ----------- |
| allowDropFiles | `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 current folder (ie, the one containing all the items shown in the list). See the [Upload directive](../../core/directives/upload.directive.md) for further details about how the file drop is handled. |
| allowDropFiles | `boolean` | false | When true, this enables you to drop files directly into subfolders shown as items in the list or into another file to trigger updating it's version. 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](../../core/directives/upload.directive.md) for further details about how the file drop is handled. |
| contentActions | `boolean` | false | Toggles content actions for each row |
| contentActionsPosition | `string` | "right" | Position of the content actions dropdown menu. Can be set to "left" or "right". |
| contextMenuActions | `boolean` | false | Toggles context menus for each row |
Expand Down
2 changes: 2 additions & 0 deletions docs/content-services/components/upload-button.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Activates a file upload.
| acceptedFilesType | `string` | "\*" | Filter for accepted file types. |
| comment | `string` | | When you overwrite existing content, you can use the comment field to add a version comment that appears in the version history |
| disabled | `boolean` | false | Toggles component disabled state (if there is no node permission checking). |
| file | `File` | | Custom added file. The upload button type will be 'button' instead of 'file' |
| majorVersion | `boolean` | false | majorVersion boolean field to true to indicate a major version should be created. |
| maxFilesSize | `number` | | Sets a limit on the maximum size (in bytes) of a file to be uploaded. Has no effect if undefined. |
| multipleFiles | `boolean` | false | Allows/disallows multiple files |
Expand All @@ -50,6 +51,7 @@ Activates a file upload.
| error | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<>` | Emitted when an error occurs. |
| permissionEvent | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`PermissionModel`](../../../lib/content-services/src/lib/document-list/models/permissions.model.ts)`>` | Emitted when create permission is missing. |
| success | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<>` | Emitted when the file is uploaded successfully. |
| updateFileVersion | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<CustomEvent<any>>` | Emitted when dropping a file over another file to update the version. |

## Details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ as the drag/drop target:
| beginUpload | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`UploadFilesEvent`](../../../lib/content-services/src/lib/upload/components/upload-files.event.ts)`>` | Emitted when the upload begins. |
| error | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<>` | Emitted when an error occurs. |
| success | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<>` | Emitted when the file is uploaded successfully. |
| updateFileVersion | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<CustomEvent<any>>` | Emitted when dropping a file over another file to update the version. |

## Details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ to enrich the features and decrease the restrictions currently applied to node v
| acceptedFilesType | `string` | "\*" | Filter for accepted file types. |
| comment | `string` | | When you overwrite existing content, you can use the comment field to add a version comment that appears in the version history |
| disabled | `boolean` | false | Toggles component disabled state (if there is no node permission checking). |
| file | `File` | | Custom added file. The upload button type will be 'button' instead of 'file' |
| majorVersion | `boolean` | false | majorVersion boolean field to true to indicate a major version should be created. |
| maxFilesSize | `number` | | Sets a limit on the maximum size (in bytes) of a file to be uploaded. Has no effect if undefined. |
| multipleFiles | `boolean` | false | Allows/disallows multiple files |
Expand All @@ -53,6 +54,7 @@ to enrich the features and decrease the restrictions currently applied to node v
| error | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<>` | Emitted when an error occurs. |
| permissionEvent | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`PermissionModel`](../../../lib/content-services/src/lib/document-list/models/permissions.model.ts)`>` | Emitted when create permission is missing. |
| success | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<>` | Emitted when the file is uploaded successfully. |
| updateFileVersion | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<CustomEvent<any>>` | Emitted when dropping a file over another file to update the version. |

## Details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Displays the version history of a node with the ability to upload a new version.
| Name | Type | Default value | Description |
| ---- | ---- | ------------- | ----------- |
| allowDownload | `boolean` | true | Enable/disable downloading a version of the current node. |
| newFileVersion | `File` | | New file for updating current version. |
| node | [`Node`](https://github.com/Alfresco/alfresco-js-api/blob/development/src/api/content-rest-api/docs/Node.md) | | Target node to manage version history. |
| showComments | `boolean` | true | Toggles showing/hiding of comments. |

Expand Down
1 change: 0 additions & 1 deletion docs/core/components/datatable.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ Learm more about styling your datatable: [Customizing the component's styles](#c
| ---- | ---- | ------------- | ----------- |
| actions | `boolean` | false | Toggles the data actions column. |
| actionsPosition | `string` | "right" | Position of the actions dropdown menu. Can be "left" or "right". |
| allowDropFiles | `boolean` | false | Toggles file drop support for rows (see [Upload directive](upload.directive.md) for further details). |
| columns | `any[]` | \[] | The columns that the datatable will show. |
| contextMenu | `boolean` | false | Toggles custom context menu for the component. |
| data | [`DataTableAdapter`](../../../lib/core/datatable/data/datatable-adapter.ts) | | Data source for the table |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[actions]="contentActions"
[actionsPosition]="contentActionsPosition"
[multiselect]="multiselect"
[allowDropFiles]="allowDropFiles"
[contextMenu]="contextMenuActions"
[rowStyle]="rowStyle"
[rowStyleClass]="rowStyleClass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { takeUntil } from 'rxjs/operators';
styleUrls: ['./document-list.component.scss'],
templateUrl: './document-list.component.html',
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-document-list' }
host: {class: 'adf-document-list'}
})
export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, AfterContentInit, PaginatedComponent, NavigableComponentInterface {

Expand Down Expand Up @@ -163,7 +163,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte

/**
* 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
* as items in the list or into another file to trigger updating it's version.
* 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.
Expand Down Expand Up @@ -380,7 +381,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
ngOnInit() {
this.rowMenuCache = {};
this.loadLayoutPresets();
this.data = new ShareDataTableAdapter(this.thumbnailService, this.contentService, null, this.getDefaultSorting(), this.sortingMode);
this.data = new ShareDataTableAdapter(this.thumbnailService, this.contentService, null, this.getDefaultSorting(),
this.sortingMode, this.allowDropFiles);
this.data.thumbnails = this.thumbnails;
this.data.permissionsStyle = this.permissionsStyle;

Expand Down Expand Up @@ -555,14 +557,14 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
if (typeof node === 'string') {
this.resetNewFolderPagination();
this._currentFolderId = node;
this.folderChange.emit(new NodeEntryEvent(<Node> { id: node }));
this.folderChange.emit(new NodeEntryEvent(<Node> {id: node}));
this.reload();
return true;
} else {
if (this.canNavigateFolder(node)) {
this.resetNewFolderPagination();
this._currentFolderId = this.getNodeFolderDestinationId(node);
this.folderChange.emit(new NodeEntryEvent(<Node> { id: this._currentFolderId }));
this.folderChange.emit(new NodeEntryEvent(<Node> {id: this._currentFolderId}));
this.reload();
return true;
}
Expand Down Expand Up @@ -651,7 +653,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte

onPageLoaded(nodePaging: NodePaging) {
if (nodePaging) {
this.data.loadPage(nodePaging, this._pagination.merge);
this.data.loadPage(nodePaging, this._pagination.merge, this.allowDropFiles);
this.setLoadingState(false);
this.onDataReady(nodePaging);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ export class ShareDataRow implements DataRow {
constructor(private obj: NodeEntry,
private contentService: ContentService,
private permissionsStyle: PermissionStyleModel[],
private thumbnailService?: ThumbnailService) {
private thumbnailService?: ThumbnailService,
private allowDropFiles?: boolean) {
if (!obj) {
throw new Error(ShareDataRow.ERR_OBJECT_NOT_FOUND);
}

this.isDropTarget = this.isFolderAndHasPermissionToUpload(obj);

this.isDropTarget = allowDropFiles !== undefined ? this.allowDropFiles && this.checkNodeTypeAndPermissions(obj) : this.checkNodeTypeAndPermissions(obj);
if (permissionsStyle) {
this.cssClass = this.getPermissionClass(obj);
}
}

checkNodeTypeAndPermissions(nodeEntry: NodeEntry) {
return this.isFolderAndHasPermissionToUpload(nodeEntry) || this.isFileAndHasParentFolderPermissionToUpload(nodeEntry);
}

getPermissionClass(nodeEntity: NodeEntry): string {
let permissionsClasses = '';

Expand Down Expand Up @@ -81,6 +85,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 @@ -44,6 +44,7 @@ export class ShareDataTableAdapter implements DataTableAdapter {
thumbnails: boolean = false;
permissionsStyle: PermissionStyleModel[];
selectedRow: DataRow;
allowDropFiles: boolean;

set sortingMode(value: string) {
let newValue = (value || 'client').toLowerCase();
Expand All @@ -61,11 +62,13 @@ export class ShareDataTableAdapter implements DataTableAdapter {
private contentService: ContentService,
schema: DataColumn[] = [],
sorting?: DataSorting,
sortingMode: string = 'client') {
sortingMode: string = 'client',
allowDropFiles: boolean = false) {
this.rows = [];
this.columns = schema || [];
this.sorting = sorting;
this.sortingMode = sortingMode;
this.allowDropFiles = allowDropFiles;
}

getRows(): Array<DataRow> {
Expand Down Expand Up @@ -242,13 +245,16 @@ export class ShareDataTableAdapter implements DataTableAdapter {
}
}

public loadPage(nodePaging: NodePaging, merge: boolean = false) {
public loadPage(nodePaging: NodePaging, merge: boolean = false, allowDropFiles?: boolean) {
let shareDataRows: ShareDataRow[] = [];

if (allowDropFiles !== undefined) {
this.allowDropFiles = allowDropFiles;
}
if (nodePaging && nodePaging.list) {
const nodeEntries: NodeEntry[] = nodePaging.list.entries;
if (nodeEntries && nodeEntries.length > 0) {
shareDataRows = nodeEntries.map((item) => new ShareDataRow(item, this.contentService, this.permissionsStyle, this.thumbnailService));
shareDataRows = nodeEntries.map((item) => new ShareDataRow(item, this.contentService, this.permissionsStyle,
this.thumbnailService, this.allowDropFiles));

if (this.filter) {
shareDataRows = shareDataRows.filter(this.filter);
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

0 comments on commit 4cb3a87

Please sign in to comment.