Lucas Werkmeister (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/390430 )
Change subject: Allow specifying options for non-default views
......................................................................
Allow specifying options for non-default views
This change lets you specify options for non-default views, using a
different comment – #view:Name{} instead of #defaultView:Name{}. When
the same name is configured multiple times, the options are merged, so
you can also use this to split up options and make them more readable:
#view:Map{"layer": "?partyLabel"} # use ?partyLabel as ?layer
#view:Map{"hide": ["?rgb", "?shape", "?sanityCheckMdb",
"?votesPercentage"]} # hide these auxiliary columns from map
#defaultView:Map
Change-Id: I0da902c055c6c1f270e1557f58b4d0a919c52cdb
---
M wikibase/queryService/ui/ResultView.js
1 file changed, 34 insertions(+), 20 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui
refs/changes/30/390430/1
diff --git a/wikibase/queryService/ui/ResultView.js
b/wikibase/queryService/ui/ResultView.js
index bd9cfaa..0e125c7 100644
--- a/wikibase/queryService/ui/ResultView.js
+++ b/wikibase/queryService/ui/ResultView.js
@@ -344,11 +344,11 @@
SELF.prototype._createResultBrowsers = function( resultData ) {
var self = this;
- var defaultBrowserOptions = this._getDefaultBrowserOptions();
+ var browserOptions = this._getBrowserOptions();
var defaultBrowser = null;
- if ( defaultBrowserOptions !== null ) {
- this._track( 'result.browser.' +
defaultBrowserOptions.name );
+ if ( browserOptions.defaultName !== null ) {
+ this._track( 'result.browser.' +
browserOptions.defaultName );
} else {
this._track( 'result.browser.default' );
}
@@ -358,16 +358,18 @@
var instance = new
wikibase.queryService.ui.resultBrowser[b.class]();
instance.setSparqlApi( self._sparqlApi );
- if ( defaultBrowserOptions !== null &&
defaultBrowserOptions.name === key ) {
+ if ( browserOptions.defaultName === key ) {
self._setSelectedDisplayType( b );
defaultBrowser = instance;
- if ( 'options' in defaultBrowserOptions ) {
- var options = new
wikibase.queryService.ui.resultBrowser.helper.Options(
- defaultBrowserOptions.options
- );
- instance.setOptions( options );
- }
}
+
+ if ( browserOptions.optionsMap.has( key ) ) {
+ var options = new
wikibase.queryService.ui.resultBrowser.helper.Options(
+ browserOptions.optionsMap.get( key )
+ );
+ instance.setOptions( options );
+ }
+
b.object = instance;
} );
if ( defaultBrowser === null ) {
@@ -387,24 +389,36 @@
/**
* @private
- * @return {?{name: string, options: ?Object}}
+ * @return {{defaultName: string?, optionsMap: Map.<string, Object>}}
*/
- SELF.prototype._getDefaultBrowserOptions = function() {
- var match = this._query.match( /#defaultView:(\w+)(\{.*\})?/ );
+ SELF.prototype._getBrowserOptions = function() {
+ var defaultName = null,
+ optionsMap = new Map(),
+ regex = /#(defaultView|view):(\w+)(\{.*\})?/g,
+ match;
- if ( match && this._resultBrowsers.hasOwnProperty( match[1] ) )
{
- var result = { name: match[1] };
- if ( match[2] ) {
+ while ( ( match = regex.exec( this._query ) ) !== null ) {
+ var name = match[2];
+ if ( !this._resultBrowsers.hasOwnProperty( name ) ) {
+ continue;
+ }
+ if ( match[1] === 'defaultView' ) {
+ defaultName = name;
+ }
+ if ( match[3] ) {
+ var options = optionsMap.has( name ) ?
optionsMap.get( name ) : {};
try {
- result.options = JSON.parse( match[2] );
+ optionsMap.set(
+ name,
+ $.extend( options, JSON.parse(
match[3] ) )
+ );
} catch ( e ) {
window.console.error( e );
}
}
- return result;
- } else {
- return null;
}
+
+ return { defaultName: defaultName, optionsMap: optionsMap };
};
/**
--
To view, visit https://gerrit.wikimedia.org/r/390430
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0da902c055c6c1f270e1557f58b4d0a919c52cdb
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits