From 3cbb7fa065c181b4a017af5bdd896b728edde4f7 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Thu, 22 Feb 2018 22:24:31 +0200 Subject: [PATCH] route defined preference data prefix (#195) --- src/app/app.routes.ts | 21 +++++++++++++++++-- .../favorites/favorites.component.ts | 12 +++++++---- src/app/components/files/files.component.ts | 12 +++++++---- .../libraries/libraries.component.ts | 12 +++++++---- .../recent-files/recent-files.component.ts | 12 +++++++---- .../shared-files/shared-files.component.ts | 12 +++++++---- .../trashcan/trashcan.component.spec.ts | 3 ++- .../components/trashcan/trashcan.component.ts | 18 +++++++++++----- 8 files changed, 74 insertions(+), 28 deletions(-) diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index ffd5f2d50..5f466094c 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -59,6 +59,9 @@ export const APP_ROUTES: Routes = [ }, { path: 'favorites', + data: { + preferencePrefix: 'favorites' + }, children: [ { path: '', @@ -80,6 +83,9 @@ export const APP_ROUTES: Routes = [ }, { path: 'libraries', + data: { + preferencePrefix: 'libraries' + }, children: [{ path: '', component: LibrariesComponent, @@ -90,7 +96,8 @@ export const APP_ROUTES: Routes = [ path: ':folderId', component: FilesComponent, data: { - i18nTitle: 'APP.BROWSE.LIBRARIES.TITLE' + i18nTitle: 'APP.BROWSE.LIBRARIES.TITLE', + preferencePrefix: 'libraries-files' } }, { @@ -106,6 +113,9 @@ export const APP_ROUTES: Routes = [ }, { path: 'personal-files', + data: { + preferencePrefix: 'personal-files' + }, children: [ { path: '', @@ -144,6 +154,9 @@ export const APP_ROUTES: Routes = [ }, { path: 'recent-files', + data: { + preferencePrefix: 'recent-files' + }, children: [ { path: '', @@ -165,6 +178,9 @@ export const APP_ROUTES: Routes = [ }, { path: 'shared', + data: { + preferencePrefix: 'shared-files' + }, children: [ { path: '', @@ -188,7 +204,8 @@ export const APP_ROUTES: Routes = [ path: 'trashcan', component: TrashcanComponent, data: { - i18nTitle: 'APP.BROWSE.TRASHCAN.TITLE' + i18nTitle: 'APP.BROWSE.TRASHCAN.TITLE', + preferencePrefix: 'trashcan' } }, { diff --git a/src/app/components/favorites/favorites.component.ts b/src/app/components/favorites/favorites.component.ts index b3dcd385a..1d656df89 100644 --- a/src/app/components/favorites/favorites.component.ts +++ b/src/app/components/favorites/favorites.component.ts @@ -54,8 +54,8 @@ export class FavoritesComponent extends PageComponent implements OnInit, OnDestr preferences: UserPreferencesService) { super(preferences); - const sortingKey = preferences.get('favorites.sorting.key') || 'modifiedAt'; - const sortingDirection = preferences.get('favorites.sorting.direction') || 'desc'; + const sortingKey = preferences.get(`${this.prefix}.sorting.key`) || 'modifiedAt'; + const sortingDirection = preferences.get(`${this.prefix}.sorting.direction`) || 'desc'; this.sorting = [sortingKey, sortingDirection]; } @@ -118,7 +118,11 @@ export class FavoritesComponent extends PageComponent implements OnInit, OnDestr } onSortingChanged(event: CustomEvent) { - this.preferences.set('favorites.sorting.key', event.detail.key || 'modifiedAt'); - this.preferences.set('favorites.sorting.direction', event.detail.direction || 'desc'); + this.preferences.set(`${this.prefix}.sorting.key`, event.detail.key || 'modifiedAt'); + this.preferences.set(`${this.prefix}.sorting.direction`, event.detail.direction || 'desc'); + } + + private get prefix() { + return this.route.snapshot.data.preferencePrefix; } } diff --git a/src/app/components/files/files.component.ts b/src/app/components/files/files.component.ts index febb2936c..04e3032d0 100644 --- a/src/app/components/files/files.component.ts +++ b/src/app/components/files/files.component.ts @@ -64,8 +64,8 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { preferences: UserPreferencesService) { super(preferences); - const sortingKey = preferences.get('personal-files.sorting.key') || 'modifiedAt'; - const sortingDirection = preferences.get('personal-files.sorting.direction') || 'desc'; + const sortingKey = this.preferences.get(`${this.prefix}.sorting.key`) || 'modifiedAt'; + const sortingDirection = this.preferences.get(`${this.prefix}.sorting.direction`) || 'desc'; this.sorting = [sortingKey, sortingDirection]; } @@ -309,7 +309,11 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { } onSortingChanged(event: CustomEvent) { - this.preferences.set('personal-files.sorting.key', event.detail.key || 'modifiedAt'); - this.preferences.set('personal-files.sorting.direction', event.detail.direction || 'desc'); + this.preferences.set(`${this.prefix}.sorting.key`, event.detail.key || 'modifiedAt'); + this.preferences.set(`${this.prefix}.sorting.direction`, event.detail.direction || 'desc'); + } + + private get prefix() { + return this.route.snapshot.data.preferencePrefix; } } diff --git a/src/app/components/libraries/libraries.component.ts b/src/app/components/libraries/libraries.component.ts index 2c14279c4..8f3c503a2 100644 --- a/src/app/components/libraries/libraries.component.ts +++ b/src/app/components/libraries/libraries.component.ts @@ -46,8 +46,8 @@ export class LibrariesComponent extends PageComponent { preferences: UserPreferencesService) { super(preferences); - const sortingKey = preferences.get('libraries.sorting.key') || 'title'; - const sortingDirection = preferences.get('libraries.sorting.direction') || 'desc'; + const sortingKey = preferences.get(`${this.prefix}.sorting.key`) || 'title'; + const sortingDirection = preferences.get(`${this.prefix}.sorting.direction`) || 'desc'; this.sorting = [sortingKey, sortingDirection]; } @@ -98,7 +98,11 @@ export class LibrariesComponent extends PageComponent { } onSortingChanged(event: CustomEvent) { - this.preferences.set('libraries.sorting.key', event.detail.key || 'modifiedAt'); - this.preferences.set('libraries.sorting.direction', event.detail.direction || 'desc'); + this.preferences.set(`${this.prefix}.sorting.key`, event.detail.key || 'modifiedAt'); + this.preferences.set(`${this.prefix}.sorting.direction`, event.detail.direction || 'desc'); + } + + private get prefix() { + return this.route.snapshot.data.preferencePrefix; } } diff --git a/src/app/components/recent-files/recent-files.component.ts b/src/app/components/recent-files/recent-files.component.ts index 63601861f..69a64aa05 100644 --- a/src/app/components/recent-files/recent-files.component.ts +++ b/src/app/components/recent-files/recent-files.component.ts @@ -52,8 +52,8 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes preferences: UserPreferencesService) { super(preferences); - const sortingKey = preferences.get('recent-files.sorting.key') || 'modifiedAt'; - const sortingDirection = preferences.get('recent-files.sorting.direction') || 'desc'; + const sortingKey = preferences.get(`${this.prefix}.sorting.key`) || 'modifiedAt'; + const sortingDirection = preferences.get(`${this.prefix}.sorting.direction`) || 'desc'; this.sorting = [sortingKey, sortingDirection]; } @@ -90,7 +90,11 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes } onSortingChanged(event: CustomEvent) { - this.preferences.set('recent-files.sorting.key', event.detail.key || 'modifiedAt'); - this.preferences.set('recent-files.sorting.direction', event.detail.direction || 'desc'); + this.preferences.set(`${this.prefix}.sorting.key`, event.detail.key || 'modifiedAt'); + this.preferences.set(`${this.prefix}.sorting.direction`, event.detail.direction || 'desc'); + } + + private get prefix() { + return this.route.snapshot.data.preferencePrefix; } } diff --git a/src/app/components/shared-files/shared-files.component.ts b/src/app/components/shared-files/shared-files.component.ts index c3b3a940c..2c0eaaa52 100644 --- a/src/app/components/shared-files/shared-files.component.ts +++ b/src/app/components/shared-files/shared-files.component.ts @@ -52,8 +52,8 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes preferences: UserPreferencesService) { super(preferences); - const sortingKey = preferences.get('shared-files.sorting.key') || 'modifiedAt'; - const sortingDirection = preferences.get('shared-files.sorting.direction') || 'desc'; + const sortingKey = preferences.get(`${this.prefix}.sorting.key`) || 'modifiedAt'; + const sortingDirection = preferences.get(`${this.prefix}.sorting.direction`) || 'desc'; this.sorting = [sortingKey, sortingDirection]; } @@ -99,7 +99,11 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes } onSortingChanged(event: CustomEvent) { - this.preferences.set('shared-files.sorting.key', event.detail.key || 'modifiedAt'); - this.preferences.set('shared-files.sorting.direction', event.detail.direction || 'desc'); + this.preferences.set(`${this.prefix}.sorting.key`, event.detail.key || 'modifiedAt'); + this.preferences.set(`${this.prefix}.sorting.direction`, event.detail.direction || 'desc'); + } + + private get prefix() { + return this.route.snapshot.data.preferencePrefix; } } diff --git a/src/app/components/trashcan/trashcan.component.spec.ts b/src/app/components/trashcan/trashcan.component.spec.ts index 912bd6f2f..0ec8dc934 100644 --- a/src/app/components/trashcan/trashcan.component.spec.ts +++ b/src/app/components/trashcan/trashcan.component.spec.ts @@ -22,7 +22,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with Alfresco. If not, see . */ - +import { RouterTestingModule } from '@angular/router/testing'; import { TestBed, async } from '@angular/core/testing'; import { CoreModule, AlfrescoApiService } from '@alfresco/adf-core'; import { TrashcanComponent } from './trashcan.component'; @@ -49,6 +49,7 @@ describe('TrashcanComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ + RouterTestingModule, CoreModule, CommonModule ], diff --git a/src/app/components/trashcan/trashcan.component.ts b/src/app/components/trashcan/trashcan.component.ts index 53dcf03ea..ccbf3a7b6 100644 --- a/src/app/components/trashcan/trashcan.component.ts +++ b/src/app/components/trashcan/trashcan.component.ts @@ -24,6 +24,7 @@ */ import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { Subscription } from 'rxjs/Rx'; import { Pagination } from 'alfresco-js-api'; import { UserPreferencesService } from '@alfresco/adf-core'; @@ -41,9 +42,12 @@ export class TrashcanComponent implements OnInit, OnDestroy { sorting = [ 'archivedAt', 'desc' ]; constructor(private contentManagementService: ContentManagementService, - private preferences: UserPreferencesService) { - const sortingKey = preferences.get('trashcan.sorting.key') || 'archivedAt'; - const sortingDirection = preferences.get('trashcan.sorting.direction') || 'desc'; + private preferences: UserPreferencesService, + private route: ActivatedRoute) { + + const sortingKey = preferences.get(`${this.prefix}.sorting.key`) || 'archivedAt'; + const sortingDirection = preferences.get(`${this.prefix}.sorting.direction`) || 'desc'; + this.sorting = [sortingKey, sortingDirection]; } @@ -65,7 +69,11 @@ export class TrashcanComponent implements OnInit, OnDestroy { } onSortingChanged(event: CustomEvent) { - this.preferences.set('trashcan.sorting.key', event.detail.key || 'archivedAt'); - this.preferences.set('trashcan.sorting.direction', event.detail.direction || 'desc'); + this.preferences.set(`${this.prefix}.sorting.key`, event.detail.key || 'archivedAt'); + this.preferences.set(`${this.prefix}.sorting.direction`, event.detail.direction || 'desc'); + } + + private get prefix() { + return this.route.snapshot.data.preferencePrefix; } }