mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
preserve state (#358)
This commit is contained in:
committed by
Denys Vuika
parent
60da9d8b94
commit
90caabafc0
@@ -19,6 +19,10 @@
|
|||||||
"allowDownload": true,
|
"allowDownload": true,
|
||||||
"allowDelete": true
|
"allowDelete": true
|
||||||
},
|
},
|
||||||
|
"sideNav" : {
|
||||||
|
"preserveState" : true,
|
||||||
|
"expandedSidenav": true
|
||||||
|
},
|
||||||
"navigation": {
|
"navigation": {
|
||||||
"main": [
|
"main": [
|
||||||
{
|
{
|
||||||
|
@@ -7,14 +7,13 @@
|
|||||||
[sidenavMin]="70"
|
[sidenavMin]="70"
|
||||||
[sidenavMax]="320"
|
[sidenavMax]="320"
|
||||||
[stepOver]="600"
|
[stepOver]="600"
|
||||||
[hideSidenav]="isPreview"
|
[hideSidenav]="hideSidenav"
|
||||||
[expandedSidenav]="true">
|
[expandedSidenav]="expandedSidenav"
|
||||||
|
(expanded)="setState($event)">
|
||||||
|
|
||||||
<adf-sidenav-layout-header>
|
<adf-sidenav-layout-header>
|
||||||
<ng-template let-toggleMenu="toggleMenu">
|
<ng-template let-toggleMenu="toggleMenu">
|
||||||
|
<app-header (menu)="toggleMenu()"></app-header>
|
||||||
<app-header (menu)="toggleMenu()"></app-header>
|
|
||||||
|
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</adf-sidenav-layout-header>
|
</adf-sidenav-layout-header>
|
||||||
|
|
||||||
|
@@ -45,6 +45,8 @@ describe('LayoutComponent', () => {
|
|||||||
let fixture: ComponentFixture<LayoutComponent>;
|
let fixture: ComponentFixture<LayoutComponent>;
|
||||||
let component: LayoutComponent;
|
let component: LayoutComponent;
|
||||||
let browsingFilesService: BrowsingFilesService;
|
let browsingFilesService: BrowsingFilesService;
|
||||||
|
let appConfig: AppConfigService;
|
||||||
|
let userPreference: UserPreferencesService;
|
||||||
const navItem = {
|
const navItem = {
|
||||||
label: 'some-label',
|
label: 'some-label',
|
||||||
route: {
|
route: {
|
||||||
@@ -86,18 +88,114 @@ describe('LayoutComponent', () => {
|
|||||||
fixture = TestBed.createComponent(LayoutComponent);
|
fixture = TestBed.createComponent(LayoutComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
browsingFilesService = TestBed.get(BrowsingFilesService);
|
browsingFilesService = TestBed.get(BrowsingFilesService);
|
||||||
|
appConfig = TestBed.get(AppConfigService);
|
||||||
const appConfig = TestBed.get(AppConfigService);
|
userPreference = TestBed.get(UserPreferencesService);
|
||||||
spyOn(appConfig, 'get').and.returnValue([navItem]);
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets current node', () => {
|
it('sets current node', () => {
|
||||||
|
appConfig.config = {
|
||||||
|
navigation: [navItem]
|
||||||
|
};
|
||||||
|
|
||||||
const currentNode = <MinimalNodeEntryEntity>{ id: 'someId' };
|
const currentNode = <MinimalNodeEntryEntity>{ id: 'someId' };
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
browsingFilesService.onChangeParent.next(currentNode);
|
browsingFilesService.onChangeParent.next(currentNode);
|
||||||
|
|
||||||
expect(component.node).toEqual(currentNode);
|
expect(component.node).toEqual(currentNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('sidenav state', () => {
|
||||||
|
it('should get state from configuration', () => {
|
||||||
|
appConfig.config = {
|
||||||
|
sideNav: {
|
||||||
|
expandedSidenav: false,
|
||||||
|
preserveState: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.expandedSidenav).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve state to true is no configuration', () => {
|
||||||
|
appConfig.config = {};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.expandedSidenav).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get state from user settings as true', () => {
|
||||||
|
appConfig.config = {
|
||||||
|
sideNav: {
|
||||||
|
expandedSidenav: false,
|
||||||
|
preserveState: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(userPreference, 'get').and.callFake(key => {
|
||||||
|
if (key === 'expandedSidenav') {
|
||||||
|
return 'true';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.expandedSidenav).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get state from user settings as false', () => {
|
||||||
|
appConfig.config = {
|
||||||
|
sideNav: {
|
||||||
|
expandedSidenav: false,
|
||||||
|
preserveState: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(userPreference, 'get').and.callFake(key => {
|
||||||
|
if (key === 'expandedSidenav') {
|
||||||
|
return 'false';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.expandedSidenav).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set expandedSidenav to true if configuration is true', () => {
|
||||||
|
spyOn(userPreference, 'set');
|
||||||
|
|
||||||
|
appConfig.config = {
|
||||||
|
sideNav: {
|
||||||
|
expandedSidenav: false,
|
||||||
|
preserveState: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.setState(true);
|
||||||
|
|
||||||
|
expect(userPreference.set).toHaveBeenCalledWith( 'expandedSidenav', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set expandedSidenav to false if configuration is true', () => {
|
||||||
|
spyOn(userPreference, 'set');
|
||||||
|
|
||||||
|
appConfig.config = {
|
||||||
|
sideNav: {
|
||||||
|
expandedSidenav: false,
|
||||||
|
preserveState: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.setState(false);
|
||||||
|
|
||||||
|
expect(userPreference.set).toHaveBeenCalledWith( 'expandedSidenav', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -27,6 +27,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
|
|||||||
import { Router, NavigationEnd } from '@angular/router';
|
import { Router, NavigationEnd } from '@angular/router';
|
||||||
import { Subscription } from 'rxjs/Rx';
|
import { Subscription } from 'rxjs/Rx';
|
||||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
|
import { UserPreferencesService, AppConfigService } from '@alfresco/adf-core';
|
||||||
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
|
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
|
||||||
import { NodePermissionService } from '../../common/services/node-permission.service';
|
import { NodePermissionService } from '../../common/services/node-permission.service';
|
||||||
|
|
||||||
@@ -37,22 +38,27 @@ import { NodePermissionService } from '../../common/services/node-permission.ser
|
|||||||
})
|
})
|
||||||
export class LayoutComponent implements OnInit, OnDestroy {
|
export class LayoutComponent implements OnInit, OnDestroy {
|
||||||
node: MinimalNodeEntryEntity;
|
node: MinimalNodeEntryEntity;
|
||||||
isPreview = false;
|
hideSidenav: boolean;
|
||||||
|
expandedSidenav: boolean;
|
||||||
|
private hideConditions: string[] = ['preview'];
|
||||||
private subscriptions: Subscription[] = [];
|
private subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private browsingFilesService: BrowsingFilesService,
|
private browsingFilesService: BrowsingFilesService,
|
||||||
|
private userPreferenceService: UserPreferencesService,
|
||||||
|
private appConfigService: AppConfigService,
|
||||||
public permission: NodePermissionService) {
|
public permission: NodePermissionService) {
|
||||||
this.router.events
|
this.router.events
|
||||||
.filter(event => event instanceof NavigationEnd)
|
.filter(event => event instanceof NavigationEnd)
|
||||||
.subscribe( (event: any ) => {
|
.subscribe( (event: any ) => {
|
||||||
this.isPreview = event.urlAfterRedirects.includes('preview');
|
this.hideSidenav = this.hideConditions.some(el => event.urlAfterRedirects.includes(el));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.expandedSidenav = this.sidenavState;
|
||||||
|
|
||||||
this.subscriptions.concat([
|
this.subscriptions.concat([
|
||||||
this.browsingFilesService.onChangeParent.subscribe((node: MinimalNodeEntryEntity) => this.node = node)
|
this.browsingFilesService.onChangeParent.subscribe((node: MinimalNodeEntryEntity) => this.node = node)
|
||||||
]);
|
]);
|
||||||
@@ -61,4 +67,21 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.subscriptions.forEach(s => s.unsubscribe());
|
this.subscriptions.forEach(s => s.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sidenavState(): boolean {
|
||||||
|
const expand = this.appConfigService.get<boolean>('sideNav.expandedSidenav', true);
|
||||||
|
const preserveState = this.appConfigService.get<boolean>('sideNav.preserveState', true);
|
||||||
|
|
||||||
|
if (preserveState) {
|
||||||
|
return (this.userPreferenceService.get('expandedSidenav', expand.toString()) === 'true');
|
||||||
|
}
|
||||||
|
|
||||||
|
return expand;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(state) {
|
||||||
|
if (this.appConfigService.get('sideNav.preserveState')) {
|
||||||
|
this.userPreferenceService.set('expandedSidenav', state);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user