Widget: DevGuidelines: Difference between revisions
From LINKS Community Center
Cschwentker (talk | contribs) No edit summary |
Cschwentker (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<noinclude>Development version of the List of Guidelines.<br><strong style="color:red;">Not ready for production!</strong></noinclude> | <noinclude>Development version of the List of Guidelines.<br><strong style="color:red;">Not ready for | ||
production!</strong></noinclude> | |||
<includeonly> | <includeonly> | ||
<link href="/resources/assets/tabulator.min.css" rel="stylesheet"> | <link href="/resources/assets/tabulator.min.css" rel="stylesheet"> | ||
Line 30: | Line 31: | ||
margin-right: .5em; | margin-right: .5em; | ||
} | } | ||
#filter-bar { position: relative; margin: 1em 0 2em 0; } | |||
#filter-bar { | |||
position: relative; | |||
margin: 1em 0 2em 0; | |||
} | |||
#gl-filters { | #gl-filters { | ||
position: absolute; | position: absolute; | ||
Line 44: | Line 50: | ||
transition: all 400ms ease-in-out; | transition: all 400ms ease-in-out; | ||
} | } | ||
#gl-filters.open { | #gl-filters.open { | ||
clip-path: inset(0 0 -50px -50px); | clip-path: inset(0 0 -50px -50px); | ||
Line 102: | Line 109: | ||
} | } | ||
.filter-wrapper .filter-container { display: none; } | .filter-wrapper .filter-container { | ||
.filter-wrapper.open .filter-container { display: block; } | display: none; | ||
} | |||
.filter-wrapper.open .filter-container { | |||
display: block; | |||
} | |||
.filter-wrapper h4 { | .filter-wrapper h4 { | ||
Line 173: | Line 185: | ||
border: 0 none; | border: 0 none; | ||
} | } | ||
#guideline-tabulator.tabulator .tabulator-header .tabulator-col { | #guideline-tabulator.tabulator .tabulator-header .tabulator-col { | ||
border-bottom: 4px double var(--links-orange); | border-bottom: 4px double var(--links-orange); | ||
Line 203: | Line 215: | ||
} | } | ||
#filter-summary { margin-right: 1em; } | #filter-summary { | ||
margin-right: 1em; | |||
} | |||
#filter-summary table tr td { vertical-align: top; } | #filter-summary table tr td { | ||
#filter-summary table tr td:first-of-type { padding-right: 10px; } | vertical-align: top; | ||
} | |||
#filter-summary table tr td:first-of-type { | |||
padding-right: 10px; | |||
} | |||
Line 218: | Line 237: | ||
} | } | ||
#guideline-tabulator.tabulator .guideline-title a, | #guideline-tabulator.tabulator .guideline-title a, | ||
#guideline-tabulator.tabulator .tabulator-responsive-collapse table a { | #guideline-tabulator.tabulator .tabulator-responsive-collapse table a { | ||
color: var(--links-orange); | color: var(--links-orange); | ||
} | } | ||
.data-source-img, | |||
.func-img { | |||
width: 1.2rem; | |||
height: 1.2rem; | |||
margin-right: .4rem; | |||
margin-bottom: .4rem; | |||
filter: grayscale(1); | |||
} | |||
</style> | </style> | ||
Line 236: | Line 262: | ||
* @property {string[]} audienceTargets | * @property {string[]} audienceTargets | ||
* @property {string[]} languages | * @property {string[]} languages | ||
*/ | * @property {string[]} dataSources | ||
*/ | |||
let table; // Tabulator instance | let table; // Tabulator instance | ||
Line 242: | Line 269: | ||
const EX_LEVEL = ["Starter", "Intermediate", "Advanced"]; | const EX_LEVEL = ["Starter", "Intermediate", "Advanced"]; | ||
// Helpers | |||
const escapeAttr = text => text ? text.replace(/\W/g, '-') : text; | |||
const getFilePath = title => title ? '/index.php/Special:FilePath/' + title : title; | |||
const getQueryUrl = query => '/api.php?action=ask&format=json&query=' + encodeURIComponent(query); | const getQueryUrl = query => '/api.php?action=ask&format=json&query=' + encodeURIComponent(query); | ||
const | const removePrefix = str => str.substring(str.indexOf(':') + 1); | ||
const DATASRC_PROP = 'Data Sources'; | |||
const PHASE_PROP = 'Disaster Management Phase'; | const PHASE_PROP = 'Disaster Management Phase'; | ||
const THEME_PROP = 'Covers Thematic'; | const THEME_PROP = 'Covers Thematic'; | ||
Line 253: | Line 284: | ||
const guidelineQuery = '[[Category:Guideline]]' | const guidelineQuery = '[[Category:Guideline]]' | ||
+ '|?' + DATASRC_PROP | |||
+ '|?' + PHASE_PROP | + '|?' + PHASE_PROP | ||
+ '|?' + THEME_PROP | + '|?' + THEME_PROP | ||
Line 259: | Line 291: | ||
+ '|?' + EX_PROP | + '|?' + EX_PROP | ||
+ '|?' + TA_PROP; | + '|?' + TA_PROP; | ||
+ '|limit=500' | |||
async function getGuidelines() { | async function getGuidelines() { | ||
const guidelinesResponse = await fetch(getQueryUrl(guidelineQuery)).then(response => response.json()); | const guidelinesResponse = await fetch(getQueryUrl(guidelineQuery)).then(response => response.json()); | ||
Line 271: | Line 304: | ||
guideline.title = title; | guideline.title = title; | ||
guideline.url = guidelineResult.fullurl; | guideline.url = guidelineResult.fullurl; | ||
guideline[DATASRC_PROP] = guidelineResult.printouts[DATASRC_PROP].map(source => source.fulltext).sort(); | |||
guideline[PHASE_PROP] = guidelineResult.printouts[PHASE_PROP].map(value => value.fulltext); | guideline[PHASE_PROP] = guidelineResult.printouts[PHASE_PROP].map(value => value.fulltext); | ||
guideline[THEME_PROP] = guidelineResult.printouts[THEME_PROP].map(value => value.fulltext); | guideline[THEME_PROP] = guidelineResult.printouts[THEME_PROP].map(value => value.fulltext); | ||
Line 281: | Line 315: | ||
} | } | ||
// Fetches platform / data source information. | |||
async function getSources() { | |||
const IMG_KEY = 'IMAGE'; | |||
const sourceResponse = await fetch( | |||
getQueryUrl('[[Category:Social media platform]]|?' + IMG_KEY) | |||
).then(response => response.json()); | |||
return Object.keys(sourceResponse.query.results).map(platform => { | |||
const img = sourceResponse.query.results[platform].printouts[IMG_KEY][0]; | |||
return { | |||
name: platform, | |||
image: img ? getFilePath(img.fulltext) : undefined | |||
}; | |||
}); | |||
} | |||
function applyFilters(clear) { | function applyFilters(clear) { | ||
// TODO: apply Filters | // TODO: apply Filters | ||
Line 291: | Line 341: | ||
} | } | ||
/** @type {FilterState} **/ | |||
/** @type {FilterState} **/ | |||
const filterState = {}; | const filterState = {}; | ||
Line 302: | Line 351: | ||
const selectedthematics = thematicOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | const selectedthematics = thematicOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | ||
filterState.thematics = selectedthematics.length === thematicOptions.length ? undefined : selectedthematics; | filterState.thematics = selectedthematics.length === thematicOptions.length ? undefined : selectedthematics; | ||
const audienceExperienceOptions = Array.from(document.querySelectorAll('#audience-experience-filter input[type="checkbox"]')); | const audienceExperienceOptions = Array.from(document.querySelectorAll('#audience-experience-filter input[type="checkbox"]')); | ||
const selectedaudienceExperiences = audienceExperienceOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | const selectedaudienceExperiences = audienceExperienceOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | ||
Line 314: | Line 363: | ||
const selectedlanguages = languageOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | const selectedlanguages = languageOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | ||
filterState.languages = selectedlanguages.length === languageOptions.length ? undefined : selectedlanguages; | filterState.languages = selectedlanguages.length === languageOptions.length ? undefined : selectedlanguages; | ||
const sourceOptions = Array.from(document.querySelectorAll('#data-source-filter input[type="checkbox"]')); | |||
const selectedSources = sourceOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | |||
filterState.dataSources = selectedSources.length === sourceOptions.length ? undefined : selectedSources; | |||
table.setFilter(guidelineFilter, filterState); | table.setFilter(guidelineFilter, filterState); | ||
Line 323: | Line 377: | ||
* @param {FilterState} filterState | * @param {FilterState} filterState | ||
*/ | */ | ||
function guidelineFilter(guideline, filterState) { | |||
// If filtering property is empty, don't apply the filter (set the check to true). | // If filtering property is empty, don't apply the filter (set the check to true). | ||
// Passing an empty object (as with applyFilters(true)) should result in an unfiltered table. | // Passing an empty object (as with applyFilters(true)) should result in an unfiltered table. | ||
Line 340: | Line 394: | ||
const langCheck = filterState.languages | const langCheck = filterState.languages | ||
? guideline[LANG_PROP].some(lang => filterState.languages.includes(lang)) | ? guideline[LANG_PROP].some(lang => filterState.languages.includes(lang)) | ||
: true; | |||
const sourcesCheck = filterState.dataSources | |||
? guideline[DATASRC_PROP].some(source => filterState.dataSources.includes(source)) | |||
: true; | : true; | ||
return phaseCheck && thematicCheck && audienceExperiencesCheck && audienceTargetCheck && langCheck; | return phaseCheck && thematicCheck && audienceExperiencesCheck && audienceTargetCheck && langCheck && sourcesCheck; | ||
} | } | ||
Promise.all([getGuidelines()]).then(data => { | Promise.all([getSources(), getGuidelines()]).then(data => { | ||
let COVERS_THEMATIC_VALUES = | const [dataSources, guidelines] = data; | ||
let COVERS_THEMATIC_VALUES = [] | |||
let LANGUAGES_VALUES = []; | let LANGUAGES_VALUES = []; | ||
let TARGET_AUDIENCE_VALUES = []; | let TARGET_AUDIENCE_VALUES = []; | ||
Line 355: | Line 414: | ||
let PHASE_VALUES = []; | let PHASE_VALUES = []; | ||
for(const guideline of guidelines){ | for (const guideline of guidelines) { | ||
LANGUAGES_VALUES = LANGUAGES_VALUES.concat(guideline[LANG_PROP]); | LANGUAGES_VALUES = LANGUAGES_VALUES.concat(guideline[LANG_PROP]); | ||
COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.concat(guideline[THEME_PROP]) | COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.concat(guideline[THEME_PROP]) | ||
TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.concat(guideline[TA_PROP]) | TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.concat(guideline[TA_PROP]) | ||
YEAR_LEVEL_VALUES = | YEAR_LEVEL_VALUES = YEAR_LEVEL_VALUES.concat(guideline[YEAR_PROP]) | ||
} | } | ||
Line 373: | Line 432: | ||
PHASE_VALUES = PHASES; | PHASE_VALUES = PHASES; | ||
EXPERIENCE_LEVEL_VALUES = EX_LEVEL; | EXPERIENCE_LEVEL_VALUES = EX_LEVEL; | ||
// Set up sources filter | |||
const groupedSources = []; | |||
const sourcesCopy = Array.from(dataSources); | |||
for (const layoutGroup of sourcesLayout) { | |||
const group = []; | |||
for (const source of layoutGroup.sources) { | |||
let idx = sourcesCopy.findIndex(src => src.name === source); | |||
if (idx !== -1) { group.push(sourcesCopy.splice(idx, 1)[0]); } | |||
} | |||
if (group.length > 0) { groupedSources.push({ title: layoutGroup.title, sources: group }); } | |||
} | |||
groupedSources.push({ title: 'More platforms', sources: sourcesCopy }); | |||
let dataSourceFilterHtml = ''; | |||
groupedSources.forEach(group => { | |||
dataSourceFilterHtml += '<div class="filter-group-header">' + group.title + '</div>'; | |||
dataSourceFilterHtml += group.sources.reduce((acc, curr, idx) => { | |||
const identifier = escapeAttr(curr.name); | |||
return acc + | |||
'<div ' + (idx === 0 ? ' class="filter-group-start">' : '>') + | |||
'<input type="checkbox" id="filter-' + identifier + '" value="' + curr.name + '" checked>' + | |||
'<label for="filter-' + identifier + '"><img src="' + curr.image + '"> ' + curr.name + '</label></div>' | |||
}, ''); | |||
}); | |||
document.getElementById('data-source-filter').innerHTML = dataSourceFilterHtml; | |||
let languageFilterHtml = Array.from(LANGUAGES_VALUES.values()).reduce((acc, curr) => { | let languageFilterHtml = Array.from(LANGUAGES_VALUES.values()).reduce((acc, curr) => { | ||
Line 391: | Line 478: | ||
}, ''); | }, ''); | ||
document.getElementById('thematic-filter').innerHTML = coversThematicHtml; | document.getElementById('thematic-filter').innerHTML = coversThematicHtml; | ||
let phaseHtml = Array.from(PHASE_VALUES.values()).reduce((acc, curr) => { | let phaseHtml = Array.from(PHASE_VALUES.values()).reduce((acc, curr) => { | ||
const identifier = escapeAttr(curr); | const identifier = escapeAttr(curr); | ||
Line 400: | Line 487: | ||
}, ''); | }, ''); | ||
document.getElementById('phase-filter').innerHTML = phaseHtml; | document.getElementById('phase-filter').innerHTML = phaseHtml; | ||
let targetAudienceHtml = Array.from(TARGET_AUDIENCE_VALUES.values()).reduce((acc, curr) => { | let targetAudienceHtml = Array.from(TARGET_AUDIENCE_VALUES.values()).reduce((acc, curr) => { | ||
const identifier = escapeAttr(curr); | const identifier = escapeAttr(curr); | ||
Line 418: | Line 505: | ||
}, ''); | }, ''); | ||
document.getElementById('audience-experience-filter').innerHTML = targetAudienceExperienceHtml; | document.getElementById('audience-experience-filter').innerHTML = targetAudienceExperienceHtml; | ||
const tabulator = new Tabulator('#guideline-tabulator', { | const tabulator = new Tabulator('#guideline-tabulator', { | ||
data: guidelines, | data: guidelines, | ||
Line 459: | Line 546: | ||
formatter: cell => cell.getValue().join(', ') | formatter: cell => cell.getValue().join(', ') | ||
} | } | ||
], | ], | ||
initialSort: [ | initialSort: [ | ||
Line 475: | Line 562: | ||
const summary = document.getElementById('filter-summary'); | const summary = document.getElementById('filter-summary'); | ||
const filter = filters[0]; | const filter = filters[0]; | ||
// Set result counter | // Set result counter | ||
document.getElementById('result-count').textContent = rows.length; | document.getElementById('result-count').textContent = rows.length; | ||
Line 483: | Line 570: | ||
// Update filter text. | // Update filter text. | ||
if ( | if ( | ||
Line 490: | Line 577: | ||
!filter.type.phases && | !filter.type.phases && | ||
!filter.type.audienceTargets && | !filter.type.audienceTargets && | ||
!filter.type.audienceExperiences | !filter.type.audienceExperiences && | ||
!filter.type.dataSources | |||
) { summary.textContent = 'No filter. Showing all results.'; } | ) { summary.textContent = 'No filter. Showing all results.'; } | ||
else { | else { | ||
Line 517: | Line 605: | ||
summaryHtml += '<tr><td><strong>Audience experience level</strong></td><td>' | summaryHtml += '<tr><td><strong>Audience experience level</strong></td><td>' | ||
+ (filter.type.audienceExperiences.length > 0 ? filter.type.audienceExperiences.join(', ') : 'none') | + (filter.type.audienceExperiences.length > 0 ? filter.type.audienceExperiences.join(', ') : 'none') | ||
+ '</td></tr>'; | |||
} | |||
if (filter.type.dataSources) { | |||
summaryHtml += '<tr><td><strong>Platforms</strong></td><td>' | |||
+ (filter.type.dataSources.length > 0 ? filter.type.dataSources.join(', ') : 'none') | |||
+ '</td></tr>'; | + '</td></tr>'; | ||
} | } | ||
Line 522: | Line 615: | ||
summary.innerHTML = summaryHtml; | summary.innerHTML = summaryHtml; | ||
} | } | ||
}); | }); | ||
Line 548: | Line 641: | ||
}); | }); | ||
// Close filter pane when clicked outside of it. | |||
document.body.addEventListener('click', event => { | document.body.addEventListener('click', event => { | ||
const filterPane = document.getElementById('gl-filters'); | const filterPane = document.getElementById('gl-filters'); | ||
Line 558: | Line 651: | ||
}, { passive: true }); | }, { passive: true }); | ||
// Fix bug where the table is truncated to zero height despite having visible rows. | |||
tabulator.on('renderComplete', function () { | |||
// TODO: Check the bugfix for a possible infinite event loop. | // TODO: Check the bugfix for a possible infinite event loop. | ||
// This will help detect it, in case it happens. | // This will help detect it, in case it happens. | ||
console.log('Table height bugfix: render complete.'); | console.log('Table height bugfix: render complete.'); | ||
try { | try { | ||
const holderHeight = tabulator.rowManager.element.offsetHeight; | const holderHeight = tabulator.rowManager.element.offsetHeight; | ||
Line 597: | Line 690: | ||
} | } | ||
</script> | </script> | ||
<!-- Icon definitons --> | |||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" style="display:none;"> | |||
<defs> | |||
<symbol id="chevron-down" viewBox="0 0 96 96"> | |||
<clipPath id="chev"> | |||
<path d="M592 312h96v96h-96z" /> | |||
</clipPath> | |||
<g clip-path="url(#chev)" transform="translate(-592 -312)"> | |||
<path | |||
d="m640 370.586-25.293-25.293-1.414 1.414L640 373.414l26.707-26.707-1.414-1.414L640 370.586Z" /> | |||
</g> | |||
</symbol> | |||
</svg> | </defs> | ||
</svg> | |||
Line 629: | Line 723: | ||
</h1> | </h1> | ||
<div id="guideline-intro"> | <div id="guideline-intro"> | ||
<p>The guidelines library gathers and structures existing guiding documents (guidelines, legal documents, Standard Operation Procedures) that support the implementation and use of social media and crowdsourcing in disaster management organisations. | <p>The guidelines library gathers and structures existing guiding documents (guidelines, legal documents, | ||
</p> | Standard Operation Procedures) that support the implementation and use of social media and crowdsourcing | ||
in disaster management organisations. | |||
</p> | |||
<ul> | <ul> | ||
<li>Building a communication strategy for social media and consideration of the main elements (e.g. | <li>Building a communication strategy for social media and consideration of the main elements (e.g. | ||
Line 657: | Line 753: | ||
</div> | </div> | ||
</div> | </div> | ||
<h2 style="margin-top: 2.5rem; margin-bottom: 0;">Results: <span id="result-count"></span></h2> | <h2 style="margin-top: 2.5rem; margin-bottom: 0;">Results: <span id="result-count"></span></h2> | ||
<div id="gl-filters"> | <div id="gl-filters"> | ||
<h2 style="display: flex; justify-content: space-between;"> | <h2 style="display: flex; justify-content: space-between;"> | ||
Line 671: | Line 765: | ||
<g clip-path="url(#b)" transform="translate(-592 -312)"> | <g clip-path="url(#b)" transform="translate(-592 -312)"> | ||
<path | <path | ||
d="M636 356.012v38.011l8-8v-30.011L674 326h-68Zm6.588-1.412-.588.584v30.008l-4 4v-34.008l-.585-.586L610.828 328h58.348Z" /> | |||
</g> | </g> | ||
</svg> | </svg> | ||
Line 682: | Line 776: | ||
</div> | </div> | ||
<div class="filter-wrapper"> | <div class="filter-wrapper"> | ||
<h4>Covers Thematic <span class="filter-toggle"><svg><use href="#chevron-down"/></svg></span></h4> | <h4>Covers Thematic <span class="filter-toggle"><svg> | ||
<use href="#chevron-down" /> | |||
</svg></span></h4> | |||
<div class="filter-container"> | <div class="filter-container"> | ||
<div class="filter-button-wrapper"> | <div class="filter-button-wrapper"> | ||
Line 692: | Line 788: | ||
</div> | </div> | ||
<div class="filter-wrapper"> | <div class="filter-wrapper"> | ||
<h4>Language<span class="filter-toggle"><svg><use href="#chevron-down"/></svg></span></h4> | <h4>Language<span class="filter-toggle"><svg> | ||
<use href="#chevron-down" /> | |||
</svg></span></h4> | |||
<div class="filter-container"> | <div class="filter-container"> | ||
<div class="filter-button-wrapper"> | <div class="filter-button-wrapper"> | ||
Line 702: | Line 800: | ||
</div> | </div> | ||
<div class="filter-wrapper"> | <div class="filter-wrapper"> | ||
<h4>Disaster Management Phase<span class="filter-toggle"><svg><use href="#chevron-down"/></svg></span></h4> | <h4>Disaster Management Phase<span class="filter-toggle"><svg> | ||
<use href="#chevron-down" /> | |||
</svg></span></h4> | |||
<div class="filter-container"> | <div class="filter-container"> | ||
<div class="filter-button-wrapper"> | <div class="filter-button-wrapper"> | ||
Line 712: | Line 812: | ||
</div> | </div> | ||
<div class="filter-wrapper"> | <div class="filter-wrapper"> | ||
<h4>Target audience<span class="filter-toggle"><svg><use href="#chevron-down"/></svg></span></h4> | <h4>Target audience<span class="filter-toggle"><svg> | ||
<use href="#chevron-down" /> | |||
</svg></span></h4> | |||
<div class="filter-container"> | <div class="filter-container"> | ||
<div class="filter-button-wrapper"> | <div class="filter-button-wrapper"> | ||
Line 722: | Line 824: | ||
</div> | </div> | ||
<div class="filter-wrapper"> | <div class="filter-wrapper"> | ||
<h4>Audience experience level<span class="filter-toggle"><svg><use href="#chevron-down"/></svg></span></h4> | <h4>Audience experience level<span class="filter-toggle"><svg> | ||
<use href="#chevron-down" /> | |||
</svg></span></h4> | |||
<div class="filter-container"> | <div class="filter-container"> | ||
<div class="filter-button-wrapper"> | <div class="filter-button-wrapper"> | ||
Line 729: | Line 833: | ||
</div> | </div> | ||
<div class="filter-content" id="audience-experience-filter"></div> | <div class="filter-content" id="audience-experience-filter"></div> | ||
</div> | |||
</div> | |||
<div class="filter-wrapper"> | |||
<h4>Supported Platforms <span class="filter-toggle"><svg> | |||
<use href="#chevron-down" /> | |||
</svg></span></h4> | |||
<div class="filter-container"> | |||
<div class="filter-button-wrapper"> | |||
<button type="button" onclick="selectAll('#data-source-filter')">Select all</button> | | |||
<button type="button" onclick="deselectAll('#data-source-filter')">Clear all</button> | |||
</div> | |||
<div class="filter-content" id="data-source-filter"></div> | |||
</div> | </div> | ||
</div> | </div> |
Revision as of 12:04, 24 November 2022
Development version of the List of Guidelines.
Not ready for
production!