From 701e441228724c5b701d94cc3f1e520ce656398a Mon Sep 17 00:00:00 2001 From: franciscovila Date: Thu, 24 Nov 2022 10:29:04 +0000 Subject: Import data type in UI Develop all necessary changes in the UI to allow importing a data type from a yaml file Issue-ID: SDC-4279 Signed-off-by: franciscovila Change-Id: Id413386fad8b362e8c4a1d25c859a22178189074 --- .../src/app/ng2/services/data-type.service.ts | 25 +++++++++++++++++----- catalog-ui/src/app/ng2/services/model.service.ts | 3 +++ 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'catalog-ui/src/app/ng2/services') diff --git a/catalog-ui/src/app/ng2/services/data-type.service.ts b/catalog-ui/src/app/ng2/services/data-type.service.ts index 298ba90b31..3a27801315 100644 --- a/catalog-ui/src/app/ng2/services/data-type.service.ts +++ b/catalog-ui/src/app/ng2/services/data-type.service.ts @@ -26,8 +26,9 @@ import { PROPERTY_DATA } from "app/utils"; import {DerivedFEAttribute} from "../../models/attributes-outputs/derived-fe-attribute"; import {ISdcConfig} from "../config/sdc-config.config.factory"; import {SdcConfigToken} from "../config/sdc-config.config"; -import {HttpClient} from "@angular/common/http"; +import {HttpBackend, HttpClient, HttpHeaders} from "@angular/common/http"; import {Observable} from "rxjs/Observable"; +import {AuthenticationService} from "./authentication.service"; /** This is a new service for NG2, to eventually replace app/services/data-types-service.ts * @@ -40,14 +41,17 @@ export class DataTypeService { public dataTypes: DataTypesMap; private readonly baseUrl: string; private readonly dataTypeUrl: string; + private readonly dataTypeUploadUrl: string; - constructor(private dataTypeService: DataTypesService, private httpClient: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) { + + constructor(private dataTypeService: DataTypesService, private authService: AuthenticationService, private handler: HttpBackend, private httpClient: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) { this.dataTypes = dataTypeService.getAllDataTypes(); //This should eventually be replaced by an NG2 call to the backend instead of utilizing Angular1 downgraded component. this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root; - this.dataTypeUrl = `${this.baseUrl}data-types` + this.dataTypeUrl = `${this.baseUrl}data-types`; + this.dataTypeUploadUrl = `${this.baseUrl}uploadType`; + this.httpClient = new HttpClient(handler); } - public getDataTypeByModelAndTypeName(modelName: string, typeName: string): DataTypeModel { this.dataTypes = this.dataTypeService.getAllDataTypesFromModel(modelName); let dataTypeFound = this.dataTypes[typeName]; @@ -88,6 +92,18 @@ export class DataTypeService { return this.httpClient.post(url, property); } + public createImportedType(model: string, importingFile: File): Observable { + const url = `${this.dataTypeUploadUrl}/datatypesyaml`; + const formData = new FormData(); + formData.append('dataTypesYaml', importingFile); + formData.append('model', model != 'SDC AID' ? model : "") + formData.append('includeToModelImport', "true"); + let headers = new HttpHeaders({'USER_ID': this.authService.getLoggedinUser().userId}); + let options = {headers: headers}; + + return this.httpClient.post(url, formData, options); + } + public getConstraintsByParentTypeAndUniqueID(rootPropertyType, propertyName){ // const property = this.dataTypes[rootPropertyType].properties.filter(property => // property.name == propertyName); @@ -149,6 +165,5 @@ export class DataTypeService { if (prop.name == 'instance_name') prop.hidden = generatedNamingVal; }); } - } diff --git a/catalog-ui/src/app/ng2/services/model.service.ts b/catalog-ui/src/app/ng2/services/model.service.ts index 83e16b12c7..60b7ac902d 100644 --- a/catalog-ui/src/app/ng2/services/model.service.ts +++ b/catalog-ui/src/app/ng2/services/model.service.ts @@ -39,4 +39,7 @@ export class ModelService { return this.http.get(this.baseUrl + "/v1/catalog/model?modelType=" + type); } + getDataTypeModels(typeName: string):Observable { + return this.http.get>(this.baseUrl + "/v1/catalog/data-types/" + typeName + "/models"); + } } -- cgit 1.2.3-korg