import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; import { Description } from '@app/core/model/description/description'; import { DescriptionTemplatesInSection, DmpBlueprint, DmpBlueprintDefinition, DmpBlueprintDefinitionSection, FieldInSection } from '@app/core/model/dmp-blueprint/dmp-blueprint'; import { Dmp, DmpBlueprintValue, DmpContact, DmpDescriptionTemplate, DmpProperties } from '@app/core/model/dmp/dmp'; import { DmpReference, DmpReferenceData } from '@app/core/model/dmp/dmp-reference'; import { Reference } from '@app/core/model/reference/reference'; import { DmpService } from '@app/core/services/dmp/dmp.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 DmpEditorResolver extends BaseEditorResolver { constructor(private descriptionService: DmpService, private breadcrumbService: BreadcrumbService) { super(); } public static lookupFields(): string[] { return [ ...BaseEditorResolver.lookupFields(), nameof(x => x.id), nameof(x => x.label), nameof(x => x.status), nameof(x => x.versionStatus), nameof(x => x.groupId), nameof(x => x.description), nameof(x => x.language), nameof(x => x.accessType), nameof(x => x.isActive), nameof(x => x.version), nameof(x => x.updatedAt), nameof(x => x.publicAfter), [nameof(x => x.properties), nameof(x => x.dmpBlueprintValues), nameof(x => x.fieldId)].join('.'), [nameof(x => x.properties), nameof(x => x.dmpBlueprintValues), nameof(x => x.fieldValue)].join('.'), [nameof(x => x.properties), nameof(x => x.contacts), nameof(x => x.userId)].join('.'), [nameof(x => x.properties), nameof(x => x.contacts), nameof(x => x.firstName)].join('.'), [nameof(x => x.properties), nameof(x => x.contacts), nameof(x => x.lastName)].join('.'), [nameof(x => x.properties), nameof(x => x.contacts), nameof(x => x.email)].join('.'), // [nameof(x => x.entityDois), nameof(x => x.id)].join('.'), // [nameof(x => x.entityDois), nameof(x => x.repositoryId)].join('.'), // [nameof(x => x.entityDois), nameof(x => x.doi)].join('.'), [nameof(x => x.descriptions), nameof(x => x.id)].join('.'), [nameof(x => x.descriptions), nameof(x => x.label)].join('.'), [nameof(x => x.descriptions), nameof(x => x.status)].join('.'), [nameof(x => x.descriptions), nameof(x => x.dmpDescriptionTemplate), nameof(x => x.id)].join('.'), [nameof(x => x.descriptions), nameof(x => x.dmpDescriptionTemplate), nameof(x => x.sectionId)].join('.'), // [nameof(x => x.dmpUsers), nameof(x => x.id)].join('.'), // [nameof(x => x.dmpUsers), nameof(x => x.user.id)].join('.'), // [nameof(x => x.dmpUsers), nameof(x => x.user.name)].join('.'), // [nameof(x => x.dmpUsers), nameof(x => x.role)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.id)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.data), nameof(x => x.blueprintFieldId)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.id)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.label)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.type)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.source)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.reference)].join('.'), [nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.sourceType)].join('.'), [nameof(x => x.dmpDescriptionTemplates), nameof(x => x.sectionId)].join('.'), [nameof(x => x.dmpDescriptionTemplates), nameof(x => x.descriptionTemplateGroupId)].join('.'), // nameof(x => x.id), // nameof(x => x.label), // nameof(x => x.status), // nameof(x => x.description), // nameof(x => x.status), ...DmpEditorResolver.blueprintLookupFields(nameof(x => x.blueprint)), ] } public static blueprintLookupFields(prefix?: string): string[] { return [ (prefix ? prefix + '.' : '') + [nameof(x => x.id)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.id)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.label)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.ordinal)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.hasTemplates)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.descriptionTemplates), nameof(x => x.id)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.descriptionTemplates), nameof(x => x.descriptionTemplateId)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.id)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.category)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.dataType)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.systemFieldType)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.label)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.placeholder)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.description)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.required)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.fields), nameof(x => x.ordinal)].join('.') ] } resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { const fields = [ ...DmpEditorResolver.lookupFields() ]; const id = route.paramMap.get('id'); // const cloneid = route.paramMap.get('cloneid'); if (id != null) { return this.descriptionService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed)); } //TODO: check this // else if (cloneid != null) { // return this.descriptionService.clone(Guid.parse(cloneid), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed)); // } } }