56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
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<Dashboard>{
|
|
return this.http.post<Dashboard>('//'+window.location.hostname+':'+window.location.port+'/api/dashboards/', data);
|
|
}
|
|
|
|
getDashboards(): Observable<DashboardList>{
|
|
return this.http.get<DashboardList>('//'+window.location.hostname+':'+window.location.port+'/api/dashboards/');
|
|
}
|
|
|
|
getDashboard(id: string): Observable<Dashboard>{
|
|
return this.http.get<Dashboard>('//'+window.location.hostname+':'+window.location.port+'/api/dashboards/'+id);
|
|
}
|
|
|
|
saveDashboard(dashboard: Dashboard): Observable<Dashboard>{
|
|
return this.http.put<Dashboard>('//'+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);
|
|
}
|
|
} |