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';
25 selector: 'app-sources-template',
26 templateUrl: './sources-template.component.html',
27 styleUrls: ['./sources-template.component.css']
29 export class SourcesTemplateComponent implements OnInit {
30 private searchQuery = '';
42 constructor(private sourcesStore: SourcesStore) {
43 this.sourcesStore.state$.subscribe(sources => {
44 this.sources = sources.sources;
45 for (const key in this.sources) {
47 const sourceObj = { name: key, value: JSON.stringify(this.sources[key]) };
48 this.option.push(sourceObj);
55 this.sourcesStore.getAllSources();
58 saveSorcesDataToStore() {
59 this.sourcesStore.saveSources(this.ddSource);
62 drop(event: CdkDragDrop<string[]>) {
64 if (event.previousContainer === event.container) {
65 moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
67 transferArrayItem(event.previousContainer.data,
73 for (const key2 in this.sources) {
75 const originalSources = this.sourcesOptions;
76 for (const key of originalSources) {
77 if (key.name === key2) {
78 const obj = `{${key.name}: ${key.value}}`;
79 this.ddSource.push(obj);
86 searchDictionary(event: any) {
87 this.searchQuery = event.target.value;
88 this.searchQuery = this.searchQuery.trim();
89 console.log(this.searchQuery);
90 // this.dictionaryStore.search(this.searchQuery);
93 onChange(item: string, isChecked: boolean) {
95 this.selectedArray.push(item);
99 textChanged(event, item) {
100 const editedData = JSON.parse(event);
101 const originalSources = this.sources;
102 for (const key in originalSources) {
103 if (key === item.name) {
104 this.sources[key] = editedData;
108 this.sourcesStore.changeSources(this.sources);