lems-select.component.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Component, EventEmitter, Output } from '@angular/core';
  2. import { AppConfig } from '../../app.config';
  3. import { EvtIconInfo } from '../../ui-components/icon/icon.component';
  4. export interface LemsSelectItemGroup {
  5. label: string;
  6. items: LemsSelectItem[];
  7. disabled?: boolean;
  8. }
  9. export interface LemsSelectItem {
  10. label: string;
  11. value: string; // This will be used to identify the items to be selected, by indicating tag name and attributes (for XML)
  12. color?: string;
  13. disabled?: boolean;
  14. }
  15. @Component({
  16. selector: 'evt-lems-select',
  17. templateUrl: './lems-select.component.html',
  18. styleUrls: ['./lems-select.component.scss'],
  19. })
  20. export class LemsSelectComponent {
  21. @Output() selectionChange: EventEmitter<LemsSelectItem[]> = new EventEmitter();
  22. lemsTypes: Array<LemsSelectItem & { group: string }> = (AppConfig.evtSettings.edition.lemsSelectItems || [])
  23. .filter(g => !g.disabled)
  24. .reduce((x, y) => [...x, ...y.items.filter(i => !i.disabled).map(i => ({ ...i, group: y.label }))], []);
  25. iconColor: EvtIconInfo = {
  26. icon: 'circle',
  27. iconSet: 'fas',
  28. additionalClasses: 'ml-2 mr-1',
  29. };
  30. public selectedLemTypes: LemsSelectItem[] = [];
  31. updateSelectedLemTypes(lemsTypes: LemsSelectItem[]) {
  32. if (Array.isArray(lemsTypes)) { // BUGFIX: There is a bug in ng-select change event and second time the parameter is an event
  33. this.selectionChange.emit(lemsTypes);
  34. }
  35. }
  36. toggleSelection() {
  37. if (this.selectedLemTypes.length < this.lemsTypes.length) {
  38. this.selectedLemTypes = this.lemsTypes;
  39. } else {
  40. this.selectedLemTypes = [];
  41. }
  42. this.selectionChange.emit(this.selectedLemTypes);
  43. }
  44. }