[ADF-2562] Download a previous version (#3141)

* [ADF-2562] Download a previous version

* [ADF-2562] add input property to enable/disable version downloads

* [ADF-2562] add example in demo-shell

* [ADF-2562] unit tests

* [ADF-2561] View comments on previous versions (#3137)

* [ADF-2561] View comments on previous versions

add input property to enable/disable viewing version comments

* [ADF-2561] add more tests

* remove name property

* test fixes
This commit is contained in:
Suzana Dirla 2018-04-05 23:24:05 +03:00 committed by Denys Vuika
parent 9792f83c9b
commit 7b7e39d989
13 changed files with 95 additions and 19 deletions

View File

@ -59,6 +59,7 @@
"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",

View File

@ -353,7 +353,8 @@
<ng-container *ngIf="userHasPermissionToManageVersions(); else no_permission_to_versions">
<adf-version-manager
[node]="documentList.selection[0].entry"
[showComments]="showVersionComments">
[showComments]="showVersionComments"
[enableDownload]="enableVersionDownload">
</adf-version-manager>
</ng-container>
</ng-container>
@ -440,8 +441,11 @@
</section>
<section>
<mat-slide-toggle [color]="'primary'" [(ngModel)]="showVersionComments">{{'DOCUMENT_LIST.SHOW_VERSION_COMMENTS' |
translate}}
<mat-slide-toggle [color]="'primary'" [(ngModel)]="showVersionComments">
{{'DOCUMENT_LIST.SHOW_VERSION_COMMENTS' | translate}}
</mat-slide-toggle>
<mat-slide-toggle [color]="'primary'" [(ngModel)]="enableVersionDownload">
{{'DOCUMENT_LIST.ENABLE_VERSION_DOWNLOAD' | translate}}
</mat-slide-toggle>
</section>

View File

@ -102,6 +102,9 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
@Input()
versioning = false;
@Input()
enableVersionDownload = true;
@Input()
acceptedFilesType = '.jpg,.pdf,.js';
@ -362,10 +365,11 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
onManageVersions(event) {
const contentEntry = event.value.entry;
const showComments = this.showVersionComments;
const enableDownload = this.enableVersionDownload;
if (this.contentService.hasPermission(contentEntry, 'update')) {
this.dialog.open(VersionManagerDialogAdapterComponent, {
data: { contentEntry, showComments },
data: { contentEntry, showComments, enableDownload },
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" [showComments]="showComments" (uploadError)="uploadError($event)"></adf-version-manager>
<adf-version-manager [node]="contentEntry" [enableDownload]="enableDownload" [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,12 +28,14 @@ export class VersionManagerDialogAdapterComponent {
public contentEntry: MinimalNodeEntryEntity;
showComments = true;
enableDownload = 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;
}
uploadError(errorMessage: string) {

View File

@ -18,6 +18,7 @@ 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. |
## Details

View File

@ -26,6 +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. |
### Events

View File

@ -44,7 +44,7 @@ export class SearchFilterComponent implements OnInit {
this.queryBuilder.execute();
});
}
ngOnInit() {
if (this.queryBuilder) {
this.queryBuilder.executed.subscribe(data => {

View File

@ -10,6 +10,7 @@
<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>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="versionMenu">

View File

@ -24,6 +24,7 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
describe('VersionListComponent', () => {
let component: VersionListComponent;
let fixture: ComponentFixture<VersionListComponent>;
let alfrescoApiService: AlfrescoApiService;
const nodeId = 'test-id';
const versionId = '1.0';
@ -44,15 +45,17 @@ describe('VersionListComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(VersionListComponent);
alfrescoApiService = TestBed.get(AlfrescoApiService);
component = fixture.componentInstance;
component.id = nodeId;
spyOn(component, 'downloadContent').and.stub();
});
describe('Version history fetching', () => {
it('should use loading bar', () => {
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
@ -67,7 +70,6 @@ describe('VersionListComponent', () => {
});
it('should load the versions for a given id', () => {
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
@ -77,9 +79,8 @@ describe('VersionListComponent', () => {
expect(alfrescoApiService.versionsApi.listVersionHistory).toHaveBeenCalledWith(nodeId);
});
it('should show the versions after loading', async(() => {
it('should show the versions after loading', (done) => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => {
return Promise.resolve({ list: { entries: [
{
@ -99,11 +100,11 @@ describe('VersionListComponent', () => {
expect(versionFileName).toBe('test-file-name');
expect(versionIdText).toBe('1.0');
expect(versionComment).toBe('test-version-comment');
done();
});
}));
});
it('should NOT show the versions comments if input property is set not to show them', async(() => {
const alfrescoApiService = TestBed.get(AlfrescoApiService);
it('should NOT show the versions comments if input property is set not to show them', (done) => {
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve(
{
@ -127,15 +128,40 @@ describe('VersionListComponent', () => {
let versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment'));
expect(versionCommentEl).toBeNull();
done();
});
}));
});
it('should be able to download a version', () => {
const versionEntry = { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }};
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve({ list: { entries: [ versionEntry ] }}));
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('the/download/url');
fixture.detectChanges();
component.downloadVersion('1.0');
expect(alfrescoApiService.contentApi.getContentUrl).toHaveBeenCalledWith(nodeId, true);
});
it('should NOT be able to download a version if configured so', () => {
const versionEntry = { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }};
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: [ versionEntry ] }}));
const spyOnDownload = spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.stub();
component.enableDownload = false;
fixture.detectChanges();
component.downloadVersion('1.0');
expect(spyOnDownload).not.toHaveBeenCalled();
});
});
describe('Version restoring', () => {
it('should load the versions for a given id', () => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
const spyOnRevertVersion = spyOn(alfrescoApiService.versionsApi, 'revertVersion').and
@ -147,9 +173,8 @@ describe('VersionListComponent', () => {
expect(spyOnRevertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: ''});
});
it('should reload the version list after a version restore', async(() => {
it('should reload the version list after a version restore', (done) => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
const spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: []}}));
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
@ -158,7 +183,8 @@ describe('VersionListComponent', () => {
fixture.whenStable().then(() => {
expect(spyOnListVersionHistory).toHaveBeenCalledTimes(1);
done();
});
}));
});
});
});

View File

@ -41,6 +41,10 @@ export class VersionListComponent implements OnChanges {
@Input()
showComments: boolean = true;
/** Enable/disable possibility to download a version of the current node. */
@Input()
enableDownload: boolean = true;
constructor(private alfrescoApi: AlfrescoApiService) {
this.versionsApi = this.alfrescoApi.versionsApi;
}
@ -62,4 +66,29 @@ export class VersionListComponent implements OnChanges {
this.isLoading = false;
});
}
downloadVersion(versionId) {
if (this.enableDownload) {
const versionDownloadUrl = this.getVersionContentUrl(this.id, versionId, true);
this.downloadContent(versionDownloadUrl);
}
}
private getVersionContentUrl(nodeId: string, versionId: string, attachment?: boolean) {
const nodeDownloadUrl = this.alfrescoApi.contentApi.getContentUrl(nodeId, attachment);
return nodeDownloadUrl.replace('/content', '/versions/' + versionId + '/content');
}
downloadContent(url: string) {
if (url) {
const link = document.createElement('a');
link.style.display = 'none';
link.href = url;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
}

View File

@ -2,5 +2,9 @@
<adf-version-upload [node]="node" (success)="onUploadSuccess($event)" (error)="onUploadError($event)"></adf-version-upload>
</div>
<div class="adf-version-list-container">
<adf-version-list #versionList [id]="node.id" [showComments]="showComments"></adf-version-list>
<adf-version-list
#versionList [id]="node.id"
[enableDownload]="enableDownload"
[showComments]="showComments">
</adf-version-list>
</div>

View File

@ -33,6 +33,9 @@ export class VersionManagerComponent {
@Input()
showComments: boolean = true;
@Input()
enableDownload: boolean = true;
@Output()
uploadSuccess: EventEmitter<any> = new EventEmitter();