New dashboard look & feel
[src/xds/xds-agent.git] / webapp / src / app / @theme / components / theme-settings / theme-settings.component.ts
1 import { Component, Input, OnInit } from '@angular/core';
2
3 import { StateService } from '../../../@core/data/state.service';
4
5 @Component({
6   selector: 'ngx-theme-settings',
7   styleUrls: ['./theme-settings.component.scss'],
8   template: `
9     <h6>LAYOUTS</h6>
10     <div class="settings-row">
11       <a *ngFor="let layout of layouts"
12          href="#"
13          [class.selected]="layout.selected"
14          [attr.title]="layout.name"
15          (click)="layoutSelect(layout)">
16         <i [attr.class]="layout.icon"></i>
17       </a>
18     </div>
19     <h6>SIDEBAR</h6>
20     <div class="settings-row">
21       <a *ngFor="let sidebar of sidebars"
22          href="#"
23          [class.selected]="sidebar.selected"
24          [attr.title]="sidebar.name"
25          (click)="sidebarSelect(sidebar)">
26         <i [attr.class]="sidebar.icon"></i>
27       </a>
28     </div>
29   `,
30 })
31 export class ThemeSettingsComponent {
32
33   layouts = [];
34   sidebars = [];
35
36   constructor(protected stateService: StateService) {
37     this.stateService.getLayoutStates()
38       .subscribe((layouts: any[]) => this.layouts = layouts);
39
40     this.stateService.getSidebarStates()
41       .subscribe((sidebars: any[]) => this.sidebars = sidebars);
42   }
43
44   layoutSelect(layout: any): boolean {
45     this.layouts = this.layouts.map((l: any) => {
46       l.selected = false;
47       return l;
48     });
49
50     layout.selected = true;
51     this.stateService.setLayoutState(layout);
52     return false;
53   }
54
55   sidebarSelect(sidebars: any): boolean {
56     this.sidebars = this.sidebars.map((s: any) => {
57       s.selected = false;
58       return s;
59     });
60
61     sidebars.selected = true;
62     this.stateService.setSidebarState(sidebars);
63     return false;
64   }
65 }