Combine types

This commit is contained in:
Jesse Lucas 2020-03-30 17:02:46 -04:00
parent 33398b0b6b
commit dae1f990a5
No known key found for this signature in database
GPG Key ID: 9810010C7FDCD3BB
9 changed files with 28 additions and 31 deletions

View File

@ -1,4 +0,0 @@
export const enum ChartType {
Folder = 0,
Device
}

View File

@ -5,7 +5,7 @@ import { FolderService } from 'src/app/services/folder.service';
import { DonutChartComponent } from '../donut-chart/donut-chart.component'; import { DonutChartComponent } from '../donut-chart/donut-chart.component';
import { DeviceService } from 'src/app/services/device.service'; import { DeviceService } from 'src/app/services/device.service';
import Device from 'src/app/device'; import Device from 'src/app/device';
import { ChartType } from '../../chart'; import { Type } from '../../type';
@ -17,7 +17,7 @@ import { ChartType } from '../../chart';
export class ChartComponent implements OnInit { export class ChartComponent implements OnInit {
@ViewChild(DonutChartComponent) donutChart: DonutChartComponent; @ViewChild(DonutChartComponent) donutChart: DonutChartComponent;
@Input() type: ChartType; @Input() type: Type;
title: string; title: string;
chartID: string; chartID: string;
states: { label: string, count: number, color: string }[] = []; states: { label: string, count: number, color: string }[] = [];
@ -29,12 +29,12 @@ export class ChartComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
switch (this.type) { switch (this.type) {
case ChartType.Folder: case Type.Folder:
this.title = "Folders"; this.title = "Folders";
this.chartID = 'foldersChart'; this.chartID = 'foldersChart';
this.service = this.folderService; this.service = this.folderService;
break; break;
case ChartType.Device: case Type.Device:
this.title = "Devices"; this.title = "Devices";
this.chartID = 'devicesChart'; this.chartID = 'devicesChart';
this.service = this.deviceServce; this.service = this.deviceServce;
@ -55,12 +55,12 @@ export class ChartComponent implements OnInit {
let state: string; let state: string;
let color; let color;
switch (this.type) { switch (this.type) {
case ChartType.Folder: case Type.Folder:
stateType = Folder.getStateType(folder); stateType = Folder.getStateType(folder);
state = Folder.stateTypeToString(stateType); state = Folder.stateTypeToString(stateType);
color = Folder.stateTypeToColor(stateType); color = Folder.stateTypeToColor(stateType);
break; break;
case ChartType.Device: case Type.Device:
stateType = Device.getStateType(folder); stateType = Device.getStateType(folder);
state = Device.stateTypeToString(stateType); state = Device.stateTypeToString(stateType);
color = Device.stateTypeToColor(stateType); color = Device.stateTypeToColor(stateType);

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { SystemConfigService } from '../services/system-config.service'; import { SystemConfigService } from '../services/system-config.service';
import { ChartType } from '../chart'; import { Type } from '../type';
@Component({ @Component({
selector: 'app-dashboard', selector: 'app-dashboard',
@ -8,8 +8,8 @@ import { ChartType } from '../chart';
styleUrls: ['./dashboard.component.scss'] styleUrls: ['./dashboard.component.scss']
}) })
export class DashboardComponent { export class DashboardComponent {
folderChart: ChartType = ChartType.Folder; folderChart: Type = Type.Folder;
deviceChart: ChartType = ChartType.Device; deviceChart: Type = Type.Device;
constructor(private systemConfigService: SystemConfigService) { } constructor(private systemConfigService: SystemConfigService) { }

View File

@ -1,4 +1,4 @@
<mat-button-toggle-group name="fontStyle" aria-label="Font Style" value="folders"> <mat-button-toggle-group name="fontStyle" aria-label="Font Style" value="folders">
<mat-button-toggle value="folders" (click)="onSelect(listType.Folders)">Folders</mat-button-toggle> <mat-button-toggle value="folders" (click)="onSelect(listType.Folder)">Folders</mat-button-toggle>
<mat-button-toggle value="devices" (click)="onSelect(listType.Devices)">Devices</mat-button-toggle> <mat-button-toggle value="devices" (click)="onSelect(listType.Device)">Devices</mat-button-toggle>
</mat-button-toggle-group> </mat-button-toggle-group>

View File

@ -1,5 +1,5 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { ListType } from '../list-type'; import { Type } from '../type';
@ -10,20 +10,20 @@ import { ListType } from '../list-type';
}) })
export class ListToggleComponent implements OnInit { export class ListToggleComponent implements OnInit {
public listType = ListType; public listType = Type;
@Output() listTypeEvent = new EventEmitter<ListType>(); @Output() listTypeEvent = new EventEmitter<Type>();
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {
} }
onSelect(t: ListType): void { onSelect(t: Type): void {
this.listTypeEvent.emit(t); this.listTypeEvent.emit(t);
switch (t) { switch (t) {
case ListType.Folders: case Type.Folder:
console.log("folder action"); console.log("folder action");
break; break;
case ListType.Devices: case Type.Device:
console.log("Device action"); console.log("Device action");
break; break;
} }

View File

@ -1,4 +0,0 @@
export enum ListType {
Folders = 1,
Devices,
}

View File

@ -4,7 +4,7 @@
<app-list-toggle (listTypeEvent)="onToggle($event)" class="tui-card-content"></app-list-toggle> <app-list-toggle (listTypeEvent)="onToggle($event)" class="tui-card-content"></app-list-toggle>
</div> </div>
<div class="tui-card-content"> <div class="tui-card-content">
<app-folder-list *ngIf="currentListType===listType.Folders"></app-folder-list> <app-folder-list *ngIf="currentListType===listType.Folder"></app-folder-list>
<app-device-list *ngIf="currentListType===listType.Devices"></app-device-list> <app-device-list *ngIf="currentListType===listType.Device"> </app-device-list>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ListType } from '../../list-type'; import { Type } from '../../type';
import { cardElevation } from '../../style'; import { cardElevation } from '../../style';
@ -9,17 +9,18 @@ import { cardElevation } from '../../style';
styleUrls: ['./status-list.component.scss'] styleUrls: ['./status-list.component.scss']
}) })
export class StatusListComponent implements OnInit { export class StatusListComponent implements OnInit {
currentListType: ListType = ListType.Folders; currentListType: Type = Type.Folder;
listType = ListType; // used in html listType = Type; // used in html
elevation: string = cardElevation; elevation: string = cardElevation;
title: string = 'Status'; title: string = 'Status';
folderList: Type = Type.Folder;
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {
} }
onToggle(t: ListType) { onToggle(t: Type) {
this.currentListType = t; this.currentListType = t;
} }
} }

4
src/app/type.ts Normal file
View File

@ -0,0 +1,4 @@
export enum Type {
Folder = 1,
Device,
}