Create system connections service, mocks, and work on updating devices chart

This commit is contained in:
Jesse Lucas 2020-03-25 21:36:24 -04:00
parent 78a31449aa
commit bc7d71ee3d
9 changed files with 167 additions and 17 deletions

View File

@ -1,8 +1,8 @@
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/services/folder.service';
import { DeviceService } from 'src/app/services/device.service';
import Device from '../../device';
@Component({
selector: 'app-device-chart',
@ -15,19 +15,17 @@ export class DeviceChartComponent implements OnInit {
elevation: string = cardElevation;
states: { label: string, count: number }[] = [];
constructor(private folderService: FolderService) { }
constructor(private deviceService: DeviceService) { }
ngOnInit(): void {
}
ngOnInit(): void { }
ngAfterViewInit(): void {
// TODO switch to deviceService
this.folderService.getAll().subscribe(
folder => {
this.deviceService.getAll().subscribe(
device => {
// Get StateType and convert to string
const stateType: Folder.StateType = Folder.getStateType(folder);
const state: string = Folder.stateTypeToString(stateType);
const stateType: Device.StateType = Device.getStateType(device);
const state: string = Device.stateTypeToString(stateType);
// Check if state exists
let found: boolean = false;

View File

@ -18,9 +18,7 @@ export class FolderChartComponent implements OnInit {
constructor(private folderService: FolderService) { }
ngOnInit(): void {
for (let state in Folder.StateType) {
// console.log(state);
}
// for (let state in Folder.StateType) { }
}
ngAfterViewInit() {

16
src/app/connections.ts Normal file
View File

@ -0,0 +1,16 @@
export interface SystemConnections {
connections: { deviceId?: Connection };
total: Connection;
}
export interface Connection {
address: string;
at: string;
clientVersion: string;
connected: boolean;
crypto: string;
inBytesTotal: number;
outBytesTotal: number;
paused: boolean;
type: string;
}

View File

@ -1,7 +1,7 @@
export const config = {
"version": 15,
"folders": [
{ "id": "GXWxf-3zgnU", "label": "MyFolder", "path": "...", "type": "sendreceive", "devices": [{ "deviceID": "..." }], "rescanIntervalS": 60, "ignorePerms": false, "autoNormalize": true, "minDiskFreePct": 1, "versioning": { "type": "simple", "params": { "keep": "5" } }, "copiers": 0, "pullers": 0, "hashers": 0, "order": "random", "ignoreDelete": false, "scanProgressIntervalS": 0, "pullerSleepS": 0, "pullerPauseS": 0, "maxConflicts": 10, "disableSparseFiles": false, "disableTempIndexes": false, "fsync": false, "invalid": "" },
{ "id": "GXWxf-3zgnU", "label": "MyFolder", "path": "...", "type": "sendreceive", "devices": [{ "deviceID": "YZJBJFX-RDBL7WY-6ZGKJ2D-4MJB4E7-ZATSDUY-LD6Y3L3-MLFUYWE-AEMXJAC" }], "rescanIntervalS": 60, "ignorePerms": false, "autoNormalize": true, "minDiskFreePct": 1, "versioning": { "type": "simple", "params": { "keep": "5" } }, "copiers": 0, "pullers": 0, "hashers": 0, "order": "random", "ignoreDelete": false, "scanProgressIntervalS": 0, "pullerSleepS": 0, "pullerPauseS": 0, "maxConflicts": 10, "disableSparseFiles": false, "disableTempIndexes": false, "fsync": false, "invalid": "" },
{ "id": "Tyeho-ncvqp", "label": "MyFolder", "path": "...", "type": "sendreceive", "devices": [{ "deviceID": "..." }], "rescanIntervalS": 60, "ignorePerms": false, "autoNormalize": true, "minDiskFreePct": 1, "versioning": { "type": "simple", "params": { "keep": "5" } }, "copiers": 0, "pullers": 0, "hashers": 0, "order": "random", "ignoreDelete": false, "scanProgressIntervalS": 0, "pullerSleepS": 0, "pullerPauseS": 0, "maxConflicts": 10, "disableSparseFiles": false, "disableTempIndexes": false, "fsync": false, "invalid": "" },
{ "id": "Ihpqp-3zgnq", "label": "MyFolder", "path": "...", "type": "sendreceive", "devices": [{ "deviceID": "..." }], "rescanIntervalS": 60, "ignorePerms": false, "autoNormalize": true, "minDiskFreePct": 1, "versioning": { "type": "simple", "params": { "keep": "5" } }, "copiers": 0, "pullers": 0, "hashers": 0, "order": "random", "ignoreDelete": false, "scanProgressIntervalS": 0, "pullerSleepS": 0, "pullerPauseS": 0, "maxConflicts": 10, "disableSparseFiles": false, "disableTempIndexes": false, "fsync": false, "invalid": "" },
{ "id": "Abqqp-3zgnU", "label": "MyFolder", "path": "...", "type": "sendreceive", "devices": [{ "deviceID": "..." }], "rescanIntervalS": 60, "ignorePerms": false, "autoNormalize": true, "minDiskFreePct": 1, "versioning": { "type": "simple", "params": { "keep": "5" } }, "copiers": 0, "pullers": 0, "hashers": 0, "order": "random", "ignoreDelete": false, "scanProgressIntervalS": 0, "pullerSleepS": 0, "pullerPauseS": 0, "maxConflicts": 10, "disableSparseFiles": false, "disableTempIndexes": false, "fsync": false, "invalid": "" },
@ -11,7 +11,7 @@ export const config = {
{ "id": "Poqff-3zgnU", "label": "MyFolder", "path": "...", "type": "sendreceive", "devices": [{ "deviceID": "..." }], "rescanIntervalS": 60, "ignorePerms": false, "autoNormalize": true, "minDiskFreePct": 1, "versioning": { "type": "simple", "params": { "keep": "5" } }, "copiers": 0, "pullers": 0, "hashers": 0, "order": "random", "ignoreDelete": false, "scanProgressIntervalS": 0, "pullerSleepS": 0, "pullerPauseS": 0, "maxConflicts": 10, "disableSparseFiles": false, "disableTempIndexes": false, "fsync": false, "invalid": "" },
],
"devices": [
{ "deviceID": "...", "name": "Laptop", "addresses": ["dynamic", "tcp://192.168.1.2:22000"], "compression": "metadata", "certName": "", "introducer": false },
{ "deviceID": "YZJBJFX-RDBL7WY-6ZGKJ2D-4MJB4E7-ZATSDUY-LD6Y3L3-MLFUYWE-AEMXJAC", "name": "Laptop", "addresses": ["dynamic", "tcp://192.168.1.2:22000"], "compression": "metadata", "certName": "", "introducer": false },
{ "deviceID": "...", "name": "Server", "addresses": ["dynamic", "tcp://192.168.1.3:22000"], "compression": "metadata", "certName": "", "introducer": false },
],
"gui": {

View File

@ -0,0 +1,44 @@
export const connections = {
"total": {
"paused": false,
"clientVersion": "",
"at": "2015-11-07T17:29:47.691637262+01:00",
"connected": false,
"inBytesTotal": 1479,
"type": "",
"outBytesTotal": 1318,
"address": ""
},
"connections": {
"YZJBJFX-RDBL7WY-6ZGKJ2D-4MJB4E7-ZATSDUY-LD6Y3L3-MLFUYWE-AEMXJAC": {
"connected": true,
"inBytesTotal": 556,
"paused": false,
"at": "2015-11-07T17:29:47.691548971+01:00",
"clientVersion": "v0.12.1",
"address": "127.0.0.1:22002",
"type": "TCP (Client)",
"outBytesTotal": 550
},
"DOVII4U-SQEEESM-VZ2CVTC-CJM4YN5-QNV7DCU-5U3ASRL-YVFG6TH-W5DV5AA": {
"outBytesTotal": 0,
"type": "",
"address": "",
"at": "0001-01-01T00:00:00Z",
"clientVersion": "",
"paused": false,
"inBytesTotal": 0,
"connected": false
},
"UYGDMA4-TPHOFO5-2VQYDCC-7CWX7XW-INZINQT-LE4B42N-4JUZTSM-IWCSXA4": {
"address": "",
"type": "",
"outBytesTotal": 0,
"connected": false,
"inBytesTotal": 0,
"paused": false,
"at": "0001-01-01T00:00:00Z",
"clientVersion": ""
}
}
}

View File

@ -1,10 +1,60 @@
import { Injectable } from '@angular/core';
import Device from '../device';
import { Observable } from 'rxjs';
import { SystemConfigService } from './system-config.service';
import { SystemConnectionsService } from './system-connections.service';
@Injectable({
providedIn: 'root'
})
export class DeviceService {
private devices: Device[];
constructor() { }
constructor(
private systemConfigService: SystemConfigService,
private systemConnectionsService: SystemConnectionsService
) { }
getAll(): Observable<Device> {
const deviceObservable: Observable<Device> = new Observable((observer) => {
this.systemConfigService.getDevices().subscribe(
devices => {
this.devices = devices;
// Check folder devices to see if the device is used
this.systemConfigService.getFolders().subscribe(
folders => {
// TODO: streamline
// Loop through all folder devices to see if the device is used
this.devices.forEach(device => {
folders.forEach(folder => {
folder.devices.forEach(fdevice => {
if (device.deviceID === fdevice.deviceID) {
device.used = true;
}
});
});
});
// See if the connection is connected or undefined
this.systemConnectionsService.getSystemConnections().subscribe(
connections => {
// TODO: check connection and request total
this.devices.forEach(device => {
observer.next(device);
});
observer.complete();
}
);
// Synchronously get the status of each device
// this.getDeviceStatusInOrder(observer, 0);
}
)
},
err => { console.log("getAll error!", err) },
() => { console.log("get all complete!") }
);
});
return deviceObservable
}
}

View File

@ -1,13 +1,14 @@
import { Injectable } from '@angular/core';
import { config } from '../mocks/mock-config'
import { dbStatus } from '../mocks/mock-db-status'
import { connections } from '../mocks/mock-connections'
@Injectable({
providedIn: 'root'
})
export class InMemoryConfigDataService {
createDb() {
return { config, dbStatus };
return { config, dbStatus, connections };
}
constructor() { }

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { SystemConnectionsService } from './system-connections.service';
describe('SystemConnectionsService', () => {
let service: SystemConnectionsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SystemConnectionsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { apiURL, apiRetry } from '../api-utils';
import { HttpClient } from '@angular/common/http';
import { retry, map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { SystemConnections } from '../connections';
@Injectable({
providedIn: 'root'
})
export class SystemConnectionsService {
private systemConfigUrl = environment.production ? apiURL + 'rest/system/connections' : 'api/connections';
constructor(private http: HttpClient) { }
getSystemConnections(): Observable<SystemConnections> {
return this.http
.get<SystemConnections>(this.systemConfigUrl)
.pipe(
retry(apiRetry),
map(res => {
return res;
})
);
}
}