Skip to content

Commit

Permalink
Benchmark filter issue primefaces#281
Browse files Browse the repository at this point in the history
  • Loading branch information
atretyak1985 committed Aug 19, 2019
1 parent 69593ce commit 911f546
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Component, OnInit} from '@angular/core';
import {SideFilterService} from '../side-filter.service';
import {BenchmarkFamilyService} from '../../../organization/benchmark_filter/benchmark-family.service';
import {SideFilterSectionComponent} from './side-filter-section.component';
import {BenchmarkListItem} from '../side-filter.response';
import {Filter} from '../../object';
import { Component } from '@angular/core';
import { SideFilterService } from '../side-filter.service';
import { BenchmarkFamilyService } from '../../../organization/benchmark_filter/benchmark-family.service';
import { SideFilterSectionComponent } from './side-filter-section.component';
import { BenchmarkListItem } from '../side-filter.response';
import { Filter } from '../../object';


@Component({
selector: 'benchmark-filter-section',
Expand All @@ -19,21 +20,22 @@ export class BenchmarkFilterSectionComponent extends SideFilterSectionComponent
}

ngOnInit() {
this.benchmarkFamilyService.listResponse$.subscribe (
(d: any) => {
this.benchmarkListItems = d;
this.benchmarkFamilyService.listResponse$.subscribe(
(d: any) => {
this.benchmarkListItems = d;

// Check if we had the filter saved in session storage
// Check if we had the filter saved in session storage
let filter = this.service.getFilter(this.filter.key);
if (filter) {
this.filter = filter;
this.filter = this.filterSavedValues(filter, this.benchmarkListItems, 'family_id');
this.service.updateFilter(this.filter);
for (let item of this.benchmarkListItems) {
item.in_filter = this.filter.values.indexOf(item.family_id) >= 0;
}
}
}
);
this.benchmarkFamilyService.getList();
}
);
this.benchmarkFamilyService.getList();
}

clearSection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, OnInit, ViewChild, Input, HostBinding} from '@angular/core';
import {SideFilterService} from '../side-filter.service';
import {LabelService} from '../../../organization/admin/label/label.service';
import {LabelListItem, LabelListResponse} from '../../../organization/admin/label/label.response';
import {LabelCreateDialogComponent} from '../../../organization/admin/label/label_create_dialog.component';
import {SideFilterSectionComponent} from './side-filter-section.component';
import {Filter} from '../../object';
import {BasicListRequest} from '../../request';
import { Component, ViewChild, Input, HostBinding } from '@angular/core';
import { SideFilterService } from '../side-filter.service';
import { LabelService } from '../../../organization/admin/label/label.service';
import { LabelListItem, LabelListResponse } from '../../../organization/admin/label/label.response';
import { LabelCreateDialogComponent } from '../../../organization/admin/label/label_create_dialog.component';
import { SideFilterSectionComponent } from './side-filter-section.component';
import { Filter } from '../../object';
import { BasicListRequest } from '../../request';


@Component({
selector: 'label-filter-section',
Expand Down Expand Up @@ -37,7 +38,8 @@ export class LabelFilterSectionComponent extends SideFilterSectionComponent {
// Check if we had the filter saved in session storage
let filter = this.service.getFilter(this.filter.key);
if (filter) {
this.filter = filter;
this.filter = this.filterSavedValues(filter, this.labelFilterItems, 'id');
this.service.updateFilter(this.filter);
for (let item of this.labelFilterItems) {
item.in_filter = this.filter.values.indexOf(item.id) >= 0;
}
Expand Down Expand Up @@ -66,8 +68,8 @@ export class LabelFilterSectionComponent extends SideFilterSectionComponent {
}

private getRoutePath(subPath) {
return this.service.accountService.navigateOrganization(subPath);
}
return this.service.accountService.navigateOrganization(subPath);
}
}

interface LabelFilterItem extends LabelListItem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Component} from '@angular/core';
import {SideFilterService} from '../side-filter.service';
import {SideFilterSectionComponent} from './side-filter-section.component';
import {Filter} from '../../object';
import { Component } from '@angular/core';
import { SideFilterService } from '../side-filter.service';
import { SideFilterSectionComponent } from './side-filter-section.component';
import { Filter } from '../../object';
import { OSService } from 'organization/os_filter/os-filter.service';
import { OSListItem } from 'organization/os_filter/os-filter.response';


@Component({
selector: 'os-filter-section',
templateUrl: 'os-filter-section.component.html'
Expand All @@ -19,21 +20,22 @@ export class OSFilterSectionComponent extends SideFilterSectionComponent {
}

ngOnInit() {
this.osService.listResponse$.subscribe (
(d: any) => {
this.osListItems = d;
this.osService.listResponse$.subscribe(
(d: any) => {
this.osListItems = d;

// Check if we had the filter saved in session storage
// Check if we had the filter saved in session storage
let filter = this.service.getFilter(this.filter.key);
if (filter) {
this.filter = filter;
this.filter = this.filterSavedValues(filter, this.osListItems, 'id');
this.service.updateFilter(this.filter);
for (let item of this.osListItems) {
item.in_filter = this.filter.values.indexOf(item.id) >= 0;
}
}
}
);
this.osService.getList();
}
);
this.osService.getList();
}

clearSection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Input, Output, Component, HostBinding, EventEmitter, ViewChild, ElementRef} from '@angular/core';
import {SideFilterService} from '../side-filter.service';
import {Filter} from '../../object';
import { Input, Output, Component, HostBinding, EventEmitter } from '@angular/core';
import { SideFilterService } from '../side-filter.service';
import { Filter } from '../../object';


@Component({
selector: 'side-filter-section',
Expand All @@ -12,10 +13,9 @@ export class SideFilterSectionComponent {
@Output() clearSectionEvent: EventEmitter<any> = new EventEmitter();
@HostBinding('class') cssClasses = '';
public filter: Filter;

public isCollapsed: boolean;

constructor(protected service: SideFilterService) {}
constructor(protected service: SideFilterService) { }

clearSection() {
this.clearSectionEvent.emit();
Expand All @@ -30,4 +30,14 @@ export class SideFilterSectionComponent {
this.isCollapsed = !this.isCollapsed;
}

filterSavedValues(storageFilters: Filter, itemFilters: any[], textId: string): Filter {
let filterItem;
storageFilters.values.forEach((filterValue, index) => {
filterItem = itemFilters.find(item => item[textId] === filterValue);
if (!filterItem) {
storageFilters.values.splice(index, 1);
}
});
return storageFilters;
}
}

0 comments on commit 911f546

Please sign in to comment.