jenkins-bot has submitted this change and it was merged.

Change subject: Avoid duplicate code by inlining and using || for defaults
......................................................................


Avoid duplicate code by inlining and using || for defaults

Change-Id: I5c7892385b70450f9e7cbf455e432a18dbf9ce84
---
M wikibase/queryService/api/Sparql.js
M wikibase/queryService/ui/App.js
M wikibase/queryService/ui/QueryExampleDialog.js
M wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
M wikibase/queryService/ui/resultBrowser/BubbleChartResultBrowser.js
M wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
M wikibase/queryService/ui/resultBrowser/GraphResultBrowser.js
M wikibase/queryService/ui/resultBrowser/TimelineResultBrowser.js
M wikibase/queryService/ui/resultBrowser/TreeMapResultBrowser.js
M wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
M wikibase/queryService/ui/visualEditor/SelectorBox.js
M wikibase/queryService/ui/visualEditor/SparqlQuery.js
M wikibase/queryService/ui/visualEditor/VisualEditor.js
13 files changed, 28 insertions(+), 86 deletions(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikibase/queryService/api/Sparql.js 
b/wikibase/queryService/api/Sparql.js
index 40b939c..daec77a 100644
--- a/wikibase/queryService/api/Sparql.js
+++ b/wikibase/queryService/api/Sparql.js
@@ -20,12 +20,7 @@
         * @param {string} [serviceUri] Optional URI to the SPARQL service 
endpoint
         */
        function SELF( serviceUri ) {
-
-               if ( serviceUri ) {
-                       this._serviceUri = serviceUri;
-               } else {
-                       this._serviceUri = SPARQL_SERVICE_URI;
-               }
+               this._serviceUri = serviceUri || SPARQL_SERVICE_URI;
        }
 
        /**
diff --git a/wikibase/queryService/ui/App.js b/wikibase/queryService/ui/App.js
index 2a2e71e..6eeb70d 100644
--- a/wikibase/queryService/ui/App.js
+++ b/wikibase/queryService/ui/App.js
@@ -545,8 +545,7 @@
                this._updateQueryUrl();
                this._actionBar.show( 'wdqs-action-query', 'info', 100 );
 
-               $( '#query-result' ).empty( '' );
-               $( '#query-result' ).hide();
+               $( '#query-result' ).empty().hide();
                $( '.query-total' ).hide();
                $( '#execute-button' ).prop( 'disabled', true );
                $( '#query-error' ).hide();
diff --git a/wikibase/queryService/ui/QueryExampleDialog.js 
b/wikibase/queryService/ui/QueryExampleDialog.js
index 04f1647..a9b97f2 100644
--- a/wikibase/queryService/ui/QueryExampleDialog.js
+++ b/wikibase/queryService/ui/QueryExampleDialog.js
@@ -99,7 +99,7 @@
                                if ( example.category !==  category ) {
                                        category = example.category;
                                        self._$element.find( '.searchable' 
).append( $( '<tr>' ).addClass( 'active' )
-                                                       .append( $( '<td 
colspan="100%">' ).text( category ) ) );
+                                                       .append( $( '<td 
colspan="2">' ).text( category ) ) );
                                }
                                self._addExample( example.title, example.query, 
example.href, example.tags );
                        } );
diff --git a/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
index 4818c6c..325f006 100644
--- a/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
@@ -65,12 +65,8 @@
 
                $.each( this._result.results.bindings, function( rowNum, row ) {
                        $.each( self._result.head.vars, function( rowNum1, key 
) {
-                               var field = null;
-                               if ( row[key] ) {
-                                       field = row[key];
-                               }
+                               var field = row[key] || null;
                                self.processVisitors( field, key );
-
                                cb( field, key, row, rowNum );
                        } );
                } );
diff --git a/wikibase/queryService/ui/resultBrowser/BubbleChartResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/BubbleChartResultBrowser.js
index 3892988..ddda3b2 100644
--- a/wikibase/queryService/ui/resultBrowser/BubbleChartResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/BubbleChartResultBrowser.js
@@ -151,12 +151,7 @@
         * @return {boolean}
         */
        SELF.prototype.isDrawable = function() {
-
-               if ( this._hasLabel && this._hasNumber ) {
-                       return true;
-               }
-
-               return false;
+               return this._hasLabel && this._hasNumber;
        };
 
        /**
@@ -182,11 +177,7 @@
                        this._hasLabel = true;
                }
 
-               if ( this._hasLabel && this._hasNumber ) {
-                       return false;
-               }
-
-               return true;
+               return !this.isDrawable();
        };
 
        /**
diff --git a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
index 88a4f43..1c6a8ae 100644
--- a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
@@ -144,9 +144,7 @@
                } );
 
                if ( Object.keys( markers ).length === 0 ) {
-                       var marker = L.marker( [
-                                       0, 0
-                       ] ).bindPopup( 'Nothing found!' ).openPopup();
+                       var marker = L.marker( [ 0, 0 ] ).bindPopup( 'Nothing 
found!' ).openPopup();
                        return { null: L.featureGroup( [marker] ) };
                }
 
diff --git a/wikibase/queryService/ui/resultBrowser/GraphResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/GraphResultBrowser.js
index e8ce7ed..adac217 100644
--- a/wikibase/queryService/ui/resultBrowser/GraphResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/GraphResultBrowser.js
@@ -148,11 +148,10 @@
 
                } );
 
-               var result = {
+               return {
                        nodes: new vis.DataSet( _.compact( nodes ) ),
                        edges: new vis.DataSet( _.compact( edges ) )
                };
-               return result;
        };
 
        /**
diff --git a/wikibase/queryService/ui/resultBrowser/TimelineResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/TimelineResultBrowser.js
index a705ab7..fb0c2c4 100644
--- a/wikibase/queryService/ui/resultBrowser/TimelineResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/TimelineResultBrowser.js
@@ -47,21 +47,18 @@
         * @private
         */
        SELF.prototype._getItems = function() {
-               var items = [];
+               var self = this,
+                       items = [];
 
-               var self = this, item = {};
                this._iterateResult( function( field, key, row, rowIndex ) {
 
                        if ( self._getFormatter().isDateTime( field ) ) {
                                if ( !items[rowIndex] ) {// create new
-                                       var startDate = 
self._getFormatter().parseDate( field.value );
-                                       item = {
+                                       items[rowIndex] = {
                                                id: rowIndex,
                                                content: self._getHtml( row 
).html(),
-                                               start: startDate
+                                               start: 
self._getFormatter().parseDate( field.value )
                                        };
-                                       items[rowIndex] = item;
-
                                } else { // create time span with start and end 
date
                                        var dates = [];
                                        dates.push( 
self._getFormatter().parseDate( field.value ) );
diff --git a/wikibase/queryService/ui/resultBrowser/TreeMapResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/TreeMapResultBrowser.js
index 0ea208f..ad03aeb 100644
--- a/wikibase/queryService/ui/resultBrowser/TreeMapResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/TreeMapResultBrowser.js
@@ -365,11 +365,7 @@
         * @return {boolean}
         */
        SELF.prototype.isDrawable = function() {
-
-               if ( Object.keys( this._labelColumns ).length > 1 ) {
-                       return true;
-               }
-               return false;
+               return Object.keys( this._labelColumns ).length > 1;
        };
 
        /**
@@ -389,10 +385,7 @@
 
                if ( this._getFormatter().isLabel( value, key ) ) {
                        this._labelColumns[key] = true;
-
-                       if ( Object.keys( this._labelColumns ).length > 1 ) {
-                               return false;
-                       }
+                       return !this.isDrawable();
                }
 
                return true;
diff --git a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js 
b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
index eef9df0..2808d8b 100644
--- a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
+++ b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
@@ -285,7 +285,10 @@
         * Handler for explore links
         */
        SELF.prototype.handleExploreItem = function( e ) {
-               var id, url = $( e.target ).attr( 'href' ) || '', match;
+               var id,
+                       url = $( e.target ).attr( 'href' ) || '',
+                       match;
+
                e.preventDefault();
 
                match = url.match( EXPLORE_URL + '(.+)' );
diff --git a/wikibase/queryService/ui/visualEditor/SelectorBox.js 
b/wikibase/queryService/ui/visualEditor/SelectorBox.js
index 3af306a..93d97f4 100644
--- a/wikibase/queryService/ui/visualEditor/SelectorBox.js
+++ b/wikibase/queryService/ui/visualEditor/SelectorBox.js
@@ -17,12 +17,7 @@
         * @param {wikibase.queryService.api.Wikibase} [api]
         */
        function SELF( api ) {
-
-               if ( api ) {
-                       this._api = api;
-               } else {
-                       this._api = new wikibase.queryService.api.Wikibase();
-               }
+               this._api = api || new wikibase.queryService.api.Wikibase();
        }
 
        /**
@@ -66,11 +61,7 @@
                                return $content;
                        }
                } ).click( function( e ) {
-                       if ( $element.data( 'value' ) ) {
-                               $input.val( $element.data( 'value' ) );
-                       } else {
-                               $input.val( '' );
-                       }
+                       $input.val( $element.data( 'value' ) || '' );
                } );
 
                $input.on( 'keyup mouseup', function() {
diff --git a/wikibase/queryService/ui/visualEditor/SparqlQuery.js 
b/wikibase/queryService/ui/visualEditor/SparqlQuery.js
index 3f8de44..851566d 100644
--- a/wikibase/queryService/ui/visualEditor/SparqlQuery.js
+++ b/wikibase/queryService/ui/visualEditor/SparqlQuery.js
@@ -50,8 +50,7 @@
         */
        SELF.prototype.getQueryString = function() {
                try {
-                       var q = new sparqljs.Generator().stringify( this._query 
);
-                       return q;
+                       return new sparqljs.Generator().stringify( this._query 
);
                } catch ( e ) {
                        return null;
                }
@@ -98,11 +97,7 @@
                        return true;
                }
 
-               if ( this._query.variables.indexOf( name ) >= 0 ) {
-                       return true;
-               }
-
-               return false;
+               return this._query.variables.indexOf( name ) >= 0;
        };
 
        /**
diff --git a/wikibase/queryService/ui/visualEditor/VisualEditor.js 
b/wikibase/queryService/ui/visualEditor/VisualEditor.js
index f5d8628..4563b2e 100644
--- a/wikibase/queryService/ui/visualEditor/VisualEditor.js
+++ b/wikibase/queryService/ui/visualEditor/VisualEditor.js
@@ -27,17 +27,9 @@
         * @param {wikibase.queryService.ui.visualEditor.SelectorBox} 
[selectorBox]
         */
        function SELF( api, selectorBox ) {
-               this._api = api;
-
-               if ( !this._api ) {
-                       this._api = new wikibase.queryService.api.Wikibase();
-               }
-
-               this._selectorBox = selectorBox;
-               if ( !this._selectorBox ) {
-                       this._selectorBox = new 
wikibase.queryService.ui.visualEditor.SelectorBox( this._api );
-               }
-
+               this._api = api || new wikibase.queryService.api.Wikibase();
+               this._selectorBox = selectorBox
+                       || new 
wikibase.queryService.ui.visualEditor.SelectorBox( this._api );
                this._query = new 
wikibase.queryService.ui.visualEditor.SparqlQuery();
        }
 
@@ -253,7 +245,7 @@
                                value = null;
                        }
 
-                       $value.text( value ? value : '' );
+                       $value.text( value || '' );
                        self._query.setLimit( value );
 
                        if ( self._changeListener ) {
@@ -418,10 +410,7 @@
         * @private
         */
        SELF.prototype._isVariable = function( entity ) {
-               if ( typeof entity === 'string' && entity.startsWith( '?' ) ) {
-                       return true;
-               }
-               return false;
+               return typeof entity === 'string' && entity.startsWith( '?' );
        };
 
        /**
@@ -440,11 +429,7 @@
 
                } );
 
-               if ( Object.keys( boundVariables ).length > 1 ) {
-                       return false;
-               }
-
-               return true;
+               return Object.keys( boundVariables ).length <= 1;
        };
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5c7892385b70450f9e7cbf455e432a18dbf9ce84
Gerrit-PatchSet: 2
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to