diff --git a/demo-shell/src/app.config.json b/demo-shell/src/app.config.json
index 1028d7377c..18b2181d1a 100644
--- a/demo-shell/src/app.config.json
+++ b/demo-shell/src/app.config.json
@@ -487,7 +487,6 @@
},
"adf-version-manager": {
"allowComments": true,
- "allowDownload": true,
- "allowDelete": true
+ "allowDownload": true
}
}
diff --git a/demo-shell/src/app/components/files/files.component.html b/demo-shell/src/app/components/files/files.component.html
index edd5d5652e..8a51b8c35f 100644
--- a/demo-shell/src/app/components/files/files.component.html
+++ b/demo-shell/src/app/components/files/files.component.html
@@ -361,8 +361,7 @@
+ [allowDownload]="allowVersionDownload">
@@ -460,12 +459,6 @@
-
-
- {{'APP.ADF_VERSION_MANAGER.ALLOW_DELETE' | translate}}
-
-
-
Upload
diff --git a/demo-shell/src/app/components/files/files.component.ts b/demo-shell/src/app/components/files/files.component.ts
index 063329055e..2b76690d0a 100644
--- a/demo-shell/src/app/components/files/files.component.ts
+++ b/demo-shell/src/app/components/files/files.component.ts
@@ -105,9 +105,6 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
@Input()
allowVersionDownload = true;
- @Input()
- allowVersionDelete = true;
-
@Input()
acceptedFilesType = '.jpg,.pdf,.js';
diff --git a/demo-shell/src/app/services/debug-app-config.service.ts b/demo-shell/src/app/services/debug-app-config.service.ts
index b2f2c9c915..32d53f8ea1 100644
--- a/demo-shell/src/app/services/debug-app-config.service.ts
+++ b/demo-shell/src/app/services/debug-app-config.service.ts
@@ -27,11 +27,11 @@ export class DebugAppConfigService extends AppConfigService {
}
/** @override */
- get(key: string): T {
+ get(key: string, defaultValue?: T): T {
if (key === 'ecmHost' || key === 'bpmHost') {
return ( this.storage.getItem(key) || super.get(key));
}
- return super.get(key);
+ return super.get(key, defaultValue);
}
}
diff --git a/docs/content-services/version-list.component.md b/docs/content-services/version-list.component.md
index 85930f42b2..ea0c34acb9 100644
--- a/docs/content-services/version-list.component.md
+++ b/docs/content-services/version-list.component.md
@@ -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
diff --git a/docs/content-services/version-manager.component.md b/docs/content-services/version-manager.component.md
index 7f3fb17385..60d7bd1091 100644
--- a/docs/content-services/version-manager.component.md
+++ b/docs/content-services/version-manager.component.md
@@ -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
diff --git a/lib/content-services/i18n/en.json b/lib/content-services/i18n/en.json
index 267f7a3d51..9e985fa4bb 100644
--- a/lib/content-services/i18n/en.json
+++ b/lib/content-services/i18n/en.json
@@ -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": {
diff --git a/lib/content-services/version-manager/version-list.component.html b/lib/content-services/version-manager/version-list.component.html
index 174613f3bf..9d4fd46a8a 100644
--- a/lib/content-services/version-manager/version-list.component.html
+++ b/lib/content-services/version-manager/version-list.component.html
@@ -9,7 +9,7 @@
-
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}
@@ -19,7 +19,7 @@
(click)="downloadVersion(version.entry.id)">
{{ 'ADF_VERSION_LIST.ACTIONS.DOWNLOAD' | translate }}
-
{{ 'ADF_VERSION_LIST.ACTIONS.DELETE' | translate }}
diff --git a/lib/content-services/version-manager/version-list.component.spec.ts b/lib/content-services/version-manager/version-list.component.spec.ts
index 95c29bcec2..fef67e6d30 100644
--- a/lib/content-services/version-manager/version-list.component.spec.ts
+++ b/lib/content-services/version-manager/version-list.component.spec.ts
@@ -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
diff --git a/lib/content-services/version-manager/version-list.component.ts b/lib/content-services/version-manager/version-list.component.ts
index 7ffbc54566..f80977f1fc 100644
--- a/lib/content-services/version-manager/version-list.component.ts
+++ b/lib/content-services/version-manager/version-list.component.ts
@@ -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');
diff --git a/lib/content-services/version-manager/version-manager.component.html b/lib/content-services/version-manager/version-manager.component.html
index 9057bd0855..0560a58625 100644
--- a/lib/content-services/version-manager/version-manager.component.html
+++ b/lib/content-services/version-manager/version-manager.component.html
@@ -1,11 +1,15 @@
+ [showComments]="showComments">
diff --git a/lib/content-services/version-manager/version-manager.component.spec.ts b/lib/content-services/version-manager/version-manager.component.spec.ts
index 4ef60c87da..409174237e 100644
--- a/lib/content-services/version-manager/version-manager.component.spec.ts
+++ b/lib/content-services/version-manager/version-manager.component.spec.ts
@@ -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);
- });
});
diff --git a/lib/content-services/version-manager/version-manager.component.ts b/lib/content-services/version-manager/version-manager.component.ts
index bfec36bf6c..5b1b2fd466 100644
--- a/lib/content-services/version-manager/version-manager.component.ts
+++ b/lib/content-services/version-manager/version-manager.component.ts
@@ -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');
}
}
diff --git a/lib/content-services/version-manager/version-upload.component.html b/lib/content-services/version-manager/version-upload.component.html
index dc144dfb0d..54b3d037fa 100644
--- a/lib/content-services/version-manager/version-upload.component.html
+++ b/lib/content-services/version-manager/version-upload.component.html
@@ -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)">
diff --git a/lib/content-services/version-manager/version-upload.component.ts b/lib/content-services/version-manager/version-upload.component.ts
index 58e01d0da9..2ca410ba42 100644
--- a/lib/content-services/version-manager/version-upload.component.ts
+++ b/lib/content-services/version-manager/version-upload.component.ts
@@ -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 = new EventEmitter();
+ success = new EventEmitter();
@Output()
- error: EventEmitter = 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');
}
}
diff --git a/lib/core/app-config/schema.json b/lib/core/app-config/schema.json
index 02d77c2cbe..39c0383025 100644
--- a/lib/core/app-config/schema.json
+++ b/lib/core/app-config/schema.json
@@ -474,8 +474,7 @@
"type": "object",
"properties": {
"allowComments": { "type": "boolean" },
- "allowDownload": { "type": "boolean" },
- "allowDelete": { "type": "boolean" }
+ "allowDownload": { "type": "boolean" }
}
}
}