Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/185111
Change subject: Fix rendering issues with infoboxes ...................................................................... Fix rendering issues with infoboxes * Deal with situation where no default infobox setup e.g. http://localhost:8080/wiki/Headings?wikidataid=Q7971464 * Render a message when no values found for any of the rows * Consider all instances of when rendering an infobox. For instance France is a sovereign state before a country but we only have a country infobox. Change-Id: I500821bfc885528032f1f58f9af7eab070f19201 --- M javascripts/modules/infobox/Infobox.js M javascripts/modules/wikigrok/WikiDataApi.js M templates/modules/infobox/Infobox.hogan 3 files changed, 35 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/11/185111/1 diff --git a/javascripts/modules/infobox/Infobox.js b/javascripts/modules/infobox/Infobox.js index 7753746..6a1d399 100644 --- a/javascripts/modules/infobox/Infobox.js +++ b/javascripts/modules/infobox/Infobox.js @@ -170,7 +170,21 @@ * @return {Object} default option values */ getDefaultsFromClaims: function ( claims ) { - return this.typeDefaults[claims.instanceOf || 'default']; + var defaults, + self = this, + fallback = this.typeDefaults['default'] || + { + rows: [] + }; + + // Iterate through instances assuming priority order + $.each( claims.instanceTypes, function () { + // Pick the first match + if ( !defaults ) { + defaults = self.typeDefaults[this]; + } + } ); + return defaults || fallback; }, /** * Get the deferred object associated with the infobox @@ -231,7 +245,7 @@ this.$( '.spinner' ).show(); this.api.getClaims().done( function ( claims ) { - var rows; + var rows, isEmptyInfobox = true; options = $.extend( options, self.getDefaultsFromClaims( claims ) ); if ( options.rows ) { rows = options.rows; @@ -248,11 +262,17 @@ } else { row.values = []; } - row.isEmpty = !( row.values && row.values.length ); + if ( row.values && row.values.length ) { + isEmptyInfobox = false; + } else { + row.isEmpty = true; + } } ); + options.isEmptyInfobox = isEmptyInfobox; self._mapLabels( rows ).done( function ( rows ) { options.rows = rows; + self.options = options; self.$deferred.resolve(); _super.call( self, options ); diff --git a/javascripts/modules/wikigrok/WikiDataApi.js b/javascripts/modules/wikigrok/WikiDataApi.js index 85bb449..cba7e20 100644 --- a/javascripts/modules/wikigrok/WikiDataApi.js +++ b/javascripts/modules/wikigrok/WikiDataApi.js @@ -102,10 +102,13 @@ instanceClaims = entityClaims[instanceOfId]; // Examine claims closely + claims.instanceTypes = []; $.each( instanceClaims, function ( i, claim ) { + var instanceId = claim.mainsnak.datavalue.value['numeric-id']; if ( i === 0 ) { - claims.instanceOf = claim.mainsnak.datavalue.value['numeric-id']; + claims.instanceOf = instanceId; } + claims.instanceTypes.push( instanceId ); } ); } claims.entities = entityClaims; diff --git a/templates/modules/infobox/Infobox.hogan b/templates/modules/infobox/Infobox.hogan index a4787d5..5f93e9f 100644 --- a/templates/modules/infobox/Infobox.hogan +++ b/templates/modules/infobox/Infobox.hogan @@ -1,8 +1,14 @@ -{{^rows}} <div> + {{^rows}} + {{^isEmptyInfobox}} <button class="mw-ui-button mw-ui-quiet mw-ui-progressive more">More information…</button> + {{/isEmptyInfobox}} + {{/rows}} + {{#isEmptyInfobox}} + No further information is available. + {{/isEmptyInfobox}} </div> -{{/rows}} + {{{spinner}}} {{#rows}} <div class="{{className}}"> -- To view, visit https://gerrit.wikimedia.org/r/185111 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I500821bfc885528032f1f58f9af7eab070f19201 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
