Jonas Kress (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/277531
Change subject: Introduce magic comments for setting default view ...................................................................... Introduce magic comments for setting default view This enables defining a default view for a SPARQL query by adding a comment like #defaultView:ImageGrid or #defaultView:Map Change-Id: Icfd05a37b33e0642aa02b5bff1bc95f3ff443273 --- M wikibase/queryService/ui/App.js M wikibase/queryService/ui/editor/hint/Sparql.js M wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js M wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js 4 files changed, 50 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui refs/changes/31/277531/1 diff --git a/wikibase/queryService/ui/App.js b/wikibase/queryService/ui/App.js index 46e65da..41fea75 100644 --- a/wikibase/queryService/ui/App.js +++ b/wikibase/queryService/ui/App.js @@ -68,9 +68,9 @@ * @private **/ SELF.prototype._resultBrowsers = { - TableResultBrowser: {icon: 'th', label: 'Table', object: null, $element: null }, - ImageResultBrowser: {icon: 'picture', label: 'Image Grid', object: null, $element: null }, - CoordinateResultBrowser: {icon: 'map-marker', label: 'Map', object: null, $element: null } + Table: {icon: 'th', label: 'Table', class: 'TableResultBrowser', object: null, $element: null }, + ImageGrid: {icon: 'picture', label: 'Image Grid', class: 'ImageResultBrowser', object: null, $element: null }, + Map: {icon: 'map-marker', label: 'Map', class: 'CoordinateResultBrowser', object: null, $element: null } }; /** @@ -405,25 +405,12 @@ return false; } - var defaultBrowser = null; - $.each( this._resultBrowsers, function( className, b ){ - var instance = new wikibase.queryService.ui.resultBrowser[ className ](); - instance.setResult ( api.getResultRawData() ); - - if( !defaultBrowser ){ - defaultBrowser = instance; - } else { - defaultBrowser.addVisitor( instance ); - } - - b.object = instance; - } ); - + var defaultBrowser = this._createResultBrowsers( api.getResultRawData() ); this._showActionMessage( 'Generating View' , 'success', 100); window.setTimeout( function() { + $queryResult.show(); defaultBrowser.draw( $queryResult ); self._hideActionMessage(); - $queryResult.show(); self._handleQueryResultBrowsers(); }, 20 ); @@ -432,6 +419,45 @@ /** * @private + * @return {object} default result browser + */ + SELF.prototype._createResultBrowsers = function( resultData ) { + + var defaultBrowser = this._getDefaultResultBrowser(); + + //instantiate + $.each( this._resultBrowsers, function( key, b ){ + var instance = new wikibase.queryService.ui.resultBrowser[ b.class ](); + if( defaultBrowser === null || defaultBrowser === key ){ + defaultBrowser = instance; + } + b.object = instance; + } ); + + //wire up + $.each( this._resultBrowsers, function( key, b ){ + defaultBrowser.addVisitor( b.object ); + b.object.setResult( resultData ); + } ); + + return defaultBrowser; + }; + + /** + * @private + */ + SELF.prototype._getDefaultResultBrowser = function() { + var match = this._editor.getValue().match(/\#defaultView:(.*)/); + + if( match && this._resultBrowsers[ match[1] ] ){ + return match[1]; + } + + return null; + }; + + /** + * @private */ SELF.prototype._handleQueryResultBrowsers = function() { var self = this; diff --git a/wikibase/queryService/ui/editor/hint/Sparql.js b/wikibase/queryService/ui/editor/hint/Sparql.js index 7e6ffb6..c68fc6c 100755 --- a/wikibase/queryService/ui/editor/hint/Sparql.js +++ b/wikibase/queryService/ui/editor/hint/Sparql.js @@ -20,7 +20,9 @@ 'SERVICE', 'SERVICE wikibase:label {\n bd:serviceParam wikibase:language "en" .\n}', 'BASE', 'PREFIX', 'REDUCED', 'FROM', 'LIMIT', 'OFFSET', 'HAVING', - 'UNION' ]; + 'UNION', + '#defaultView:Map', '#defaultView:ImageGrid' + ]; /** * Code completion for Wikibase entities RDF prefixes in SPARQL diff --git a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js index b06832f..4423840 100644 --- a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js +++ b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js @@ -74,6 +74,8 @@ $.each( result, function( rowKey){ $.each( this, function( key, field ){ + self.processVisitors( field ); + if( field.datatype === MAP_DATATYPE ){ var longLat = self._extractLongLat( field.value ); diff --git a/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js b/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js index c6a2692..7b6d3b9 100644 --- a/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js +++ b/wikibase/queryService/ui/resultBrowser/ImageResultBrowser.js @@ -41,6 +41,7 @@ $.each( this._result.results.bindings, function( rowNum, row ){ $.each( this, function( key, field ){ + self.processVisitors( field ); if( self._isCommonsResource( field.value ) ){ var url = field.value, regEx = new RegExp( COMMONS_FILE_PATH, "ig" ), -- To view, visit https://gerrit.wikimedia.org/r/277531 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icfd05a37b33e0642aa02b5bff1bc95f3ff443273 Gerrit-PatchSet: 1 Gerrit-Project: wikidata/query/gui Gerrit-Branch: master Gerrit-Owner: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits