2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
22 import {Component, ElementRef, OnInit, QueryList, ViewChildren} from '@angular/core';
23 import {PackagesStore} from '../../packages.store';
24 import {BlueprintModel, BluePrintPage} from '../../model/BluePrint.model';
27 selector: 'app-filter-by-tags',
28 templateUrl: './filter-by-tags.component.html',
29 styleUrls: ['./filter-by-tags.component.css']
32 export class TagsFilteringComponent implements OnInit {
36 viewedTags: string[] = [];
38 viewedPackages: BlueprintModel[] = [];
41 @ViewChildren('checkboxes') checkboxes: QueryList<ElementRef>;
43 constructor(private packagesStore: PackagesStore,
48 private refreshTags() {
49 this.packagesStore.state$.subscribe(state => {
52 this.viewedPackages = state.page.content;
54 if (state.currentPage !== this.currentPage) {
55 this.checkBoxTages = '';
56 this.currentPage = state.currentPage;
58 this.viewedPackages.forEach(element => {
59 element.tags.split(',').forEach(tag => {
60 this.tags.push(tag.trim());
62 this.tags.push('All');
63 this.tags = this.tags.filter((value, index, self) => self.indexOf(value) === index && value);
74 reloadChanges(event: any) {
75 this.searchTag = event.target.value;
76 this.filterItem(this.searchTag);
79 private assignTags() {
80 this.viewedTags = this.tags;
83 private filterItem(value) {
87 this.viewedTags = this.tags.filter(
88 item => item.toLowerCase().indexOf(value.toLowerCase()) > -1
94 reloadPackages(event: any) {
95 if (!event.target.checked) {
96 this.checkBoxTages = this.checkBoxTages.replace(event.target.id + ',', '')
97 .replace(event.target.id, '');
99 this.checkBoxTages += event.target.id.trim() + ',';
101 const tagsSelected = this.checkBoxTages.split(',').filter(item => {
109 this.packagesStore.filterByTags(tagsSelected);
114 this.checkBoxTages = '';
115 this.checkboxes.forEach((element) => {
116 element.nativeElement.checked = false;
117 this.packagesStore.getAll();