All files / src/services si-grid.service.ts

100% Statements 10/10
77.77% Branches 7/9
100% Functions 3/3
100% Lines 7/7

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          2x         44x   44x   44x 28x                 44x     43x      
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { computed, Injectable, signal } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
 
import { Widget } from '../model/widgets.model';
 
@Injectable()
export class SiGridService {
  /** @defaultValue [] */
  readonly widgetCatalog = signal<Widget[]>([]);
 
  private readonly widgetCatalogMap = computed(
    () => new Map(this.widgetCatalog().map(widget => [widget.id, widget]))
  );
 
  /**
   * Observable that emits true if si-grid is set to editable.
   * The owner of the editable state is the si-grid component.
   * This subject is used to propagate these state changes via
   * the si-widget-host components to the widgets.
   */
  editable$ = new BehaviorSubject<boolean>(false);
 
  getWidget(id: string): Widget | undefined {
    return this.widgetCatalogMap().get(id);
  }
}