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[] = [{derivedFrom: 'tosca.nodes.Component'},{derivedFrom:'tosca.nodes.VNF'},{derivedFrom:'tosca.nodes.Artifact'},{derivedFrom:'tosca.nodes.ResourceSource'}, {derivedFrom:'tosca.nodes.Workflow'},{derivedFrom:'tosca.nodes.Root'}];
45 definitionType: any[] = [{definitionType: '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 Model_Name: ['', Validators.required],
53 User_id: ['', Validators.required],
54 _tags: ['', Validators.required],
55 _type: ['', Validators.required],
56 Derived_From: ['', 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 = Object.assign({}, this.CatalogFormData.value);
94 this.catalog.definition=this.data;
98 this.store.dispatch(new SetCatalogState(catalogState));
100 this.catalogCreateService.saveCatalog(this.catalog)
101 .subscribe(response=>{
102 this.alertService.success("save success")
105 this.alertService.error('Error saving resources');
111 this.data=JSON.parse($event.srcElement.value);
112 console.log(this.data);