2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import { Component, OnInit, ViewChild, ɵConsole } from '@angular/core';
22 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
23 import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';
24 import { Observable } from 'rxjs';
25 import { ICatalogState } from 'src/app/common/core/store/models/catalogState.model';
26 import { ICatalog } from 'src/app/common/core/store/models/catalog.model';
27 import { Store } from '@ngrx/store';
28 import { IAppState } from 'src/app/common/core/store/state/app.state';
29 import { SetCatalogState } from 'src/app/common/core/store/actions/catalog.action';
30 import { CreateCatalogService } from './create-catalog.service';
31 import { NotificationHandlerService } from 'src/app/common/core/services/notification-handler.service';
34 selector: 'app-create-catalog',
35 templateUrl: './create-catalog.component.html',
36 styleUrls: ['./create-catalog.component.scss']
38 export class CreateCatalogComponent implements OnInit {
40 CatalogFormData: FormGroup;
41 @ViewChild(JsonEditorComponent) editor: JsonEditorComponent;
42 options = new JsonEditorOptions();
44 derivedFrom: any[] = ['tosca.nodes.Component','tosca.nodes.VNF','tosca.nodes.Artifact','tosca.nodes.ResourceSource','tosca.nodes.Workflow','tosca.nodes.Root'];
45 definitionType: any[] = ['node_type'];
46 ccState: Observable<ICatalogState>;
49 constructor(private formBuilder: FormBuilder, private store: Store<IAppState>, private catalogCreateService: CreateCatalogService, private alertService: NotificationHandlerService) {
50 this.ccState = this.store.select('catalog');
51 this.CatalogFormData = this.formBuilder.group({
52 modelName: ['', Validators.required],
53 updatedBy: ['', Validators.required],
54 tags: ['', Validators.required],
55 definitionType: ['', Validators.required],
56 derivedFrom: ['', Validators.required],
57 description : ['', Validators.required]
61 this.options.mode = 'text';
62 this.options.modes = [ 'text', 'tree', 'view'];
63 this.options.statusBar = false;
65 this.ccState.subscribe(
67 var catalogState: ICatalogState = { catalog: catalogdata.catalog, isLoadSuccess: catalogdata.isLoadSuccess, isSaveSuccess: catalogdata.isSaveSuccess, isUpdateSuccess: catalogdata.isUpdateSuccess };
68 this.catalog = catalogState.catalog;
69 console.log( this.catalog );
72 // this.catalogCreateService.getDefinition()
75 // data.forEach(element => {
76 // this.definitionType.push(element)
79 // window.alert('error' + error);
82 // this.catalogCreateService.getDerivedFrom()
85 // data.forEach(element => {
86 // this.derivedFrom.push(element)
89 // window.alert('error' + error);
93 this.catalog.modelName=this.CatalogFormData.controls['modelName'].value;
94 this.catalog.updatedBy=this.CatalogFormData.controls['updatedBy'].value
95 this.catalog.tags=this.CatalogFormData.controls['tags'].value
96 this.catalog.definitionType=this.CatalogFormData.controls['definitionType'].value
97 this.catalog.derivedFrom=this.CatalogFormData.controls['derivedFrom'].value
98 this.catalog.description=this.CatalogFormData.controls['description'].value
99 this.catalog.definition=this.data;
100 console.log(this.catalog);
102 catalog: this.catalog
104 this.store.dispatch(new SetCatalogState(catalogState));
106 this.catalogCreateService.saveCatalog(this.catalog)
107 .subscribe(response=>{
108 this.alertService.success("save success")
111 this.alertService.error('Error saving resources');
117 this.data=JSON.parse($event.srcElement.value);
118 console.log(this.data);