b2748d87116e74e5e2593edbd14bd04eb2b870d8
[ccsdk/cds.git] /
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : CDS
4 * ================================================================================
5 * Copyright (C) 2019 TechMahindra
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20 import { Component, OnInit, Inject } from '@angular/core';
21 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
22 import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; 
23 import { Store } from '@ngrx/store';
24 import { Observable } from 'rxjs';
25
26 import { ICatalog } from 'src/app/common/core/store/models/catalog.model'; 
27 import { ICatalogState } from 'src/app/common/core/store/models/catalogState.model';
28 import { IAppState } from 'src/app/common/core/store/state/app.state';
29
30 @Component({
31   selector: 'app-catalog-data-dialog',
32   templateUrl: './catalog-data-dialog.component.html',
33   styleUrls: ['./catalog-data-dialog.component.scss']
34 })
35 export class CatalogDataDialogComponent implements OnInit{
36
37   catalog:any=[];
38   
39   CatalogFormData: FormGroup;
40   ccState: Observable<ICatalogState>;
41   isDisabled: boolean=true;
42   optionSelected:string;
43   // derivedFrom: any[] = [{derivedFrom: 'tosca.nodes.Component'},{derivedFrom:'tosca.nodes.VNF'},{derivedFrom:'tosca.nodes.Artifact'},{derivedFrom:'tosca.nodes.ResourceSource'}, {derivedFrom:'tosca.nodes.Workflow'},{derivedFrom:'tosca.nodes.Root'}];
44   // definitionType: any[] = [{definitionType: 'node_type'}];
45   property:any=[];
46   constructor(public dialogRef: MatDialogRef<CatalogDataDialogComponent>, @Inject(MAT_DIALOG_DATA) public item: any,private formBuilder: FormBuilder, private store: Store<IAppState> ) {
47     console.log(item);
48     this.optionSelected=item['option'];
49     for (let key in item['item']) {
50       this.catalog.push(item['item'][key]);
51     }
52     console.log(this.catalog);
53     for (let key in this.catalog) {
54       this.property.push(this.catalog[key]);  
55     }
56     if(this.optionSelected == 'Info'){
57       this.isDisabled = true;
58     }
59     else{
60       this.isDisabled = false;
61     }
62
63     this.ccState = this.store.select('catalog');
64     this.CatalogFormData = this.formBuilder.group({
65         modelName: [{value:this.property[0], disabled: this.isDisabled}, Validators.required],
66         derivedFrom: [{value:this.property[1], disabled: this.isDisabled}, Validators.required],
67         definitionType: [{value:this.property[2], disabled: this.isDisabled}, Validators.required],
68         definition: [{value:JSON.stringify(this.property[3]), disabled: this.isDisabled}, Validators.required],
69         tags: [{value:this.property[6], disabled: this.isDisabled}, Validators.required],
70         updatedBy: [{value:this.property[8], disabled: this.isDisabled}, Validators.required],    
71       });  
72   }
73   
74   ngOnInit(){
75   }
76
77   onNoClick(): void {
78     this.dialogRef.close();
79   }
80
81   onClickSave(){
82     //this.catalog = Object.assign({}, this.CatalogFormData.value);
83     this.dialogRef.close(this.CatalogFormData.value);
84   }
85 }