From: Dan Scott Date: Sun, 25 Mar 2018 15:16:26 +0000 (-0400) Subject: Group and display instruments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8130b7427b9cfaad90e0c12c794841c44bed3a93;p=contrib%2FConifer.git Group and display instruments For multi-instrumentalists like Joni Mitchell, this offers a better representation of their diverse skills. A side effect of the GROUP_CONCAT() is that a value is now always returned for the instruments variable, even if the performer has no associated instruments; avoid displaying it if it is nothing more than whitespace. Signed-off-by: Dan Scott --- diff --git a/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js b/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js index cf4730421a..2e4bb13afc 100644 --- a/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js +++ b/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js @@ -86,7 +86,9 @@ function findPerformer(icon_node, entity_name) { var url = 'https://query.wikidata.org/sparql'; - var query = 'SELECT DISTINCT ?item ?itemLabel ?itemDescription ?image ?instrumentLabel ?birthPlace ?birthPlaceLabel ' + + var query = 'SELECT DISTINCT ?item ?itemLabel ?itemDescription ?image ' + + '(GROUP_CONCAT(DISTINCT ?instrumentLabel;separator="; ") AS ?instruments) ' + + '?birthPlace ?birthPlaceLabel ' + '?website ?musicbrainz ?songKick ?twitter ?facebook ?wplink ' + 'WHERE { ' + '?item rdfs:label|skos:altLabel|wdt:P1449 "' + entity_name + '"@en . ' + @@ -108,8 +110,15 @@ '?wplink schema:inLanguage "en" . ' + '?wplink schema:isPartOf . ' + '} ' + - 'SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } ' + + 'SERVICE wikibase:label { ' + + ' bd:serviceParam wikibase:language "en". ' + + ' ?instrument rdfs:label ?instrumentLabel. ' + + ' ?item rdfs:label ?itemLabel. ' + + ' ?item schema:description ?itemDescription. ' + + ' ?birthPlace rdfs:label ?birthPlaceLabel ' + + '} ' + '} ' + + 'GROUP BY ?item ?itemLabel ?itemDescription ?image ?birthPlace ?birthPlaceLabel ?website ?musicbrainz ?songKick ?twitter ?facebook ?wplink' 'LIMIT 10'; var q = '?query=' + encodeURIComponent(query); @@ -216,7 +225,7 @@ function addWDValue(property, propertyLabel, label, isLink, linkFormatter) { var value = ''; - if (r.hasOwnProperty(property)) { + if (r.hasOwnProperty(property) && r[property].value.trim()) { value = r[property].value; var valueDiv = document.createElement('div'); var labelText = value; @@ -255,7 +264,7 @@ } } - addWDValue('instrumentLabel', 'Instrument: ', 'instrumentLabel', false); + addWDValue('instruments', 'Instruments: ', 'instruments', false); addWDValue('birthPlace', 'Birth place: ', 'birthPlaceLabel', true); addWDValue('website', 'Web site: ', null, true); addWDValue('musicbrainz', null, 'Discography (Musicbrainz)', true, function(value) { return 'https://musicbrainz.org/artist/' + value });