Widget: DevGuidelines: Difference between revisions
From LINKS Community Center
Eschmidt (talk | contribs) No edit summary |
Cschwentker (talk | contribs) No edit summary |
||
(107 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
<script type="text/javascript" src="/resources/assets/tabulator.min.js"></script> | <script type="text/javascript" src="/resources/assets/tabulator.min.js"></script> | ||
<style> | <style> | ||
#guideline-list-wrapper { font-family: 'Open Sans'; margin-top: 4em; } | #guideline-list-wrapper { | ||
#guideline-list-wrapper h1, #guideline-list-wrapper h2, #guideline-list-wrapper h3 { | font-family: 'Open Sans'; | ||
margin-top: 4em; | |||
} | |||
#guideline-list-wrapper h1, | |||
#guideline-list-wrapper h2, | |||
#guideline-list-wrapper h3 { | |||
font-family: 'Raleway'; | font-family: 'Raleway'; | ||
font-weight: 300; | font-weight: 300; | ||
letter-spacing: .06em; | letter-spacing: .06em; | ||
} | } | ||
#guideline-list-wrapper h1, #guideline-filters h2 { | |||
#guideline-list-wrapper h1, | |||
#guideline-filters h2 { | |||
color: var(--links-orange); | color: var(--links-orange); | ||
display: flex; | display: flex; | ||
align-items: center; | align-items: center; | ||
} | } | ||
#guideline-list-wrapper h1 svg { | #guideline-list-wrapper h1 svg { | ||
height: 2.5em; | height: 2.5em; | ||
Line 21: | Line 30: | ||
margin-right: .5em; | margin-right: .5em; | ||
} | } | ||
#filter-bar { | |||
position: relative; | |||
margin: 1em 0 2em 0; | |||
} | |||
#gl-filters { | |||
position: absolute; | |||
top: 0; | |||
right: 0; | |||
z-index: 100; | |||
padding: 2em; | |||
width: 45vw; | |||
background: #fff; | |||
border: 1px solid var(--links-orange); | |||
clip-path: inset(0 0 100% 100%); | |||
box-shadow: -10px 10px 10px 5px rgb(0 0 0 / 10%); | |||
transition: all 400ms ease-in-out; | |||
} | |||
#gl-filters.open { | |||
clip-path: inset(0 0 -50px -50px); | |||
} | |||
#close-filter-button { | |||
display: block; | |||
cursor: pointer; | |||
font-size: 2.5em; | |||
line-height: .7em; | |||
margin-top: -.2em; | |||
font-weight: 100; | |||
color: var(--links-orange); | |||
} | |||
#gl-filters h2 svg { | |||
height: 1.5em; | |||
width: 1.5em; | |||
margin-right: .5em; | |||
margin-left: -.2em; | |||
} | |||
.large-button { | |||
border: 1px solid var(--links-orange); | |||
font-size: 1.5em; | |||
font-family: 'Open Sans'; | |||
font-weight: 100; | |||
margin-bottom: 2em; | |||
padding: 0.3em 0.8em; | |||
color: var(--links-orange); | |||
background: transparent; | |||
font-variant: small-caps; | |||
display: inline-block; | |||
transition: all 200ms ease-in-out; | |||
} | |||
.large-button:hover { | |||
background-color: var(--links-orange); | |||
color: #fff; | |||
} | |||
#guidelines-list-wrapper h2 { | |||
margin-bottom: 1em; | |||
} | |||
.filter-button-wrapper { | |||
margin-bottom: 1em; | |||
} | |||
.filter-wrapper button { | |||
border: 0 none; | |||
color: var(--links-orange); | |||
background-color: transparent; | |||
font-variant: small-caps; | |||
font-size: 1.2em; | |||
text-decoration: underline; | |||
padding: 0; | |||
} | |||
.filter-wrapper .filter-container { | |||
display: none; | |||
} | |||
.filter-wrapper.open .filter-container { | |||
display: block; | |||
} | |||
.filter-wrapper h4 { | |||
display: flex; | |||
justify-content: space-between; | |||
align-items: flex-start; | |||
} | |||
.filter-wrapper .filter-toggle svg { | |||
width: 1.5em; | |||
height: 1.5em; | |||
fill: var(--links-orange); | |||
cursor: pointer; | |||
} | |||
.filter-wrapper.open .filter-toggle { | |||
transform: rotate(180deg); | |||
} | |||
.filter-content { | |||
font-size: 1.2em; | |||
margin-bottom: 4em; | |||
display: grid; | |||
grid-template-columns: repeat(auto-fit, minmax(14em, 1fr)); | |||
gap: 1em 1em; | |||
align-items: start; | |||
} | |||
.filter-group-header { | |||
grid-column: 1/-1; | |||
margin-bottom: -.5em; | |||
margin-top: 1em; | |||
font-family: 'Raleway'; | |||
font-weight: 200; | |||
letter-spacing: .06em; | |||
} | |||
.filter-group-start { | |||
grid-column-start: 1; | |||
} | |||
.filter-content input[type="checkbox"] { | |||
margin-right: .5em; | |||
} | |||
.filter-content img { | |||
width: 2em; | |||
height: 2em; | |||
margin: 0 .5em 0 0; | |||
} | |||
#guideline-intro { | #guideline-intro { | ||
font-size: larger; | font-size: larger; | ||
margin-bottom: 4em; | margin-bottom: 4em; | ||
} | } | ||
#guideline-intro ul { font-size: initial; } | |||
#guideline-intro ul { | |||
font-size: initial; | |||
} | |||
#guideline-tabulator.tabulator { | |||
border: 0 none; | |||
background-color: transparent; | |||
font-size: 1.2em; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-header { | |||
background-color: transparent; | |||
border: 0 none; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-header .tabulator-col { | |||
border-bottom: 4px double var(--links-orange); | |||
border-right: 0 none; | |||
background: transparent; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-header .tabulator-col-content { | |||
padding: .5em 0; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-header .tabulator-col-sorter { | |||
right: .5em; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-row { | |||
background-color: transparent; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-cell { | |||
border-right: 0 none; | |||
border-top: 1px solid var(--links-orange); | |||
padding: .5em .5em .5em 0; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse { | |||
border: 0 none; | |||
padding: 0 .5em 2em 0; | |||
} | |||
#filter-summary { | |||
margin-right: 1em; | |||
} | |||
#filter-summary table tr td { | |||
vertical-align: top; | |||
} | |||
#filter-summary table tr td:first-of-type { | |||
padding-right: 10px; | |||
} | |||
#guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse table { | |||
font-size: smaller; | |||
} | |||
#filter-summary table tr td strong, | |||
#guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse td>strong { | |||
font-weight: 300; | |||
} | |||
#guideline-tabulator.tabulator .guideline-title a, | |||
#guideline-tabulator.tabulator .tabulator-responsive-collapse table a { | |||
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> | ||
<script> | <script> | ||
'use strict'; | |||
/** | |||
* @typedef {Object} FilterState | |||
* @property {string[]} phases | |||
* @property {string[]} thematics | |||
* @property {string[]} audienceExperiences | |||
* @property {string[]} audienceTargets | |||
* @property {string[]} languages | |||
* @property {string[]} dataSources | |||
* @property {string[]} techs | |||
*/ | |||
let table; // Tabulator instance | |||
// This defines how sources are grouped in the filter. | |||
// Any source not listed here will be added to the last group entitled "More platforms". | |||
const sourcesLayout = [ | |||
{ | |||
title: 'General', | |||
sources: ['Crowd', 'Web'] | |||
}, | |||
{ | |||
title: 'Platforms', | |||
sources: ['Facebook', 'Twitter', 'Instagram', 'YouTube'] | |||
} | |||
]; | |||
const PHASES = ["Before", "During", "After"]; | |||
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 removePrefix = str => str.substring(str.indexOf(':') + 1); | |||
const DATASRC_PROP = 'Data Sources'; | |||
const PHASE_PROP = 'Disaster Management Phase'; | |||
const THEME_PROP = 'Covers Thematic'; | |||
const LANG_PROP = 'Language'; | |||
const YEAR_PROP = 'Year Published'; | |||
const EX_PROP = 'Audience Experience Level'; | |||
const TA_PROP = 'Target Audience'; | |||
const TECH_PROP = 'Technologies' | |||
const guidelineQuery = '[[Category:Guideline]]' | |||
+ '|?' + DATASRC_PROP | |||
+ '|?' + PHASE_PROP | |||
+ '|?' + THEME_PROP | |||
+ '|?' + LANG_PROP | |||
+ '|?' + YEAR_PROP | |||
+ '|?' + EX_PROP | |||
+ '|?' + TA_PROP | |||
+ '|?' + TECH_PROP; | |||
+ '|limit=500' | |||
async function getGuidelines() { | |||
const guidelinesResponse = await fetch(getQueryUrl(guidelineQuery)).then(response => response.json()); | |||
return Object.keys(guidelinesResponse.query.results).map(title => { | |||
const guidelineResult = guidelinesResponse.query.results[title]; | |||
/** @type {Guideline} **/ | |||
const guideline = {}; | |||
guideline.title = title; | |||
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[THEME_PROP] = guidelineResult.printouts[THEME_PROP].map(value => value.fulltext); | |||
guideline[LANG_PROP] = guidelineResult.printouts[LANG_PROP].map(value => value.fulltext); | |||
guideline[TA_PROP] = guidelineResult.printouts[TA_PROP].map(value => value.fulltext); | |||
guideline[EX_PROP] = guidelineResult.printouts[EX_PROP].map(value => value.fulltext); | |||
guideline[YEAR_PROP] = guidelineResult.printouts[YEAR_PROP][0] && guidelineResult.printouts[YEAR_PROP][0].raw.slice(-4); | |||
guideline[TECH_PROP] = guidelineResult.printouts[TECH_PROP].map(value => value.fulltext); | |||
return guideline; | |||
}); | |||
} | |||
// 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) { | |||
// TODO: apply Filters | |||
if (!table) return; | |||
// If clear=true, pass empty object to the filter to disable it. | |||
if (clear) { | |||
table.setFilter(guidelineFilter, {}); | |||
return; | |||
} | |||
/** @type {FilterState} **/ | |||
const filterState = {}; | |||
const phaseOptions = Array.from(document.querySelectorAll('#phase-filter input[type="checkbox"]')); | |||
const selectedPhases = phaseOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | |||
filterState.phases = selectedPhases.length === phaseOptions.length ? undefined : selectedPhases; | |||
const thematicOptions = Array.from(document.querySelectorAll('#thematic-filter input[type="checkbox"]')); | |||
const selectedthematics = thematicOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | |||
filterState.thematics = selectedthematics.length === thematicOptions.length ? undefined : selectedthematics; | |||
const audienceExperienceOptions = Array.from(document.querySelectorAll('#audience-experience-filter input[type="checkbox"]')); | |||
const selectedaudienceExperiences = audienceExperienceOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | |||
filterState.audienceExperiences = selectedaudienceExperiences.length === audienceExperienceOptions.length ? undefined : selectedaudienceExperiences; | |||
const audienceTargetOptions = Array.from(document.querySelectorAll('#target-audience-filter input[type="checkbox"]')); | |||
const selectedaudienceTargets = audienceTargetOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | |||
filterState.audienceTargets = selectedaudienceTargets.length === audienceTargetOptions.length ? undefined : selectedaudienceTargets; | |||
const languageOptions = Array.from(document.querySelectorAll('#language-filter input[type="checkbox"]')); | |||
const selectedlanguages = languageOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | |||
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; | |||
const techOptions = Array.from(document.querySelectorAll('#tech-filter input[type="checkbox"]')); | |||
const selectedTechs = techOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value); | |||
filterState.techs = selectedTechs.length === techOptions.length ? undefined : selectedTechs; | |||
table.setFilter(guidelineFilter, filterState); | |||
} | |||
/** | |||
* @param {Guideline} guideline | |||
* @param {FilterState} filterState | |||
*/ | |||
function guidelineFilter(guideline, filterState) { | |||
// 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. | |||
const phaseCheck = filterState.phases | |||
? guideline[PHASE_PROP].some(phase => filterState.phases.includes(phase)) | |||
: true; | |||
const thematicCheck = filterState.thematics | |||
? guideline[THEME_PROP].some(theme => filterState.thematics.includes(theme)) | |||
: true; | |||
const audienceExperiencesCheck = filterState.audienceExperiences | |||
? guideline[EX_PROP].some(ex => filterState.audienceExperiences.includes(ex)) | |||
: true; | |||
const audienceTargetCheck = filterState.audienceTargets | |||
? guideline[TA_PROP].some(target => filterState.audienceTargets.includes(target)) | |||
: true; | |||
const langCheck = filterState.languages | |||
? guideline[LANG_PROP].some(lang => filterState.languages.includes(lang)) | |||
: true; | |||
const sourcesCheck = filterState.dataSources | |||
? guideline[DATASRC_PROP].some(source => filterState.dataSources.includes(source)) | |||
: true; | |||
const techCheck = filterState.techs | |||
? guideline[TECH_PROP].some(source => filterState.techs.includes(source)) | |||
: true | |||
return phaseCheck && thematicCheck && audienceExperiencesCheck && audienceTargetCheck && langCheck && sourcesCheck & techCheck; | |||
} | |||
Promise.all([getSources(), getGuidelines()]).then(data => { | |||
const [dataSources, guidelines] = data; | |||
let COVERS_THEMATIC_VALUES = [] | |||
let LANGUAGES_VALUES = []; | |||
let TARGET_AUDIENCE_VALUES = []; | |||
let EXPERIENCE_LEVEL_VALUES = []; | |||
let YEAR_LEVEL_VALUES = []; | |||
let PHASE_VALUES = []; | |||
let MENTIONS_TECHNOLOGIES_VALUES = []; | |||
for (const guideline of guidelines) { | |||
LANGUAGES_VALUES = LANGUAGES_VALUES.concat(guideline[LANG_PROP]); | |||
COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.concat(guideline[THEME_PROP]); | |||
TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.concat(guideline[TA_PROP]); | |||
YEAR_LEVEL_VALUES = YEAR_LEVEL_VALUES.concat(guideline[YEAR_PROP]); | |||
MENTIONS_TECHNOLOGIES_VALUES = MENTIONS_TECHNOLOGIES_VALUES.concat(guideline[TECH_PROP]); | |||
} | |||
LANGUAGES_VALUES = LANGUAGES_VALUES.sort(); | |||
COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.sort(); | |||
TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.sort(); | |||
MENTIONS_TECHNOLOGIES_VALUES = MENTIONS_TECHNOLOGIES_VALUES.sort(); | |||
LANGUAGES_VALUES = new Set(LANGUAGES_VALUES); | |||
COVERS_THEMATIC_VALUES = new Set(COVERS_THEMATIC_VALUES); | |||
TARGET_AUDIENCE_VALUES = new Set(TARGET_AUDIENCE_VALUES); | |||
YEAR_LEVEL_VALUES = new Set(YEAR_LEVEL_VALUES); | |||
MENTIONS_TECHNOLOGIES_VALUES = new Set(MENTIONS_TECHNOLOGIES_VALUES); | |||
PHASE_VALUES = PHASES; | |||
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) => { | |||
const identifier = escapeAttr(curr); | |||
return acc | |||
+ '<div><input type="checkbox" checked id="language-filter-' + identifier | |||
+ '" value="' + curr + '">' | |||
+ '<label for="language-filter-' + identifier + '">' + curr + '</label></div>' | |||
}, ''); | |||
document.getElementById('language-filter').innerHTML = languageFilterHtml; | |||
let coversThematicHtml = Array.from(COVERS_THEMATIC_VALUES.values()).reduce((acc, curr) => { | |||
const identifier = escapeAttr(curr); | |||
return acc | |||
+ '<div><input type="checkbox" checked id="thematic-filter-' + identifier | |||
+ '" value="' + curr + '">' | |||
+ '<label for="thematic-filter-' + identifier + '">' + curr + '</label></div>' | |||
}, ''); | |||
document.getElementById('thematic-filter').innerHTML = coversThematicHtml; | |||
let phaseHtml = Array.from(PHASE_VALUES.values()).reduce((acc, curr) => { | |||
const identifier = escapeAttr(curr); | |||
return acc | |||
+ '<div><input type="checkbox" checked id="phase-filter-' + identifier | |||
+ '" value="' + curr + '">' | |||
+ '<label for="phase-filter-' + identifier + '">' + curr + '</label></div>' | |||
}, ''); | |||
document.getElementById('phase-filter').innerHTML = phaseHtml; | |||
let targetAudienceHtml = Array.from(TARGET_AUDIENCE_VALUES.values()).reduce((acc, curr) => { | |||
const identifier = escapeAttr(curr); | |||
return acc | |||
+ '<div><input type="checkbox" checked id="target-audience-filter-' + identifier | |||
+ '" value="' + curr + '">' | |||
+ '<label for="target-audience-filter-' + identifier + '">' + curr + '</label></div>' | |||
}, ''); | |||
document.getElementById('target-audience-filter').innerHTML = targetAudienceHtml; | |||
let targetAudienceExperienceHtml = Array.from(EXPERIENCE_LEVEL_VALUES.values()).reduce((acc, curr) => { | |||
const identifier = escapeAttr(curr); | |||
return acc | |||
+ '<div><input type="checkbox" checked id="audience-experience-filter-' + identifier | |||
+ '" value="' + curr + '">' | |||
+ '<label for="audience-experience-filter-' + identifier + '">' + curr + '</label></div>' | |||
}, ''); | |||
document.getElementById('audience-experience-filter').innerHTML = targetAudienceExperienceHtml; | |||
let techHtml = Array.from(MENTIONS_TECHNOLOGIES_VALUES.values()).reduce((acc, curr) => { | |||
const identifier = escapeAttr(curr); | |||
return acc | |||
+ '<div><input type="checkbox" checked id="tech-filter-' + identifier | |||
+ '" value="' + curr + '">' | |||
+ '<label for="tech-filter-' + identifier + '">' + curr + '</label></div>' | |||
}, ''); | |||
document.getElementById('tech-filter').innerHTML = techHtml; | |||
const tabulator = new Tabulator('#guideline-tabulator', { | |||
data: guidelines, | |||
layout: 'fitDataFill', | |||
responsiveLayout: 'collapse', | |||
columns: [ | |||
{ | |||
title: 'Title', | |||
field: 'title', | |||
cssClass: 'guideline-title', | |||
formatter: cell => '<a href="' + cell.getData().url + '">' + cell.getValue() + '</a>' | |||
}, | |||
{ | |||
title: 'Year', | |||
field: YEAR_PROP | |||
}, | |||
{ | |||
title: 'Language', | |||
field: LANG_PROP, | |||
formatter: cell => cell.getValue().join(', ') | |||
}, | |||
{ | |||
title: 'Audience experience level', | |||
field: EX_PROP, | |||
formatter: cell => cell.getValue().join(', ') | |||
}, | |||
{ | |||
title: 'Covers thematic', | |||
field: THEME_PROP, | |||
formatter: cell => cell.getValue().join(', ') | |||
}, | |||
{ | |||
title: 'Target audience', | |||
field: TA_PROP, | |||
formatter: cell => cell.getValue().join(', ') | |||
}, | |||
{ | |||
title: 'Disaster Management Phase', | |||
field: PHASE_PROP, | |||
formatter: cell => cell.getValue().join(', ') | |||
}, | |||
{ | |||
title: 'Mentions Technologies', | |||
field: TECH_PROP, | |||
formatter: cell => cell.getValue().join(', ') | |||
}, | |||
{ | |||
title: 'Mentions Platforms', | |||
field: DATASRC_PROP, | |||
minWidth: 300, // required for responsiveness when using fitColumns | |||
cssClass: 'data-sources-cell', | |||
formatter: function (cell) { | |||
const val = cell.getValue(); | |||
let out = '<div>'; | |||
groupedSources.forEach((group, gIndex) => { | |||
// if (gIndex === groupedSources.length - 1) { out += '<div class="sources-collapse">'; } | |||
out += group.sources.reduce((prev, curr) => { | |||
const idx = val.findIndex(src => src === curr.name); | |||
if (idx === -1) { | |||
return prev; | |||
} else { | |||
return curr.image | |||
? prev + '<img class="data-source-img" data-value="' + curr.name | |||
+ '" src="' + curr.image | |||
+ '" alt="' + curr.name | |||
+ '" title="' + curr.name + '">' | |||
: prev + ' ' + curr.name; | |||
} | |||
}, ''); | |||
if (gIndex === groupedSources.length - 1) { | |||
// out += '<span class="sources-collapse-toggle"></span>'; | |||
// out += '</div>'; | |||
} | |||
}); | |||
return out + '</div>'; | |||
} | |||
} | |||
], | |||
initialSort: [ | |||
{ column: 'title', dir: 'asc' } | |||
] | |||
}); | |||
tabulator.on('tableBuilt', () => { | |||
tabulator.redraw(true); | |||
console.log('done') | |||
table = tabulator; | |||
}); | |||
tabulator.on('dataFiltered', (filters, rows) => { | |||
const summary = document.getElementById('filter-summary'); | |||
/** @type {FilterState} **/ | |||
const filter = filters[0]; | |||
// Set result counter | |||
document.getElementById('result-count').textContent = rows.length; | |||
// Exit if filter object/type doesn't exist (happens after Tabulator's own filter reset). | |||
if (!(filter && filter.type)) { summary.textContent = 'No filter. Showing all results.'; return; } | |||
// Update filter text. | |||
if ( | |||
!filter.type.thematics && | |||
!filter.type.languages && | |||
!filter.type.phases && | |||
!filter.type.audienceTargets && | |||
!filter.type.audienceExperiences && | |||
!filter.type.dataSources && | |||
!filter.type.techs | |||
) { summary.textContent = 'No filter. Showing all results.'; } | |||
else { | |||
let summaryHtml = '<table>'; | |||
if (filter.type.thematics) { | |||
summaryHtml += '<tr><td><strong>Covers Thematic</strong></td><td>' | |||
+ (filter.type.thematics.length > 0 ? filter.type.thematics.join(', ') : 'none') | |||
+ '</td></tr>'; | |||
} | |||
if (filter.type.languages) { | |||
summaryHtml += '<tr><td><strong>Language</strong></td><td>' | |||
+ (filter.type.languages.length > 0 ? filter.type.languages.join(', ') : 'none') | |||
+ '</td></tr>'; | |||
} | |||
if (filter.type.phases) { | |||
summaryHtml += '<tr><td><strong>Disaster Management Phase</strong></td><td>' | |||
+ (filter.type.phases.length > 0 ? filter.type.phases.join(', ') : 'none') | |||
+ '</td></tr>'; | |||
} | |||
if (filter.type.audienceTargets) { | |||
summaryHtml += '<tr><td><strong>Target audience</strong></td><td>' | |||
+ (filter.type.audienceTargets.length > 0 ? filter.type.audienceTargets.join(', ') : 'none') | |||
+ '</td></tr>'; | |||
} | |||
if (filter.type.audienceExperiences) { | |||
summaryHtml += '<tr><td><strong>Audience experience level</strong></td><td>' | |||
+ (filter.type.audienceExperiences.length > 0 ? filter.type.audienceExperiences.join(', ') : 'none') | |||
+ '</td></tr>'; | |||
} | |||
if (filter.type.dataSources) { | |||
summaryHtml += '<tr><td><strong>Mentions Platforms</strong></td><td>' | |||
+ (filter.type.dataSources.length > 0 ? filter.type.dataSources.join(', ') : 'none') | |||
+ '</td></tr>'; | |||
} | |||
if (filter.type.techs) { | |||
summaryHtml += '<tr><td><strong>Mentions Technologies</strong></td><td>' | |||
+ (filter.type.techs.length > 0 ? filter.type.techs.join(', ') : 'none') | |||
+ '</td></tr>'; | |||
} | |||
summaryHtml += '</table>'; | |||
summary.innerHTML = summaryHtml; | |||
} | |||
const markImages = () => { | |||
const selectedSources = filter.type.dataSources; | |||
const selectedFunctions = filter.type.functions; | |||
// Mark data source images | |||
document.querySelectorAll('.data-sources-cell .data-source-img, .tabulator-responsive-collapse .data-source-img') | |||
.forEach(img => { | |||
if (!selectedSources || selectedSources.includes(img.dataset.value)) { img.classList.remove('unselected'); } | |||
else { img.classList.add('unselected'); } | |||
}); | |||
// Mark functions images | |||
document.querySelectorAll('.functions-cell .func-img').forEach(img => { | |||
if (!selectedFunctions || selectedFunctions.includes(img.dataset.value)) { img.classList.remove('unselected'); } | |||
else { img.classList.add('unselected'); } | |||
}); | |||
tabulator.off('renderComplete', markImages); | |||
} | |||
tabulator.on('renderComplete', markImages); // TODO: Prevent this from running if corresponding filters are not active. | |||
}); | |||
// Listen for changes in filter checkbox state. | |||
document.getElementById('thematic-filter').addEventListener('change', event => { | |||
applyFilters(); | |||
}, { passive: true }); | |||
document.getElementById('audience-experience-filter').addEventListener('change', event => { | |||
applyFilters(); | |||
}, { passive: true }); | |||
document.getElementById('language-filter').addEventListener('change', event => { | |||
applyFilters(); | |||
}, { passive: true }); | |||
document.getElementById('phase-filter').addEventListener('change', event => { | |||
applyFilters(); | |||
}, { passive: true }); | |||
document.getElementById('target-audience-filter').addEventListener('change', event => { | |||
applyFilters(); | |||
}, { passive: true }); | |||
document.getElementById('data-source-filter').addEventListener('change', event => { | |||
applyFilters(); | |||
}, { passive: true }); | |||
document.getElementById('tech-filter').addEventListener('change', event => { | |||
applyFilters(); | |||
}, { passive: true }); | |||
// Listen for clicks on filter toggles | |||
document.querySelectorAll('.filter-wrapper .filter-toggle').forEach(el => { | |||
const wrapper = el.closest('.filter-wrapper'); | |||
el.addEventListener('click', event => void wrapper.classList.toggle('open')); | |||
}); | |||
// Close filter pane when clicked outside of it. | |||
document.body.addEventListener('click', event => { | |||
const filterPane = document.getElementById('gl-filters'); | |||
if ( | |||
filterPane.classList.contains('open') && | |||
!filterPane.contains(event.target) && | |||
event.target !== document.querySelector('#filter-bar .large-button') | |||
) { filterPane.classList.remove('open'); } | |||
}, { 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. | |||
// This will help detect it, in case it happens. | |||
console.log('Table height bugfix: render complete.'); | |||
try { | |||
const holderHeight = tabulator.rowManager.element.offsetHeight; | |||
const tableHeight = tabulator.rowManager.tableElement.offsetHeight; | |||
if ( | |||
holderHeight < tableHeight || // table is truncated vertically (including zero-height) | |||
holderHeight - tableHeight > window.screen.availHeight // table is more than a screen longer than content | |||
) { | |||
tabulator.redraw(); | |||
} | |||
} catch (ignore) { } | |||
}); | |||
// End bugfix | |||
}); | |||
function selectAll(context) { | |||
document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = true); | |||
applyFilters(); | |||
} | |||
function deselectAll(context) { | |||
document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = false); | |||
applyFilters(); | |||
} | |||
function clearFilters() { | |||
document.querySelectorAll('#gl-filters input[type="checkbox"]').forEach(checkbox => checkbox.checked = checkbox.defaultChecked); | |||
applyFilters(true); | |||
} | |||
function toggleFilter() { | |||
document.getElementById('gl-filters').classList.toggle('open'); | |||
} | |||
</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> | |||
</defs> | |||
</svg> | |||
<div id="guideline-list-wrapper"> | <div id="guideline-list-wrapper"> | ||
<h1> | <h1> | ||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96"><defs><clipPath id="b"><path d="M65 455h96v96H65z"/></clipPath></defs><g clip-path="url(#b)" transform="translate(-65 -455)"><path d="M138 463H84v79.961h54a5.014 5.014 0 0 0 5.019-5V468a5.014 5.014 0 0 0-5.019-5Zm-52 2h6.261v75.961H86Zm55.019 72.963a3.012 3.012 0 0 1-3.019 3H94.261V465H138a3.013 3.013 0 0 1 3.019 3Z"/><path d="M104 489h28v2h-28ZM110 500h16v2h-16Z"/></g></svg> | <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96"> | ||
<defs> | |||
<clipPath id="b"> | |||
<path d="M65 455h96v96H65z" /> | |||
</clipPath> | |||
</defs> | |||
<g clip-path="url(#b)" transform="translate(-65 -455)"> | |||
<path | |||
d="M138 463H84v79.961h54a5.014 5.014 0 0 0 5.019-5V468a5.014 5.014 0 0 0-5.019-5Zm-52 2h6.261v75.961H86Zm55.019 72.963a3.012 3.012 0 0 1-3.019 3H94.261V465H138a3.013 3.013 0 0 1 3.019 3Z" /> | |||
<path d="M104 489h28v2h-28ZM110 500h16v2h-16Z" /> | |||
</g> | |||
</svg> | |||
<span>Guidelines</span> | <span>Guidelines</span> | ||
</h1> | </h1> | ||
<div id="guideline-intro"> | <div id="guideline-intro"> | ||
<p> | <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> | |||
<ul> | <ul> | ||
<li>Building a communication strategy for social media and consideration of the main elements (e.g. needed roles | <li>Building a communication strategy for social media and consideration of the main elements (e.g. | ||
needed roles for the team)</li> | |||
<li>Set up and evaluate social media activities</li> | <li>Set up and evaluate social media activities</li> | ||
<li>Recommended actions on social media before, during and after a crisis</li> | <li>Recommended actions on social media before, during and after a crisis</li> | ||
Line 51: | Line 844: | ||
</div> | </div> | ||
</div> | </div> | ||
<!-- FILTERS --> | |||
<div id="filter-bar"> | |||
<div style="display: flex; justify-content: space-between;"> | |||
<div style="flex: 1 1;"> | |||
<h2 style="margin-bottom: 1rem;">Applied Filters</h2> | |||
<div id="filter-summary">No filter. Showing all results.</div> | |||
</div> | |||
<div style="flex: 0 0;"> | |||
<button class="large-button" type="button" onclick="toggleFilter()">Filters</button> | |||
</div> | |||
</div> | |||
<h2 style="margin-top: 2.5rem; margin-bottom: 0;">Results: <span id="result-count"></span></h2> | |||
<div id="gl-filters"> | |||
<h2 style="display: flex; justify-content: space-between;"> | |||
<div> | |||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96"> | |||
<defs> | |||
<clipPath id="b"> | |||
<path d="M592 312h96v96h-96z" /> | |||
</clipPath> | |||
</defs> | |||
<g clip-path="url(#b)" transform="translate(-592 -312)"> | |||
<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> | |||
</svg> | |||
<span>Filters</span> | |||
</div> | |||
<a onclick="toggleFilter()" id="close-filter-button">×</a> | |||
</h2> | |||
<div style="text-align: center;"> | |||
<button class="large-button" type="button" onclick="clearFilters()">Clear Filters</button> | |||
</div> | |||
<div class="filter-wrapper"> | |||
<h4>Covers Thematic <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('#thematic-filter')">Select all</button> | | |||
<button type="button" onclick="deselectAll('#thematic-filter')">Clear all</button> | |||
</div> | |||
<div class="filter-content" id="thematic-filter"></div> | |||
</div> | |||
</div> | |||
<div class="filter-wrapper"> | |||
<h4>Language<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('#language-filter')">Select all</button> | | |||
<button type="button" onclick="deselectAll('#language-filter')">Clear all</button> | |||
</div> | |||
<div class="filter-content" id="language-filter"></div> | |||
</div> | |||
</div> | |||
<div class="filter-wrapper"> | |||
<h4>Disaster Management Phase<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('#phase-filter')">Select all</button> | | |||
<button type="button" onclick="deselectAll('#phase-filter')">Clear all</button> | |||
</div> | |||
<div class="filter-content" id="phase-filter"></div> | |||
</div> | |||
</div> | |||
<div class="filter-wrapper"> | |||
<h4>Target audience<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('#target-audience-filter')">Select all</button> | | |||
<button type="button" onclick="deselectAll('#target-audience-filter')">Clear all</button> | |||
</div> | |||
<div class="filter-content" id="target-audience-filter"></div> | |||
</div> | |||
</div> | |||
<div class="filter-wrapper"> | |||
<h4>Audience experience level<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('#audience-experience-filter')">Select all</button> | | |||
<button type="button" onclick="deselectAll('#audience-experience-filter')">Clear all</button> | |||
</div> | |||
<div class="filter-content" id="audience-experience-filter"></div> | |||
</div> | |||
</div> | |||
<div class="filter-wrapper"> | |||
<h4>Mentions 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 class="filter-wrapper"> | |||
<h4>Mentions Techologies <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('#tech-filter')">Select all</button> | | |||
<button type="button" onclick="deselectAll('#tech-filter')">Clear all</button> | |||
</div> | |||
<div class="filter-content" id="tech-filter"></div> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
<div id="guideline-tabulator"></div> | |||
</includeonly> | </includeonly> |
Latest revision as of 16:08, 24 November 2022
Development version of the List of Guidelines.
Not ready for production!