Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
feat: keep sidenav visibility state on the server for every user (#1194)
Browse files Browse the repository at this point in the history
PR Close #994
  • Loading branch information
tamazlykar authored Aug 15, 2018
1 parent 28aca8b commit 02ae499
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/app/core/components/sidenav/sidenav.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<button
class="hide-button"
mat-icon-button
(click)="toggleDrawer()"
(click)="closeSidenav()"
>
<mat-icon class="mdi-chevron-left"></mat-icon>
</button>
Expand Down
18 changes: 5 additions & 13 deletions src/app/core/components/sidenav/sidenav.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { AfterViewInit, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { DragulaService } from 'ng2-dragula';
import * as cloneDeep from 'lodash/cloneDeep';

import { ConfigService } from '../../services';
import { LayoutService } from '../../../shared/services/layout.service';
import { RouterUtilsService } from '../../../shared/services/router-utils.service';
import { WithUnsubscribe } from '../../../utils/mixins/with-unsubscribe';
import { transformHandle, transformLinks } from './sidenav-animations';
import { NavigationItem, nonDraggableRoutes, SidenavRoute, sidenavRoutes } from './sidenav-routes';
import { State, UserTagsActions, UserTagsSelectors } from '../../../root-store';
import { layoutActions, State, UserTagsActions, UserTagsSelectors } from '../../../root-store';


@Component({
Expand All @@ -19,7 +18,7 @@ import { State, UserTagsActions, UserTagsSelectors } from '../../../root-store';
styleUrls: ['./sidenav.component.scss'],
animations: [transformHandle, transformLinks]
})
export class SidenavComponent extends WithUnsubscribe() implements AfterViewInit, OnInit, OnDestroy {
export class SidenavComponent extends WithUnsubscribe() implements OnInit, OnDestroy {
@ViewChild('navigationBar') public navigationBar: ElementRef;
@Input() public open: boolean;
@Input() public title: string;
Expand All @@ -38,7 +37,6 @@ export class SidenavComponent extends WithUnsubscribe() implements AfterViewInit
constructor(
private configService: ConfigService,
private dragula: DragulaService,
private layoutService: LayoutService,
private routerUtilsService: RouterUtilsService,
private router: Router,
private store: Store<State>
Expand All @@ -52,12 +50,6 @@ export class SidenavComponent extends WithUnsubscribe() implements AfterViewInit
this.initNavigationOrder();
}

public ngAfterViewInit(): void {
this.layoutService.drawerToggled
.takeUntil(this.unsubscribe$)
.subscribe(() => this.toggleDrawer());
}

public ngOnDestroy(): void {
super.ngOnDestroy();
this.dragula.destroy(this.dragulaContainerName);
Expand All @@ -83,8 +75,8 @@ export class SidenavComponent extends WithUnsubscribe() implements AfterViewInit
return new Date().getFullYear().toString();
}

public toggleDrawer(): void {
this.layoutService.toggleDrawer();
public closeSidenav(): void {
this.store.dispatch(new layoutActions.CloseSidenav());
}

public toggleEditing(): void {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/config/config-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ConfigInterface {
askToCreateVolume: boolean;
savePasswordForAllVMs: boolean | null;
lastVMId: number;
isSidenavVisible: boolean;
showSystemTags: boolean;
navigationOrder: string;
}
1 change: 1 addition & 0 deletions src/app/core/config/default-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const defaultConfig: ConfigInterface = {
// The application will ask him about autosave passwords and set the value based on the user's choice.
savePasswordForAllVMs: null,
lastVMId: 1,
isSidenavVisible: true,
showSystemTags: false,
navigationOrder: ''
};
4 changes: 4 additions & 0 deletions src/app/core/services/system-tags.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class SystemTagsService {
key: userTagKeys.sessionTimeout,
value: `${this.configService.get<number>('sessionTimeout')}`
},
{
key: userTagKeys.sidenavVisible,
value: `${this.configService.get<boolean>('isSidenavVisible')}`
},
{
key: userTagKeys.showSystemTags,
value: `${this.configService.get<boolean>('showSystemTags')}`
Expand Down
14 changes: 6 additions & 8 deletions src/app/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<div class="wrapper">
<mat-sidenav-container>
<mat-sidenav [opened]="isDrawerOpen" mode="side">
<cs-sidenav [title]="title"></cs-sidenav>
</mat-sidenav>
<mat-sidenav-container fullscreen>
<mat-sidenav [opened]="isSidenavVisible$ | async" mode="side">
<cs-sidenav [title]="title"></cs-sidenav>
</mat-sidenav>

<router-outlet></router-outlet>
</mat-sidenav-container>
</div>
<router-outlet></router-outlet>
</mat-sidenav-container>
16 changes: 0 additions & 16 deletions src/app/home/home.component.scss
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
:host {
height: 100%;
}

.wrapper {
display: flex;
flex: 1 1 auto;
height: 100%;
}

mat-sidenav-container {
flex-grow: 1;
min-height: 100%;
height: auto !important;
max-width: 100%;
margin: 0;

mat-sidenav {
display: flex;
flex-direction: column;
Expand Down
9 changes: 2 additions & 7 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';

import { State, UserTagsActions } from '../root-store';
import { layoutSelectors, State, UserTagsActions } from '../root-store';
import { AuthService } from '../shared/services/auth.service';
import { LayoutService } from '../shared/services/layout.service';
import { WithUnsubscribe } from '../utils/mixins/with-unsubscribe';
import { getName } from '../shared/models';
import * as authActions from '../reducers/auth/redux/auth.actions';
Expand All @@ -16,10 +15,10 @@ import * as serviceOfferingActions from '../reducers/service-offerings/redux/ser
})
export class HomeComponent extends WithUnsubscribe() implements OnInit {
public disableSecurityGroups = false;
public isSidenavVisible$ = this.store.select(layoutSelectors.isSidenavVisible);

constructor(
private auth: AuthService,
private layoutService: LayoutService,
private store: Store<State>
) {
super();
Expand All @@ -44,8 +43,4 @@ export class HomeComponent extends WithUnsubscribe() implements OnInit {
public get title(): string {
return this.auth.user ? getName(this.auth.user) : '';
}

public get isDrawerOpen(): boolean {
return this.layoutService.drawerOpen;
}
}
1 change: 1 addition & 0 deletions src/app/root-store/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { RootStoreModule } from './root-store.module';
export * from './state';
export * from './server-data';
export * from './layout';
export { IdleMonitorActions } from './idle-monitor';
7 changes: 7 additions & 0 deletions src/app/root-store/layout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as layoutActions from './layout.actions';
import * as layoutSelectors from './layout.selectors';

export {
layoutActions,
layoutSelectors
};
1 change: 1 addition & 0 deletions src/app/root-store/layout/layout.actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { OpenSidenav, CloseSidenav } from '../server-data/user-tags/user-tags.actions';
3 changes: 3 additions & 0 deletions src/app/root-store/layout/layout.selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as UserTagsSelectors from '../server-data/user-tags/user-tags.selectors';

export const isSidenavVisible = UserTagsSelectors.isSidenavVisible;
Loading

0 comments on commit 02ae499

Please sign in to comment.