[ADF-2626] changed logic for preserving the sidenav component state

This commit is contained in:
georgiana-roman
2018-05-08 21:06:50 +03:00
parent c5479dc9c2
commit cf50dc5f4b
7 changed files with 40 additions and 49 deletions

View File

@@ -491,7 +491,7 @@
}, },
"sideNav": { "sideNav": {
"openedSidenav": true, "expandedSidenav": true,
"preserveState": true "preserveState": true
} }
} }

View File

@@ -1,4 +1,4 @@
<adf-sidenav-layout [sidenavMin]="70" [sidenavMax]="220" [stepOver]="780" [hideSidenav]="false"[expandedSidenav]= "expandedSidenav"> <adf-sidenav-layout [sidenavMin]="70" [sidenavMax]="220" [stepOver]="780" [hideSidenav]="false"[expandedSidenav]= "expandedSidenav" (notify)='setState($event)'>
<adf-sidenav-layout-header> <adf-sidenav-layout-header>
<ng-template let-toggleMenu="toggleMenu"> <ng-template let-toggleMenu="toggleMenu">

View File

@@ -15,8 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, ViewEncapsulation, Input } from '@angular/core'; import { Component, ViewEncapsulation, OnInit from '@angular/core';
import { StorageService, AppConfigService } from '@alfresco/adf-core'; import { UserPreferencesService, AppConfigService } from '@alfresco/adf-core';
@Component({ @Component({
templateUrl: 'app-layout.component.html', templateUrl: 'app-layout.component.html',
@@ -27,7 +27,7 @@ import { StorageService, AppConfigService } from '@alfresco/adf-core';
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class AppLayoutComponent { export class AppLayoutComponent implements OnInit {
links: Array<any> = [ links: Array<any> = [
{ href: '/home', icon: 'home', title: 'APP_LAYOUT.HOME' }, { href: '/home', icon: 'home', title: 'APP_LAYOUT.HOME' },
@@ -50,18 +50,25 @@ export class AppLayoutComponent {
{ href: '/about', icon: 'info_outline', title: 'APP_LAYOUT.ABOUT' } { href: '/about', icon: 'info_outline', title: 'APP_LAYOUT.ABOUT' }
]; ];
@Input() expandedSidenav = false; expandedSidenav: Boolean = false;
constructor(private storage: StorageService, private config: AppConfigService) {
const preserved = this.storage.getItem('openedSidenav'); ngOnInit() {
if (preserved !== null) { const expand = this.config.get<boolean>('sideNav.expandedSidenav');
if (preserved === 'false') { const preserveState = this.config.get('sideNav.preserveState');
this.expandedSidenav = false;
} else { if (preserveState && expand) {
this.expandedSidenav = true; this.expandedSidenav = (this.userpreference.get('expandedSidenav', String(expand)) === 'true');
} } else if (expand) {
} else { this.expandedSidenav = expand;
this.expandedSidenav = this.config.get('sideNav.openedSidenav'); }
}
constructor( private userpreference: UserPreferencesService, private config: AppConfigService) {
}
setState(state) {
if (this.config.get('sideNav.preserveState')) {
this.userpreference.set('expendedSidenav', state);
} }
} }
} }

View File

@@ -121,7 +121,7 @@ Beside this, it is also possible to set the default value in the appConfig.json
``` ```
"sideNav" : { "sideNav" : {
"openedSidenav" : true "expandedSidenav" : true
} }
``` ```

View File

@@ -1,26 +1,18 @@
/*! /*!
* @license * @license
* Alfresco Example Content Application * Copyright 2016 Alfresco Software, Ltd.
* *
* Copyright (C) 2005 - 2018 Alfresco Software Limited * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* *
* This file is part of the Alfresco Example Content Application. * http://www.apache.org/licenses/LICENSE-2.0
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* *
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify * Unless required by applicable law or agreed to in writing, software
* it under the terms of the GNU Lesser General Public License as published by * distributed under the License is distributed on an "AS IS" BASIS,
* the Free Software Foundation, either version 3 of the License, or * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* (at your option) any later version. * See the License for the specific language governing permissions and
* * limitations under the License.
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Pipe, PipeTransform } from '@angular/core'; import { Pipe, PipeTransform } from '@angular/core';

View File

@@ -24,4 +24,3 @@ export * from './user-initial.pipe';
export * from './app-config.pipe'; export * from './app-config.pipe';
export * from './pipe.module'; export * from './pipe.module';

View File

@@ -15,16 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, ContentChild, Input, OnInit, AfterViewInit, ViewChild, OnDestroy, TemplateRef } from '@angular/core'; import { Component, ContentChild, Input, Output, OnInit, AfterViewInit, ViewChild, OnDestroy, TemplateRef, EventEmitter } from '@angular/core';
import { MediaMatcher } from '@angular/cdk/layout'; import { MediaMatcher } from '@angular/cdk/layout';
import { SidenavLayoutContentDirective } from '../../directives/sidenav-layout-content.directive'; import { SidenavLayoutContentDirective } from '../../directives/sidenav-layout-content.directive';
import { SidenavLayoutHeaderDirective } from '../../directives/sidenav-layout-header.directive'; import { SidenavLayoutHeaderDirective } from '../../directives/sidenav-layout-header.directive';
import { SidenavLayoutNavigationDirective } from '../../directives/sidenav-layout-navigation.directive'; import { SidenavLayoutNavigationDirective } from '../../directives/sidenav-layout-navigation.directive';
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { AppConfigService } from './../../../app-config/app-config.service';
import { StorageService } from './../../../services/storage.service';
@Component({ @Component({
selector: 'adf-sidenav-layout', selector: 'adf-sidenav-layout',
@@ -41,6 +38,8 @@ export class SidenavLayoutComponent implements OnInit, AfterViewInit, OnDestroy
@Input() hideSidenav = false; @Input() hideSidenav = false;
@Input() expandedSidenav = true; @Input() expandedSidenav = true;
@Output() notify = new EventEmitter();
@ContentChild(SidenavLayoutHeaderDirective) headerDirective: SidenavLayoutHeaderDirective; @ContentChild(SidenavLayoutHeaderDirective) headerDirective: SidenavLayoutHeaderDirective;
@ContentChild(SidenavLayoutNavigationDirective) navigationDirective: SidenavLayoutNavigationDirective; @ContentChild(SidenavLayoutNavigationDirective) navigationDirective: SidenavLayoutNavigationDirective;
@ContentChild(SidenavLayoutContentDirective) contentDirective: SidenavLayoutContentDirective; @ContentChild(SidenavLayoutContentDirective) contentDirective: SidenavLayoutContentDirective;
@@ -59,8 +58,7 @@ export class SidenavLayoutComponent implements OnInit, AfterViewInit, OnDestroy
isMenuMinimized: () => this.isMenuMinimized isMenuMinimized: () => this.isMenuMinimized
}; };
constructor(private mediaMatcher: MediaMatcher, private config: AppConfigService, private storage: StorageService) { constructor(private mediaMatcher: MediaMatcher) {
this.onMediaQueryChange = this.onMediaQueryChange.bind(this); this.onMediaQueryChange = this.onMediaQueryChange.bind(this);
} }
@@ -86,9 +84,7 @@ export class SidenavLayoutComponent implements OnInit, AfterViewInit, OnDestroy
this.mediaQueryList.removeListener(this.onMediaQueryChange); this.mediaQueryList.removeListener(this.onMediaQueryChange);
} }
toggleMenu() { toggleMenu(expandedSidenav) {
const preserve = this.config.get<string>('sideNav.preserveState');
if (!this.mediaQueryList.matches) { if (!this.mediaQueryList.matches) {
this.isMenuMinimized = !this.isMenuMinimized; this.isMenuMinimized = !this.isMenuMinimized;
} else { } else {
@@ -96,10 +92,7 @@ export class SidenavLayoutComponent implements OnInit, AfterViewInit, OnDestroy
} }
this.container.toggleMenu(); this.container.toggleMenu();
this.notify.emit((!this.isMenuMinimized).toString());
if (preserve) {
this.storage.setItem('openedSidenav', <any> !this.isMenuMinimized);
}
} }
get isMenuMinimized() { get isMenuMinimized() {