import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; import { ReferenceType } from '@app/core/model/reference-type/reference-type'; import { Definition, Field, Reference } from '@app/core/model/reference/reference'; import { ReferenceService } from '@app/core/services/reference/reference.service'; import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; import { BaseEditorResolver } from '@common/base/base-editor.resolver'; import { Guid } from '@common/types/guid'; import { takeUntil, tap } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; @Injectable() export class ReferenceEditorResolver extends BaseEditorResolver { constructor(private referenceService: ReferenceService, private breadcrumbService: BreadcrumbService) { super(); } public static lookupFields(): string[] { return [ ...BaseEditorResolver.lookupFields(), nameof(x => x.id), nameof(x => x.label), [nameof(x => x.type), nameof(x => x.id)].join('.'), nameof(x => x.description), nameof(x => x.reference), nameof(x => x.abbreviation), nameof(x => x.source), nameof(x => x.sourceType), nameof(x => x.createdAt), nameof(x => x.updatedAt), [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.code)].join('.'), [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.dataType)].join('.'), [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.value)].join('.'), nameof(x => x.hash), nameof(x => x.isActive) ] } resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { const fields = [ ...ReferenceEditorResolver.lookupFields() ]; const id = route.paramMap.get('id'); if (id != null) { return this.referenceService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed)); } } }