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=========================================================
21 import { Component, OnInit } from '@angular/core';
22 import { DictionaryModel, DictionaryPage } from '../../model/dictionary.model';
23 import { DictionaryStore } from '../../dictionary.store';
26 selector: 'app-filterby-tags',
27 templateUrl: './filterby-tags.component.html',
28 styleUrls: ['./filterby-tags.component.css']
30 export class FilterbyTagsComponent implements OnInit {
33 viewedTags: string[] = [];
35 viewedDictionary: DictionaryModel[] = [];
36 private checkBoxTages = '';
39 constructor(private dictionaryStore: DictionaryStore) {
40 this.dictionaryStore.state$.subscribe(state => {
43 this.viewedDictionary = state.page.content;
45 if (state.currentPage !== this.currentPage) {
46 this.checkBoxTages = '';
47 this.currentPage = state.currentPage;
49 this.viewedDictionary.forEach(element => {
50 element.tags.split(',').forEach(tag => {
51 this.tags.push(tag.trim());
53 this.tags.push('All');
54 this.tags = this.tags.filter((value, index, self) => self.indexOf(value) === index);
65 reloadChanges(event: any) {
66 this.searchTag = event.target.value;
67 this.filterItem(this.searchTag);
70 private assignTags() {
71 this.viewedTags = this.tags;
74 private filterItem(value) {
78 this.viewedTags = this.tags.filter(
79 item => item.toLowerCase().indexOf(value.toLowerCase()) > -1
83 reloadDictionary(event: any) {
84 if (!event.target.checked) {
85 this.checkBoxTages = this.checkBoxTages.replace(event.target.id + ',', '')
86 .replace(event.target.id, '');
88 this.checkBoxTages += event.target.id.trim() + ',';
90 const tagsSelected = this.checkBoxTages.split(',').filter(item => {
97 this.dictionaryStore.filterByTags(tagsSelected);