Resource Dictionary: fecthing data-type list 36/95236/1
authorArundathi Patil <arundpil@in.ibm.com>
Mon, 9 Sep 2019 13:57:04 +0000 (19:27 +0530)
committerArundathi Patil <arundpil@in.ibm.com>
Mon, 9 Sep 2019 13:57:10 +0000 (19:27 +0530)
Created loopback API function to fetch data-types from backend and
display them in data-type drop-down

Issue-ID: CCSDK-707
Change-Id: I797177b9042558c99a94df9c9dd4295c43389d29
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
cds-ui/client/src/app/common/constants/app-constants.ts
cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-edit.service.ts
cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-metadata/resource-metadata.component.html
cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-metadata/resource-metadata.component.ts
cds-ui/server/src/controllers/data-dictionary.controller.ts
cds-ui/server/src/datasources/resource-dictionary.datasource-template.ts
cds-ui/server/src/services/resource-dictionary.service.ts

index 5ebde91..78fefd8 100644 (file)
@@ -108,5 +108,6 @@ export const ResourceDictionaryURLs = {
     searchResourceDictionaryByTags: '/resourcedictionary/search',
     searchResourceDictionaryByName: '',
     getSources: '/resourcedictionary/source-mapping',
-    getModelType: '/resourcedictionary/model-type'
+    getModelType: '/resourcedictionary/model-type',
+    getDataType: '/resourcedictionary/model-type/by-definition/data_type'
 }
\ No newline at end of file
index ed1ef6f..f66a1c9 100644 (file)
@@ -44,4 +44,8 @@ export class ResourceEditService {
     getModelType(name) {
         return this.api.get(ResourceDictionaryURLs.getModelType + '/' + name);
     }
+
+    getDataTypes() {
+        return this.api.get(ResourceDictionaryURLs.getDataType);
+    }
 }
\ No newline at end of file
index d40dbd9..24bee27 100644 (file)
@@ -28,8 +28,9 @@
     </mat-form-field>
     <mat-form-field class="form-field">
       <mat-select matInput placeholder="Data Type" formControlName="_type">
-       <mat-option value="string">string</mat-option>
-       <mat-option value="list">list</mat-option>
+       <!-- <mat-option value="string">string</mat-option> -->
+        <!-- <mat-option value="list">list</mat-option> -->
+        <mat-option value="string" *ngFor="let item of dataTypeList">{{item.modelName}}</mat-option>
       </mat-select>
     </mat-form-field>
     <mat-form-field class="form-field" >
index e155ec1..473b200 100644 (file)
@@ -24,13 +24,15 @@ import { Component, OnInit, EventEmitter, Output  } from '@angular/core';
 import {FormBuilder, FormGroup, Validators} from '@angular/forms';
 import { IResources } from 'src/app/common/core/store/models/resources.model';
 import { IResourcesState } from 'src/app/common/core/store/models/resourcesState.model';
-import { Observable } from 'rxjs';
+import { Observable, from } from 'rxjs';
 import { Store } from '@ngrx/store';
 import { IAppState } from '../../../../common/core/store/state/app.state';
 import { A11yModule } from '@angular/cdk/a11y';
+
 import { LoadResourcesSuccess } from 'src/app/common/core/store/actions/resources.action';
 import { IPropertyData } from 'src/app/common/core/store/models/propertyData.model';
 import { IEntrySchema } from 'src/app/common/core/store/models/entrySchema.model';
+import { ResourceEditService } from '../resource-edit.service';
 
 @Component({
   selector: 'app-resource-metadata',
@@ -48,8 +50,13 @@ export class ResourceMetadataComponent implements OnInit {
     propertyValues = [];
     property = [];   
     @Output() resourcesData = new EventEmitter();
+    dataTypeList: any[] = [
+       {modelName: 'String'}, {modelName: 'Boolean'}, {modelName: 'Integer'}, {modelName: 'Float'}, {modelName: 'Double'}
+    ];
      
- constructor(private formBuilder: FormBuilder, private store: Store<IAppState>) { 
+ constructor(private formBuilder: FormBuilder, 
+             private store: Store<IAppState>, 
+             private resourceEditService: ResourceEditService) { 
     this.rdState = this.store.select('resources');
     this.ResourceMetadata = this.formBuilder.group({
         Resource_Name: ['', Validators.required],
@@ -62,6 +69,17 @@ export class ResourceMetadataComponent implements OnInit {
  }
 
  ngOnInit() {
+    this.resourceEditService.getDataTypes()
+    .subscribe(data=>{
+      console.log(data);
+      if(data) {
+         data.forEach(element => {
+            this.dataTypeList.push(element);
+         });
+      }
+    }, (error)=>{
+       console.log("There is an error");
+    });
     this.rdState.subscribe(
       resourcesdata => {
         var resourcesState: IResourcesState = { resources: resourcesdata.resources, isLoadSuccess: resourcesdata.isLoadSuccess, isSaveSuccess: resourcesdata.isSaveSuccess, isUpdateSuccess: resourcesdata.isUpdateSuccess };
index 63587e6..eab0bc5 100644 (file)
@@ -95,4 +95,15 @@ export class DataDictionaryController {
   async getmodelType(@param.path.string('source') source: string) {
     return await this.rdservice.getModelType(source);
   }
+
+  @get('/resourcedictionary/model-type/by-definition/data_type', {
+    responses: {
+      '200': {
+        content: { 'application/json': {} },
+      },
+    },
+  })
+  async getDataTypes() {
+    return await this.rdservice.getDataTypes();
+  }
 }
index af96aca..9f9d754 100644 (file)
@@ -88,7 +88,6 @@ export default {
 
             }
         },
-        ,
         {
             "template": {
                 "method": "GET",
@@ -103,6 +102,22 @@ export default {
             "functions": {
                 "getModelType": ["source"]
 
+            }
+        },
+        {
+            "template": {
+                "method": "GET",
+                "url": controllerApiConfig.http.url + "/model-type/by-definition/data_type",
+                "headers": {
+                    "accepts": "application/json",
+                    "content-type": "application/json",
+                    "authorization": controllerApiConfig.http.authToken
+                },
+                "responsePath": "$.*"
+            },
+            "functions": {
+                "getDataTypes": []
+
             }
         }
     ]
index 9a781d6..8df2208 100644 (file)
@@ -9,6 +9,7 @@ export interface ResourceDictionaryService {
   save(resourceDictionary: JSON): Promise<JSON>;
   searchbyNames(resourceDictionaryList: JSON): Promise<JSON>;  
   getModelType(source: string): Promise<JSON>;
+  getDataTypes(): Promise<JSON>;
 }
 
 export class ResourceDictionaryServiceProvider implements Provider<ResourceDictionaryService> {