Widget: DCTList: Difference between revisions
From LINKS Community Center
Eschmidt (talk | contribs) No edit summary |
Eschmidt (talk | contribs) No edit summary |
||
Line 14: | Line 14: | ||
function getUrl(title) { | function getUrl(title) { | ||
return title ? '/index.php/Special:FilePath/' + title : title; | return title ? '/index.php/Special:FilePath/' + title : title; | ||
} | } | ||
Line 34: | Line 20: | ||
const sourceResponse = await fetch(sourceQuery).then(response => response.json()); | const sourceResponse = await fetch(sourceQuery).then(response => response.json()); | ||
const sources = Object.getOwnPropertyNames( | const results = sourceResponse.query.results; | ||
const sources = Object.getOwnPropertyNames(results).map(platformName => ({ | |||
name: platformName, | name: platformName, | ||
image: getUrl(results[platformName].printouts.IMAGE[0].fulltext.replace('PAGENAME:', '')) | |||
image: getUrl( | |||
})); | })); | ||
return sources; | return sources; | ||
} | } | ||
Line 53: | Line 35: | ||
const dctQueryUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(dctQuery); | const dctQueryUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(dctQuery); | ||
const dctResponse = await fetch(dctQueryUrl).then(response => response.json()); | const dctResponse = await fetch(dctQueryUrl).then(response => response.json()); | ||
console.log('DCT Response:', dctResponse); | // console.log('DCT Response:', dctResponse); | ||
const dctList = Object.getOwnPropertyNames( | const results = dctResponse.query.results; | ||
const dctList = Object.getOwnPropertyNames(results).map(dctKey => { | |||
const dct = {}; | const dct = {}; | ||
dct.name = dctKey; | dct.name = dctKey; | ||
dct.url = results[dctKey].fullurl; | |||
dct.url = | dct.dataSources = results[dctKey].printouts['Data Sources'].map(src => src.fulltext); | ||
dct.logo = results[dctKey].printouts['Image'][0] ? getUrl(results[dctKey].printouts['Image'][0].fulltext) : void 0; | |||
dct.dataSources = | |||
dct.logo = | |||
return dct; | return dct; | ||
}) | }) | ||
return dctList; | return dctList; | ||
} | } |
Revision as of 14:36, 7 June 2022
Development verstion of the DCT List.
Not ready for production!