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 0000000..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 0000000..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()
+ } );
+
+ if ( self.value() === '' ) {
+ params.queryString( '' );
+ return;
+ }
+ var parts = self.selectedOperator().split( '|' );
+
+ if ( parts.length === 1 ) {
+ params.queryString( params.name + ' eq \'' +
self.value() + '\'' );
+ return;
+ }
+ params.queryString( parts[1] + '(\'' + self.value() +
'\',' + params.name + ')' );
+ };
+
+ this.selectedOperator.subscribe( this.changed );
+ this.value.subscribe( this.changed );
+ }
+
+ return { viewModel: TextFilterViewModel, template: template };
+} );
--
To view, visit https://gerrit.wikimedia.org/r/200097
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If2424596ce43afce1f1a40e843d9d54bb16673c2
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits