apparatus-entry-detail.component.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
  2. import { ApparatusEntry, GenericElement, Reading } from '../../../models/evt-models';
  3. import { register } from '../../../services/component-register.service';
  4. import { EVTModelService } from '../../../services/evt-model.service';
  5. @Component({
  6. selector: 'evt-apparatus-entry-detail',
  7. templateUrl: './apparatus-entry-detail.component.html',
  8. styleUrls: ['./apparatus-entry-detail.component.scss'],
  9. changeDetection: ChangeDetectionStrategy.OnPush,
  10. })
  11. @register(ApparatusEntryDetailComponent)
  12. export class ApparatusEntryDetailComponent implements OnInit {
  13. @Input() data: ApparatusEntry;
  14. nestedApps: ApparatusEntry[] = [];
  15. rdgHasCounter = false;
  16. get significantRdg(): Reading[] {
  17. return this.data.readings.filter((rdg) => rdg.significant);
  18. }
  19. get notSignificantRdg(): Reading[] {
  20. return this.data.readings.filter((rdg) => !rdg.significant);
  21. }
  22. get readings(): Reading[] {
  23. return [this.data.lemma, ...this.significantRdg, ...this.notSignificantRdg]
  24. }
  25. get rdgMetadata() {
  26. return Object.keys(this.data.attributes).filter((key) => key !== 'id')
  27. .reduce((obj, key) => ({
  28. ...obj,
  29. [key]: this.data.attributes[key],
  30. }), {});
  31. }
  32. constructor(
  33. public evtModelService: EVTModelService,
  34. ) {
  35. }
  36. ngOnInit() {
  37. if (this.data.nestedAppsIDs.length > 0) {
  38. this.recoverNestedApps(this.data);
  39. }
  40. }
  41. recoverNestedApps(app: ApparatusEntry) {
  42. const nesApps = app.lemma.content.filter((c: ApparatusEntry | GenericElement) => c.type === ApparatusEntry);
  43. nesApps.forEach((nesApp: ApparatusEntry) => {
  44. this.nestedApps = this.nestedApps.concat(nesApp);
  45. if (nesApp.nestedAppsIDs.length > 0) {
  46. this.recoverNestedApps(nesApp);
  47. }
  48. });
  49. }
  50. isAppEntry(item: GenericElement | ApparatusEntry): boolean {
  51. return item.type === ApparatusEntry;
  52. }
  53. /* gestire questo FS */
  54. getNestedAppLemma(appId: string): Reading {
  55. return this.nestedApps.find((c) => c.id === appId).lemma;
  56. }
  57. getNestedAppPos(appId: string): number {
  58. return this.nestedApps.findIndex((nesApp) => nesApp.id === appId);
  59. }
  60. }