Resource metadata changes 95/79895/1
authorSwapnali Shadanan Pode <sp00501638@techmahindra.com>
Thu, 7 Mar 2019 10:24:49 +0000 (15:54 +0530)
committerSwapnali Shadanan Pode <sp00501638@techmahindra.com>
Thu, 7 Mar 2019 10:24:49 +0000 (15:54 +0530)
Change-Id: I700b7e2bb5848272a744637c48b97880694cf89d
Issue-ID: CCSDK-807
Signed-off-by: sp00501638 <sp00501638@techmahindra.com>
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

index 3ad578d..0bbc0b7 100644 (file)
     <mat-form-field class="form-field">
       <mat-select matInput placeholder="Data Type" formControlName="_type">
        <mat-option value="string">string</mat-option>
-       <mat-option value="string">list</mat-option>
+       <mat-option value="list">list</mat-option>
       </mat-select>
     </mat-form-field>
     <mat-form-field class="form-field" >
       <input matInput placeholder="entry_schema" formControlName="entry_schema">
     </mat-form-field>
     <mat-form-field class="form-field" >
-      <mat-select placeholder="required" formControlName="_required">
+      <mat-select matInput placeholder="required" formControlName="required">
        <mat-option value="true">true</mat-option>
        <mat-option value="false">false</mat-option>
       </mat-select>
index f44c9b0..f99bddc 100644 (file)
 
 import { Component, OnInit } 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 { IResourcesMetaData } from '../../../../common/core/store/models/resourcesMetadata.model';
+import { Observable } 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';
 
 @Component({
   selector: 'app-resource-metadata',
@@ -27,19 +37,59 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
   styleUrls: ['./resource-metadata.component.scss']
 })
 export class ResourceMetadataComponent implements OnInit {
-
+    entry_schema:IEntrySchema;
+    properties: IPropertyData;
     ResourceMetadata: FormGroup;
-    
-    constructor(private _formBuilder: FormBuilder) {
-      this.ResourceMetadata = this._formBuilder.group({
-      Resource_Name: ['', Validators.required],
-      _tags: ['', Validators.required],
-      _description : ['', Validators.required],
-      _type: ['string', Validators.required],
-      _required: ['false', Validators.required],
-      entry_schema: ['']
+    resource_name: string;
+    tags: string;
+    rdState: Observable<IResourcesState>;
+    resources: IResources;
+    propertyValues = [];
+    property = [];   
+  
+ constructor(private formBuilder: FormBuilder, private store: Store<IAppState>) { 
+    this.rdState = this.store.select('resources');
+    this.ResourceMetadata = this.formBuilder.group({
+        Resource_Name: ['', Validators.required],
+       _tags: ['', Validators.required],
+       _description : ['', Validators.required],
+       _type: ['', Validators.required],
+       required: ['', Validators.required],
+       entry_schema: ['']
     });   
   }
+ }
 
-    ngOnInit() {}
-}
+ ngOnInit() {
+    this.rdState.subscribe(
+      resourcesdata => {
+        var resourcesState: IResourcesState = { resources: resourcesdata.resources, isLoadSuccess: resourcesdata.isLoadSuccess, isSaveSuccess: resourcesdata.isSaveSuccess, isUpdateSuccess: resourcesdata.isUpdateSuccess };
+        this.resource_name = resourcesState.resources.name;
+        this.tags = resourcesState.resources.tags;
+        this.resources = resourcesState.resources;
+        this.properties= resourcesState.resources.property;
+        this.propertyValues=  this.checkNested(this.properties);
+        this.ResourceMetadata = this.formBuilder.group({
+       Resource_Name: [this.resource_name, Validators.required],
+        _tags: [this.tags, Validators.required],
+        _description : [ this.propertyValues[0], Validators.required],
+        _type: [ this.propertyValues[1], Validators.required],
+        required: [ this.propertyValues[2], Validators.required],
+        entry_schema: [this.propertyValues[3]]
+      });   
+    })
+ }
+    
+ checkNested(obj) {
+  for (let key in obj) {
+    if (obj.hasOwnProperty(key)) {
+      if (typeof obj[key] == "object"){
+         console.log(`Key: ${key}`)
+         this.checkNested(obj[key]);
+      } else {
+         this.property.push(obj[key]);             
+      }   
+     }
+   }
+   return this.property
+ }
+}
\ No newline at end of file