X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=webapp%2Fsrc%2Fapp%2F%40theme%2Flayouts%2Fxds%2Fxds.layout.ts;h=b362fffc6374dd5a3d02240038a70f301626ce8b;hb=bd9463c836130c1d37e56be3658076ecd11ed76d;hp=8987584272067f859d1e03e55405b19c15211938;hpb=38c0c21a969e621c725245ce91c78e77076c5ce7;p=src%2Fxds%2Fxds-agent.git diff --git a/webapp/src/app/@theme/layouts/xds/xds.layout.ts b/webapp/src/app/@theme/layouts/xds/xds.layout.ts index 8987584..b362fff 100644 --- a/webapp/src/app/@theme/layouts/xds/xds.layout.ts +++ b/webapp/src/app/@theme/layouts/xds/xds.layout.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy } from '@angular/core'; +import { Component, OnDestroy, EventEmitter } from '@angular/core'; import { NbMediaBreakpoint, NbMediaBreakpointsService, @@ -11,8 +11,11 @@ import { import { StateService } from '../../../@core/data/state.service'; import { Subscription } from 'rxjs/Subscription'; +import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/withLatestFrom'; import 'rxjs/add/operator/delay'; +import 'rxjs/add/observable/of'; +import 'rxjs/add/operator/takeUntil'; // TODO: move layouts into the framework @Component({ @@ -26,17 +29,22 @@ export class XdsLayoutComponent implements OnDestroy { subMenu: NbMenuItem[] = []; layout: any = {}; sidebar: any = {}; + sidebarPinned = false; sidebarCompact = true; protected layoutState$: Subscription; protected sidebarState$: Subscription; protected menuClick$: Subscription; + private _mouseEnterStream: EventEmitter = new EventEmitter(); + private _mouseLeaveStream: EventEmitter = new EventEmitter(); + constructor(protected stateService: StateService, protected menuService: NbMenuService, protected themeService: NbThemeService, protected bpService: NbMediaBreakpointsService, protected sidebarService: NbSidebarService) { + this.layoutState$ = this.stateService.onLayoutState() .subscribe((layout: string) => this.layout = layout); @@ -46,26 +54,61 @@ export class XdsLayoutComponent implements OnDestroy { }); const isBp = this.bpService.getByName('is'); + this.menuClick$ = this.menuService.onItemSelect() .withLatestFrom(this.themeService.onMediaQueryChange()) .delay(20) .subscribe(([item, [bpFrom, bpTo]]: [any, [NbMediaBreakpoint, NbMediaBreakpoint]]) => { - + /* this.sidebarCompact = false; + */ + // automatically collapse sidebar for narrow screen / mobile if (bpTo.width <= isBp.width) { this.sidebarService.collapse('menu-sidebar'); } }); // Set sidebarCompact according to sidebar state changes - this.sidebarService.onToggle().subscribe(s => s.tag === 'menu-sidebar' && (this.sidebarCompact = !this.sidebarCompact)); + this.sidebarService.onToggle().subscribe(s => { + if (s.tag === 'menu-sidebar') { + this.sidebarPinned = false; + this.sidebarCompact = !this.sidebarCompact; + } + }); + this.sidebarService.onCollapse().subscribe(s => s.tag === 'menu-sidebar' && (this.sidebarCompact = true)); - this.sidebarService.onExpand().subscribe(() => this.sidebarCompact = false); + this.sidebarService.onExpand().subscribe(s => s.tag === 'menu-sidebar' && (this.sidebarCompact = false)); this.menuService.onSubmenuToggle().subscribe(i => i.item && i.item.expanded && (this.sidebarCompact = false)); - } - toogleSidebar() { - this.sidebarService.toggle(true, 'menu-sidebar'); + // Automatically expand sidebar on mouse over + this._mouseEnterStream.flatMap(e => { + return Observable + .of(e) + .delay(100) + .takeUntil(this._mouseLeaveStream); + }) + .subscribe(e => { + if (this.sidebarPinned || !this.sidebarCompact) { + return; + } + // this._mouseLeaveStream.emit(null); + this.sidebarService.toggle(false, 'menu-sidebar'); + }); + + // Automatically collapse sidebar on mouse leave + this._mouseLeaveStream.flatMap(e => { + return Observable + .of(e) + .delay(100) + .takeUntil(this._mouseEnterStream); + }) + .subscribe(e => { + if (this.sidebarPinned || this.sidebarCompact) { + return; + } + // this._mouseEnterStream.emit(null); + this.sidebarService.toggle(true, 'menu-sidebar'); + }); } ngOnDestroy() { @@ -73,4 +116,16 @@ export class XdsLayoutComponent implements OnDestroy { this.sidebarState$.unsubscribe(); this.menuClick$.unsubscribe(); } + + onMouseEnter($event) { + this._mouseEnterStream.emit($event); + } + + onMouseLeave($event) { + this._mouseLeaveStream.emit($event); + } + + pinSidebar() { + this.sidebarPinned = !this.sidebarPinned; + } }