631a0fffd9db48f435895d0d8f7735beeaca70da
[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 } from '@angular/core';
21 import { ActivatedRoute } from '@angular/router';
22 import { DictionaryModel } from '../../model/dictionary.model';
23 import { DictionaryCreationService } from '../dictionary-creation.service';
24 import { DictionaryCreationStore } from '../dictionary-creation.store';
25 import { MetaData } from '../../model/metaData.model';
26
27 @Component({
28     selector: 'app-dictionary-metadata',
29     templateUrl: './dictionary-metadata.component.html',
30     styleUrls: ['./dictionary-metadata.component.css']
31 })
32 export class DictionaryMetadataComponent implements OnInit {
33     packageNameAndVersionEnables = true;
34     counter = 0;
35     tags = new Set<string>();
36     metaDataTab: MetaData = new MetaData();
37     errorMessage: string;
38
39     constructor(
40         private route: ActivatedRoute,
41         private dictionaryCreationService: DictionaryCreationService,
42         private dictionaryCreationStore: DictionaryCreationStore
43     ) { }
44
45     ngOnInit() {
46         this.dictionaryCreationStore.state$.subscribe(element => {
47             console.log(this.metaDataTab);
48             if (element && element.metaData) {
49                 this.metaDataTab = element.metaData;
50                 this.metaDataTab.property.entry_schema = element.metaData.property.entry_schema;
51                 this.tags = new Set(element.metaData.tags.split(','));
52                 this.tags.delete('');
53                 this.tags.delete(' ');
54
55                 //  console.log(element);
56                 // console.log(element.metaData.property['entry_schema']);
57             }
58         });
59
60     }
61
62     // getSources() {
63     //     this.dictionaryCreationService.getSources().subscribe(res => {
64     //         console.log(res);
65     //     });
66     // }
67
68     removeTag(value) {
69         this.tags.delete(value);
70     }
71
72
73     addTag(event) {
74         const value = event.target.value;
75         console.log(value);
76         if (value && value.trim().length > 0) {
77             let tag = '';
78             event.target.value = '';
79             this.tags.add(value);
80             this.tags.forEach(val => {
81                 tag += val + ', ';
82             });
83         }
84     }
85
86     saveMetaDataToStore() {
87         console.log(this.metaDataTab);
88         this.dictionaryCreationStore.changeMetaData(this.metaDataTab);
89     }
90 }