mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-20 17:30:14 +01:00
feat(data): update data module, add new mock data (#1960)
This commit is contained in:
parent
773c14e74a
commit
47d232b606
53 changed files with 635 additions and 256 deletions
92
src/app/@core/utils/state.service.ts
Normal file
92
src/app/@core/utils/state.service.ts
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import { Injectable, OnDestroy } from '@angular/core';
|
||||
import { of as observableOf, Observable, BehaviorSubject } from 'rxjs';
|
||||
import { takeWhile } from 'rxjs/operators';
|
||||
|
||||
import { NbLayoutDirectionService, NbLayoutDirection } from '@nebular/theme';
|
||||
|
||||
@Injectable()
|
||||
export class StateService implements OnDestroy {
|
||||
|
||||
protected layouts: any = [
|
||||
{
|
||||
name: 'One Column',
|
||||
icon: 'nb-layout-default',
|
||||
id: 'one-column',
|
||||
selected: true,
|
||||
},
|
||||
{
|
||||
name: 'Two Column',
|
||||
icon: 'nb-layout-two-column',
|
||||
id: 'two-column',
|
||||
},
|
||||
{
|
||||
name: 'Center Column',
|
||||
icon: 'nb-layout-centre',
|
||||
id: 'center-column',
|
||||
},
|
||||
];
|
||||
|
||||
protected sidebars: any = [
|
||||
{
|
||||
name: 'Sidebar at layout start',
|
||||
icon: 'nb-layout-sidebar-left',
|
||||
id: 'start',
|
||||
selected: true,
|
||||
},
|
||||
{
|
||||
name: 'Sidebar at layout end',
|
||||
icon: 'nb-layout-sidebar-right',
|
||||
id: 'end',
|
||||
},
|
||||
];
|
||||
|
||||
protected layoutState$ = new BehaviorSubject(this.layouts[0]);
|
||||
protected sidebarState$ = new BehaviorSubject(this.sidebars[0]);
|
||||
|
||||
alive = true;
|
||||
|
||||
constructor(directionService: NbLayoutDirectionService) {
|
||||
directionService.onDirectionChange()
|
||||
.pipe(takeWhile(() => this.alive))
|
||||
.subscribe(direction => this.updateSidebarIcons(direction));
|
||||
|
||||
this.updateSidebarIcons(directionService.getDirection());
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.alive = false;
|
||||
}
|
||||
|
||||
private updateSidebarIcons(direction: NbLayoutDirection) {
|
||||
const [ startSidebar, endSidebar ] = this.sidebars;
|
||||
const isLtr = direction === NbLayoutDirection.LTR;
|
||||
const startIconClass = isLtr ? 'nb-layout-sidebar-left' : 'nb-layout-sidebar-right';
|
||||
const endIconClass = isLtr ? 'nb-layout-sidebar-right' : 'nb-layout-sidebar-left';
|
||||
startSidebar.icon = startIconClass;
|
||||
endSidebar.icon = endIconClass;
|
||||
}
|
||||
|
||||
setLayoutState(state: any): any {
|
||||
this.layoutState$.next(state);
|
||||
}
|
||||
|
||||
getLayoutStates(): Observable<any[]> {
|
||||
return observableOf(this.layouts);
|
||||
}
|
||||
|
||||
onLayoutState(): Observable<any> {
|
||||
return this.layoutState$.asObservable();
|
||||
}
|
||||
|
||||
setSidebarState(state: any): any {
|
||||
this.sidebarState$.next(state);
|
||||
}
|
||||
|
||||
getSidebarStates(): Observable<any[]> {
|
||||
return observableOf(this.sidebars);
|
||||
}
|
||||
|
||||
onSidebarState(): Observable<any> {
|
||||
return this.sidebarState$.asObservable();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue