jenkins-bot has submitted this change and it was merged. 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, 36 insertions(+), 9 deletions(-) Approvals: Phuedx: Looks good to me, approved jenkins-bot: Verified 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 c24810b..2e987d0 100644 --- a/javascripts/modules/wikigrok/WikiDataApi.js +++ b/javascripts/modules/wikigrok/WikiDataApi.js @@ -49,11 +49,12 @@ instanceClaims = entityClaims[instanceOfId]; // Examine claims closely - $.each( instanceClaims, function ( i, claim ) { - if ( i === 0 ) { - claims.instanceOf = claim.mainsnak.datavalue.value['numeric-id']; - } + claims.instanceTypes = $.map( instanceClaims, function ( claim ) { + return claim.mainsnak.datavalue.value[ 'numeric-id' ]; } ); + if ( claims.instanceTypes.length > 0 ) { + claims.instanceOf = claims.instanceTypes[ 0 ]; + } } 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: merged Gerrit-Change-Id: I500821bfc885528032f1f58f9af7eab070f19201 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <[email protected]> Gerrit-Reviewer: Jhernandez <[email protected]> Gerrit-Reviewer: Phuedx <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
