All files / src/model configuration.ts

80% Statements 4/5
75% Branches 3/4
50% Functions 1/2
80% Lines 4/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                          2x                     2x                   2x     2x        
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { InjectionToken, Provider } from '@angular/core';
 
import { DEFAULT_GRIDSTACK_OPTIONS, GridConfig } from './gridstack.model';
import { DashboardToolbarItem } from './si-dashboard-toolbar.model';
 
/**
 * Dashboard configuration object. Inject globally using the {@link SI_DASHBOARD_CONFIGURATION}
 * or configure individual dashboard instances.
 */
export type Config = {
  grid?: GridConfig;
};
 
/**
 * Injection token to configure dashboards. Use `{ provide: SI_DASHBOARD_CONFIGURATION, useValue: config }`
 * in your app configuration.
 */
export const SI_DASHBOARD_CONFIGURATION = new InjectionToken<Config>(
  'Injection token to configure dashboards.',
  {
    providedIn: 'root',
    factory: () => ({ grid: { gridStackOptions: DEFAULT_GRIDSTACK_OPTIONS } })
  }
);
 
/**
 * Injection token to configure global toolbar menu items.
 */
export const SI_DASHBOARD_TOOLBAR_ITEMS = new InjectionToken<{
  primary: DashboardToolbarItem[];
  secondary: DashboardToolbarItem[];
}>('Injection token to configure global toolbar menu items.');
 
/**
 * provider function to configure global toolbar menu items.
 * @param toolbarItems - primary and secondary edit actions which are common to all
 * dashboard instances on application.
 */
export const provideDashboardToolbarItems = (toolbarItems?: {
  primary?: DashboardToolbarItem[];
  secondary?: DashboardToolbarItem[];
}): Provider => ({
  provide: SI_DASHBOARD_TOOLBAR_ITEMS,
  useValue: { primary: toolbarItems?.primary ?? [], secondary: toolbarItems?.secondary ?? [] }
});