Skip to content

Commit

Permalink
fix(filter): ensure examples follow PatternFly guidelines (#413)
Browse files Browse the repository at this point in the history
This also simplifies filters in table and toolbar by removing type ahead features where it is not necessary.

Fixes #329
  • Loading branch information
dlabrecq committed Jun 30, 2018
1 parent 4465908 commit c03e642
Show file tree
Hide file tree
Showing 19 changed files with 462 additions and 529 deletions.
41 changes: 26 additions & 15 deletions src/app/filter/example/filter-basic-example.component.ts
Expand Up @@ -32,7 +32,8 @@ export class FilterBasicExampleComponent implements OnInit {
weekDay: 'Sunday',
weekdayId: 'day1'
}, {
name: 'John Smith', address: '415 East Main Street, Norfolk, Virginia',
name: 'John Smith',
address: '415 East Main Street, Norfolk, Virginia',
birthMonth: 'October',
birthMonthId: '10',
weekDay: 'Monday',
Expand Down Expand Up @@ -115,22 +116,31 @@ export class FilterBasicExampleComponent implements OnInit {
value: 'December'
}]
}, {
id: 'byIcon',
title: 'By Icon',
placeholder: 'Filter by Icon...',
id: 'weekDay',
title: 'Week Day',
placeholder: 'Filter by Week Day...',
type: FilterType.SELECT,
queries: [{
id: 'bookmark',
value: 'Bookmark',
iconStyleClass: 'fa fa-bookmark'
id: 'day1',
value: 'Sunday'
}, {
id: 'map',
value: 'Map',
iconStyleClass: 'fa fa-map-marker'
id: 'day2',
value: 'Monday'
}, {
id: 'gift',
value: 'Gift',
iconStyleClass: 'fa fa-gift'
id: 'day3',
value: 'Tuesday'
}, {
id: 'day4',
value: 'Wednesday'
}, {
id: 'day5',
value: 'Thursday'
}, {
id: 'day6',
value: 'Friday'
}, {
id: 'day7',
value: 'Saturday'
}]
}] as FilterField[],
resultsCount: this.items.length,
Expand Down Expand Up @@ -164,10 +174,11 @@ export class FilterBasicExampleComponent implements OnInit {

matchesFilter(item: any, filter: Filter): boolean {
let match = true;
let re = new RegExp(filter.value, 'i');
if (filter.field.id === 'name') {
match = item.name.match(filter.value) !== null;
match = item.name.match(re) !== null;
} else if (filter.field.id === 'address') {
match = item.address.match(filter.value) !== null;
match = item.address.match(re) !== null;
} else if (filter.field.id === 'birthMonth') {
match = item.birthMonth === filter.value;
} else if (filter.field.id === 'weekDay') {
Expand Down
3 changes: 3 additions & 0 deletions src/app/filter/example/filter-example.component.html
Expand Up @@ -18,5 +18,8 @@ <h4>Filter Component Example</h4>
<tab heading="Lazy Load" (select)="tabSelected($event)">
<filter-lazy-example *ngIf="activeTab === 'Lazy Load'"></filter-lazy-example>
</tab>
<tab heading="Icon" (select)="tabSelected($event)">
<filter-icon-example *ngIf="activeTab === 'Icon'"></filter-icon-example>
</tab>
</tabset>
</div>
2 changes: 2 additions & 0 deletions src/app/filter/example/filter-example.module.ts
Expand Up @@ -7,6 +7,7 @@ import { TabsetConfig, TabsModule } from 'ngx-bootstrap/tabs';
import { DemoComponentsModule } from '../../../demo/components/demo-components.module';
import { FilterBasicExampleComponent } from './filter-basic-example.component';
import { FilterExampleComponent } from './filter-example.component';
import { FilterIconExampleComponent } from './filter-icon-example.component';
import { FilterLazyExampleComponent } from './filter-lazy-example.component';
import { FilterModule } from '../filter.module';
import { FilterSaveExampleComponent } from './filter-save-example.component';
Expand All @@ -23,6 +24,7 @@ import { FilterTypeAheadExampleComponent } from './filter-type-ahead-example.com
declarations: [
FilterBasicExampleComponent,
FilterExampleComponent,
FilterIconExampleComponent,
FilterLazyExampleComponent,
FilterSaveExampleComponent,
FilterTypeAheadExampleComponent
Expand Down
87 changes: 87 additions & 0 deletions src/app/filter/example/filter-icon-example.component.html
@@ -0,0 +1,87 @@
<div class="padding-15">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<p>Warning: This example is for development testing purposes. It is not an official pattern and subject to change</p>
<p>This ensures the filter field can display icons</p>
<pfng-filter [config]="filterConfig"
(onChange)="filterChanged($event)"></pfng-filter>
</div>
</div>
</div>
<div class="row padding-top-10">
<div class="col-sm-12">
<h4 class="actions-label">Items</h4>
<hr/>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div *ngFor="let item of items" class="col-sm-12">
<div class="row">
<div class="col-sm-3">
<i class="padding-right-10" [ngClass]="item.iconStyleClass"></i>
<span>{{item.name}}</span>
</div>
<div class="col-sm-5">
<span>{{item.address}}</span>
</div>
<div class="col-sm-2">
<span>{{item.birthMonth}}</span>
</div>
<div class="col-sm-2">
<span>{{item.weekDay}}</span>
</div>
</div>
</div>
</div>
</div>
<div class="row padding-top-10">
<div class="col-sm-12">
<h4 class="actions-label">Settings</h4>
<hr/>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form role="form">
<div class="form-group">
<label class="checkbox-inline">
<input id="disabled" name="disabled" type="checkbox"
[(ngModel)]="filterConfig.disabled">Disabled
</label>
</div>
</form>
</div>
</div>
<div class="row padding-top-10">
<div class="col-sm-12">
<h4 class="actions-label">Filters</h4>
<hr/>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<textarea rows="3" class="col-sm-12">{{filtersText}}</textarea>
</div>
</div>
<div class="row padding-top-10">
<div class="col-sm-12">
<h4>Code</h4>
<hr/>
</div>
</div>
<div>
<tabset>
<tab heading="api">
<iframe class="demoframe" src="docs/classes/filtercomponent.html"></iframe>
</tab>
<tab heading="html">
<include-content src="src/app/filter/example/filter-icon-example.component.html"></include-content>
</tab>
<tab heading="typescript">
<include-content src="src/app/filter/example/filter-icon-example.component.ts"></include-content>
</tab>
</tabset>
</div>
</div>
141 changes: 141 additions & 0 deletions src/app/filter/example/filter-icon-example.component.ts
@@ -0,0 +1,141 @@
import {
Component,
OnInit,
} from '@angular/core';

import { Filter } from '../filter';
import { FilterConfig } from '../filter-config';
import { FilterField } from '../filter-field';
import { FilterEvent } from '../filter-event';
import { FilterType } from '../filter-type';

@Component({
selector: 'filter-icon-example',
templateUrl: './filter-icon-example.component.html'
})
export class FilterIconExampleComponent implements OnInit {
allItems: any[];
items: any[];
filterConfig: FilterConfig;
filtersText: string = '';
separator: Object;

constructor() {
}

ngOnInit(): void {
this.allItems = [{
name: 'Fred Flintstone',
address: '20 Dinosaur Way, Bedrock, Washingstone',
birthMonth: 'February',
birthMonthId: 'month2',
icon: 'bookmark',
iconStyleClass: 'fa fa-bookmark',
weekDay: 'Sunday',
weekdayId: 'day1'
}, {
name: 'John Smith', address: '415 East Main Street, Norfolk, Virginia',
birthMonth: 'October',
birthMonthId: '10',
icon: 'map',
iconStyleClass: 'fa fa-map-marker',
weekDay: 'Monday',
weekdayId: 'day2'
}, {
name: 'Frank Livingston',
address: '234 Elm Street, Pittsburgh, Pennsylvania',
birthMonth: 'March',
birthMonthId: 'month3',
icon: 'gift',
iconStyleClass: 'fa fa-gift',
weekDay: 'Tuesday',
weekdayId: 'day3'
}, {
name: 'Judy Green',
address: '2 Apple Boulevard, Cincinatti, Ohio',
birthMonth: 'December',
birthMonthId: 'month12',
icon: 'map',
iconStyleClass: 'fa fa-map-marker',
weekDay: 'Wednesday',
weekdayId: 'day4'
}, {
name: 'Pat Thomas',
address: '50 Second Street, New York, New York',
birthMonth: 'February',
birthMonthId: 'month2',
icon: 'bookmark',
iconStyleClass: 'fa fa-bookmark',
weekDay: 'Thursday',
weekdayId: 'day5'
}];
this.items = this.allItems;

this.filterConfig = {
fields: [{
id: 'icon',
title: 'By Icon',
placeholder: 'Filter by Icon...',
type: FilterType.SELECT,
queries: [{
id: 'bookmark',
value: 'bookmark',
iconStyleClass: 'fa fa-bookmark'
}, {
id: 'map',
value: 'map',
iconStyleClass: 'fa fa-map-marker'
}, {
id: 'gift',
value: 'gift',
iconStyleClass: 'fa fa-gift'
}]
}] as FilterField[],
resultsCount: this.items.length,
appliedFilters: []
} as FilterConfig;
}

// Filter functions

applyFilters(filters: Filter[]): void {
this.items = [];
if (filters && filters.length > 0) {
this.allItems.forEach((item) => {
if (this.matchesFilters(item, filters)) {
this.items.push(item);
}
});
} else {
this.items = this.allItems;
}
this.filterConfig.resultsCount = this.items.length;
}

filterChanged($event: FilterEvent): void {
this.filtersText = '';
$event.appliedFilters.forEach((filter) => {
this.filtersText += filter.field.title + ' : ' + filter.value + '\n';
});
this.applyFilters($event.appliedFilters);
}

matchesFilter(item: any, filter: Filter): boolean {
let match = true;
if (filter.field.id === 'icon') {
match = item.icon === filter.value;
}
return match;
}

matchesFilters(item: any, filters: Filter[]): boolean {
let matches = true;
filters.forEach((filter) => {
if (!this.matchesFilter(item, filter)) {
matches = false;
return matches;
}
});
return matches;
}
}
1 change: 1 addition & 0 deletions src/app/filter/example/filter-lazy-example.component.html
Expand Up @@ -4,6 +4,7 @@
<div class="form-group">
<p>Warning: This example is for development testing purposes. It is not an official pattern and subject to change</p>
<p>This ensures filters can be added lazily. Click the "Load Filters" button to add more filter options</p>
<p>The 'Week Day' filter field is shown as a type ahead for testing</p>
<pfng-filter [config]="filterConfig"
(onChange)="filterChanged($event)"
(onFieldSelect)="filterFieldSelected($event)"
Expand Down

0 comments on commit c03e642

Please sign in to comment.