aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui/client/src/app/feature-modules/controller-catalog/search-catalog/catalog-data-dialog/catalog-data-dialog.component.ts
blob: b2748d87116e74e5e2593edbd14bd04eb2b870d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* ============LICENSE_START=======================================================
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
import { Component, OnInit, Inject } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; 
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';

import { ICatalog } from 'src/app/common/core/store/models/catalog.model'; 
import { ICatalogState } from 'src/app/common/core/store/models/catalogState.model';
import { IAppState } from 'src/app/common/core/store/state/app.state';

@Component({
  selector: 'app-catalog-data-dialog',
  templateUrl: './catalog-data-dialog.component.html',
  styleUrls: ['./catalog-data-dialog.component.scss']
})
export class CatalogDataDialogComponent implements OnInit{

  catalog:any=[];
  
  CatalogFormData: FormGroup;
  ccState: Observable<ICatalogState>;
  isDisabled: boolean=true;
  optionSelected:string;
  // 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'}];
  // definitionType: any[] = [{definitionType: 'node_type'}];
  property:any=[];
  constructor(public dialogRef: MatDialogRef<CatalogDataDialogComponent>, @Inject(MAT_DIALOG_DATA) public item: any,private formBuilder: FormBuilder, private store: Store<IAppState> ) {
    console.log(item);
    this.optionSelected=item['option'];
    for (let key in item['item']) {
      this.catalog.push(item['item'][key]);
    }
    console.log(this.catalog);
    for (let key in this.catalog) {
      this.property.push(this.catalog[key]);  
    }
    if(this.optionSelected == 'Info'){
      this.isDisabled = true;
    }
    else{
      this.isDisabled = false;
    }

    this.ccState = this.store.select('catalog');
    this.CatalogFormData = this.formBuilder.group({
        modelName: [{value:this.property[0], disabled: this.isDisabled}, Validators.required],
        derivedFrom: [{value:this.property[1], disabled: this.isDisabled}, Validators.required],
        definitionType: [{value:this.property[2], disabled: this.isDisabled}, Validators.required],
        definition: [{value:JSON.stringify(this.property[3]), disabled: this.isDisabled}, Validators.required],
        tags: [{value:this.property[6], disabled: this.isDisabled}, Validators.required],
        updatedBy: [{value:this.property[8], disabled: this.isDisabled}, Validators.required],    
      });  
  }
  
  ngOnInit(){
  }

  onNoClick(): void {
    this.dialogRef.close();
  }

  onClickSave(){
    //this.catalog = Object.assign({}, this.CatalogFormData.value);
    this.dialogRef.close(this.CatalogFormData.value);
  }
}