Rename folders

This commit is contained in:
Jesse Lucas
2020-03-29 16:51:12 -04:00
parent 7a657bf3c7
commit 03c6fb2f82
35 changed files with 65 additions and 45 deletions
@@ -0,0 +1,5 @@
<div fxLayout="row" fxLayoutAlign="space-between start">
<div></div>
<div>{{state}}: &nbsp;</div>
<div>{{count}}</div>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ChartItemComponent } from './chart-item.component';
describe('ChartItemComponent', () => {
let component: ChartItemComponent;
let fixture: ComponentFixture<ChartItemComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ChartItemComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ChartItemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,16 @@
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-chart-item',
templateUrl: './chart-item.component.html',
styleUrls: ['./chart-item.component.scss']
})
export class ChartItemComponent implements OnInit {
@Input() state: string;
@Input() count: number;
constructor() { }
ngOnInit(): void {
}
}
@@ -0,0 +1,12 @@
<mat-card class="{{elevation}}">
<mat-card-title>Devices</mat-card-title>
<mat-card-content>
<div fxLayout="row" fxLayoutAlign="space-between start">
<app-donut-chart [elementID]="chartID"></app-donut-chart>
<div class="items" fxLayout="column" fxLayoutAlign="space-evenly end">
<app-chart-item *ngFor="let state of states | keyvalue" [state]="state.key" [count]="state.value">
</app-chart-item>
</div>
</div>
</mat-card-content>
</mat-card>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DeviceChartComponent } from './device-chart.component';
describe('DeviceChartComponent', () => {
let component: DeviceChartComponent;
let fixture: ComponentFixture<DeviceChartComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DeviceChartComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DeviceChartComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,46 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { cardElevation } from '../../style';
import { DonutChartComponent } from '../donut-chart/donut-chart.component';
import Folder from '../../folder'
import { FolderService } from 'src/app/folder.service';
@Component({
selector: 'app-device-chart',
templateUrl: './device-chart.component.html',
styleUrls: ['./device-chart.component.scss']
})
export class DeviceChartComponent implements OnInit {
@ViewChild(DonutChartComponent) donutChart: DonutChartComponent;
chartID: string = 'devicesChart';
elevation: string = cardElevation;
states: Map<string, number>;
constructor(private folderService: FolderService) {
this.states = new Map();
}
ngOnInit(): void {
}
ngAfterViewInit(): void {
// TODO switch to deviceService
this.folderService.getAll().subscribe(
folder => {
// TODO: Clear existing data
this.donutChart.data([10]);
// Get StateType and convert to string
const stateType: Folder.StateType = Folder.getStateType(folder);
const state: string = Folder.stateTypeToString(stateType);
// Instantiate empty count states
if (!this.states.has(state)) {
this.states.set(state, 0);
}
const count: number = this.states.get(state) + 1;
this.states.set(state, count);
}
);
}
}
@@ -0,0 +1 @@
<canvas id={{elementID}} width="200%" height="100%"></canvas>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DonutChartComponent } from './donut-chart.component';
describe('DonutChartComponent', () => {
let component: DonutChartComponent;
let fixture: ComponentFixture<DonutChartComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DonutChartComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DonutChartComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,59 @@
import { Component, Input } from '@angular/core';
import { Chart } from 'chart.js'
@Component({
selector: 'app-donut-chart',
templateUrl: './donut-chart.component.html',
styleUrls: ['./donut-chart.component.scss']
})
export class DonutChartComponent {
@Input() elementID: string;
private canvas: any;
private ctx: any;
private chart: Chart;
constructor() { }
data(val: number[]) {
if (this.chart) {
val.forEach((v) => {
this.addData(v)
});
}
}
addData(data: number): void {
// this.chart.data.labels.push(label);
this.chart.data.datasets.forEach((dataset) => {
dataset.data.push(data);
});
this.chart.update();
}
ngAfterViewInit(): void {
this.canvas = document.getElementById(this.elementID);
this.ctx = this.canvas.getContext('2d');
this.chart = new Chart(this.ctx, {
type: 'doughnut',
data: {
labels: ["Up to Date", "Syncing", "Waiting to Sync", "Out of Sync", "Failed Items"],
datasets: [{
data: [],
backgroundColor: [
'#56C568',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: false,
legend: {
display: false
}
}
});
}
}
@@ -0,0 +1,12 @@
<mat-card class="{{elevation}}">
<mat-card-title>Folders</mat-card-title>
<mat-card-content>
<div fxLayout="row" fxLayoutAlign="space-between start">
<app-donut-chart [elementID]="chartID"></app-donut-chart>
<div class="items" fxLayout="column" fxLayoutAlign="space-evenly end">
<app-chart-item *ngFor="let state of states | keyvalue" [state]="state.key" [count]="state.value">
</app-chart-item>
</div>
</div>
</mat-card-content>
</mat-card>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FolderChartComponent } from './folder-chart.component';
describe('FolderChartComponent', () => {
let component: FolderChartComponent;
let fixture: ComponentFixture<FolderChartComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FolderChartComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FolderChartComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,47 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import Folder from '../../folder'
import { cardElevation } from '../../style'
import { FolderService } from 'src/app/folder.service';
import { DonutChartComponent } from '../donut-chart/donut-chart.component';
@Component({
selector: 'app-folder-chart',
templateUrl: './folder-chart.component.html',
styleUrls: ['./folder-chart.component.scss']
})
export class FolderChartComponent implements OnInit {
@ViewChild(DonutChartComponent) donutChart: DonutChartComponent;
chartID: string = 'foldersChart';
states: Map<string, number>;
elevation: string = cardElevation;
constructor(private folderService: FolderService) {
this.states = new Map();
}
ngOnInit(): void {
for (let state in Folder.StateType) {
console.log(state);
}
}
ngAfterViewInit() {
this.folderService.getAll().subscribe(
folder => {
// TODO: Clear existing data
this.donutChart.data([40]);
// Get StateType and convert to string
const stateType: Folder.StateType = Folder.getStateType(folder);
const state: string = Folder.stateTypeToString(stateType);
// Instantiate empty count states
if (!this.states.has(state)) {
this.states.set(state, 0);
}
const count: number = this.states.get(state) + 1;
this.states.set(state, count);
}
);
}
}