diff --git a/projects/aca-content/src/lib/aca-content.module.ts b/projects/aca-content/src/lib/aca-content.module.ts index 47df9abc1..97e3bc9e3 100644 --- a/projects/aca-content/src/lib/aca-content.module.ts +++ b/projects/aca-content/src/lib/aca-content.module.ts @@ -55,7 +55,6 @@ import { CommentsTabComponent } from './components/info-drawer/comments-tab/comm import { LibraryMetadataTabComponent } from './components/info-drawer/library-metadata-tab/library-metadata-tab.component'; import { MetadataTabComponent } from './components/info-drawer/metadata-tab/metadata-tab.component'; import { VersionsTabComponent } from './components/info-drawer/versions-tab/versions-tab.component'; -import { PreviewComponent } from '@alfresco/aca-content/viewer'; import { ToggleEditOfflineComponent } from './components/toolbar/toggle-edit-offline/toggle-edit-offline.component'; import { ToggleFavoriteLibraryComponent } from './components/toolbar/toggle-favorite-library/toggle-favorite-library.component'; import { ToggleFavoriteComponent } from './components/toolbar/toggle-favorite/toggle-favorite.component'; @@ -132,7 +131,6 @@ export class ContentServiceExtensionModule { 'app.components.tabs.library.metadata': LibraryMetadataTabComponent, 'app.components.tabs.comments': CommentsTabComponent, 'app.components.tabs.versions': VersionsTabComponent, - 'app.components.preview': PreviewComponent, 'app.toolbar.toggleInfoDrawer': ToggleInfoDrawerComponent, 'app.toolbar.toggleFavorite': ToggleFavoriteComponent, 'app.toolbar.toggleFavoriteLibrary': ToggleFavoriteLibraryComponent, diff --git a/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.html b/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.html index a5145fe99..cd89b7fed 100644 --- a/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.html +++ b/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.html @@ -45,7 +45,6 @@ [class]="column.class" [sortable]="column.sortable" [isHidden]="column.isHidden" - [sortingKey]="column.sortingKey || column.key" > @@ -65,7 +64,6 @@ [class]="column.class" [sortable]="column.sortable" [isHidden]="column.isHidden" - [sortingKey]="column.sortingKey || column.key" > diff --git a/projects/aca-content/src/lib/components/favorites/favorites.component.html b/projects/aca-content/src/lib/components/favorites/favorites.component.html index 12530b423..7a48f7507 100644 --- a/projects/aca-content/src/lib/components/favorites/favorites.component.html +++ b/projects/aca-content/src/lib/components/favorites/favorites.component.html @@ -40,7 +40,6 @@ [class]="column.class" [sortable]="column.sortable" [isHidden]="column.isHidden" - [sortingKey]="column.sortingKey || column.key" > @@ -60,7 +59,6 @@ [class]="column.class" [sortable]="column.sortable" [isHidden]="column.isHidden" - [sortingKey]="column.sortingKey || column.key" > diff --git a/projects/aca-content/src/lib/components/files/files.component.html b/projects/aca-content/src/lib/components/files/files.component.html index bcee7562e..a5e10cbcc 100644 --- a/projects/aca-content/src/lib/components/files/files.component.html +++ b/projects/aca-content/src/lib/components/files/files.component.html @@ -23,7 +23,7 @@ [node]="nodeResult" [allowDropFiles]="true" [navigate]="false" - [sorting]="['name', 'asc']" + [sorting]="['name', 'ASC']" [imageResolver]="imageResolver" [headerFilters]="true" [filterValue]="queryParams" @@ -31,6 +31,7 @@ [blurOnResize]="false" (node-dblclick)="handleNodeClick($event)" (name-click)="handleNodeClick($event)" + (sorting-changed)="onSortingChanged($event)" (filterSelection)="onFilterSelected($event)" (error)="onError()" > diff --git a/projects/aca-content/src/lib/components/files/files.component.ts b/projects/aca-content/src/lib/components/files/files.component.ts index e4e083183..b16592f88 100644 --- a/projects/aca-content/src/lib/components/files/files.component.ts +++ b/projects/aca-content/src/lib/components/files/files.component.ts @@ -39,7 +39,7 @@ import { } from '@alfresco/aca-shared'; import { SetCurrentFolderAction, isAdmin, UploadFileVersionAction, showLoaderSelector } from '@alfresco/aca-shared/store'; import { debounceTime, takeUntil } from 'rxjs/operators'; -import { BreadcrumbModule, DocumentListModule, FileUploadEvent, FilterSearch, ShareDataRow, UploadModule } from '@alfresco/adf-content-services'; +import { FilterSearch, ShareDataRow, FileUploadEvent, BreadcrumbModule, UploadModule, DocumentListModule } from '@alfresco/adf-content-services'; import { DocumentListPresetRef, ExtensionsModule } from '@alfresco/adf-extensions'; import { CommonModule } from '@angular/common'; import { TranslateModule } from '@ngx-translate/core'; @@ -74,13 +74,14 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { isAdmin = false; selectedNode: NodeEntry; queryParams = null; + showLoader$ = this.store.select(showLoaderSelector); private nodePath: PathElement[]; columns: DocumentListPresetRef[] = []; isFilterHeaderActive = false; - constructor(private contentApi: ContentApiService, private nodeActionsService: NodeActionsService, private route: ActivatedRoute) { + constructor(private route: ActivatedRoute, private contentApi: ContentApiService, private nodeActionsService: NodeActionsService) { super(); } @@ -102,9 +103,9 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { this.isValidPath = true; if (node?.entry?.isFolder) { - void this.updateCurrentNode(node.entry); + this.updateCurrentNode(node.entry); } else { - void this.router.navigate(['/personal-files', node.entry.parentId], { + this.router.navigate(['/personal-files', node.entry.parentId], { replaceUrl: true }); } @@ -144,7 +145,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { const currentNodeId = this.route.snapshot.paramMap.get('folderId'); const urlWithoutParams = decodeURIComponent(this.router.url).split('?')[0]; const urlToNavigate: string[] = this.getUrlToNavigate(urlWithoutParams, currentNodeId, nodeId); - void this.router.navigate(urlToNavigate); + this.router.navigate(urlToNavigate); } private getUrlToNavigate(currentURL: string, currentNodeId: string, nextNodeId: string): string[] { @@ -344,12 +345,13 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { } onFilterSelected(activeFilters: FilterSearch[]) { + console.log(activeFilters) if (activeFilters.length) { this.showHeader = ShowHeaderMode.Always; this.isFilterHeaderActive = true; this.navigateToFilter(activeFilters); } else { - void this.router.navigate(['.'], { relativeTo: this.route }); + this.router.navigate(['.'], { relativeTo: this.route }); this.isFilterHeaderActive = false; this.showHeader = ShowHeaderMode.Data; this.onAllFilterCleared(); @@ -368,7 +370,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { objectFromMap[filter.key] = paramValue; }); - void this.router.navigate([], { relativeTo: this.route, queryParams: objectFromMap }); + this.router.navigate([], { relativeTo: this.route, queryParams: objectFromMap }); } onError() { 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 742fe40d2..9ccddf28a 100644 --- a/projects/aca-content/src/lib/directives/document-list.directive.ts +++ b/projects/aca-content/src/lib/directives/document-list.directive.ts @@ -66,6 +66,11 @@ export class DocumentListDirective implements OnInit, OnDestroy { this.router.url.startsWith('/search-libraries'); if (this.sortingPreferenceKey) { + const current = this.documentList.sorting; + + const key = this.preferences.get(`${this.sortingPreferenceKey}.sorting.sortingKey`, current[0]); + const direction = this.preferences.get(`${this.sortingPreferenceKey}.sorting.direction`, current[1]); + if (this.preferences.hasItem(`${this.sortingPreferenceKey}.columns.width`)) { this.documentList.setColumnsWidths = JSON.parse(this.preferences.get(`${this.sortingPreferenceKey}.columns.width`)); } @@ -78,11 +83,9 @@ export class DocumentListDirective implements OnInit, OnDestroy { this.documentList.setColumnsOrder = JSON.parse(this.preferences.get(`${this.sortingPreferenceKey}.columns.order`)); } - const mode = this.documentList.sortingMode; - this.preferences.set(`${this.sortingPreferenceKey}.sorting.mode`, mode); - if (mode === 'server') { - this.restoreSorting(); - } + this.documentList.sorting = [key, direction]; + // TODO: bug in ADF, the `sorting` binding is not updated when changed from code + this.documentList.data.setSorting({ key, direction }); } this.documentList.ready @@ -109,9 +112,6 @@ export class DocumentListDirective implements OnInit, OnDestroy { @HostListener('sorting-changed', ['$event']) onSortingChanged(event: CustomEvent) { if (this.sortingPreferenceKey) { - if (this.documentList.sortingMode === 'client') { - this.storePreviousSorting(); - } this.preferences.set(`${this.sortingPreferenceKey}.sorting.key`, event.detail.key); this.preferences.set(`${this.sortingPreferenceKey}.sorting.sortingKey`, event.detail.sortingKey); this.preferences.set(`${this.sortingPreferenceKey}.sorting.direction`, event.detail.direction); @@ -154,7 +154,6 @@ export class DocumentListDirective implements OnInit, OnDestroy { onReady() { this.updateSelection(); - this.restoreSorting(); } private updateSelection() { @@ -177,40 +176,4 @@ export class DocumentListDirective implements OnInit, OnDestroy { this.documentList.resetSelection(); this.store.dispatch(new SetSelectedNodesAction([])); } - - private setSorting(key: string, direction: string) { - this.documentList.sorting = [key, direction]; - this.documentList.data.setSorting({ key, direction }); - } - - private storePreviousSorting() { - if (this.preferences.hasItem(`${this.sortingPreferenceKey}.sorting.key`)) { - const keyToSave = this.preferences.get(`${this.sortingPreferenceKey}.sorting.key`); - - if (!keyToSave.includes(this.documentList.sorting[0])) { - const dirToSave = this.preferences.get(`${this.sortingPreferenceKey}.sorting.direction`); - this.preferences.set(`${this.sortingPreferenceKey}.sorting.previousKey`, keyToSave); - this.preferences.set(`${this.sortingPreferenceKey}.sorting.previousDirection`, dirToSave); - } - } - } - - private restoreSorting() { - const [previousKey, previousDir] = [ - this.preferences.get(`${this.sortingPreferenceKey}.sorting.previousKey`, null), - this.preferences.get(`${this.sortingPreferenceKey}.sorting.previousDirection`, null) - ]; - - const [currentKey, currentDir] = [ - this.preferences.get(`${this.sortingPreferenceKey}.sorting.key`, null), - this.preferences.get(`${this.sortingPreferenceKey}.sorting.direction`, null) - ]; - - if (previousKey) { - this.setSorting(previousKey, previousDir); - } - if (currentKey) { - this.setSorting(currentKey, currentDir); - } - } } diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts index fe17f45c2..660a6afa7 100644 --- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts +++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts @@ -25,7 +25,7 @@ import { DocumentListComponent, ShareDataRow, UploadService } from '@alfresco/adf-content-services'; import { ShowHeaderMode } from '@alfresco/adf-core'; import { ContentActionRef, DocumentListPresetRef, SelectionState } from '@alfresco/adf-extensions'; -import { OnDestroy, OnInit, OnChanges, ViewChild, SimpleChanges, Directive, inject, HostListener } from '@angular/core'; +import { OnDestroy, OnInit, OnChanges, ViewChild, SimpleChanges, Directive, inject } from '@angular/core'; import { Store } from '@ngrx/store'; import { NodeEntry, Node, NodePaging } from '@alfresco/js-api'; import { Observable, Subject, Subscription } from 'rxjs'; @@ -207,7 +207,6 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges { return location.href.includes('viewer:view'); } - @HostListener('sorting-changed', ['$event']) onSortingChanged(event: any) { this.filterSorting = event.detail.key + '-' + event.detail.direction; } diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts index bf5742704..8e0693855 100644 --- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts +++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts @@ -25,18 +25,64 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { PageComponent } from './document-base-page.component'; import { AppState, ReloadDocumentListAction, SetSelectedNodesAction, ViewNodeAction } from '@alfresco/aca-shared/store'; -import { AppExtensionService, LibTestingModule, discoveryApiServiceMockValue, DocumentBasePageServiceMock } from '@alfresco/aca-shared'; -import { NodeEntry, NodePaging } from '@alfresco/js-api'; +import { AppExtensionService } from '@alfresco/aca-shared'; +import { NodeEntry, NodePaging, RepositoryInfo, VersionInfo } from '@alfresco/js-api'; import { DocumentBasePageService } from './document-base-page.service'; -import { Store } from '@ngrx/store'; -import { Component } from '@angular/core'; +import { Store, StoreModule } from '@ngrx/store'; +import { Component, Injectable } from '@angular/core'; import { DiscoveryApiService, DocumentListComponent } from '@alfresco/adf-content-services'; import { MockStore, provideMockStore } from '@ngrx/store/testing'; -import { AuthModule, MaterialModule } from '@alfresco/adf-core'; +import { AuthModule, MaterialModule, PipeModule } from '@alfresco/adf-core'; import { HttpClientModule } from '@angular/common/http'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; -import { Subscription } from 'rxjs'; +import { EffectsModule } from '@ngrx/effects'; +import { BehaviorSubject, Observable, of, Subscription } from 'rxjs'; + +export const INITIAL_APP_STATE: AppState = { + appName: 'Alfresco Content Application', + logoPath: 'assets/images/alfresco-logo-white.svg', + customCssPath: '', + webFontPath: '', + sharedUrl: '', + user: { + isAdmin: null, + id: null, + firstName: '', + lastName: '' + }, + selection: { + nodes: [], + libraries: [], + isEmpty: true, + count: 0 + }, + navigation: { + currentFolder: null + }, + currentNodeVersion: null, + infoDrawerOpened: false, + infoDrawerPreview: false, + infoDrawerMetadataAspect: '', + showFacetFilter: true, + fileUploadingDialog: true, + showLoader: false, + repository: { + status: { + isQuickShareEnabled: true + } + } as any +}; + +@Injectable() +class DocumentBasePageServiceMock extends DocumentBasePageService { + canUpdateNode(): boolean { + return true; + } + canUploadContent(): boolean { + return true; + } +} @Component({ selector: 'aca-test', @@ -61,11 +107,47 @@ describe('PageComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [LibTestingModule, MaterialModule, AuthModule.forRoot()], + imports: [ + NoopAnimationsModule, + HttpClientModule, + RouterTestingModule, + MaterialModule, + AuthModule.forRoot(), + StoreModule.forRoot( + { app: (state) => state }, + { + initialState: { + app: INITIAL_APP_STATE + }, + runtimeChecks: { + strictStateImmutability: false, + strictActionImmutability: false + } + } + ), + EffectsModule.forRoot([]), + PipeModule + ], declarations: [TestComponent], providers: [ - { provide: DocumentBasePageService, useClass: DocumentBasePageServiceMock }, - { provide: DiscoveryApiService, useValue: discoveryApiServiceMockValue }, + { + provide: DocumentBasePageService, + useClass: DocumentBasePageServiceMock + }, + { + provide: DiscoveryApiService, + useValue: { + ecmProductInfo$: new BehaviorSubject(null), + getEcmProductInfo: (): Observable => + of( + new RepositoryInfo({ + version: { + major: '10.0.0' + } as VersionInfo + }) + ) + } + }, AppExtensionService ] }); @@ -216,7 +298,20 @@ describe('Info Drawer state', () => { providers: [ { provide: DocumentBasePageService, useClass: DocumentBasePageServiceMock }, AppExtensionService, - { provide: DiscoveryApiService, useValue: discoveryApiServiceMockValue }, + { + provide: DiscoveryApiService, + useValue: { + ecmProductInfo$: new BehaviorSubject(null), + getEcmProductInfo: (): Observable => + of( + new RepositoryInfo({ + version: { + major: '10.0.0' + } as VersionInfo + }) + ) + } + }, provideMockStore({ initialState: { app: appState } }) @@ -242,7 +337,7 @@ describe('Info Drawer state', () => { window.history.pushState({}, null, `${locationHref}#test`); fixture.detectChanges(); - void fixture.whenStable().then(() => { + fixture.whenStable().then(() => { component.infoDrawerOpened$.subscribe((state) => { expect(state).toBe(true); done(); @@ -261,7 +356,7 @@ describe('Info Drawer state', () => { window.history.pushState({}, null, `${locationHref}#test(viewer:view)`); fixture.detectChanges(); - void fixture.whenStable().then(() => { + fixture.whenStable().then(() => { component.infoDrawerOpened$.subscribe((state) => { expect(state).toBe(true); done();