iperlems-select.component.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 IperlemsSelectItemGroup {
  5. label: string;
  6. items: IperlemsSelectItem[];
  7. disabled?: boolean;
  8. }
  9. export interface IperlemsSelectItem {
  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-iperlems-select',
  17. templateUrl: './iperlems-select.component.html',
  18. styleUrls: ['./iperlems-select.component.scss'],
  19. })
  20. export class IperlemsSelectComponent {
  21. @Output() selectionChange: EventEmitter<IperlemsSelectItem[]> = new EventEmitter();
  22. iperlemsTypes: Array<IperlemsSelectItem & { group: string }> = (AppConfig.evtSettings.edition.iperlemsSelectItems || [])
  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 selectedIperlemTypes: IperlemsSelectItem[] = [];
  31. updateSelectedIperlemTypes(iperlemsTypes: IperlemsSelectItem[]) {
  32. if (Array.isArray(iperlemsTypes)) { // BUGFIX: There is a bug in ng-select change event and second time the parameter is an event
  33. this.selectionChange.emit(iperlemsTypes);
  34. // console.log('Prova', AppConfig.evtSettings.edition.iperlemsSelectItems || [])
  35. }
  36. }
  37. toggleSelection() {
  38. if (this.selectedIperlemTypes.length < this.iperlemsTypes.length) {
  39. this.selectedIperlemTypes = this.iperlemsTypes;
  40. } else {
  41. this.selectedIperlemTypes = [];
  42. }
  43. this.selectionChange.emit(this.selectedIperlemTypes);
  44. // console.log('Prova 0', AppConfig.evtSettings.edition.iperlemsSelectItems[0])
  45. // console.log('Prova 1', AppConfig.evtSettings.edition.iperlemsSelectItems[1])
  46. }
  47. }