global-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 { NamedEntitiesList, Relation } from '../../models/evt-models';
  5. import { EVTModelService } from '../../services/evt-model.service';
  6. import { Map } from '../../utils/js-utils';
  7. interface GlobalList extends NamedEntitiesList {
  8. icon: string;
  9. }
  10. @Component({
  11. selector: 'evt-global-lists',
  12. templateUrl: './global-lists.component.html',
  13. styleUrls: ['./global-lists.component.scss'],
  14. })
  15. export class GlobalListsComponent {
  16. lists$: Observable<GlobalList[]> = this.evtModelService.namedEntities$.pipe(
  17. map(ne => (ne.persons.lists.concat(ne.places.lists, ne.organizations.lists, ne.events.lists))),
  18. map(lists => (lists.map(list => ({
  19. ...list,
  20. icon: this.listsIcons[list.namedEntityType] || 'list',
  21. })))),
  22. tap(lists => {
  23. if (!this.selectedList && lists[0]) {
  24. this.openList(undefined, lists[0]);
  25. }
  26. }),
  27. );
  28. selectedList: NamedEntitiesList;
  29. relations$: Observable<Relation[]> = this.evtModelService.namedEntities$.pipe(
  30. map(ne => ne.relations),
  31. );
  32. showRelations = false;
  33. private listsIcons: Map<string> = {
  34. person: '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: NamedEntitiesList) {
  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. }