named-entity-ref.component.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { Component, Input } from '@angular/core';
  2. import { map, tap } from 'rxjs/operators';
  3. import { NamedEntityRef } from '../../models/evt-models';
  4. import { register } from '../../services/component-register.service';
  5. import { EntitiesSelectService } from '../../services/entities-select.service';
  6. import { EVTModelService } from '../../services/evt-model.service';
  7. import { EVTStatusService } from '../../services/evt-status.service';
  8. import { EditionlevelSusceptible, Highlightable, TextFlowSusceptible } from '../components-mixins';
  9. export interface NamedEntityRefComponent extends EditionlevelSusceptible, Highlightable, TextFlowSusceptible { }
  10. @Component({
  11. selector: 'evt-named-entity-ref',
  12. templateUrl: './named-entity-ref.component.html',
  13. styleUrls: ['./named-entity-ref.component.scss'],
  14. })
  15. @register(NamedEntityRef)
  16. export class NamedEntityRefComponent {
  17. @Input() data: NamedEntityRef;
  18. availableEntities$ = this.evtModelService.namedEntities$.pipe(
  19. map(ne => ne.all.entities.length > 0),
  20. );
  21. entity$ = this.evtModelService.namedEntities$.pipe(
  22. map(ne => ne.all.entities.find(e => e.id === this.data.entityId) || 'notFound'),
  23. );
  24. public highlighted$ = this.entitiesSelectService.selectedItems$.pipe(
  25. tap(items => {
  26. if (this.data) {
  27. this.data.class = this.data.class || '';
  28. this.data.attributes = this.data.attributes || {};
  29. }
  30. return items;
  31. }),
  32. map(items => items.some(i => i && this.data &&
  33. this.entitiesSelectService.matchClassAndAttributes(i.value, this.data.attributes, this.data.class))),
  34. );
  35. public opened = false;
  36. constructor(
  37. public evtStatusService: EVTStatusService,
  38. private evtModelService: EVTModelService,
  39. private entitiesSelectService: EntitiesSelectService,
  40. ) {
  41. }
  42. toggleEntityData(event: MouseEvent) {
  43. event.stopPropagation();
  44. this.opened = !this.opened;
  45. }
  46. }