8eb126d21f2fdad41c009a600861af8ecd934437
[ccsdk/cds.git] /
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 import { ToastrService } from 'ngx-toastr';
29
30 @Component({
31   selector: 'app-resource-dictionary-creation',
32   templateUrl: './resource-dictionary-creation.component.html',
33   styleUrls: ['./resource-dictionary-creation.component.css']
34 })
35 export class ResourceDictionaryCreationComponent implements OnInit {
36
37   constructor(
38     private router: Router,
39     private dictionaryCreationStore: DictionaryCreationStore,
40     private dictionaryService: DictionaryCreationService,
41     private toaster: ToastrService
42   ) {
43   }
44
45   modes: object[] = [
46     { name: 'Designer Mode', style: 'mode-icon icon-designer-mode' },
47     { name: 'Scripting Mode', style: 'mode-icon icon-scripting-mode' }
48   ];
49
50   metaDataTab: DictionaryModel = new DictionaryModel();
51   definition: Definition = new Definition();
52   createDate = '';
53
54   @ViewChild(DictionaryMetadataComponent, { static: false })
55   private metadataTabComponent: DictionaryMetadataComponent;
56
57   @ViewChild(SourcesTemplateComponent, { static: false })
58   private sourcesTemplateComponent: SourcesTemplateComponent;
59
60   @ViewChild('nameit', { static: true })
61   private elementRef: ElementRef;
62
63   ngOnInit() {
64     this.elementRef.nativeElement.focus();
65     // this.elementRef2.nativeElement.focus();
66   }
67
68   saveDictionaryToStore() {
69     this.metadataTabComponent.saveMetaDataToStore();
70     // console.log('00000000000');
71     // this.dictionaryCreationStore.getSources();
72     // this.dictionaryCreationStore.state$.subscribe(dd => {
73     //   console.log(dd);
74     // });
75   }
76
77   createDictionary() {
78
79     console.log('-----');
80     this.metadataTabComponent.saveMetaDataToStore();
81     this.dictionaryCreationStore.state$.subscribe(res => {
82       console.log('---------------------------------------');
83       console.log(res);
84       this.dictionaryService.save(res.metaData).subscribe(data => {
85         this.toaster.success('Dictionary Resource created');
86       }, err => {
87         this.toaster.error('An error happened ...');
88       }, () => {
89
90       });
91     }).unsubscribe();
92     // this.sourcesTemplateComponent.saveSorcesDataToStore();
93   }
94
95   goBackToDashBorad() {
96     this.router.navigate(['/resource-dictionary']);
97   }
98
99 }