diff --git a/config/webpack.demo.js b/config/webpack.demo.js index acbbe16..e2adeac 100644 --- a/config/webpack.demo.js +++ b/config/webpack.demo.js @@ -35,13 +35,7 @@ module.exports = { }, resolve: { - extensions: ['.webpack.js', '.wep.js', '.js', '.ts'], - plugins: [ - // Todo: config is not loading. - new TsConfigPathsPlugin({ - configFileName: helpers.root("tsconfig-demo.json") - }) - ] + extensions: ['.webpack.js', '.wep.js', '.js', '.ts'] }, stats: { @@ -124,6 +118,11 @@ module.exports = { */ new NamedModulesPlugin(), + // Todo: config is not loading. + new TsConfigPathsPlugin({ + configFileName: helpers.root("tsconfig-demo.json") + }), + /** * Plugin: ContextReplacementPlugin * Description: Provides context to Angular's use of System.import diff --git a/index.ts b/index.ts index ea0b223..0cb8972 100644 --- a/index.ts +++ b/index.ts @@ -31,6 +31,7 @@ export { FilterEvent } from './src/app/filters/filter-event'; export { FilterField } from './src/app/filters/filter-field'; export { FilterFieldsComponent } from './src/app/filters/filter-fields.component'; export { FilterResultsComponent } from './src/app/filters/filter-results.component'; +export { FilterQuery } from './src/app/filters/filter-query'; // Notification export { ToastNotificationComponent } from './src/app/notification/toast-notification.component'; diff --git a/src/app/filters/examples/filter-example.component.ts b/src/app/filters/examples/filter-example.component.ts index 974877c..ca6ab63 100644 --- a/src/app/filters/examples/filter-example.component.ts +++ b/src/app/filters/examples/filter-example.component.ts @@ -26,63 +26,92 @@ export class FilterExampleComponent implements OnInit { } ngOnInit(): void { - this.allItems = [ - { - name: "Fred Flintstone", - address: "20 Dinosaur Way, Bedrock, Washingstone", - birthMonth: 'February' - }, - { - name: "John Smith", - address: "415 East Main Street, Norfolk, Virginia", - birthMonth: 'October' - }, - { - name: "Frank Livingston", - address: "234 Elm Street, Pittsburgh, Pennsylvania", - birthMonth: 'March' - }, - { - name: "Judy Green", - address: "2 Apple Boulevard, Cincinatti, Ohio", - birthMonth: 'December' - }, - { - name: "Pat Thomas", - address: "50 Second Street, New York, New York", - birthMonth: 'February' - } - ]; + this.allItems = [{ + name: "Fred Flintstone", + address: "20 Dinosaur Way, Bedrock, Washingstone", + birthMonth: 'February', + birthMonthId: 'month2' + },{ + name: "John Smith", address: "415 East Main Street, Norfolk, Virginia", + birthMonth: 'October', + birthMonthId: '10' + },{ + name: "Frank Livingston", + address: "234 Elm Street, Pittsburgh, Pennsylvania", + birthMonth: 'March', + birthMonthId: 'month3' + },{ + name: "Judy Green", + address: "2 Apple Boulevard, Cincinatti, Ohio", + birthMonth: 'December', + birthMonthId: 'month12' + },{ + name: "Pat Thomas", + address: "50 Second Street, New York, New York", + birthMonth: 'February', + birthMonthId: 'month2' + }]; this.items = this.allItems; this.filterConfig = { - fields: [ - { - id: 'name', - title: 'Name', - placeholder: 'Filter by Name...', - filterType: 'text' - }, - { - id: 'age', - title: 'Age', - placeholder: 'Filter by Age...', - filterType: 'text' - }, - { - id: 'address', - title: 'Address', - placeholder: 'Filter by Address...', - filterType: 'text' - }, - { - id: 'birthMonth', - title: 'Birth Month', - placeholder: 'Filter by Birth Month...', - filterType: 'select', - filterValues: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] - } - ] as FilterField[], + fields: [{ + id: 'name', + title: 'Name', + placeholder: 'Filter by Name...', + type: 'text' + },{ + id: 'age', + title: 'Age', + placeholder: 'Filter by Age...', + type: 'text' + },{ + id: 'address', + title: 'Address', + placeholder: 'Filter by Address...', + type: 'text' + },{ + id: 'birthMonth', + title: 'Birth Month', + placeholder: 'Filter by Birth Month...', + type: 'select', + queries: [{ + id: 'month1', + value: 'January' + },{ + id: 'month2', + value: 'February' + },{ + id: 'month3', + value: 'March' + },{ + id: 'month4', + value: 'April' + },{ + id: 'month5', + value: 'May' + },{ + id: 'month6', + value: 'June' + },{ + id: 'month7', + value: 'July' + },{ + id: 'month8', + value: 'August' + },{ + id: 'month9', + value: 'September' + },{ + id: 'month10', + value: 'October' + },{ + id: 'month11', + value: 'November' + },{ + id: 'month12', + value: 'December' + }] + }] as FilterField[], resultsCount: this.items.length, appliedFilters: [] } as FilterConfig; @@ -107,7 +136,7 @@ export class FilterExampleComponent implements OnInit { filterChange($event: FilterEvent): void { this.filtersText = ""; $event.appliedFilters.forEach((filter) => { - this.filtersText += filter.title + " : " + filter.value + "\n"; + this.filtersText += filter.field.title + " : " + filter.value + "\n"; }); this.applyFilters($event.appliedFilters); } @@ -115,11 +144,11 @@ export class FilterExampleComponent implements OnInit { matchesFilter(item: any, filter: Filter): boolean { let match = true; - if (filter.id === 'name') { + if (filter.field.id === 'name') { match = item.name.match(filter.value) !== null; - } else if (filter.id === 'address') { + } else if (filter.field.id === 'address') { match = item.address.match(filter.value) !== null; - } else if (filter.id === 'birthMonth') { + } else if (filter.field.id === 'birthMonth') { match = item.birthMonth === filter.value; } return match; diff --git a/src/app/filters/filter-event.ts b/src/app/filters/filter-event.ts index 86de6e9..162b7da 100644 --- a/src/app/filters/filter-event.ts +++ b/src/app/filters/filter-event.ts @@ -1,15 +1,18 @@ import { Filter } from './filter'; import { FilterField } from './filter-field'; +import { FilterQuery } from './filter-query'; /* * A filter event containing: * * appliedFilters - List of the currently applied filters * field - A filterable field + * query - A filterable query * value - The filter input field value */ export class FilterEvent { appliedFilters?: Filter[]; - field?: FilterField; + field: FilterField; + query: FilterQuery; value?: string; } diff --git a/src/app/filters/filter-field.ts b/src/app/filters/filter-field.ts index 4fe3679..7c6c69d 100644 --- a/src/app/filters/filter-field.ts +++ b/src/app/filters/filter-field.ts @@ -1,16 +1,18 @@ +import { FilterQuery } from './filter-query'; + /* * A filterable field containing: * * id - Optional unique Id for the filter field, useful for comparisons - * title - The title to display for the filter field * placeholder - Optional text to display when no filter value has been entered - * filterType - The filter input field type (any html input type, or 'select' for a select box) - * filterValues - Optional list of values used when filterType is 'select' + * queries - Optional list of filter queries used when filterType is 'select' + * title - The title to display for the filter field + * type - The filter input field type (any html input type, or 'select' for a select box) */ export class FilterField { id?: string; - title: string; placeholder?: string; - filterType: string; - filterValues?: string[]; + queries?: FilterQuery[]; + title: string; + type: string; } diff --git a/src/app/filters/filter-fields.component.html b/src/app/filters/filter-fields.component.html index 459dd9a..b302a9d 100644 --- a/src/app/filters/filter-fields.component.html +++ b/src/app/filters/filter-fields.component.html @@ -6,19 +6,19 @@
-