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 = '';
40 constructor(private sourcesStore: SourcesStore) {
41 this.sourcesStore.state$.subscribe(sources => {
42 this.sources = sources.sources;
43 for (const key in this.sources) {
45 const sourceObj = { name: key, value: JSON.stringify(this.sources[key] )};
46 this.option.push(sourceObj);
53 this.sourcesStore.getAllSources();
56 saveSorcesDataToStore() {
57 this.sourcesStore.saveSources(this.ddSource);
60 drop(event: CdkDragDrop<string[]>) {
62 if (event.previousContainer === event.container) {
63 moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
65 transferArrayItem(event.previousContainer.data,
71 for (const key2 in this.sources) {
73 const originalSources = this.sourcesOptions;
74 for (const key of originalSources) {
75 if (key.name === key2) {
76 const obj = `{${key.name}: ${key.value}}`;
77 this.ddSource.push(obj);
84 searchDictionary(event: any) {
85 this.searchQuery = event.target.value;
86 this.searchQuery = this.searchQuery.trim();
87 console.log(this.searchQuery);
88 // this.dictionaryStore.search(this.searchQuery);
91 onChange(item: string, isChecked: boolean) {
93 this.selectedArray.push(item);
97 textChanged(event, item) {
98 const editedData = JSON.parse(event);
99 const originalSources = this.sources;
100 for (const key in originalSources) {
101 if (key === item.name) {
102 this.sources[key] = editedData;
106 this.sourcesStore.changeSources(this.sources);