ngx-admin/src/app/pages/dashboard/dashboard.component.ts

89 lines
1.9 KiB
TypeScript
Raw Normal View History

import {Component, OnDestroy} from '@angular/core';
import { NbThemeService } from '@nebular/theme';
import { takeWhile } from 'rxjs/operators/takeWhile' ;
interface ICardSettings {
title: string;
iconClass: string;
type: string;
}
2017-04-13 14:24:23 +03:00
@Component({
2017-05-06 15:35:15 +03:00
selector: 'ngx-dashboard',
2017-06-12 19:43:44 +03:00
styleUrls: ['./dashboard.component.scss'],
templateUrl: './dashboard.component.html',
2017-04-13 14:24:23 +03:00
})
export class DashboardComponent implements OnDestroy {
private alive = true;
lightCard: ICardSettings = {
title: 'Light',
iconClass: 'nb-lightbulb',
type: 'primary',
};
rollerShadesCard: ICardSettings = {
title: 'Roller Shades',
iconClass: 'nb-roller-shades',
type: 'success',
};
wirelessAudioCard: ICardSettings = {
title: 'Wireless Audio',
iconClass: 'nb-audio',
type: 'info',
};
coffeeMakerCard: ICardSettings = {
title: 'Coffee Maker',
iconClass: 'nb-coffee-maker',
type: 'warning',
};
statusCards: string;
commonStatusCardsSet: ICardSettings[] = [
this.lightCard,
this.rollerShadesCard,
this.wirelessAudioCard,
this.coffeeMakerCard,
];
statusCardsByThemes: {
default: ICardSettings[];
cosmic: ICardSettings[];
corporate: ICardSettings[];
} = {
default: this.commonStatusCardsSet,
cosmic: this.commonStatusCardsSet,
corporate: [
{
...this.lightCard,
type: 'warning',
},
{
...this.rollerShadesCard,
type: 'primary',
},
{
...this.wirelessAudioCard,
type: 'danger',
},
{
...this.coffeeMakerCard,
type: 'secondary',
},
],
};
constructor(private themeService: NbThemeService) {
this.themeService.getJsTheme()
.pipe(takeWhile(() => this.alive))
.subscribe(theme => {
this.statusCards = this.statusCardsByThemes[theme.name];
});
}
ngOnDestroy() {
this.alive = false;
}
2017-04-13 14:24:23 +03:00
}