-
-
Notifications
You must be signed in to change notification settings - Fork 932
/
register-dashboard-widget.ts
42 lines (39 loc) · 1.33 KB
/
register-dashboard-widget.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
import { APP_INITIALIZER, FactoryProvider } from '@angular/core';
import {
DashboardWidgetConfig,
WidgetLayoutDefinition,
} from '../providers/dashboard-widget/dashboard-widget-types';
import { DashboardWidgetService } from '../providers/dashboard-widget/dashboard-widget.service';
/**
* @description
* Registers a dashboard widget. Once registered, the widget can be set as part of the default
* (using {@link setDashboardWidgetLayout}).
*
* @docsCategory dashboard-widgets
*/
export function registerDashboardWidget(id: string, config: DashboardWidgetConfig): FactoryProvider {
return {
provide: APP_INITIALIZER,
multi: true,
useFactory: (dashboardWidgetService: DashboardWidgetService) => () => {
dashboardWidgetService.registerWidget(id, config);
},
deps: [DashboardWidgetService],
};
}
/**
* @description
* Sets the default widget layout for the Admin UI dashboard.
*
* @docsCategory dashboard-widgets
*/
export function setDashboardWidgetLayout(layoutDef: WidgetLayoutDefinition): FactoryProvider {
return {
provide: APP_INITIALIZER,
multi: true,
useFactory: (dashboardWidgetService: DashboardWidgetService) => () => {
dashboardWidgetService.setDefaultLayout(layoutDef);
},
deps: [DashboardWidgetService],
};
}