import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { PlotConfig } from './plot.service'; @Injectable({ providedIn: 'root' }) export class DashboardService { constructor(private http: HttpClient) { } createDashboard(data: DashboardCreationData): Observable{ return this.http.post('//'+window.location.hostname+':'+window.location.port+'/api/dashboards/', data); } getDashboards(): Observable{ return this.http.get('//'+window.location.hostname+':'+window.location.port+'/api/dashboards/'); } getDashboard(id: string): Observable{ return this.http.get('//'+window.location.hostname+':'+window.location.port+'/api/dashboards/'+id); } saveDashboard(dashboard: Dashboard): Observable{ return this.http.put('//'+window.location.hostname+':'+window.location.port+'/api/dashboards/'+dashboard.id, dashboard); } } export class DashboardCreationData{ constructor(public name: string, public description: string){} } export class Dashboard{ constructor(public id: string, public name: string, public description: string, public texts: TextWidget[], public plots: PlotWidget[]){} } export class DashboardList{ constructor(public dashboards: [Dashboard]){} } export abstract class BaseWidget { constructor(public type: 'TEXT'|'PLOT', public size: 'SMALL'|'MEDIUM'|'LARGE') {} } export class TextWidget extends BaseWidget { constructor(override size: 'SMALL'|'MEDIUM'|'LARGE', public text: string) { super('TEXT', size); } } export class PlotWidget extends BaseWidget { constructor(override size: 'SMALL'|'MEDIUM'|'LARGE', public config: PlotConfig) { super('PLOT', size); } }