[ADF-2567] delete a version (#3151)

* configuration support for version manager

* checkbox for version deletion demo

* i18n support for version manager

* deleting versions

* confirmation dialog for version deletion

* readme update

* update schema

* update code as per code review

* update i18n resources for demo shell

* unit tests
This commit is contained in:
Denys Vuika
2018-04-06 18:40:17 +01:00
committed by GitHub
parent 313d7f30cf
commit 5325fd4cd4
19 changed files with 285 additions and 43 deletions

View File

@@ -5,6 +5,11 @@
"COMMENTS": "Comments",
"PROPERTIES": "Properties",
"VERSIONS": "Versions"
},
"ADF_VERSION_MANAGER": {
"ALLOW_DELETE": "Allow delete",
"SHOW_COMMENTS" : "Show comments on versions",
"ALLOW_DOWNLOAD" :"Enable version download"
}
},
"title": "Welcome",
@@ -67,11 +72,9 @@
"CUSTOM_FILTER" :"Custom extensions filter",
"MAX_SIZE" : "Max size filter",
"ENABLE_VERSIONING" :"Enable versioning",
"ENABLE_VERSION_DOWNLOAD" :"Enable version download",
"DESCRIPTION_UPLOAD" : "Enable upload",
"ENABLE_INFINITE_SCROLL":"Enable Infinite Scrolling",
"MULTISELECT_DESCRIPTION" : "Use Cmd (Mac) or Ctrl (Windows) to toggle selection of multiple items",
"SHOW_VERSION_COMMENTS" : "Show comments on versions",
"RECENT" : {
"EMPTY_STATE": {
"TITLE": "Recent is empty"

View File

@@ -484,5 +484,10 @@
"exif:exif": "*"
}
}
},
"adf-version-manager": {
"allowComments": true,
"allowDownload": true,
"allowDelete": true
}
}

View File

@@ -362,7 +362,8 @@
<adf-version-manager
[node]="documentList.selection[0].entry"
[showComments]="showVersionComments"
[enableDownload]="enableVersionDownload">
[allowDownload]="allowVersionDownload"
[allowDelete]="allowVersionDelete">
</adf-version-manager>
</ng-container>
</ng-container>
@@ -437,23 +438,32 @@
</section>
<section>
<mat-slide-toggle [color]="'primary'" [(ngModel)]="versioning">{{'DOCUMENT_LIST.ENABLE_VERSIONING' |
translate}}
<mat-slide-toggle [color]="'primary'" [(ngModel)]="versioning">
{{'DOCUMENT_LIST.ENABLE_VERSIONING' | translate}}
</mat-slide-toggle>
</section>
<section>
<mat-slide-toggle [color]="'primary'" [(ngModel)]="infiniteScrolling">
<mat-slide-toggle color="primary" [(ngModel)]="infiniteScrolling">
{{'DOCUMENT_LIST.ENABLE_INFINITE_SCROLL' | translate}}
</mat-slide-toggle>
</section>
<section>
<mat-slide-toggle [color]="'primary'" [(ngModel)]="showVersionComments">
{{'DOCUMENT_LIST.SHOW_VERSION_COMMENTS' | translate}}
<mat-slide-toggle color="primary" [(ngModel)]="showVersionComments">
{{'APP.ADF_VERSION_MANAGER.SHOW_COMMENTS' | translate}}
</mat-slide-toggle>
<mat-slide-toggle [color]="'primary'" [(ngModel)]="enableVersionDownload">
{{'DOCUMENT_LIST.ENABLE_VERSION_DOWNLOAD' | translate}}
</section>
<section>
<mat-slide-toggle color="primary" [(ngModel)]="allowVersionDownload">
{{'APP.ADF_VERSION_MANAGER.ALLOW_DOWNLOAD' | translate}}
</mat-slide-toggle>
</section>
<section>
<mat-slide-toggle color="primary" [(ngModel)]="allowVersionDelete">
{{'APP.ADF_VERSION_MANAGER.ALLOW_DELETE' | translate}}
</mat-slide-toggle>
</section>

View File

