2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 TechMahindra
7 * Modifications Copyright (C) 2019 IBM
8 *=================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 import { Component, OnInit, EventEmitter, Output } from '@angular/core';
24 import {FormBuilder, FormGroup, Validators} from '@angular/forms';
25 import { IResources } from 'src/app/common/core/store/models/resources.model';
26 import { IResourcesState } from 'src/app/common/core/store/models/resourcesState.model';
27 import { Observable } from 'rxjs';
28 import { Store } from '@ngrx/store';
29 import { IAppState } from '../../../../common/core/store/state/app.state';
30 import { A11yModule } from '@angular/cdk/a11y';
31 import { LoadResourcesSuccess } from 'src/app/common/core/store/actions/resources.action';
32 import { IPropertyData } from 'src/app/common/core/store/models/propertyData.model';
33 import { IEntrySchema } from 'src/app/common/core/store/models/entrySchema.model';
36 selector: 'app-resource-metadata',
37 templateUrl: './resource-metadata.component.html',
38 styleUrls: ['./resource-metadata.component.scss']
40 export class ResourceMetadataComponent implements OnInit {
41 entry_schema:IEntrySchema;
42 properties: IPropertyData;
43 ResourceMetadata: FormGroup;
44 resource_name: string;
46 rdState: Observable<IResourcesState>;
47 resources: IResources;
50 @Output() resourcesData = new EventEmitter();
52 constructor(private formBuilder: FormBuilder, private store: Store<IAppState>) {
53 this.rdState = this.store.select('resources');
54 this.ResourceMetadata = this.formBuilder.group({
55 Resource_Name: ['', Validators.required],
56 _tags: ['', Validators.required],
57 _description : ['', Validators.required],
58 _type: ['', Validators.required],
59 required: ['', Validators.required],
65 this.rdState.subscribe(
67 var resourcesState: IResourcesState = { resources: resourcesdata.resources, isLoadSuccess: resourcesdata.isLoadSuccess, isSaveSuccess: resourcesdata.isSaveSuccess, isUpdateSuccess: resourcesdata.isUpdateSuccess };
68 this.resource_name = resourcesState.resources.name;
69 this.tags = resourcesState.resources.tags;
70 this.resources = resourcesState.resources;
71 this.properties= resourcesState.resources.property;
72 this.propertyValues= this.checkNested(this.properties);
73 this.ResourceMetadata = this.formBuilder.group({
74 Resource_Name: [this.resource_name, Validators.required],
75 _tags: [this.tags, Validators.required],
76 _description : [ this.propertyValues[0], Validators.required],
77 _type: [ this.propertyValues[1], Validators.required],
78 required: [ JSON.stringify(this.propertyValues[2]), Validators.required],
79 entry_schema: [this.propertyValues[3]]
86 this.resources.name = this.ResourceMetadata.value.Resource_Name;
87 this.resources.tags = this.ResourceMetadata.value._tags;
88 this.resources.property.description = this.ResourceMetadata.value._description;
89 this.resources.property.type = this.ResourceMetadata.value._type;
90 this.resources.property.required = this.ResourceMetadata.value.required;
91 this.resources.property.entry_schema = this.ResourceMetadata.value.entry_schema;
92 this.resourcesData.emit(this.resources);
96 for (let key in obj) {
97 if (obj.hasOwnProperty(key)) {
98 if (typeof obj[key] == "object"){
99 console.log(`Key: ${key}`)
100 this.checkNested(obj[key]);
102 this.property.push(obj[key]);