diff --git a/projects/aca-content/src/lib/aca-content.routes.ts b/projects/aca-content/src/lib/aca-content.routes.ts index 82646ab446..e6a5b2deed 100644 --- a/projects/aca-content/src/lib/aca-content.routes.ts +++ b/projects/aca-content/src/lib/aca-content.routes.ts @@ -440,7 +440,8 @@ export const CONTENT_LAYOUT_ROUTES: Route = { path: '', component: SearchResultsComponent, data: { - title: 'APP.BROWSE.SEARCH.TITLE' + title: 'APP.BROWSE.SEARCH.TITLE', + sortingPreferenceKey: 'search' } }, { @@ -478,7 +479,8 @@ export const CONTENT_LAYOUT_ROUTES: Route = { path: '', component: SearchLibrariesResultsComponent, data: { - title: 'APP.BROWSE.SEARCH.TITLE' + title: 'APP.BROWSE.SEARCH.TITLE', + sortingPreferenceKey: 'search-libraries' } }, { diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.html b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.html index 103b60ebe7..bffcc6baa1 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.html +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.html @@ -39,11 +39,13 @@ @@ -55,6 +57,7 @@ - + @@ -58,13 +58,13 @@ - + - + {{context.row?.node?.entry?.properties && context.row?.node?.entry?.properties['cm:description']}} @@ -72,10 +72,10 @@ - - - - + + + + diff --git a/projects/aca-content/src/lib/directives/document-list.directive.spec.ts b/projects/aca-content/src/lib/directives/document-list.directive.spec.ts index a060cac03c..440da3005e 100644 --- a/projects/aca-content/src/lib/directives/document-list.directive.spec.ts +++ b/projects/aca-content/src/lib/directives/document-list.directive.spec.ts @@ -40,7 +40,10 @@ describe('DocumentListDirective', () => { selection: [], reload: jasmine.createSpy('reload'), resetSelection: jasmine.createSpy('resetSelection'), - ready: new Subject() + ready: new Subject(), + setColumnsWidths: {}, + setColumnsVisibility: {}, + setColumnsOrder: {} }; const storeMock: any = { @@ -66,7 +69,8 @@ describe('DocumentListDirective', () => { const userPreferencesServiceMock: any = { set: jasmine.createSpy('set'), - get: jasmine.createSpy('get') + get: jasmine.createSpy('get'), + hasItem: jasmine.createSpy('hasItem') }; beforeEach(() => { @@ -158,4 +162,45 @@ describe('DocumentListDirective', () => { expect(storeMock.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([])); expect(documentListDirective.selectedNode).toBeNull(); }); + + it('should set user preferences for columns visibility`', () => { + const event = new CustomEvent('columnsVisibilityChanged', { detail: { 'app.tags': true, 'app.name': false } }); + mockRoute.snapshot.data.sortingPreferenceKey = 'files'; + documentListDirective.ngOnInit(); + documentListDirective.onColumnsVisibilityChange(event); + + expect(userPreferencesServiceMock.set).toHaveBeenCalledWith('files.columns.visibility', JSON.stringify(event)); + }); + + it('should set user preferences for columns order`', () => { + const event = new CustomEvent('columnsOrderChanged', { detail: ['app.tags', 'app.name'] }); + mockRoute.snapshot.data.sortingPreferenceKey = 'files'; + documentListDirective.ngOnInit(); + documentListDirective.onColumnOrderChanged(event); + + expect(userPreferencesServiceMock.set).toHaveBeenCalledWith('files.columns.order', JSON.stringify(event)); + }); + + it('should set user preferences for columns width`', () => { + const event = new CustomEvent('columnsWidthChanged', { detail: { 'app.tags': 65, 'app.name': 75 } }); + mockRoute.snapshot.data.sortingPreferenceKey = 'files'; + documentListDirective.ngOnInit(); + documentListDirective.onColumnsWidthChanged(event); + + expect(userPreferencesServiceMock.set).toHaveBeenCalledWith('files.columns.width', JSON.stringify(event)); + }); + + it('should set document list properties from user preferences`', () => { + mockRoute.snapshot.data.sortingPreferenceKey = 'files'; + userPreferencesServiceMock.hasItem.and.returnValue(true); + userPreferencesServiceMock.get.and.returnValue(false); + userPreferencesServiceMock.get.withArgs('files.columns.width').and.returnValue(JSON.stringify({ 'app.tag': 87 })); + userPreferencesServiceMock.get.withArgs('files.columns.order').and.returnValue(JSON.stringify(['app.tag', 'app.name'])); + userPreferencesServiceMock.get.withArgs('files.columns.visibility').and.returnValue(JSON.stringify({ 'app.tag': true })); + documentListDirective.ngOnInit(); + + expect(documentListMock.setColumnsWidths).toEqual({ 'app.tag': 87 }); + expect(documentListMock.setColumnsOrder).toEqual(['app.tag', 'app.name']); + expect(documentListMock.setColumnsVisibility).toEqual({ 'app.tag': true }); + }); }); diff --git a/projects/aca-content/src/lib/directives/document-list.directive.ts b/projects/aca-content/src/lib/directives/document-list.directive.ts index b60ece9631..0994c82446 100644 --- a/projects/aca-content/src/lib/directives/document-list.directive.ts +++ b/projects/aca-content/src/lib/directives/document-list.directive.ts @@ -72,13 +72,15 @@ export class DocumentListDirective implements OnInit, OnDestroy { const direction = this.preferences.get(`${this.sortingPreferenceKey}.sorting.direction`, current[1]); if (this.preferences.hasItem(`${this.sortingPreferenceKey}.columns.width`)) { - const columnsWidths = JSON.parse(this.preferences.get(`${this.sortingPreferenceKey}.columns.width`)); - this.documentList.setColumnsWidths(columnsWidths); + this.documentList.setColumnsWidths = JSON.parse(this.preferences.get(`${this.sortingPreferenceKey}.columns.width`)); } if (this.preferences.hasItem(`${this.sortingPreferenceKey}.columns.visibility`)) { - const columnsVisibility = JSON.parse(this.preferences.get(`${this.sortingPreferenceKey}.columns.visibility`)); - this.documentList.setColumnsVisibility(columnsVisibility); + this.documentList.setColumnsVisibility = JSON.parse(this.preferences.get(`${this.sortingPreferenceKey}.columns.visibility`)); + } + + if (this.preferences.hasItem(`${this.sortingPreferenceKey}.columns.order`)) { + this.documentList.setColumnsOrder = JSON.parse(this.preferences.get(`${this.sortingPreferenceKey}.columns.order`)); } this.documentList.sorting = [key, direction]; @@ -130,6 +132,13 @@ export class DocumentListDirective implements OnInit, OnDestroy { } } + @HostListener('columnsOrderChanged', ['$event']) + onColumnOrderChanged(event: CustomEvent) { + if (this.sortingPreferenceKey) { + this.preferences.set(`${this.sortingPreferenceKey}.columns.order`, JSON.stringify(event)); + } + } + @HostListener('node-select', ['$event']) onNodeSelect(event: CustomEvent) { if (!!event.detail && !!event.detail.node) {