mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -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');
|
||||
|
Reference in New Issue
Block a user