lemmatized-entity-ref.component.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { Component, Input } from '@angular/core';
  2. import { map, tap } from 'rxjs/operators';
  3. import { LemmatizedEntityRef } 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 LemmatizedEntityRefComponent extends EditionlevelSusceptible, Highlightable, TextFlowSusceptible { }
  10. @Component({
  11. selector: 'evt-lemmatized-entity-ref',
  12. templateUrl: './lemmatized-entity-ref.component.html',
  13. styleUrls: ['./lemmatized-entity-ref.component.scss'],
  14. })
  15. @register(LemmatizedEntityRef)
  16. export class LemmatizedEntityRefComponent {
  17. @Input() data: LemmatizedEntityRef;
  18. availableLemEntities$ = this.evtModelService.lemmatizedEntities$.pipe(
  19. map(ne => ne.all.entities.length > 0),
  20. );
  21. entity$ = this.evtModelService.lemmatizedEntities$.pipe(
  22. map(ne => ne.all.entities.find(e => e.id === this.data.entityLemId) || '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. toggleLemEntityData(event: MouseEvent) {
  43. event.stopPropagation();
  44. this.opened = !this.opened;
  45. }
  46. }