lemmatized-entity-ref.component.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 { LemsSelectService } from '../../services/lems-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.lementities.length > 0),
  20. );
  21. entity$ = this.evtModelService.lemmatizedEntities$.pipe(
  22. map(ne => ne.all.lementities.find(e => e.id === this.data.entityLemId) || 'notFound'),
  23. );
  24. public highlighted$ = this.lemsSelectService.selectedLemsItems$.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.lemsSelectService.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 lemsSelectService: LemsSelectService,
  40. ) {
  41. }
  42. toggleLemEntityData(event: MouseEvent) {
  43. event.stopPropagation();
  44. this.opened = !this.opened;
  45. }
  46. }