Gabriel Birke has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371072 )

Change subject: Separate values in multiterm search preview
......................................................................

Separate values in multiterm search preview

The prototype in issue T171756 shows that mult-term field values should
be separated with commas.

Change-Id: I47c00c3234d4b30bf6993e0c338c1d1f1ef2325f
---
M extension.json
M modules/ui/ext.advancedSearch.SearchPreview.js
M tests/qunit/ui/SearchPreview.test.js
3 files changed, 42 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AdvancedSearch 
refs/changes/72/371072/1

diff --git a/extension.json b/extension.json
index 2697ac0..3b54d8c 100644
--- a/extension.json
+++ b/extension.json
@@ -201,6 +201,11 @@
                        ],
                        "dependencies": [
                                "oojs-ui"
+                       ],
+                       "messages": [
+                               "advancedSearch-filesize-equals",
+                               "advancedSearch-filesize-greater-than",
+                               "advancedSearch-filesize-smaller-than"
                        ]
                },
                "ext.advancedSearch.ui.TextInput": {
diff --git a/modules/ui/ext.advancedSearch.SearchPreview.js 
b/modules/ui/ext.advancedSearch.SearchPreview.js
index f2e47a4..8a39611 100644
--- a/modules/ui/ext.advancedSearch.SearchPreview.js
+++ b/modules/ui/ext.advancedSearch.SearchPreview.js
@@ -5,6 +5,17 @@
        mw.libs.advancedSearch = mw.libs.advancedSearch || {};
        mw.libs.advancedSearch.ui = mw.libs.advancedSearch.ui || {};
 
+       var fileComparatorToMessage = function ( comparator ) {
+               switch ( comparator ) {
+                       case '':
+                               return 'advancedSearch-filesize-equals';
+                       case '>':
+                               return 'advancedSearch-filesize-greater-than';
+                       case '<':
+                               return 'advancedSearch-filesize-smaller-than';
+               }
+       };
+
        /**
         * @class
         * @extends {OO.ui.Widget}
@@ -92,7 +103,7 @@
         * @return {OO.ui.TagItemWidget}
         */
        mw.libs.advancedSearch.ui.SearchPreview.prototype.generateTag = 
function ( optionId, value ) {
-               var formattedValue = this.formatValue( value ),
+               var formattedValue = this.formatValue( optionId, value ),
                        tag = new OO.ui.TagItemWidget( {
                                label: mw.msg( 'advancedsearch-field-' + 
optionId ),
                                content: [
@@ -124,12 +135,22 @@
        /**
         * Format a value to be used in the preview
         *
+        * @param {string} optionId
         * @param {string|array} value
         * @return {string}
         */
-       mw.libs.advancedSearch.ui.SearchPreview.prototype.formatValue = 
function ( value ) {
+       mw.libs.advancedSearch.ui.SearchPreview.prototype.formatValue = 
function ( optionId, value ) {
+               if ( optionId.match( '^file[hw]$' ) && $.isArray( value ) ) {
+                       return mw.msg( fileComparatorToMessage( value[ 0 ] ) ) 
+ ' ' + value[ 1 ];
+               }
                if ( $.isArray( value ) ) {
-                       value = value.join( ' ' );
+                       return $.grep(
+                               $.map( value, function ( v ) {
+                                       return String( v ).trim();
+                               } ),
+                               function ( v ) {
+                                       return v !== '';
+                               } ).join( ', ' );
                }
 
                return value.trim();
diff --git a/tests/qunit/ui/SearchPreview.test.js 
b/tests/qunit/ui/SearchPreview.test.js
index e316656..508d958 100644
--- a/tests/qunit/ui/SearchPreview.test.js
+++ b/tests/qunit/ui/SearchPreview.test.js
@@ -150,18 +150,22 @@
 
        QUnit.test( 'Values get formatted well', 9, function ( assert ) {
                var searchPreview = new SearchPreview( store, config );
+               var translationStub = sandbox.stub( mw, 'msg' );
+               translationStub.withArgs( 'advancedSearch-filesize-equals' 
).returns( '=' );
+               translationStub.withArgs( 
'advancedSearch-filesize-greater-than' ).returns( '>' );
+               translationStub.withArgs( 
'advancedSearch-filesize-smaller-than' ).returns( '<' );
 
-               assert.equal( searchPreview.formatValue( '' ), '' );
-               assert.equal( searchPreview.formatValue( 'hello' ), 'hello' );
-               assert.equal( searchPreview.formatValue( ' stray whitespace  ' 
), 'stray whitespace' );
+               assert.equal( searchPreview.formatValue( 'someOption', '' ), '' 
);
+               assert.equal( searchPreview.formatValue( 'someOption', 'hello' 
), 'hello' );
+               assert.equal( searchPreview.formatValue( 'someOption', ' stray 
whitespace  ' ), 'stray whitespace' );
 
-               assert.equal( searchPreview.formatValue( [ '', '' ] ), '' );
-               assert.equal( searchPreview.formatValue( [ '', 1000 ] ), '1000' 
);
-               assert.equal( searchPreview.formatValue( [ '>', 300 ] ), '> 
300' );
-               assert.equal( searchPreview.formatValue( [ '<', 1400 ] ), '< 
1400' );
+               assert.equal( searchPreview.formatValue( 'someOption', [ '', '' 
] ), '' );
+               assert.equal( searchPreview.formatValue( 'fileh', [ '', 1000 ] 
), '= 1000' );
+               assert.equal( searchPreview.formatValue( 'fileh', [ '>', 300 ] 
), '> 300' );
+               assert.equal( searchPreview.formatValue( 'filew', [ '<', 1400 ] 
), '< 1400' );
 
-               assert.equal( searchPreview.formatValue( [ 'some', 'words', 
'in', 'combination' ] ), 'some words in combination' );
-               assert.equal( searchPreview.formatValue( [ '', ' stray', 
'whitespace  ' ] ), 'stray whitespace' );
+               assert.equal( searchPreview.formatValue( 'someOption', [ 
'some', 'words', 'in', 'combination' ] ), 'some, words, in, combination' );
+               assert.equal( searchPreview.formatValue( 'someOption', [ '', ' 
stray', 'whitespace  ' ] ), 'stray, whitespace' );
        } );
 
 }( jQuery, QUnit, sinon, mediaWiki ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/371072
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I47c00c3234d4b30bf6993e0c338c1d1f1ef2325f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AdvancedSearch
Gerrit-Branch: master
Gerrit-Owner: Gabriel Birke <gabriel.bi...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to