lemmatized-entity.component.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { Component, Input, OnInit, ViewChild } from '@angular/core';
  2. import { NgbNav } from '@ng-bootstrap/ng-bootstrap';
  3. import { map, shareReplay } from 'rxjs/operators';
  4. import { LemmatizedEntity } from '../../models/evt-models';
  5. import { register } from '../../services/component-register.service';
  6. import { EVTModelService } from '../../services/evt-model.service';
  7. import { normalizeUrl } from '../../utils/js-utils';
  8. @register(LemmatizedEntity)
  9. @Component({
  10. selector: 'evt-lemmatized-entity',
  11. templateUrl: './lemmatized-entity.component.html',
  12. styleUrls: ['./lemmatized-entity.component.scss'],
  13. })
  14. export class LemmatizedEntityComponent implements OnInit {
  15. @Input() data: LemmatizedEntity;
  16. @Input() inList: boolean;
  17. occurrences$ = this.evtModelService.lemsOccurrences$.pipe(
  18. map(occ => occ[this.data.id] || []),
  19. shareReplay(1),
  20. );
  21. relations$ = this.evtModelService.relations$.pipe(
  22. map(el => el.filter(rel => rel.activeParts.indexOf(this.data.id) >= 0 ||
  23. rel.passiveParts.indexOf(this.data.id) >= 0 || rel.mutualParts.indexOf(this.data.id) >= 0)));
  24. @ViewChild('lemDetails') lemDetails: NgbNav;
  25. public contentOpened = true;
  26. get selectedSection() {
  27. if (this.contentOpened) {
  28. return `${this.data && this.data.content.length === 0 ? 'occurrences' : 'info'}_${this.data.id}`;
  29. }
  30. return '';
  31. }
  32. get linkLem() {
  33. return normalizeUrl('http://tlio.ovi.cnr.it/TLIO/');
  34. }
  35. constructor(
  36. private evtModelService: EVTModelService,
  37. ) {
  38. }
  39. ngOnInit() {
  40. if (this.inList) {
  41. this.contentOpened = false;
  42. }
  43. }
  44. toggleContent() {
  45. if (this.inList) {
  46. this.contentOpened = !this.contentOpened;
  47. }
  48. }
  49. tabSelected(event: MouseEvent) {
  50. event.stopPropagation();
  51. }
  52. openlinkLem() {
  53. if (this.linkLem) {
  54. window.open(this.linkLem, '_blank');
  55. }
  56. }
  57. }