01df118d2919746ce5c416db77acf240dffb6eac
[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 dictionaryCreationStore: DictionaryCreationStore
41     ) { }
42
43     ngOnInit() {
44         this.dictionaryCreationStore.state$.subscribe(element => {
45             console.log(this.metaDataTab);
46             if (element && element.metaData) {
47                 this.metaDataTab = element.metaData;
48                 this.metaDataTab.property.entry_schema = element.metaData.property.entry_schema;
49                 this.tags = new Set(element.metaData.tags.split(','));
50                 this.tags.delete('');
51                 this.tags.delete(' ');
52
53                 //  console.log(element);
54                 // console.log(element.metaData.property['entry_schema']);
55             }
56         });
57
58     }
59
60     // getSources() {
61     //     this.dictionaryCreationService.getSources().subscribe(res => {
62     //         console.log(res);
63     //     });
64     // }
65
66     removeTag(value) {
67         this.tags.delete(value);
68         this.mergeTags();
69     }
70
71
72     addTag(event) {
73         const value = event.target.value;
74         console.log(value);
75         if (value && value.trim().length > 0) {
76             event.target.value = '';
77             this.tags.add(value);
78             // merge
79             this.mergeTags();
80         }
81     }
82
83     mergeTags() {
84         let tag = '';
85         this.tags.forEach((val, index) => {
86             tag += val + ', ';
87         });
88         this.metaDataTab.tags = tag.trim();
89         this.saveMetaDataToStore();
90     }
91
92     saveMetaDataToStore() {
93         console.log(this.metaDataTab);
94         this.dictionaryCreationStore.changeMetaData(this.metaDataTab);
95     }
96 }