[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

@@ -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();