Jonas Kress (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/277744

Change subject: Introduce injectable formatter
......................................................................

Introduce injectable formatter

Allows better reusing of Resultbrowsers and cleans AbstractResultBrowser
constructor.

Change-Id: Ic9c0c78c48f6458bcd6988ed185c5ead5f43613b
---
M index.html
M wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
M wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
M wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js
M wikibase/queryService/ui/resultBrowser/TableResultBrowser.js
R wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
6 files changed, 48 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/44/277744/1

diff --git a/index.html b/index.html
index 7653cc2..507404b 100644
--- a/index.html
+++ b/index.html
@@ -203,7 +203,7 @@
        <script src="wikibase/queryService/ui/editor/hint/Rdf.js"></script>
        <script src="wikibase/queryService/ui/editor/Editor.js"></script>
        <script src="wikibase/queryService/ui/QueryExampleDialog.js"></script>
-       <script 
src="wikibase/queryService/ui/resultBrowser/helper/ContentHelper.js"></script>
+       <script 
src="wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js"></script>
        <script 
src="wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js"></script>
        <script 
src="wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js"></script>
        <script 
src="wikibase/queryService/ui/resultBrowser/TableResultBrowser.js"></script>
diff --git a/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
index 0665810..eb4a45c 100644
--- a/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js
@@ -3,7 +3,7 @@
 wikibase.queryService.ui = wikibase.queryService.ui || {};
 wikibase.queryService.ui.resultBrowser = 
wikibase.queryService.ui.resultBrowser || {};
 
-wikibase.queryService.ui.resultBrowser.AbstractResultBrowser = ( function( $ ) 
{
+wikibase.queryService.ui.resultBrowser.AbstractResultBrowser = ( function( $, 
wikibase ) {
        "use strict";
 
        /**
@@ -16,16 +16,15 @@
         * @constructor
         */
        function SELF() {
-
-               this._contentHelper = new 
wikibase.queryService.ui.resultBrowser.helper.ContentHelper();
                this._visitors = [];
        }
 
        /**
-        * @property 
{wikibase.queryService.ui.resultBrowser.helper.ContentHelper}
+        * @property 
{wikibase.queryService.ui.resultBrowser.helper.FormatterHelper}
         * @private
-        **/
-       SELF.prototype._formattingHelper = null;
+        */
+       SELF.prototype._formatter = null;
+
 
        /**
         * @property {object}
@@ -56,6 +55,22 @@
        };
 
        /**
+        * Checks whether the result browser can draw the given result
+        * @return {boolean}
+        **/
+       SELF.prototype.isDrawable = function() {
+               return this._drawable;
+       };
+
+       /**
+        * Draws the result browser to the given element
+        * @param {jQuery} $element to draw at
+        **/
+       SELF.prototype.draw = function( $element ) {
+               jQuery.error( 'Method draw() needs to be implemented!' );
+       };
+
+       /**
         * Add visitor function.
         * @param {function} callback
         */
@@ -82,22 +97,28 @@
        SELF.prototype.visit = function( data ) {
        };
 
-
        /**
-        * Checks whether the result browser can draw the given result
-        * @return {boolean}
-        **/
-       SELF.prototype.isDrawable = function() {
-               return this._drawable;
+        * Set a formatter in order to replace the default formatter
+        * @param formatter 
{wikibase.queryService.ui.resultBrowser.helper.FormatterHelper}
+        */
+       SELF.prototype.setFormatter = function( formatter ) {
+               this._formatter = formatter;
        };
 
+
        /**
-        * Draws the result browser to the given element
-        * @param {jQuery} $element to draw at
-        **/
-       SELF.prototype.draw = function( $element ) {
-               jQuery.error( 'Method draw() needs to be implemented!' );
+        * Get the formatter
+        * @protected
+        * @return 
{wikibase.queryService.ui.resultBrowser.helper.FormatterHelper}
+        */
+       SELF.prototype._getFormatter = function() {
+               if( this._formatter === null ){
+                       this._formatter = new 
wikibase.queryService.ui.resultBrowser.helper.FormatterHelper();
+               }
+
+               return this._formatter;
        };
+
 
        return SELF;
-}( jQuery ) );
+}( jQuery, wikibase ) );
diff --git a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
index 4423840..fda7f35 100644
--- a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
@@ -121,7 +121,7 @@
         */
        SELF.prototype._getItemDescription = function( rowKey ) {
                var row = this._result.results.bindings[rowKey],
-               $result = $( '<div/>' ).append( this._contentHelper.formatRow( 
row ) );
+               $result = $( '<div/>' ).append( this._getFormatter().formatRow( 
row ) );
 
                return $result;
        };
diff --git a/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js
index 7b6d3b9..e8ff5fa 100644
--- a/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js
@@ -63,10 +63,10 @@
         **/
        SELF.prototype._getItem = function( thumbnailUrl, url, title, row ) {
                var $image = $( '<a href="' + url +'" data-gallery="g">' )
-                       .click( this._contentHelper.handleCommonResourceItem )
+                       .click( this._getFormatter().handleCommonResourceItem )
                        .attr( 'data-title',  title )
                        .append( $( '<img src="' + thumbnailUrl +'"></div>' ) ),
-                       $summary = this._contentHelper.formatRow( row );
+                       $summary = this._getFormatter().formatRow( row );
 
                return $( '<div class="item">' ).append( $image, $summary );
        };
diff --git a/wikibase/queryService/ui/resultBrowser/TableResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/TableResultBrowser.js
index c9ca508..2e15591 100644
--- a/wikibase/queryService/ui/resultBrowser/TableResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/TableResultBrowser.js
@@ -77,7 +77,7 @@
                                return '';
                        }
                        self.processVisitors( data );
-                       return self._contentHelper.formatValue( data ).html();
+                       return self._getFormatter().formatValue( data ).html();
                };
 
                var stringSorter = function( data1, data2 ){
@@ -85,8 +85,8 @@
                };
 
                var events = {
-                               'click .explore': $.proxy( 
this._contentHelper.handleExploreItem, this ),
-                               'click .gallery': 
this._contentHelper.handleCommonResourceItem
+                               'click .explore': $.proxy( 
this._getFormatter().handleExploreItem, this ),
+                               'click .gallery': 
this._getFormatter().handleCommonResourceItem
                };
 
                $element.bootstrapTable( {
diff --git a/wikibase/queryService/ui/resultBrowser/helper/ContentHelper.js 
b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
similarity index 96%
rename from wikibase/queryService/ui/resultBrowser/helper/ContentHelper.js
rename to wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
index 7813b26..45ab17c 100644
--- a/wikibase/queryService/ui/resultBrowser/helper/ContentHelper.js
+++ b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
@@ -5,7 +5,7 @@
 wikibase.queryService.ui.resultBrowser.helper = 
wikibase.queryService.ui.resultBrowser.helper || {};
 window.mediaWiki = window.mediaWiki || {};
 
-wikibase.queryService.ui.resultBrowser.helper.ContentHelper = ( function( $, 
mw ) {
+wikibase.queryService.ui.resultBrowser.helper.FormatterHelper = ( function( $, 
mw ) {
        "use strict";
 
        var EXPLORE_URL = 'http://www.wikidata.org/entity/Q';
@@ -14,7 +14,7 @@
        /**
         * Formatting helper provides methods useful for formatting results
         *
-        * @class wikibase.queryService.ui.resultBrowser.helper.ContentHelper
+        * @class wikibase.queryService.ui.resultBrowser.helper.FormatterHelper
         * @license GNU GPL v2+
         *
         * @author Jonas Kress

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic9c0c78c48f6458bcd6988ed185c5ead5f43613b
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Jonas Kress (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to