-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault-dashboard.ts
96 lines (82 loc) · 2.76 KB
/
default-dashboard.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { DataSource } from '../data/data-source/data-source';
import { DataRefreshEvent } from '../data/data-source/events/data-refresh-event';
import { DataSourceManager } from '../data/data-source/manager/data-source-manager';
import { TimeRangeManager } from '../data/time-range/manager/time-range-manager';
import { TimeRange } from '../data/time-range/time-range';
import { ModelManager } from '../model/manager/model-manager';
import { SerializationManager } from '../persistence/serialization/serialization-manager';
import { Constructable } from '../util/constructable';
import { VariableManager } from '../variable/manager/variable-manager';
import { Dashboard } from './dashboard';
// tslint:disable-next-line: completed-docs
export class DefaultDashboard<TRoot extends object> implements Dashboard<TRoot> {
public constructor(
public readonly root: TRoot,
private readonly variableManager: VariableManager,
private readonly timeRangeManager: TimeRangeManager,
private readonly serializationManager: SerializationManager,
private readonly modelManager: ModelManager,
private readonly dataRefreshEvent: DataRefreshEvent,
private readonly dataSourceManager: DataSourceManager
) {}
/**
* @inheritdoc
*/
public setVariable(variableName: string, value: unknown): this {
this.variableManager.set(variableName, value, this.root);
return this;
}
/**
* @inheritdoc
*/
public setTimeRange(timeRange: TimeRange): this {
this.timeRangeManager.setRootTimeRange(this.root, timeRange);
return this;
}
/**
* @inheritdoc
*/
public serialize(): object {
return this.serializationManager.serialize(this.root);
}
/**
* @inheritdoc
*/
public destroy(): void {
this.modelManager.destroy(this.root);
}
/**
* @inheritdoc
*/
public refresh(): this {
this.dataRefreshEvent.publishRefresh(this.root);
return this;
}
/**
* @inheritdoc
*/
public setRootDataSource<T>(rootDataSource: DataSource<T>): this {
this.modelManager.destroy(this.getRootDataSource());
this.dataSourceManager.setRootDataSource(rootDataSource, this.root);
return this;
}
/**
* @inheritdoc
*/
public createAndSetRootDataFromModelClass<T>(dataSourceModelClass: Constructable<DataSource<T>>): this {
return this.setRootDataSource(this.modelManager.create(dataSourceModelClass, this.root));
}
/**
* @inheritdoc
*/
// tslint:disable-next-line: no-any
public getRootDataSource<T extends DataSource<any>>(): T | undefined {
return this.dataSourceManager.getRootDataSource(this.root) as T | undefined;
}
/**
* @inheritdoc
*/
public getModelInstances<T extends object>(modelClass: Constructable<T>): object[] {
return this.modelManager.getModelInstances<T>(modelClass);
}
}