import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from "@angular/Router" import { Injectable,Inject, OnDestroy } from "@angular/core"; import { HttpClient } from "@angular/Common/http"; import { Observable, Subject } from "rxjs"; import { ObjectService } from "./ObjectService"; import { DyCommon } from "../Common"; @Injectable() export class CustomFieldGroupResolver implements Resolve,OnDestroy{ private http: HttpClient; private OService:ObjectService constructor(@Inject(HttpClient) _http: HttpClient,@Inject(ObjectService) _osvc) { this.http = _http; this.OService = _osvc; } private ngUnsubscribe: Subject = new Subject(); ngOnDestroy(): any { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } public static fixModel = (res:any) => { if (res.filter != undefined) { res.hasCondition = true; res.filter = JSON.parse(res.filter); } res.customFieldDefinitions.forEach((item) => { if (item.filter != undefined) { item.hasCondition = true; item.filter = JSON.parse(item.filter); } }); } resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): orderViewModel | Observable | Promise { console.log(route); var promise = new Promise((fres, rej) => { this.http.get(`dyapi/object/CustomFieldGroupInfo/${route.params["id"]}`).takeUntil(this.ngUnsubscribe).subscribe(res => { CustomFieldGroupResolver.fixModel(res); fres(res); }); }) return promise; } } @Injectable() export class NewCustomFieldGroupResolver implements Resolve, OnDestroy { private http: HttpClient; private OService: ObjectService constructor(@Inject(HttpClient) _http: HttpClient, @Inject(ObjectService) _osvc) { this.http = _http; this.OService = _osvc; } private ngUnsubscribe: Subject = new Subject(); ngOnDestroy(): any { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any | Observable | Promise { console.log(route); var promise = new Promise((fres, rej) => { DyCommon.newGuid().then((id) => { var res = { id: id, customFieldDefinitions: [], objectName: route.params["type"]} CustomFieldGroupResolver.fixModel(res); fres(res); }); }) return promise; } }