specific-lists.component.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Component } from '@angular/core';
  2. import { Observable } from 'rxjs';
  3. import { map, tap } from 'rxjs/operators';
  4. import { LemmatizedEntitiesList, Relation } from '../../models/evt-models';
  5. import { EVTModelService } from '../../services/evt-model.service';
  6. import { Map } from '../../utils/js-utils';
  7. interface SpecificList extends LemmatizedEntitiesList {
  8. icon: string;
  9. }
  10. @Component({
  11. selector: 'evt-specific-lists',
  12. templateUrl: './specific-lists.component.html',
  13. styleUrls: ['./specific-lists.component.scss'],
  14. })
  15. export class SpecificListsComponent {
  16. lists$: Observable<SpecificList[]> = this.evtModelService.lemmatizedEntities$.pipe(
  17. map(ne => (ne.lemmas.lists)),
  18. map(lists => (lists.map(list => ({
  19. ...list,
  20. icon: this.listsIcons[list.lemmatizedEntityType] || 'list',
  21. })))),
  22. tap(lists => {
  23. if (!this.selectedList && lists[0]) {
  24. this.openList(undefined, lists[0]);
  25. }
  26. }),
  27. );
  28. selectedList: LemmatizedEntitiesList;
  29. relations$: Observable<Relation[]> = this.evtModelService.lemmatizedEntities$.pipe(
  30. map(ne => ne.relations),
  31. );
  32. showRelations = false;
  33. private listsIcons: Map<string> = {
  34. lem: 'user',
  35. place: 'map-marker',
  36. org: 'users',
  37. event: 'calendar',
  38. };
  39. constructor(
  40. private evtModelService: EVTModelService,
  41. ) {
  42. }
  43. openList(event: MouseEvent, list: LemmatizedEntitiesList) {
  44. if (event) {
  45. event.stopPropagation();
  46. }
  47. if (this.selectedList !== list) {
  48. this.selectedList = list;
  49. }
  50. this.showRelations = false;
  51. }
  52. openRelations() {
  53. this.showRelations = true;
  54. this.selectedList = undefined;
  55. }
  56. }