@@ -103,7 +103,10 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
versioning = false;
@Input()
enableVersionDownload = true;
allowVersionDownload = true;
@Input()
allowVersionDelete = true;
@Input()
acceptedFilesType = '.jpg,.pdf,.js';
@@ -365,11 +368,11 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
onManageVersions(event) {
const contentEntry = event.value.entry;
const showComments = this.showVersionComments;
const enableDownload = this.enableVersionDownload;
const allowDownload = this.allowVersionDownload;
if (this.contentService.hasPermission(contentEntry, 'update')) {
this.dialog.open(VersionManagerDialogAdapterComponent, {
data: { contentEntry, showComments, enableDownload },
data: { contentEntry, showComments, allowDownload },
panelClass: 'adf-version-manager-dialog',
width: '630px'
});

View File

@@ -1,6 +1,6 @@
<header mat-dialog-title>{{'VERSION.DIALOG.TITLE' | translate}}</header>
<section mat-dialog-content>
<adf-version-manager [node]="contentEntry" [enableDownload]="enableDownload" [showComments]="showComments" (uploadError)="uploadError($event)"></adf-version-manager>
<adf-version-manager [node]="contentEntry" [allowDownload]="allowDownload" [showComments]="showComments" (uploadError)="uploadError($event)"></adf-version-manager>
</section>
<footer mat-dialog-actions fxLayout="row" fxLayoutAlign="end center">
<button mat-button (click)="close()">{{'VERSION.DIALOG.CLOSE' | translate}}</button>

View File

@@ -28,14 +28,14 @@ export class VersionManagerDialogAdapterComponent {
public contentEntry: MinimalNodeEntryEntity;
showComments = true;
enableDownload = true;
allowDownload = true;
constructor(@Inject(MAT_DIALOG_DATA) data: any,
private snackBar: MatSnackBar,
private containingDialog?: MatDialogRef<VersionManagerDialogAdapterComponent>) {
this.contentEntry = data.contentEntry;
this.showComments = data.hasOwnProperty('showComments') ? data.showComments : this.showComments;
this.enableDownload = data.hasOwnProperty('enableDownload') ? data.enableDownload : this.enableDownload;
this.allowDownload = data.hasOwnProperty('allowDownload') ? data.enableDownload : this.allowDownload;
}
uploadError(errorMessage: string) {

View File

@@ -18,7 +18,8 @@ Displays the version history of a node in a Version Manager component
| ---- | ---- | ------------- | ----------- |
| id | `string` | | ID of the node whose version history you want to display. |
| showComments | `boolean` | true | Set this to false if version comments should not be displayed. |
| enableDownload | `boolean` | true | Configuration to enable/disable downloads of previous versions. Set this to false to not show the menu item for version download. |
| allowDownload | `boolean` | true | Toggles downloads of previous versions. Set this to false to not show the menu item for version download. |
| allowDelete | `boolean` | true | Toggles the version delete feature. |
## Details

View File

@@ -54,19 +54,19 @@ import { SearchQueryBuilderService } from './search/search-query-builder.service
WebScriptModule,
FormsModule,
ReactiveFormsModule,
DialogModule,
SearchModule,
DocumentListModule,
UploadModule,
MaterialModule,
SitesDropdownModule,
BreadcrumbModule,
VersionManagerModule,
ContentNodeSelectorModule,
ContentMetadataModule,
DialogModule,
FolderDirectiveModule,
ContentDirectiveModule,
PermissionManagerModule
PermissionManagerModule,
VersionManagerModule
],
providers: [
{
@@ -95,13 +95,13 @@ import { SearchQueryBuilderService } from './search/search-query-builder.service
SearchModule,
SitesDropdownModule,
BreadcrumbModule,
VersionManagerModule,
ContentNodeSelectorModule,
ContentMetadataModule,
DialogModule,
FolderDirectiveModule,
ContentDirectiveModule,
PermissionManagerModule
PermissionManagerModule,
VersionManagerModule
]
})
export class ContentModule {

View File

@@ -0,0 +1,58 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material';
@Component({
selector: 'adf-confirm-dialog',
template: `
<h1 mat-dialog-title>{{ title | translate }}</h1>
<mat-dialog-content>
<p>{{ message | translate }}</p>
</mat-dialog-content>
<mat-dialog-actions>
<span class="spacer"></span>
<button mat-button [mat-dialog-close]="true">{{ yesLabel | translate }}</button>
<button mat-button [mat-dialog-close]="false" cdkFocusInitial>{{ noLabel | translate }}</button>
</mat-dialog-actions>
`,
styles: [`
.spacer { flex: 1 1 auto; }
.adf-confirm-dialog .mat-dialog-actions .mat-button-wrapper {
text-transform: uppercase;
}
`],
host: { 'class': 'adf-confirm-dialog' },
encapsulation: ViewEncapsulation.None
})
export class ConfirmDialogComponent {
title: string;
message: string;
yesLabel: string;
noLabel: string;
constructor(@Inject(MAT_DIALOG_DATA) data) {
data = data || {};
this.title = data.title || 'ADF_CONFIRM_DIALOG.CONFIRM';
this.message = data.message || 'ADF_CONFIRM_DIALOG.MESSAGE';
this.yesLabel = data.yesLabel || 'ADF_CONFIRM_DIALOG.YES_LABEL';
this.noLabel = data.noLabel || 'ADF_CONFIRM_DIALOG.NO_LABEL';
}
}

View File

@@ -23,6 +23,7 @@ import { DownloadZipDialogComponent } from './download-zip.dialog';
import { FolderDialogComponent } from './folder.dialog';
import { NodeLockDialogComponent } from './node-lock.dialog';
import { ShareDialogComponent } from './share.dialog';
import { ConfirmDialogComponent } from './confirm.dialog';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
@@ -46,19 +47,22 @@ import { MatMomentDatetimeModule } from '@mat-datetimepicker/moment';
DownloadZipDialogComponent,
FolderDialogComponent,
NodeLockDialogComponent,
ShareDialogComponent
ShareDialogComponent,
ConfirmDialogComponent
],
exports: [
DownloadZipDialogComponent,
FolderDialogComponent,
NodeLockDialogComponent,
ShareDialogComponent
ShareDialogComponent,
ConfirmDialogComponent
],
entryComponents: [
DownloadZipDialogComponent,
FolderDialogComponent,
NodeLockDialogComponent,
ShareDialogComponent
ShareDialogComponent,
ConfirmDialogComponent
]
})
export class DialogModule {}

