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 = '';
44 metaDataTab: MetaData = new MetaData();
46 tempSources = new Map();
47 toDeleteSource = new Map<string, any>();
48 sourcesOptions = new Map<string, any>();
51 private sourcesStore: SourcesStore,
52 private dictionaryCreationService: DictionaryCreationService,
53 private dictionaryCreationStore: DictionaryCreationStore
59 // this.sourcesStore.getAllSources();
60 this.dictionaryCreationService.getSources().subscribe(sources => {
61 // console.log(sources);
62 this.sources = sources[0];
64 // "input": "source-input", "rest": "source-rest", "default": "source-default", "capability": "source-capability",
65 // "sdnc": "source-rest", "vault-data": "source-rest", "processor-db": "source-db", "aai-data": "source-rest",
66 // "script": "source-capability"
68 for (const key in this.sources) {
70 console.log(key + ' - ' + this.sources[key]);
71 const sourceObj = { name: key, value: this.sources[key] };
72 this.option.push(sourceObj);
78 this.dictionaryCreationStore.state$.subscribe(element => {
79 console.log('################');
80 console.log(this.metaDataTab);
81 if (element && element.metaData) {
82 this.metaDataTab = element.metaData;
83 this.addSourcesInUI();
89 // add sources from json to UI
90 const originalSources = this.sourcesOptions;
91 // for (const key of this.sourcesOptions) {
92 // this.sourcesOptions;
93 for (const source in this.metaDataTab.sources) {
100 saveSorcesDataToStore() {
102 for (const key of this.sourcesOptions.keys()) {
103 ddSource.push(this.sourcesOptions.get(key));
105 console.log(ddSource);
106 this.metaDataTab.sources = {};
107 for (const obj of ddSource) {
108 this.metaDataTab.sources = { ...this.metaDataTab.sources, ...obj };
110 // this.metaDataTab.sources = { ...this.ddSource }
111 console.log(this.metaDataTab.sources);
112 this.dictionaryCreationStore.changeMetaData(this.metaDataTab);
115 setTempSources(event, item) {
116 console.log(event.target.checked);
117 if (event.target.checked) {
118 this.tempSources.set(item.name, item);
120 this.tempSources.delete(item.name);
122 console.log(this.tempSources);
126 if (this.tempSources.size === 0) {
127 for (const option of this.option) {
128 if (!this.sourcesOptions.has(option.name)) {
129 this.tempSources.set(option.name, option);
133 this.tempSources = new Map<string, any>();
137 setToDeleteSources(event, item) {
138 console.log(event.target.checked);
139 if (event.target.checked) {
140 this.toDeleteSource.set(item.key, item);
142 this.toDeleteSource.delete(item.key);
149 const originalSources = this.tempSources;
150 for (const key of originalSources.keys()) {
151 /* tslint:disable:no-string-literal */
152 this.sourcesOptions.set(key, {
154 type: originalSources.get(key).value,
161 console.log(this.sourcesOptions);
162 this.tempSources.clear();
163 this.saveSorcesDataToStore();
167 console.log(this.toDeleteSource);
168 for (const key of this.toDeleteSource.keys()) {
170 this.sourcesOptions.delete(key);
172 this.toDeleteSource = new Map<string, any>();
173 this.saveSorcesDataToStore();
176 // drop(event: CdkDragDrop<string[]>) {
177 // console.log('-------------');
178 // // console.log(event);
180 // if (event.previousContainer === event.container) {
181 // moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
183 // transferArrayItem(event.previousContainer.data,
184 // event.container.data,
185 // event.previousIndex,
186 // event.currentIndex);
189 // console.log(this.sourcesOptions);
190 // console.log(this.sources);
192 // this.ddSource = [];
194 // const originalSources = this.sourcesOptions;
195 // for (const key of originalSources) {
196 // /* tslint:disable:no-string-literal */
197 // this.ddSource.push({
206 // this.saveSorcesDataToStore();
210 return Object.assign({}, map.keys());
213 searchDictionary(event: any) {
214 this.searchQuery = event.target.value;
215 this.searchQuery = this.searchQuery.trim();
216 console.log(this.searchQuery);
217 // this.dictionaryStore.search(this.searchQuery);
220 onChange(item: string, isChecked: boolean) {
222 this.selectedArray.push(item);
226 textChanged(event, item) {
227 // const editedData = JSON.parse(event);
228 // const originalSources = this.sources;
229 // for (const key in originalSources) {
230 // if (key === item.name) {
231 // this.sources[key] = editedData;
235 // this.sourcesStore.changeSources(this.sources);
240 // this.metaDataTab.sources[item.name].properties = editedData;