[ADF-2672] version manager fixes (#3169)

* fix app config, add extra flags for version manager

* add docs and tests

* update i18n strings

* rename "id" to "nodeId"

* automatically detect permissions

* restore 'id' and mark as deprecated
This commit is contained in:
Denys Vuika
2018-04-11 17:34:45 +01:00
committed by Eugenio Romano
parent 8b4af90b46
commit aba9f41af1
16 changed files with 117 additions and 89 deletions

View File

@@ -487,7 +487,6 @@
},
"adf-version-manager": {
"allowComments": true,
"allowDownload": true,
"allowDelete": true
"allowDownload": true
}
}

View File

@@ -361,8 +361,7 @@
<adf-version-manager
[node]="documentList.selection[0].entry"
[showComments]="showVersionComments"
[allowDownload]="allowVersionDownload"
[allowDelete]="allowVersionDelete">
[allowDownload]="allowVersionDownload">
</adf-version-manager>
</ng-container>
</ng-container>
@@ -460,12 +459,6 @@
</mat-slide-toggle>
</section>
<section>
<mat-slide-toggle color="primary" [(ngModel)]="allowVersionDelete">
{{'APP.ADF_VERSION_MANAGER.ALLOW_DELETE' | translate}}
</mat-slide-toggle>
</section>
<h5>Upload</h5>
<section *ngIf="acceptedFilesTypeShow">
<mat-form-field floatPlaceholder="float">

View File

@@ -105,9 +105,6 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
@Input()
allowVersionDownload = true;
@Input()
allowVersionDelete = true;
@Input()
acceptedFilesType = '.jpg,.pdf,.js';

View File

@@ -27,11 +27,11 @@ export class DebugAppConfigService extends AppConfigService {
}
/** @override */
get<T>(key: string): T {
get<T>(key: string, defaultValue?: T): T {
if (key === 'ecmHost' || key === 'bpmHost') {
return <T> (<any> this.storage.getItem(key) || super.get<T>(key));
}
return super.get<T>(key);
return super.get<T>(key, defaultValue);
}
}

View File

@@ -16,10 +16,18 @@ Displays the version history of a node in a Version Manager component
| Name | Type | Default value | Description |
| ---- | ---- | ------------- | ----------- |
| id | `string` | | ID of the node whose version history you want to display. |
| node | `MinimalNodeEntryEntity` | | Node whose version history you want to display. |
| showComments | `boolean` | true | Set this to false if version comments should not be displayed. |
| 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. |
### DOM events
All DOM events are bubbling and can be handled in the parent components up to the root application component.
| Name | Description |
| --- | --- |
| version-deleted | Raised after a version is deleted. |
| version-restored | Raised after a version is restored. |
## Details

View File

@@ -26,7 +26,7 @@ Displays the version history of a node with the ability to upload a new version.
| ---- | ---- | --- | ----------- |
| node | [MinimalNodeEntryEntity](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md) | |The node you want to manage the version history of. |
| 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. |
### Events

View File

@@ -11,9 +11,9 @@
},
"CONFIRM_DELETE": {
"TITLE": "Delete version",
"MESSAGE": "Deleted file versions can not be restored. Delete?",
"YES_LABEL": "Yes",
"NO_LABEL": "No"
"MESSAGE": "Deleted file versions can not be restored.",
"YES_LABEL": "DELETE",
"NO_LABEL": "KEEP"
}
},
"ADF_CONFIRM_DIALOG": {

View File

@@ -9,7 +9,7 @@
<p mat-line class="adf-version-list-item-comment" *ngIf="showComments">{{version.entry.versionComment}}</p>
<mat-menu #versionMenu="matMenu" yPosition="below" xPosition="before">
<button
<button *ngIf="canUpdate()"
mat-menu-item
(click)="restore(version.entry.id)">
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}
@@ -19,7 +19,7 @@
(click)="downloadVersion(version.entry.id)">
{{ 'ADF_VERSION_LIST.ACTIONS.DOWNLOAD' | translate }}
</button>
<button *ngIf="allowDelete"
<button *ngIf="canUpdate()"
(click)="deleteVersion(version.entry.id)"
mat-menu-item>
{{ 'ADF_VERSION_LIST.ACTIONS.DELETE' | translate }}

View File

@@ -52,7 +52,7 @@ describe('VersionListComponent', () => {
dialog = TestBed.get(MatDialog);
component = fixture.componentInstance;
component.id = nodeId;
component.node = { id: nodeId, allowableOperations: [ 'update' ] };
spyOn(component, 'downloadContent').and.stub();
});
@@ -64,7 +64,6 @@ describe('VersionListComponent', () => {
}
});
component.allowDelete = true;
component.deleteVersion('1');
expect(dialog.open).toHaveBeenCalled();
@@ -79,12 +78,10 @@ describe('VersionListComponent', () => {
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
component.id = '0';
component.allowDelete = true;
component.deleteVersion('1');
component.deleteVersion(versionId);
expect(dialog.open).toHaveBeenCalled();
expect(alfrescoApiService.versionsApi.deleteVersion).toHaveBeenCalledWith('0', '1');
expect(alfrescoApiService.versionsApi.deleteVersion).toHaveBeenCalledWith(nodeId, versionId);
});
it('should not delete version if user rejects', () => {
@@ -96,9 +93,7 @@ describe('VersionListComponent', () => {
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
component.id = '0';
component.allowDelete = true;
component.deleteVersion('1');
component.deleteVersion(versionId);
expect(dialog.open).toHaveBeenCalled();
expect(alfrescoApiService.versionsApi.deleteVersion).not.toHaveBeenCalled();
@@ -115,15 +110,23 @@ describe('VersionListComponent', () => {
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
component.id = '0';
component.allowDelete = true;
component.deleteVersion('1');
component.deleteVersion(versionId);
tick();
expect(component.loadVersionHistory).toHaveBeenCalled();
}));
it('should reload and raise version-deleted DOM event', (done) => {
spyOn(component, 'loadVersionHistory').and.stub();
fixture.nativeElement.addEventListener('version-deleted', () => {
expect(component.loadVersionHistory).toHaveBeenCalled();
done();
});
fixture.detectChanges();
component.onVersionDeleted();
});
describe('Version history fetching', () => {
it('should use loading bar', () => {
@@ -231,6 +234,23 @@ describe('VersionListComponent', () => {
describe('Version restoring', () => {
it('should reload and raise version-restored DOM event', (done) => {
spyOn(component, 'loadVersionHistory').and.stub();
fixture.nativeElement.addEventListener('version-restored', () => {
expect(component.loadVersionHistory).toHaveBeenCalled();
done();
});
fixture.detectChanges();
component.onVersionRestored();
});
it('should restore version only when restore allowed', () => {
component.node.allowableOperations = [];
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.stub();
component.restore('1');
expect(alfrescoApiService.versionsApi.revertVersion).not.toHaveBeenCalled();
});
it('should load the versions for a given id', () => {
fixture.detectChanges();
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and

View File

@@ -15,9 +15,9 @@
* limitations under the License.
*/
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Component, Input, OnChanges, ViewEncapsulation } from '@angular/core';
import { VersionsApi } from 'alfresco-js-api';
import { AlfrescoApiService, ContentService } from '@alfresco/adf-core';
import { Component, Input, OnChanges, ViewEncapsulation, ElementRef } from '@angular/core';
import { VersionsApi, MinimalNodeEntryEntity } from 'alfresco-js-api';
import { MatDialog } from '@angular/material';
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
@@ -36,10 +36,13 @@ export class VersionListComponent implements OnChanges {
versions: any = [];
isLoading = true;
/** ID of the node whose version history you want to display. */
/** @deprecated in 2.3.0 */
@Input()
id: string;
@Input()
node: MinimalNodeEntryEntity;
@Input()
showComments = true;
@@ -47,11 +50,11 @@ export class VersionListComponent implements OnChanges {
@Input()
allowDownload = true;
/** Toggle version deletion feature. */
@Input()
allowDelete = true;
constructor(private alfrescoApi: AlfrescoApiService, private dialog: MatDialog) {
constructor(
private alfrescoApi: AlfrescoApiService,
private contentService: ContentService,
private dialog: MatDialog,
private el: ElementRef) {
this.versionsApi = this.alfrescoApi.versionsApi;
}
@@ -59,15 +62,21 @@ export class VersionListComponent implements OnChanges {
this.loadVersionHistory();
}
canUpdate(): boolean {
return this.contentService.hasPermission(this.node, 'update');
}
restore(versionId) {
this.versionsApi
.revertVersion(this.id, versionId, { majorVersion: true, comment: ''})
.then(this.loadVersionHistory.bind(this));
if (this.canUpdate()) {
this.versionsApi
.revertVersion(this.node.id, versionId, { majorVersion: true, comment: ''})
.then(() => this.onVersionRestored());
}
}
loadVersionHistory() {
this.isLoading = true;
this.versionsApi.listVersionHistory(this.id).then((data) => {
this.versionsApi.listVersionHistory(this.node.id).then((data) => {
this.versions = data.list.entries;
this.isLoading = false;
});
@@ -75,13 +84,13 @@ export class VersionListComponent implements OnChanges {
downloadVersion(versionId: string) {
if (this.allowDownload) {
const versionDownloadUrl = this.getVersionContentUrl(this.id, versionId, true);
const versionDownloadUrl = this.getVersionContentUrl(this.node.id, versionId, true);
this.downloadContent(versionDownloadUrl);
}
}
deleteVersion(versionId: string) {
if (this.allowDelete) {
if (this.canUpdate()) {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
title: 'ADF_VERSION_LIST.CONFIRM_DELETE.TITLE',
@@ -95,15 +104,27 @@ export class VersionListComponent implements OnChanges {
dialogRef.afterClosed().subscribe(result => {
if (result === true) {
this.alfrescoApi.versionsApi
.deleteVersion(this.id, versionId)
.then(() => {
this.loadVersionHistory();
});
.deleteVersion(this.node.id, versionId)
.then(() => this.onVersionDeleted());
}
});
}
}
onVersionDeleted() {
this.loadVersionHistory();
const event = new CustomEvent('version-deleted', { bubbles: true });
this.el.nativeElement.dispatchEvent(event);
}
onVersionRestored() {
this.loadVersionHistory();
const event = new CustomEvent('version-restored', { bubbles: true });
this.el.nativeElement.dispatchEvent(event);
}
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

@@ -1,11 +1,15 @@
<div class="adf-new-version-uploader-container" fxLayout="row" fxLayoutAlign="end center">
<adf-version-upload [node]="node" (success)="onUploadSuccess($event)" (error)="onUploadError($event)"></adf-version-upload>
<adf-version-upload
[node]="node"
(success)="onUploadSuccess($event)"
(error)="uploadError.emit($event)">
</adf-version-upload>
</div>
<div class="adf-version-list-container">
<adf-version-list
#versionList [id]="node.id"
#versionList
[node]="node"
[allowDownload]="allowDownload"
[showComments]="showComments"
[allowDelete]="allowDelete">
[showComments]="showComments">
</adf-version-list>
</div>

View File

@@ -98,14 +98,4 @@ describe('VersionManagerComponent', () => {
});
component.onUploadSuccess(emittedData);
});
it('should emit error event upon failure to upload a new version', () => {
fixture.detectChanges();
const errorEvent = new CustomEvent('error');
component.uploadError.subscribe(event => {
expect(event).toBe(errorEvent);
});
component.onUploadError(errorEvent);
});
});

View File

@@ -18,7 +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';
import { AppConfigService, ContentService } from '@alfresco/adf-core';
@Component({
selector: 'adf-version-manager',
@@ -31,9 +31,6 @@ export class VersionManagerComponent {
@Input()
node: MinimalNodeEntryEntity;
@Input()
allowDelete = true;
@Input()
showComments = true;
@@ -49,8 +46,9 @@ export class VersionManagerComponent {
@ViewChild('versionList')
versionListComponent: VersionListComponent;
constructor(config: AppConfigService) {
this.allowDelete = config.get('adf-version-manager.allowDelete', true);
constructor(
config: AppConfigService,
private contentService: ContentService) {
this.showComments = config.get('adf-version-manager.allowComments', true);
this.allowDownload = config.get('adf-version-manager.allowDownload', true);
}
@@ -60,7 +58,7 @@ export class VersionManagerComponent {
this.uploadSuccess.emit(event);
}
onUploadError(event): any {
this.uploadError.emit(event);
canUpdate(): boolean {
return this.contentService.hasPermission(this.node, 'update');
}
}

View File

@@ -3,9 +3,10 @@
class="adf-new-version-file-upload"
staticTitle="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.TITLE' | translate }}"
[node]="node"
[disabled]="!canUpload()"
[rootFolderId]="node.parentId"
tooltip="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.TOOLTIP' | translate }}"
[versioning]="true"
(success)="onUploadSuccess($event)"
(error)="onUploadError($event)">
(success)="success.emit($event)"
(error)="error.emit($event)">
</adf-upload-version-button>

View File

@@ -17,14 +17,13 @@
import { Component, Input, ViewEncapsulation, Output, EventEmitter } from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { ContentService } from '@alfresco/adf-core';
@Component({
selector: 'adf-version-upload',
templateUrl: './version-upload.component.html',
encapsulation: ViewEncapsulation.None,
host: {
'class': 'adf-version-upload'
}
host: { 'class': 'adf-version-upload' }
})
export class VersionUploadComponent {
@@ -32,17 +31,16 @@ export class VersionUploadComponent {
node: MinimalNodeEntryEntity;
@Output()
success: EventEmitter<any> = new EventEmitter();
success = new EventEmitter();
@Output()
error: EventEmitter<any> = new EventEmitter();
error = new EventEmitter();
onUploadSuccess(event): void {
this.success.emit(event);
constructor(private contentService: ContentService) {
}
onUploadError(event): void {
this.error.emit(event);
canUpload(): boolean {
return this.contentService.hasPermission(this.node, 'update');
}
}

View File

@@ -474,8 +474,7 @@
"type": "object",
"properties": {
"allowComments": { "type": "boolean" },
"allowDownload": { "type": "boolean" },
"allowDelete": { "type": "boolean" }
"allowDownload": { "type": "boolean" }
}
}
}