diff --git a/docs/README.md b/docs/README.md index 4f678c8a8e..0088bfc47c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -314,9 +314,10 @@ for more information about installing and using the source code. | [Upload Drag Area Component](content-services/components/upload-drag-area.component.md) | Adds a drag and drop area to upload files to ACS. | [Source](../lib/content-services/src/lib/upload/components/upload-drag-area.component.ts) | | [Upload Version Button Component (Workaround)](content-services/components/upload-version-button.component.md) ![Experimental](docassets/images/ExperimentalIcon.png) | Activates a file version upload. | [Source](../lib/content-services/src/lib/upload/components/upload-version-button.component.ts) | | [Version Comparison Component](content-services/components/version-comparison.component.md) | Displays the side by side comparison between the current target node (type, name, icon) and the new file that should update it's version. | [Source](../lib/content-services/src/lib/version-manager/version-comparison.component.ts) | -| [Version List component](content-services/components/version-list.component.md) ![Experimental](docassets/images/ExperimentalIcon.png) | Displays the version history of a node in a Version Manager component. | [Source](../lib/content-services/src/lib/version-manager/version-list.component.ts) | -| [Version Manager Component](content-services/components/version-manager.component.md) ![Experimental](docassets/images/ExperimentalIcon.png) | Displays the version history of a node with the ability to upload a new version. | [Source](../lib/content-services/src/lib/version-manager/version-manager.component.ts) | +| [Version List component](content-services/components/version-list.component.md) | Displays the version history of a node in a Version Manager component. | [Source](../lib/content-services/src/lib/version-manager/version-list.component.ts) | +| [Version Manager Component](content-services/components/version-manager.component.md) | Displays the version history of a node with the ability to upload a new version. | [Source](../lib/content-services/src/lib/version-manager/version-manager.component.ts) | | [Version Upload component](content-services/components/version-upload.component.md) ![Experimental](docassets/images/ExperimentalIcon.png) | Displays the new version's minor/major changes and the optional comment of a node in a Version Manager component. | [Source](../lib/content-services/src/lib/version-manager/version-upload.component.ts) | +| [New Version Uploader dialog](content-services/components/new-version-uploader.dialog.md) | Displays list of versions history of a node in a dialog. | [Source](../lib/content-services/src/lib/new-version-uploader/new-version-uploader.dialog.ts) | ### Directives diff --git a/docs/content-services/components/new-version-uploader.dialog.md b/docs/content-services/components/new-version-uploader.dialog.md new file mode 100644 index 0000000000..f402c59732 --- /dev/null +++ b/docs/content-services/components/new-version-uploader.dialog.md @@ -0,0 +1,52 @@ +--- +Title: Version List component +Added: v4.1.1 +Status: Active +Last reviewed: 2024-10-21 +--- + +# [New Version Uploader dialog](../../../lib/content-services/src/lib/new-version-uploader/new-version-uploader.dialog.ts "Defined in new-version-uploader.dialog.ts") + +Displays list of versions history of a node in a dialog. + +![Version Manager](../../docassets/images/new-version-uploader.png) +### Basic Usage + +```ts +this.dialog.open( + NewVersionUploaderDialogComponent, + { + data: { + file, + node, + currentVersion: version, + showComments: true, + allowDownload: true, + showVersionsOnly: true, + allowViewVersions: true, + allowVersionDelete: true, + showActions: true + }, + width: '630px' + } +) +``` + +## Class members + +### Events + +| Name | Type | Description | +|--------------|--------------------------------------------------------------------------------------|-----------------------------------| +| dialogAction | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when any action occurs. | +| uploadError | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when upload error occurs. | + +## Details + +This component can be used by calling openUploadNewVersionDialog function of [New Version Uploader service](../services/new-version-uploader.dialog.service.md). + +## See also + +- [Version manager component](version-manager.component.md) +- [New Version Uploader service](../services/new-version-uploader.dialog.service.md) +- [Version List component](version-list.component.md) diff --git a/docs/content-services/components/version-list.component.md b/docs/content-services/components/version-list.component.md index ff35792d5e..56d401d9f9 100644 --- a/docs/content-services/components/version-list.component.md +++ b/docs/content-services/components/version-list.component.md @@ -1,7 +1,7 @@ --- Title: Version List component Added: v2.0.0 -Status: Experimental +Status: Active Last reviewed: 2019-01-16 --- @@ -19,21 +19,22 @@ Displays the version history of a node in a [Version Manager component](version- ### Properties -| Name | Type | Default value | Description | -| ---- | ---- | ------------- | ----------- | -| allowDownload | `boolean` | true | Enable/disable downloading a version of the current node. | -| allowViewVersions | `boolean` | true | Enable/disable viewing a version of the current node. | -| node | `Node` | | The target node. | -| showActions | `boolean` | true | Toggles showing/hiding of version actions | -| showComments | `boolean` | true | Toggles showing/hiding of comments | +| Name | Type | Default value | Description | +|--------------------|-----------|---------------|-----------------------------------------------------------| +| allowDownload | `boolean` | true | Enable/disable downloading a version of the current node. | +| allowViewVersions | `boolean` | true | Enable/disable viewing a version of the current node. | +| node | `Node` | | The target node. | +| showActions | `boolean` | true | Toggles showing/hiding of version actions | +| showComments | `boolean` | true | Toggles showing/hiding of comments | +| allowVersionDelete | `boolean` | true | Enable/disable deletion of version | ### Events -| Name | Type | Description | -| ---- | ---- | ----------- | -| deleted | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when a version is deleted | -| restored | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when a version is restored | -| viewVersion | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when viewing a version | +| Name | Type | Description | +|-------------|----------------------------------------------------------------------|------------------------------------| +| deleted | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when a version is deleted | +| restored | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when a version is restored | +| viewVersion | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when viewing a version | ## Details @@ -49,3 +50,5 @@ If you want show readonly version list you set this component with showActions f ## See also - [Version manager component](version-manager.component.md) +- [New Version Uploader service](../services/new-version-uploader.dialog.service.md) +- [New Version Uploader component](new-version-uploader.dialog.md) diff --git a/docs/content-services/components/version-manager.component.md b/docs/content-services/components/version-manager.component.md index a962e6057b..a588ffab20 100644 --- a/docs/content-services/components/version-manager.component.md +++ b/docs/content-services/components/version-manager.component.md @@ -1,7 +1,7 @@ --- Title: Version Manager Component Added: v2.0.0 -Status: Experimental +Status: Active Last reviewed: 2019-01-16 --- @@ -11,8 +11,6 @@ Displays the version history of a node with the ability to upload a new version. ![Version Manager](../../docassets/images/version-manager.png) -`This component is still in experimental phase. It has several limitations which will be resolved soon.` - ## Basic Usage ```html @@ -27,13 +25,16 @@ Displays the version history of a node with the ability to upload a new version. ### Properties -| Name | Type | Default value | Description | -| ---- | ---- | ------------- | ----------- | -| allowDownload | `boolean` | true | Enable/disable downloading a version of the current node. | -| newFileVersion | `File` | | New file for updating current version. | -| node | `Node` | | Target node to manage version history. | -| showComments | `boolean` | true | Toggles showing/hiding of comments. | -| showVersionComparison | `boolean` | false | Toggles showing/hiding the [version comparison component](../../content-services/components/version-comparison.component.md). | +| Name | Type | Default value | Description | +|-----------------------|-----------|---------------|-------------------------------------------------------------------------------------------------------------------------------| +| allowDownload | `boolean` | true | Enable/disable downloading a version of the current node. | +| newFileVersion | `File` | | New file for updating current version. | +| node | `Node` | | Target node to manage version history. | +| showComments | `boolean` | true | Toggles showing/hiding of comments. | +| showVersionComparison | `boolean` | false | Toggles showing/hiding the [version comparison component](../../content-services/components/version-comparison.component.md). | +| showActions | `boolean` | true | Toggles showing/hiding of version actions. | +| allowViewVersions | `boolean` | true | Enable/disable viewing versions of the current node. | +| allowVersionDelete | `boolean` | true | Enable/disable deletion of version | ### Events @@ -50,11 +51,16 @@ Displays the version history of a node with the ability to upload a new version. Each version has a context menu on the right, with the following actions. -| Action | Versions | Description | -| ------ | -------- | ----------- | -| Restore | All | Revert the current version to the selected one with creating a new version of it. | +| Action | Versions | Description | +|----------|----------|-----------------------------------------------------------------------------------| +| View | All | View selected version. | +| Restore | All | Revert the current version to the selected one with creating a new version of it. | +| Download | All | Download selected version. | +| Delete | All | Delete selected version. | ## See also - [Version list component](version-list.component.md) - [Document list component](document-list.component.md) +- [New Version Uploader service](../services/new-version-uploader.dialog.service.md) +- [New Version Uploader component](new-version-uploader.dialog.md) diff --git a/docs/content-services/services/new-version-uploader.dialog.service.md b/docs/content-services/services/new-version-uploader.dialog.service.md index 55f656fab1..64538c753f 100644 --- a/docs/content-services/services/new-version-uploader.dialog.service.md +++ b/docs/content-services/services/new-version-uploader.dialog.service.md @@ -88,6 +88,6 @@ yourFunctionToOpenDialog(){ ## See Also -- [Version list component](../components/docs/content-services/components/version-list.component.md) -- [Version Comparison Component](../components/docs/content-services/components/version-comparison.component.md) -- [Version Upload Component](../components/docs/content-services/components/version-upload.component.md) +- [Version list component](../components/version-list.component.md) +- [Version Comparison Component](../components/version-comparison.component.md) +- [Version Upload Component](../components/version-upload.component.md) diff --git a/docs/docassets/images/new-version-uploader.png b/docs/docassets/images/new-version-uploader.png new file mode 100644 index 0000000000..aa31b2356d Binary files /dev/null and b/docs/docassets/images/new-version-uploader.png differ diff --git a/docs/docassets/images/version-manager.png b/docs/docassets/images/version-manager.png index 7fa3fdc679..c804527146 100644 Binary files a/docs/docassets/images/version-manager.png and b/docs/docassets/images/version-manager.png differ diff --git a/docs/versionIndex.md b/docs/versionIndex.md index 0dc74bfd3f..dcfb75a78c 100644 --- a/docs/versionIndex.md +++ b/docs/versionIndex.md @@ -26,6 +26,7 @@ backend services have been tested with each released version of ADF. - [v4.4.0](#v440) - [v4.3.0](#v430) - [v4.2.0](#v420) +- [v4.1.1](#v411) - [v4.1.0](#v410) - [v4.0.0](#v400) - [v3.9.0](#v390) @@ -196,6 +197,14 @@ backend services have been tested with each released version of ADF. +## v4.1.1 + + + +- [New version uploader dialog](content-services/components/new-version-uploader.dialog.md) + + + ## v4.1.0 diff --git a/lib/content-services/src/lib/new-version-uploader/models/new-version-uploader.model.ts b/lib/content-services/src/lib/new-version-uploader/models/new-version-uploader.model.ts index 1de798ac20..18c4b256ae 100644 --- a/lib/content-services/src/lib/new-version-uploader/models/new-version-uploader.model.ts +++ b/lib/content-services/src/lib/new-version-uploader/models/new-version-uploader.model.ts @@ -25,7 +25,10 @@ export interface NewVersionUploaderDialogData { currentVersion?: Version; showVersionsOnly?: boolean; showComments?: boolean; + showActions?: boolean; allowDownload?: boolean; + allowViewVersions?: boolean; + allowVersionDelete?: boolean; } export type NewVersionUploaderData = VersionManagerUploadData | ViewVersion | RefreshData; diff --git a/lib/content-services/src/lib/new-version-uploader/new-version-uploader.dialog.html b/lib/content-services/src/lib/new-version-uploader/new-version-uploader.dialog.html index b8d774c4e7..a7ed1a30f1 100644 --- a/lib/content-services/src/lib/new-version-uploader/new-version-uploader.dialog.html +++ b/lib/content-services/src/lib/new-version-uploader/new-version-uploader.dialog.html @@ -19,7 +19,10 @@ { let component: NewVersionUploaderDialogComponent; @@ -138,6 +140,8 @@ describe('NewVersionUploaderDialog', () => { describe('Manage Versions', () => { const expectedManageVersionsTitle = 'ADF-NEW-VERSION-UPLOADER.DIALOG_LIST.TITLE'; + const getVersionListComponent = (): VersionListComponent => fixture.debugElement.query(By.css(cssSelectors.adfVersionList)).componentInstance; + it('should display adf version list if showVersionsOnly is passed as true from parent component', () => { component.data.showVersionsOnly = true; fixture.detectChanges(); @@ -182,5 +186,53 @@ describe('NewVersionUploaderDialog', () => { const matDialogTitle = nativeElement.querySelector(cssSelectors.title); expect(matDialogTitle.innerHTML).toEqual('TEST_TITLE'); }); + + it('should have assigned allowViewVersions to true if allowViewVersions from data is true', () => { + component.data.showVersionsOnly = true; + component.data.allowViewVersions = true; + + fixture.detectChanges(); + expect(getVersionListComponent().allowViewVersions).toBeTrue(); + }); + + it('should have assigned allowViewVersions to false if allowViewVersions from data is false', () => { + component.data.showVersionsOnly = true; + component.data.allowViewVersions = false; + + fixture.detectChanges(); + expect(getVersionListComponent().allowViewVersions).toBeFalse(); + }); + + it('should have assigned showActions to true if showActions from data is true', () => { + component.data.showVersionsOnly = true; + component.data.showActions = true; + + fixture.detectChanges(); + expect(getVersionListComponent().showActions).toBeTrue(); + }); + + it('should have assigned showActions to false if showActions from data is false', () => { + component.data.showVersionsOnly = true; + component.data.showActions = false; + + fixture.detectChanges(); + expect(getVersionListComponent().showActions).toBeFalse(); + }); + + it('should have assigned allowVersionDelete to true if allowVersionDelete from data is true', () => { + component.data.showVersionsOnly = true; + component.data.allowVersionDelete = true; + + fixture.detectChanges(); + expect(getVersionListComponent().allowVersionDelete).toBeTrue(); + }); + + it('should have assigned allowVersionDelete to false if allowVersionDelete from data is false', () => { + component.data.showVersionsOnly = true; + component.data.allowVersionDelete = false; + + fixture.detectChanges(); + expect(getVersionListComponent().allowVersionDelete).toBeFalse(); + }); }); }); diff --git a/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.spec.ts b/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.spec.ts index 82e8bd5ea1..cd8cc6d2a5 100644 --- a/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.spec.ts +++ b/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.spec.ts @@ -31,6 +31,7 @@ import { } from './models'; import { NewVersionUploaderDialogComponent } from './new-version-uploader.dialog'; import { NewVersionUploaderService } from './new-version-uploader.service'; +import { Version, VersionPaging } from '@alfresco/js-api'; @Component({ template: '' @@ -75,208 +76,245 @@ describe('NewVersionUploaderService', () => { }); describe('openUploadNewVersionDialog', () => { - describe('Mat Dialog configuration', () => { - let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData; - beforeEach(() => { - spyOn(service.versionsApi, 'listVersionHistory').and.returnValue( - Promise.resolve({ - list: { entries: [{ entry: '2' }] } - } as any) - ); - mockNewVersionUploaderDialogData = { - node: mockNode, + let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData; + let expectedConfig: MatDialogConfig; + + beforeEach(() => { + spyOn(service.versionsApi, 'listVersionHistory').and.returnValue( + Promise.resolve({ + list: { + entries: [ + { + entry: { + id: '2' + } + } + ] + } + } as VersionPaging) + ); + mockNewVersionUploaderDialogData = { + node: mockNode, + file: mockFile, + showComments: true, + allowDownload: true + }; + expectedConfig = { + data: { file: mockFile, - showComments: true, - allowDownload: true - }; - }); - - it('Should open dialog with default configuration', fakeAsync(() => { - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).toPromise(); - tick(); - expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, { - data: { - file: mockFile, - node: mockNode, - currentVersion: '2', - showComments: true, - allowDownload: true, - showVersionsOnly: undefined - }, - panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'], - width: '630px' - } as any); - })); - - it('Should override default dialog panelClass', fakeAsync(() => { - const mockDialogConfiguration: MatDialogConfig = { - panelClass: 'adf-custom-class', - width: '500px' - }; - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); - tick(); - expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, { - data: { - file: mockFile, - node: mockNode, - currentVersion: '2', - showComments: true, - allowDownload: true, - showVersionsOnly: undefined - }, - panelClass: 'adf-custom-class', - width: '500px' - } as any); - })); - - it('Should set dialog height', fakeAsync(() => { - const mockDialogConfiguration: MatDialogConfig = { - height: '600px' - }; - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); - tick(); - expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, { - data: { - file: mockFile, - node: mockNode, - currentVersion: '2', - showComments: true, - allowDownload: true, - showVersionsOnly: undefined - }, - panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'], - width: '630px', - height: '600px' - } as any); - })); - - it('Should not override dialog configuration, if dialog configuration is empty', fakeAsync(() => { - const mockDialogConfiguration: MatDialogConfig = {}; - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); - tick(); - expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, { - data: { - file: mockFile, - node: mockNode, - currentVersion: '2', - showComments: true, - allowDownload: true, - showVersionsOnly: undefined - }, - panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'], - width: '630px' - } as any); - })); - - it('Should dialog add list css class if showVersionsOnly is true', fakeAsync(() => { - const mockNewVersionUploaderDialogDataWithVersionsOnly = { node: mockNode, - file: mockFile, - showVersionsOnly: true, + currentVersion: { + id: '2' + } as Version, showComments: true, - allowDownload: true - }; - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly).toPromise(); - tick(); - expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, { - data: { - file: mockFile, - node: mockNode, - currentVersion: '2', - showComments: true, - allowDownload: true, - showVersionsOnly: true - }, - panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-list'], - width: '630px' - } as any); - })); + allowDownload: true, + showVersionsOnly: undefined, + allowViewVersions: true, + allowVersionDelete: true, + showActions: true + }, + panelClass: ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-upload'], + width: '630px' + }; }); - describe('Subscribe events from Dialog', () => { - let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData; + it('should open dialog with default configuration', fakeAsync(() => { + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).toPromise(); + tick(); + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + })); - beforeEach(() => { - spyOn(service.versionsApi, 'listVersionHistory').and.returnValue( - Promise.resolve({ - list: { entries: [{ entry: '2' }] } - }) as any - ); - mockNewVersionUploaderDialogData = { - node: mockNode, - file: mockFile - }; + it('should override default dialog panelClass', fakeAsync(() => { + const mockDialogConfiguration: MatDialogConfig = { + panelClass: 'adf-custom-class', + width: '500px' + }; + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); + tick(); + expectedConfig.panelClass = 'adf-custom-class'; + expectedConfig.width = '500px'; + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + })); + + it('should set dialog height', fakeAsync(() => { + const mockDialogConfiguration: MatDialogConfig = { + height: '600px' + }; + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); + tick(); + expectedConfig.height = '600px'; + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + })); + + it('should not override dialog configuration, if dialog configuration is empty', fakeAsync(() => { + const mockDialogConfiguration: MatDialogConfig = {}; + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); + tick(); + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + })); + + it('should dialog add list css class if showVersionsOnly is true', fakeAsync(() => { + const mockNewVersionUploaderDialogDataWithVersionsOnly = { + node: mockNode, + file: mockFile, + showVersionsOnly: true, + showComments: true, + allowDownload: true + }; + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly).toPromise(); + tick(); + expectedConfig.data.showVersionsOnly = true; + expectedConfig.panelClass = ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-list']; + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + })); + + it('should open dialog with correct configuration when allowViewVersions is true', (done) => { + dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); + mockNewVersionUploaderDialogData.allowViewVersions = true; + + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => { + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + done(); }); + }); - it('Should return Refresh action', (done) => { - dialogRefSpyObj.componentInstance = { - dialogAction: new BehaviorSubject({ - action: NewVersionUploaderDataAction.refresh, - node: mockNode - }), - uploadError: new Subject() - }; - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => { - expect(res).toEqual({ action: NewVersionUploaderDataAction.refresh, node: mockNode }); - done(); - }); + it('should open dialog with correct configuration when allowViewVersions is false', (done) => { + dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); + mockNewVersionUploaderDialogData.allowViewVersions = false; + + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => { + expectedConfig.data.allowViewVersions = false; + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + done(); }); + }); - it('Should return Upload action', (done) => { - dialogRefSpyObj.componentInstance = { - dialogAction: new BehaviorSubject(mockNewVersionUploaderData), - uploadError: new Subject() - }; - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => { - expect(res).toEqual(mockNewVersionUploaderData); - done(); - }); + it('should open dialog with correct configuration when allowVersionDelete is true', (done) => { + dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); + mockNewVersionUploaderDialogData.allowVersionDelete = true; + + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => { + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + done(); }); + }); - it('Should return View Version action', (done) => { - dialogRefSpyObj.componentInstance = { - dialogAction: new BehaviorSubject({ - action: NewVersionUploaderDataAction.view, - versionId: '2' - }), - uploadError: new Subject() - }; - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => { - expect(res).toEqual({ action: NewVersionUploaderDataAction.view, versionId: '2' }); - done(); - }); + it('should open dialog with correct configuration when allowVersionDelete is false', (done) => { + dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); + mockNewVersionUploaderDialogData.allowVersionDelete = false; + + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => { + expectedConfig.data.allowVersionDelete = false; + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + done(); }); + }); - it('Should return upload error', (done) => { - dialogRefSpyObj.componentInstance = { - dialogAction: new Subject(), - uploadError: new BehaviorSubject({ value: 'Upload error' }) - }; - spyOnDialogOpen.and.returnValue(dialogRefSpyObj); - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe( - () => { - fail('An error should have been thrown'); - }, - (error) => { - expect(error).toEqual({ value: 'Upload error' }); - done(); - } - ); + it('should open dialog with correct configuration when showActions is true', (done) => { + dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); + mockNewVersionUploaderDialogData.showActions = true; + + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => { + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + done(); }); + }); - it('should focus element indicated by passed selector after closing modal', (done) => { - dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); - const afterClosed$ = new BehaviorSubject(undefined); - dialogRefSpyObj.afterClosed = () => afterClosed$; - const elementToFocusSelector = 'button'; - const elementToFocus = document.createElement(elementToFocusSelector); - spyOn(elementToFocus, 'focus').and.callFake(() => { - expect(elementToFocus.focus).toHaveBeenCalled(); - done(); - }); - spyOn(document, 'querySelector').and.returnValue(elementToFocus); - service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, undefined, elementToFocusSelector).subscribe(); + it('should open dialog with correct configuration when showActions is false', (done) => { + dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); + mockNewVersionUploaderDialogData.showActions = false; + + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe(() => { + expectedConfig.data.showActions = false; + expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); + done(); }); }); }); + + describe('Subscribe events from Dialog', () => { + let mockNewVersionUploaderDialogData: NewVersionUploaderDialogData; + + beforeEach(() => { + spyOn(service.versionsApi, 'listVersionHistory').and.returnValue( + Promise.resolve({ + list: { entries: [{ entry: '2' }] } + }) as any + ); + mockNewVersionUploaderDialogData = { + node: mockNode, + file: mockFile + }; + }); + + it('Should return Refresh action', (done) => { + dialogRefSpyObj.componentInstance = { + dialogAction: new BehaviorSubject({ + action: NewVersionUploaderDataAction.refresh, + node: mockNode + }), + uploadError: new Subject() + }; + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => { + expect(res).toEqual({ action: NewVersionUploaderDataAction.refresh, node: mockNode }); + done(); + }); + }); + + it('Should return Upload action', (done) => { + dialogRefSpyObj.componentInstance = { + dialogAction: new BehaviorSubject(mockNewVersionUploaderData), + uploadError: new Subject() + }; + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => { + expect(res).toEqual(mockNewVersionUploaderData); + done(); + }); + }); + + it('Should return View Version action', (done) => { + dialogRefSpyObj.componentInstance = { + dialogAction: new BehaviorSubject({ + action: NewVersionUploaderDataAction.view, + versionId: '2' + }), + uploadError: new Subject() + }; + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe((res) => { + expect(res).toEqual({ action: NewVersionUploaderDataAction.view, versionId: '2' }); + done(); + }); + }); + + it('Should return upload error', (done) => { + dialogRefSpyObj.componentInstance = { + dialogAction: new Subject(), + uploadError: new BehaviorSubject({ value: 'Upload error' }) + }; + spyOnDialogOpen.and.returnValue(dialogRefSpyObj); + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).subscribe( + () => { + fail('An error should have been thrown'); + }, + (error) => { + expect(error).toEqual({ value: 'Upload error' }); + done(); + } + ); + }); + + it('should focus element indicated by passed selector after closing modal', (done) => { + dialogRefSpyObj.componentInstance.dialogAction = new BehaviorSubject(mockNewVersionUploaderData); + const afterClosed$ = new BehaviorSubject(undefined); + dialogRefSpyObj.afterClosed = () => afterClosed$; + const elementToFocusSelector = 'button'; + const elementToFocus = document.createElement(elementToFocusSelector); + spyOn(elementToFocus, 'focus').and.callFake(() => { + expect(elementToFocus.focus).toHaveBeenCalled(); + done(); + }); + spyOn(document, 'querySelector').and.returnValue(elementToFocus); + service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, undefined, elementToFocusSelector).subscribe(); + }); + }); }); diff --git a/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.ts b/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.ts index f318ca86bc..ba80d18eab 100644 --- a/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.ts +++ b/lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.ts @@ -62,7 +62,17 @@ export class NewVersionUploaderService { const dialogRef = this.dialog.open( NewVersionUploaderDialogComponent, { - data: { file, node, currentVersion: versionPaging.list.entries[0].entry, showComments, allowDownload, showVersionsOnly }, + data: { + file, + node, + currentVersion: versionPaging.list.entries[0].entry, + showComments, + allowDownload, + showVersionsOnly, + allowViewVersions: data.allowViewVersions ?? true, + allowVersionDelete: data.allowVersionDelete ?? true, + showActions: data.showActions ?? true + }, panelClass: this.composePanelClass(showVersionsOnly), width: '630px', ...(config && Object.keys(config).length > 0 && config) diff --git a/lib/content-services/src/lib/version-manager/version-list.component.html b/lib/content-services/src/lib/version-manager/version-list.component.html index 790dcc3ad6..71a71e23c6 100644 --- a/lib/content-services/src/lib/version-manager/version-list.component.html +++ b/lib/content-services/src/lib/version-manager/version-list.component.html @@ -1,7 +1,7 @@ - + insert_drive_file @@ -50,6 +50,7 @@ {{ 'ADF_VERSION_LIST.ACTIONS.DOWNLOAD' | translate }} @@ -32,6 +33,9 @@ [node]="node" [allowDownload]="allowDownload" [showComments]="showComments" + [showActions]="showActions" + [allowViewVersions]="allowViewVersions" + [allowVersionDelete]="allowVersionDelete" (deleted)="refresh($event)" (restored)="refresh($event)" (viewVersion)="onViewVersion($event)"> diff --git a/lib/content-services/src/lib/version-manager/version-manager.component.scss b/lib/content-services/src/lib/version-manager/version-manager.component.scss index 65e9eabb4b..13ce9ff3d8 100644 --- a/lib/content-services/src/lib/version-manager/version-manager.component.scss +++ b/lib/content-services/src/lib/version-manager/version-manager.component.scss @@ -41,6 +41,15 @@ adf-version-manager { .adf-version-list-table { width: 100%; + + .adf-version-manager-upload-button { + margin-left: 20px; + } + + adf-version-list { + display: flex; + height: 538px; + } } .adf-version-upload-table { diff --git a/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts b/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts index 45a3d19570..4e9339b840 100644 --- a/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts +++ b/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts @@ -118,4 +118,106 @@ describe('VersionManagerComponent', () => { expect(component.uploadState).toEqual('open'); }); }); + + describe('Version list', () => { + it('should have assigned showActions to true by default', () => { + fixture.detectChanges(); + + expect(component.versionListComponent.showActions).toBeTrue(); + }); + + it('should have assigned showActions to true if true is passed to showActions for component', () => { + component.showActions = true; + fixture.detectChanges(); + + expect(component.versionListComponent.showActions).toBeTrue(); + }); + + it('should have assigned showActions to false if false is passed to showActions for component', () => { + component.showActions = false; + fixture.detectChanges(); + + expect(component.versionListComponent.showActions).toBeFalse(); + }); + + it('should have assigned allowViewVersions to true by default', () => { + fixture.detectChanges(); + + expect(component.versionListComponent.allowViewVersions).toBeTrue(); + }); + + it('should have assigned allowViewVersions to true if true is passed to allowViewVersions for component', () => { + component.allowViewVersions = true; + fixture.detectChanges(); + + expect(component.versionListComponent.allowViewVersions).toBeTrue(); + }); + + it('should have assigned allowViewVersions to false if false is passed to allowViewVersions for component', () => { + component.allowViewVersions = false; + fixture.detectChanges(); + + expect(component.versionListComponent.allowViewVersions).toBeFalse(); + }); + + it('should have assigned allowVersionDelete to true by default', () => { + fixture.detectChanges(); + + expect(component.versionListComponent.allowVersionDelete).toBeTrue(); + }); + + it('should have assigned allowVersionDelete to true if true is passed to allowVersionDelete for component', () => { + component.allowVersionDelete = true; + fixture.detectChanges(); + + expect(component.versionListComponent.allowVersionDelete).toBeTrue(); + }); + + it('should have assigned allowVersionDelete to false if false is passed to allowVersionDelete for component', () => { + component.allowVersionDelete = false; + fixture.detectChanges(); + + expect(component.versionListComponent.allowVersionDelete).toBeFalse(); + }); + + it('should have assigned showComments to true by default', () => { + fixture.detectChanges(); + + expect(component.versionListComponent.showComments).toBeTrue(); + }); + + it('should have assigned showComments to true if true is passed to showComments for component', () => { + component.showComments = true; + fixture.detectChanges(); + + expect(component.versionListComponent.showComments).toBeTrue(); + }); + + it('should have assigned showComments to false if false is passed to showComments for component', () => { + component.showComments = false; + fixture.detectChanges(); + + expect(component.versionListComponent.showComments).toBeFalse(); + }); + + it('should have assigned allowDownload to true by default', () => { + fixture.detectChanges(); + + expect(component.versionListComponent.showComments).toBeTrue(); + }); + + it('should have assigned allowDownload to true if true is passed to allowDownload for component', () => { + component.allowDownload = true; + fixture.detectChanges(); + + expect(component.versionListComponent.allowDownload).toBeTrue(); + }); + + it('should have assigned allowDownload to false if false is passed to allowDownload for component', () => { + component.allowDownload = false; + fixture.detectChanges(); + + expect(component.versionListComponent.allowDownload).toBeFalse(); + }); + }); }); diff --git a/lib/content-services/src/lib/version-manager/version-manager.component.ts b/lib/content-services/src/lib/version-manager/version-manager.component.ts index 986fee08af..e9393581ca 100644 --- a/lib/content-services/src/lib/version-manager/version-manager.component.ts +++ b/lib/content-services/src/lib/version-manager/version-manager.component.ts @@ -65,6 +65,18 @@ export class VersionManagerComponent implements OnInit { @Input() allowDownload = true; + /** Toggles showing/hiding of version actions. */ + @Input() + showActions = true; + + /** Enable/disable viewing versions of the current node. */ + @Input() + allowViewVersions = true; + + /** Enable/disable deletion of version */ + @Input() + allowVersionDelete = true; + /** Emitted when a file is uploaded successfully. */ @Output() uploadSuccess = new EventEmitter();