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:
@@ -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">
|
||||
|
@@ -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');
|
||||
|
@@ -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');
|
||||
|
@@ -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>
|
||||
|
@@ -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);
|
||||
|
@@ -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)">
|
||||
|
Reference in New Issue
Block a user