c40679718107f74797412984c06388742b7f8f6f
[ccsdk/cds.git] / cds-ui / designer-client / src / app / modules / feature-modules / resource-dictionary / resource-dictionary-creation / resource-dictionary-creation.component.ts
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : CDS
4 * ================================================================================
5 * Copyright (C) 2020 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, ViewChild, ElementRef } from '@angular/core';
21 import { Router } from '@angular/router';
22 import { DictionaryCreationStore } from './dictionary-creation.store';
23 import { DictionaryModel } from '../model/dictionary.model';
24 import { Definition } from '../model/definition.model';
25 import { DictionaryMetadataComponent } from './dictionary-metadata/dictionary-metadata.component';
26 import { SourcesTemplateComponent } from './sources-template/sources-template.component';
27 import { DictionaryCreationService } from './dictionary-creation.service';
28
29 @Component({
30   selector: 'app-resource-dictionary-creation',
31   templateUrl: './resource-dictionary-creation.component.html',
32   styleUrls: ['./resource-dictionary-creation.component.css']
33 })
34 export class ResourceDictionaryCreationComponent implements OnInit {
35
36   constructor(
37     private router: Router,
38     private dictionaryCreationStore: DictionaryCreationStore,
39     private dictionaryService: DictionaryCreationService
40   ) {
41   }
42
43   modes: object[] = [
44     { name: 'Designer Mode', style: 'mode-icon icon-designer-mode' },
45     { name: 'Scripting Mode', style: 'mode-icon icon-scripting-mode' }
46   ];
47
48   metaDataTab: DictionaryModel = new DictionaryModel();
49   definition: Definition = new Definition();
50   createDate = '';
51
52   @ViewChild(DictionaryMetadataComponent, { static: false })
53   private metadataTabComponent: DictionaryMetadataComponent;
54
55   @ViewChild(SourcesTemplateComponent, { static: false })
56   private sourcesTemplateComponent: SourcesTemplateComponent;
57
58   @ViewChild('nameit', { static: true })
59   private elementRef: ElementRef;
60
61   ngOnInit() {
62     this.elementRef.nativeElement.focus();
63     // this.elementRef2.nativeElement.focus();
64   }
65
66   saveDictionaryToStore() {
67     // console.log('00000000000');
68     // this.dictionaryCreationStore.getSources();
69     // this.dictionaryCreationStore.state$.subscribe(dd => {
70     //   console.log(dd);
71     // });
72   }
73
74   createDictionary() {
75     console.log('-----');
76     this.metadataTabComponent.saveMetaDataToStore();
77     this.dictionaryCreationStore.state$.subscribe(res => {
78       console.log('---------------------------------------');
79       console.log(res);
80       this.dictionaryService.save(res.metaData).subscribe(data => {
81
82       }, err => {
83
84       });
85     });
86     // this.sourcesTemplateComponent.saveSorcesDataToStore();
87   }
88
89   goBackToDashBorad() {
90     this.router.navigate(['/resource-dictionary']);
91   }
92
93 }