From 25711b71e913e42fd961434fca1ac8c589f1f4e1 Mon Sep 17 00:00:00 2001 From: Sergey Andrievskiy Date: Wed, 26 Jun 2019 14:05:38 +0300 Subject: [PATCH] refactor(room): hide background grid in corporate theme --- .../room-selector/room-selector.component.ts | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/app/pages/dashboard/rooms/room-selector/room-selector.component.ts b/src/app/pages/dashboard/rooms/room-selector/room-selector.component.ts index 89d804e2..0fee56fc 100644 --- a/src/app/pages/dashboard/rooms/room-selector/room-selector.component.ts +++ b/src/app/pages/dashboard/rooms/room-selector/room-selector.component.ts @@ -1,15 +1,22 @@ -import { Component, EventEmitter, Output } from '@angular/core'; +import { Component, EventEmitter, HostBinding, OnDestroy, OnInit, Output } from '@angular/core'; import { Location, LocationStrategy } from '@angular/common'; +import { NbThemeService } from '@nebular/theme'; +import { map, takeUntil } from 'rxjs/operators'; +import { Subject } from 'rxjs'; @Component({ selector: 'ngx-room-selector', templateUrl: './room-selector.component.html', styleUrls: ['./room-selector.component.scss'], }) -export class RoomSelectorComponent { +export class RoomSelectorComponent implements OnInit, OnDestroy { + + private destroy$ = new Subject(); + private hideGrid: boolean; + @Output() select: EventEmitter = new EventEmitter(); - selectedRoom: null; + selectedRoom = null; sortedRooms = []; viewBox = '-20 -20 618.88 407.99'; isIE = !!(navigator.userAgent.match(/Trident/) @@ -59,13 +66,35 @@ export class RoomSelectorComponent { ], }; + @HostBinding('style.background') + get background(): 'none' | null { + return this.hideGrid ? 'none' : null; + } + constructor( private location: Location, private locationStrategy: LocationStrategy, + private themeService: NbThemeService, ) { this.selectRoom('2'); } + ngOnInit() { + this.hideGrid = this.themeService.currentTheme === 'corporate'; + + this.themeService.onThemeChange() + .pipe( + map(({ name }) => name === 'corporate'), + takeUntil(this.destroy$), + ) + .subscribe((hideGrid: boolean) => this.hideGrid = hideGrid); + } + + ngOnDestroy() { + this.destroy$.next(); + this.destroy$.complete(); + } + private sortRooms() { this.sortedRooms = this.roomSvg.rooms.slice(0).sort((a, b) => { if (a.id === this.selectedRoom) {