Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/257202
Change subject: Fix filter summary for non-dropdowns ...................................................................... Fix filter summary for non-dropdowns FIXME: introduce a filter base class with this functionality, override it in dropdown-filter. Change-Id: I3867f92932a4202d083e22afac017d4201b89276 --- M src/app/require.config.js M src/app/widgetBase.js A src/components/filters/operators.js 3 files changed, 67 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash refs/changes/02/257202/1 diff --git a/src/app/require.config.js b/src/app/require.config.js index 5a06a8a..ea6a69d 100644 --- a/src/app/require.config.js +++ b/src/app/require.config.js @@ -25,7 +25,8 @@ 'c3': 'bower_modules/c3/c3', 'numeraljs': 'bower_modules/numeraljs/numeral', 'decemberData': 'bower_modules/fakeData/decemberData', - 'WidgetBase': 'app/widgetBase' + 'WidgetBase': 'app/widgetBase', + 'operators': 'components/filters/operators' }, shim: { 'bootstrap': { diff --git a/src/app/widgetBase.js b/src/app/widgetBase.js index 77369a4..71d623b 100644 --- a/src/app/widgetBase.js +++ b/src/app/widgetBase.js @@ -1,8 +1,8 @@ define([ 'jquery', 'knockout', - 'momentjs' -], function( $, ko, moment ){ + 'operators' +], function( $, ko, ops ){ function zeroPad( number ) { if ( number < 10 ) { @@ -42,17 +42,45 @@ localStorage.setItem( storageKey, JSON.stringify( fetchedData ) ); } ); } )(); + self.filterText = ko.computed( function() { - var filterName, text, parts = [], choices = self.userChoices(); + var filterName, + text, + parts = [], + choices = self.userChoices(), + filterChoices, + operator; + for ( filterName in choices ) { - if ( !choices.hasOwnProperty( filterName ) || choices[filterName].length === 0 ) { + if ( !choices.hasOwnProperty( filterName ) ) { continue; } - text = filterName; - if ( choices[filterName].length === 1 ) { - text += ' = ' + choices[filterName][0]; + text = filterName + ' '; + filterChoices = choices[filterName]; + // FIXME: this should be part of a filter base class so different + // types of filter can define their own summary text generation + if ( filterChoices.constructor === Array ) { + // Dropdown filter + if ( filterChoices.length === 0 ) { + continue; + } + if ( filterChoices.length === 1 ) { + text += '= ' + filterChoices[0]; + } else { + text += 'in (' + filterChoices.join( ', ' ) + ')'; + } } else { - text += ' in (' + choices[filterName].join( ', ' ) + ')'; + // Text or numeric filter + if ( filterChoices.value === '' ) { + continue; + } + operator = ops[filterChoices.operator]; + if ( operator.abbr ) { + text += operator.abbr; + } else { + text += operator.text.toLowerCase(); + } + text += ' ' + filterChoices.value; } parts.push( text ); } diff --git a/src/components/filters/operators.js b/src/components/filters/operators.js new file mode 100644 index 0000000..a3ba22e --- /dev/null +++ b/src/components/filters/operators.js @@ -0,0 +1,29 @@ +define({ + gt: { + value: 'gt', + text: 'Greater than', + abbr: '>' + }, + lt: { + value: 'lt', + text: 'Less than', + abbr: '<' + }, + eq: { + value: 'eq', + text: 'Equal to', + abbr: '=' + }, + startswith: { + value: 'fn|startswith', + text: 'Starts with' + }, + endswith: { + value: 'fn|endswith', + text: 'Ends with' + }, + substringof: { + value: 'fn|substringof', + text: 'Contains' + } +}); -- To view, visit https://gerrit.wikimedia.org/r/257202 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3867f92932a4202d083e22afac017d4201b89276 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/dash Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits