lemmatized-entity.component.ts 1.9 KB

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