2 * ============LICENSE_START=======================================================
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
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=========================================================
20 import { Component, OnInit } from '@angular/core';
21 import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
22 import { SourcesStore } from './sources.store';
23 import { DictionaryCreationService } from '../dictionary-creation.service';
24 import { DictionaryCreationStore } from '../dictionary-creation.store';
25 import { MetaData } from '../../model/metaData.model';
28 selector: 'app-sources-template',
29 templateUrl: './sources-template.component.html',
30 styleUrls: ['./sources-template.component.css']
32 export class SourcesTemplateComponent implements OnInit {
33 private searchQuery = '';
45 metaDataTab: MetaData = new MetaData();
48 private sourcesStore: SourcesStore,
49 private dictionaryCreationService: DictionaryCreationService,
50 private dictionaryCreationStore: DictionaryCreationStore
56 // this.sourcesStore.getAllSources();
57 this.dictionaryCreationService.getSources().subscribe(sources => {
58 // console.log(sources);
59 this.sources = sources[0];
61 // "input": "source-input", "rest": "source-rest", "default":"source-default", "capability": "source-capability",
62 // "sdnc": "source-rest", "vault-data": "source-rest", "processor-db": "source-db", "aai-data": "source-rest",
63 // "script": "source-capability"
65 for (const key in this.sources) {
67 console.log(key + ' - ' + this.sources[key]);
68 const sourceObj = { name: key, value: this.sources[key] };
69 this.option.push(sourceObj);
75 this.dictionaryCreationStore.state$.subscribe(element => {
76 console.log('################');
77 console.log(this.metaDataTab);
78 if (element && element.metaData) {
79 this.metaDataTab = element.metaData;
80 this.addSourcesInUI();
86 // add sources from json to UI
87 const originalSources = this.sourcesOptions;
88 // for (const key of this.sourcesOptions) {
89 // this.sourcesOptions;
90 for (const source in this.metaDataTab.sources) {
97 saveSorcesDataToStore() {
98 console.log(this.ddSource);
99 this.metaDataTab.sources = {};
100 for (const obj of this.ddSource) {
101 this.metaDataTab.sources = { ...this.metaDataTab.sources, ...obj };
103 // this.metaDataTab.sources = { ...this.ddSource }
104 console.log(this.metaDataTab.sources);
105 this.dictionaryCreationStore.changeMetaData(this.metaDataTab);
108 drop(event: CdkDragDrop<string[]>) {
109 console.log('-------------');
110 // console.log(event);
112 if (event.previousContainer === event.container) {
113 moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
115 transferArrayItem(event.previousContainer.data,
116 event.container.data,
121 console.log(this.sourcesOptions);
122 console.log(this.sources);
126 const originalSources = this.sourcesOptions;
127 for (const key of originalSources) {
128 /* tslint:disable:no-string-literal */
138 this.saveSorcesDataToStore();
141 searchDictionary(event: any) {
142 this.searchQuery = event.target.value;
143 this.searchQuery = this.searchQuery.trim();
144 console.log(this.searchQuery);
145 // this.dictionaryStore.search(this.searchQuery);
148 onChange(item: string, isChecked: boolean) {
150 this.selectedArray.push(item);
154 textChanged(event, item) {
155 // const editedData = JSON.parse(event);
156 // const originalSources = this.sources;
157 // for (const key in originalSources) {
158 // if (key === item.name) {
159 // this.sources[key] = editedData;
163 // this.sourcesStore.changeSources(this.sources);
168 // this.metaDataTab.sources[item.name].properties = editedData;