View File

@@ -19,3 +19,4 @@ export * from './download-zip.dialog';
export * from './folder.dialog';
export * from './node-lock.dialog';
export * from './share.dialog';
export * from './confirm.dialog';

View File

@@ -1,4 +1,27 @@
{
"ADF_VERSION_LIST": {
"ACTIONS": {
"RESTORE": "Restore",
"DELETE": "Delete",
"DOWNLOAD": "Download",
"UPLOAD": {
"TITLE": "Upload new version",
"TOOLTIP": "Restriction: upload file with the same name to create a new version of it"
}
},
"CONFIRM_DELETE": {
"TITLE": "Delete version",
"MESSAGE": "Deleted file versions can not be restored. Delete?",
"YES_LABEL": "Yes",
"NO_LABEL": "No"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Confirm",
"ACTION": "Do you want to proceed?",
"YES_LABEL": "Yes",
"NO_LABEL": "No"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "This folder is empty"

View File

@@ -9,8 +9,21 @@
<p mat-line class="adf-version-list-item-comment" *ngIf="showComments">{{version.entry.versionComment}}</p>
<mat-menu #versionMenu="matMenu" yPosition="below" xPosition="before">
<button mat-menu-item (click)="restore(version.entry.id)"> Restore </button>
<button mat-menu-item (click)="downloadVersion(version.entry.id)" title="Download" *ngIf="enableDownload"> Download </button>
<button
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="allowDelete"
(click)="deleteVersion(version.entry.id)"
mat-menu-item>
{{ 'ADF_VERSION_LIST.ACTIONS.DELETE' | translate }}
</button>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="versionMenu">

View File

@@ -16,15 +16,18 @@
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { VersionListComponent } from './version-list.component';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { MatDialog } from '@angular/material';
import { Observable } from 'rxjs/Observable';
describe('VersionListComponent', () => {
let component: VersionListComponent;
let fixture: ComponentFixture<VersionListComponent>;
let alfrescoApiService: AlfrescoApiService;
let dialog: MatDialog;
const nodeId = 'test-id';
const versionId = '1.0';
@@ -46,6 +49,7 @@ describe('VersionListComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(VersionListComponent);
alfrescoApiService = TestBed.get(AlfrescoApiService);
dialog = TestBed.get(MatDialog);
component = fixture.componentInstance;
component.id = nodeId;
@@ -53,6 +57,73 @@ describe('VersionListComponent', () => {
spyOn(component, 'downloadContent').and.stub();
});
it('should raise confirmation dialog on delete', () => {
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(false)
}
});
component.allowDelete = true;
component.deleteVersion('1');
expect(dialog.open).toHaveBeenCalled();
});
it('should delete the version if user confirms', () => {
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(true)
}
});
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
component.id = '0';
component.allowDelete = true;
component.deleteVersion('1');
expect(dialog.open).toHaveBeenCalled();
expect(alfrescoApiService.versionsApi.deleteVersion).toHaveBeenCalledWith('0', '1');
});
it('should not delete version if user rejects', () => {
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(false)
}
});
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
component.id = '0';
component.allowDelete = true;
component.deleteVersion('1');
expect(dialog.open).toHaveBeenCalled();
expect(alfrescoApiService.versionsApi.deleteVersion).not.toHaveBeenCalled();
});
it('should reload list once a version is deleted', fakeAsync(() => {
spyOn(component, 'loadVersionHistory').and.stub();
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(true)
}
});
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
component.id = '0';
component.allowDelete = true;
component.deleteVersion('1');
tick()
expect(component.loadVersionHistory).toHaveBeenCalled();
}));
describe('Version history fetching', () => {
it('should use loading bar', () => {
@@ -149,7 +220,7 @@ describe('VersionListComponent', () => {
.callFake(() => Promise.resolve({ list: { entries: [ versionEntry ] }}));
const spyOnDownload = spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.stub();
component.enableDownload = false;
component.allowDownload = false;
fixture.detectChanges();
component.downloadVersion('1.0');

View File

@@ -18,6 +18,8 @@
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Component, Input, OnChanges, ViewEncapsulation } from '@angular/core';
import { VersionsApi } from 'alfresco-js-api';
import { MatDialog } from '@angular/material';
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
@Component({
selector: 'adf-version-list',
@@ -32,20 +34,24 @@ export class VersionListComponent implements OnChanges {
private versionsApi: VersionsApi;
versions: any = [];
isLoading: boolean = true;
isLoading = true;
/** ID of the node whose version history you want to display. */
@Input()
id: string;
@Input()
showComments: boolean = true;
showComments = true;
/** Enable/disable possibility to download a version of the current node. */
@Input()
enableDownload: boolean = true;
allowDownload = true;
constructor(private alfrescoApi: AlfrescoApiService) {
/** Toggle version deletion feature. */
@Input()
allowDelete = true;
constructor(private alfrescoApi: AlfrescoApiService, private dialog: MatDialog) {
this.versionsApi = this.alfrescoApi.versionsApi;
}
@@ -67,13 +73,37 @@ export class VersionListComponent implements OnChanges {
});
}
downloadVersion(versionId) {
if (this.enableDownload) {
downloadVersion(versionId: string) {
if (this.allowDownload) {
const versionDownloadUrl = this.getVersionContentUrl(this.id, versionId, true);
this.downloadContent(versionDownloadUrl);
}
}
deleteVersion(versionId: string) {
if (this.allowDelete) {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
title: 'ADF_VERSION_LIST.CONFIRM_DELETE.TITLE',
message: 'ADF_VERSION_LIST.CONFIRM_DELETE.MESSAGE',
yesLabel: 'ADF_VERSION_LIST.CONFIRM_DELETE.YES_LABEL',
noLabel: 'ADF_VERSION_LIST.CONFIRM_DELETE.NO_LABEL'
},
minWidth: '250px'
});
dialogRef.afterClosed().subscribe(result => {
if (result === true) {
this.alfrescoApi.versionsApi
.deleteVersion(this.id, versionId)
.then(() => {
this.loadVersionHistory();
});
}
});
}
}
private getVersionContentUrl(nodeId: string, versionId: string, attachment?: boolean) {
const nodeDownloadUrl = this.alfrescoApi.contentApi.getContentUrl(nodeId, attachment);
return nodeDownloadUrl.replace('/content', '/versions/' + versionId + '/content');

View File

@@ -4,7 +4,8 @@
<div class="adf-version-list-container">
<adf-version-list
#versionList [id]="node.id"
[enableDownload]="enableDownload"
[showComments]="showComments">
[allowDownload]="allowDownload"
[showComments]="showComments"
[allowDelete]="allowDelete">
</adf-version-list>
</div>

View File

@@ -18,6 +18,7 @@
import { Component, Input, ViewEncapsulation, ViewChild, Output, EventEmitter } from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { VersionListComponent } from './version-list.component';
import { AppConfigService } from '@alfresco/adf-core';
@Component({
selector: 'adf-version-manager',
@@ -31,20 +32,29 @@ export class VersionManagerComponent {
node: MinimalNodeEntryEntity;
@Input()
showComments: boolean = true;
allowDelete = true;
@Input()
enableDownload: boolean = true;
showComments = true;
@Input()
allowDownload = true;
@Output()
uploadSuccess: EventEmitter<any> = new EventEmitter();
uploadSuccess = new EventEmitter();
@Output()
uploadError: EventEmitter<any> = new EventEmitter();
uploadError = new EventEmitter();
@ViewChild('versionList')
versionListComponent: VersionListComponent;
constructor(config: AppConfigService) {
this.allowDelete = config.get('adf-version-manager.allowDelete', true);
this.showComments = config.get('adf-version-manager.allowComments', true);
this.allowDownload = config.get('adf-version-manager.allowDownload', true);
}
onUploadSuccess(event): void {
this.versionListComponent.loadVersionHistory();
this.uploadSuccess.emit(event);

View File

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

View File

@@ -468,6 +468,15 @@
"clientId": { "type": "string" },
"secret": { "type": "string" }
}
},
"adf-version-manager": {
"description": "Configuration parameters for Version Manager component",
"type": "object",
"properties": {
"allowComments": { "type": "boolean" },
"allowDownload": { "type": "boolean" },
"allowDelete": { "type": "boolean" }
}
}
}
}