[MediaWiki-commits] [Gerrit] Add text filters - change (wikimedia...dash)
Cdentinger has submitted this change and it was merged. Change subject: Add text filters .. Add text filters With 'Exactly', 'Contains', 'Starts with' and 'Ends with' TODO: investigate save bug. Saving a combination of text and selection filters and reloading the page sometimes seems to lose filters. Change-Id: If2424596ce43afce1f1a40e843d9d54bb16673c2 --- M src/app/startup.js M src/components/filters/filters.js A src/components/filters/text-filter/text-filter.html A src/components/filters/text-filter/text-filter.js 4 files changed, 68 insertions(+), 5 deletions(-) Approvals: Cdentinger: Looks good to me, approved diff --git a/src/app/startup.js b/src/app/startup.js index 2aab429..1463a94 100644 --- a/src/app/startup.js +++ b/src/app/startup.js @@ -19,6 +19,7 @@ //register filters ko.components.register( 'filters',{ require: 'components/filters/filters' }); ko.components.register( 'dropdown-filter',{ require: 'components/filters/dropdown-filter/dropdown-filter' }); + ko.components.register( 'text-filter',{ require: 'components/filters/text-filter/text-filter' }); //register individual widgets ko.components.register( 'fraud-gauge',{ require: 'components/widgets/fraud-gauge/fraud-gauge' }); diff --git a/src/components/filters/filters.js b/src/components/filters/filters.js index 6836419..c359c51 100644 --- a/src/components/filters/filters.js +++ b/src/components/filters/filters.js @@ -37,11 +37,16 @@ metadata: filterMeta, queryString: ko.observable('') }; - if ( filterMeta.type === 'dropdown' ) { - filter.userChoices = ko.observableArray( params.userChoices()[name] || [] ); - } else { - return;//temporarily only doing dropdown filters - //filter.userChoices = ko.observable( params.userChoices()[name] ); + switch( filterMeta.type ) { + case 'dropdown': + filter.userChoices = ko.observableArray( params.userChoices()[name] || [] ); + break; + case 'text': + filter.userChoices = ko.observable( params.userChoices()[name] || {} ); + break; + default: + //not yet supported filter type + return; } filter.queryString.subscribe( self.setChoices ); self.filters.push( filter ); diff --git a/src/components/filters/text-filter/text-filter.html b/src/components/filters/text-filter/text-filter.html new file mode 100644 index 000..1821328 --- /dev/null +++ b/src/components/filters/text-filter/text-filter.html @@ -0,0 +1,2 @@ +select data-bind=options:operators, value: selectedOperator, optionsText: 'text', optionsValue: 'value'/select +input type=text data-bind=value:value / diff --git a/src/components/filters/text-filter/text-filter.js b/src/components/filters/text-filter/text-filter.js new file mode 100644 index 000..a977951 --- /dev/null +++ b/src/components/filters/text-filter/text-filter.js @@ -0,0 +1,55 @@ +define( [ + 'knockout', + 'text!components/filters/text-filter/text-filter.html' + ], +function( ko, template ){ + + function TextFilterViewModel( params ){ + var self = this; + + this.operators = [ + { + value: 'eq', + text: 'Exactly' + }, + { + value: 'fn|startswith', + text: 'Starts with' + }, + { + value: 'fn|endswith', + text: 'Ends with' + }, + { + value: 'fn|substringof', + text: 'Contains' + } + ]; + this.selectedOperator = ko.observable( params.userChoices().operator || 'eq' ); + this.value = ko.observable( params.userChoices().value || '' ); + + this.changed = function() { +
[MediaWiki-commits] [Gerrit] Add text filters - change (wikimedia...dash)
Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/200097 Change subject: Add text filters .. Add text filters With 'Exactly', 'Contains', 'Starts with' and 'Ends with' Change-Id: If2424596ce43afce1f1a40e843d9d54bb16673c2 --- M src/app/startup.js M src/components/filters/filters.js A src/components/filters/text-filter/text-filter.html A src/components/filters/text-filter/text-filter.js 4 files changed, 68 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash refs/changes/97/200097/1 diff --git a/src/app/startup.js b/src/app/startup.js index 8e90dc0..a7665ea 100644 --- a/src/app/startup.js +++ b/src/app/startup.js @@ -21,6 +21,7 @@ //register filters ko.components.register( 'filters',{ require: 'components/filters/filters' }); ko.components.register( 'dropdown-filter',{ require: 'components/filters/dropdown-filter/dropdown-filter' }); +ko.components.register( 'text-filter', { require: 'components/filters/text-filter/text-filter' }); //register individual widgets ko.components.register( 'fraud-gauge',{ require: 'components/widgets/fraud-gauge/fraud-gauge' }); diff --git a/src/components/filters/filters.js b/src/components/filters/filters.js index 6836419..c359c51 100644 --- a/src/components/filters/filters.js +++ b/src/components/filters/filters.js @@ -37,11 +37,16 @@ metadata: filterMeta, queryString: ko.observable('') }; - if ( filterMeta.type === 'dropdown' ) { - filter.userChoices = ko.observableArray( params.userChoices()[name] || [] ); - } else { - return;//temporarily only doing dropdown filters - //filter.userChoices = ko.observable( params.userChoices()[name] ); + switch( filterMeta.type ) { + case 'dropdown': + filter.userChoices = ko.observableArray( params.userChoices()[name] || [] ); + break; + case 'text': + filter.userChoices = ko.observable( params.userChoices()[name] || {} ); + break; + default: + //not yet supported filter type + return; } filter.queryString.subscribe( self.setChoices ); self.filters.push( filter ); diff --git a/src/components/filters/text-filter/text-filter.html b/src/components/filters/text-filter/text-filter.html new file mode 100644 index 000..1821328 --- /dev/null +++ b/src/components/filters/text-filter/text-filter.html @@ -0,0 +1,2 @@ +select data-bind=options:operators, value: selectedOperator, optionsText: 'text', optionsValue: 'value'/select +input type=text data-bind=value:value / diff --git a/src/components/filters/text-filter/text-filter.js b/src/components/filters/text-filter/text-filter.js new file mode 100644 index 000..f194fdf --- /dev/null +++ b/src/components/filters/text-filter/text-filter.js @@ -0,0 +1,55 @@ +define( [ + 'knockout', + 'text!components/filters/text-filter/text-filter.html' + ], +function( ko, template ){ + + function TextFilterViewModel( params ){ + var self = this; + + this.operators = [ + { + value: 'eq', + text: 'Exactly' + }, + { + value: 'fn|startswith', + text: 'Starts with' + }, + { + value: 'fn|endswith', + text: 'Ends with' + }, + { + value: 'fn|substringof', + text: 'Contains' + } + ]; + this.selectedOperator = ko.observable( params.userChoices().operator || 'eq' ); + this.value = ko.observable( params.userChoices().value || '' ); + + this.changed = function() { + params.userChoices( { + operator: self.selectedOperator(), + value: self.value() +