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';
26 selector: 'app-sources-template',
27 templateUrl: './sources-template.component.html',
28 styleUrls: ['./sources-template.component.css']
30 export class SourcesTemplateComponent implements OnInit {
31 private searchQuery = '';
44 private sourcesStore: SourcesStore,
45 private dictionaryCreationService: DictionaryCreationService
51 // this.sourcesStore.getAllSources();
52 this.dictionaryCreationService.getSources().subscribe(sources => {
53 // console.log(sources);
54 this.sources = sources[0];
56 // "input": "source-input", "rest": "source-rest", "default":"source-default", "capability": "source-capability",
57 // "sdnc": "source-rest", "vault-data": "source-rest", "processor-db": "source-db", "aai-data": "source-rest",
58 // "script": "source-capability"
60 for (const key in this.sources) {
62 console.log(key + ' - ' + this.sources[key]);
63 const sourceObj = { name: key, value: this.sources[key] };
64 this.option.push(sourceObj);
71 saveSorcesDataToStore() {
72 this.sourcesStore.saveSources(this.ddSource);
75 drop(event: CdkDragDrop<string[]>) {
76 console.log('-------------');
79 if (event.previousContainer === event.container) {
80 moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
82 transferArrayItem(event.previousContainer.data,
88 for (const key2 in this.sources) {
90 const originalSources = this.sourcesOptions;
91 for (const key of originalSources) {
92 /* tslint:disable:no-string-literal */
93 if (key.name === key2['name']) {
94 const obj = `{${key.name}: ${key.value}}`;
95 this.ddSource.push(obj);
102 searchDictionary(event: any) {
103 this.searchQuery = event.target.value;
104 this.searchQuery = this.searchQuery.trim();
105 console.log(this.searchQuery);
106 // this.dictionaryStore.search(this.searchQuery);
109 onChange(item: string, isChecked: boolean) {
111 this.selectedArray.push(item);
115 textChanged(event, item) {
116 const editedData = JSON.parse(event);
117 const originalSources = this.sources;
118 for (const key in originalSources) {
119 if (key === item.name) {
120 this.sources[key] = editedData;
124 this.sourcesStore.changeSources(this.sources);