Difference between revisions of "Widget:DevGuidelines"
From LINKS Community Center
(48 intermediate revisions by the same user not shown) | |||
Line 30: | Line 30: | ||
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 { | ||
position: absolute; | position: absolute; | ||
top: 0; | top: 0; | ||
Line 39: | Line 44: | ||
width: 45vw; | width: 45vw; | ||
background: #fff; | background: #fff; | ||
− | border: 1px solid var(--links- | + | border: 1px solid var(--links-orange); |
clip-path: inset(0 0 100% 100%); | clip-path: inset(0 0 100% 100%); | ||
box-shadow: -10px 10px 10px 5px rgb(0 0 0 / 10%); | box-shadow: -10px 10px 10px 5px rgb(0 0 0 / 10%); | ||
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 55: | Line 61: | ||
margin-top: -.2em; | margin-top: -.2em; | ||
font-weight: 100; | font-weight: 100; | ||
− | color: var(--links- | + | color: var(--links-orange); |
} | } | ||
Line 66: | Line 72: | ||
.large-button { | .large-button { | ||
− | border: 1px solid var(--links- | + | border: 1px solid var(--links-orange); |
font-size: 1.5em; | font-size: 1.5em; | ||
font-family: 'Open Sans'; | font-family: 'Open Sans'; | ||
Line 72: | Line 78: | ||
margin-bottom: 2em; | margin-bottom: 2em; | ||
padding: 0.3em 0.8em; | padding: 0.3em 0.8em; | ||
− | color: var(--links- | + | color: var(--links-orange); |
background: transparent; | background: transparent; | ||
font-variant: small-caps; | font-variant: small-caps; | ||
Line 80: | Line 86: | ||
.large-button:hover { | .large-button:hover { | ||
− | background-color: var(--links- | + | background-color: var(--links-orange); |
color: #fff; | color: #fff; | ||
} | } | ||
Line 94: | Line 100: | ||
.filter-wrapper button { | .filter-wrapper button { | ||
border: 0 none; | border: 0 none; | ||
− | color: var(--links- | + | color: var(--links-orange); |
background-color: transparent; | background-color: transparent; | ||
font-variant: small-caps; | font-variant: small-caps; | ||
Line 102: | Line 108: | ||
} | } | ||
− | .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 114: | Line 125: | ||
width: 1.5em; | width: 1.5em; | ||
height: 1.5em; | height: 1.5em; | ||
− | fill: var(--links- | + | fill: var(--links-orange); |
cursor: pointer; | cursor: pointer; | ||
} | } | ||
Line 173: | Line 184: | ||
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 201: | Line 212: | ||
border: 0 none; | border: 0 none; | ||
padding: 0 .5em 2em 0; | 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; | ||
} | } | ||
Line 207: | Line 230: | ||
} | } | ||
+ | #filter-summary table tr td strong, | ||
#guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse td>strong { | #guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse td>strong { | ||
font-weight: 300; | font-weight: 300; | ||
} | } | ||
− | #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 221: | Line 254: | ||
'use strict'; | '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 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 PHASE_PROP = 'Disaster Management Phase'; | ||
const THEME_PROP = 'Covers Thematic'; | const THEME_PROP = 'Covers Thematic'; | ||
Line 229: | Line 295: | ||
const EX_PROP = 'Audience Experience Level'; | const EX_PROP = 'Audience Experience Level'; | ||
const TA_PROP = 'Target Audience'; | const TA_PROP = 'Target Audience'; | ||
+ | const TECH_PROP = 'Technologies' | ||
const guidelineQuery = '[[Category:Guideline]]' | const guidelineQuery = '[[Category:Guideline]]' | ||
+ | + '|?' + DATASRC_PROP | ||
+ '|?' + PHASE_PROP | + '|?' + PHASE_PROP | ||
+ '|?' + THEME_PROP | + '|?' + THEME_PROP | ||
Line 236: | Line 304: | ||
+ '|?' + YEAR_PROP | + '|?' + YEAR_PROP | ||
+ '|?' + EX_PROP | + '|?' + EX_PROP | ||
− | + '|?' + TA_PROP; | + | + '|?' + TA_PROP |
+ | + '|?' + TECH_PROP; | ||
+ | + '|limit=500' | ||
async function getGuidelines() { | async function getGuidelines() { | ||
Line 243: | Line 313: | ||
return Object.keys(guidelinesResponse.query.results).map(title => { | return Object.keys(guidelinesResponse.query.results).map(title => { | ||
const guidelineResult = guidelinesResponse.query.results[title]; | const guidelineResult = guidelinesResponse.query.results[title]; | ||
+ | |||
+ | /** @type {Guideline} **/ | ||
const guideline = {}; | const guideline = {}; | ||
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 252: | Line 325: | ||
guideline[EX_PROP] = guidelineResult.printouts[EX_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[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; | return guideline; | ||
}); | }); | ||
} | } | ||
− | |||
− | |||
− | const table = new Tabulator('#guideline-tabulator', { | + | // 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, | data: guidelines, | ||
layout: 'fitDataFill', | layout: 'fitDataFill', | ||
Line 293: | Line 574: | ||
field: TA_PROP, | field: TA_PROP, | ||
formatter: cell => cell.getValue().join(', ') | 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: [ | initialSort: [ | ||
Line 300: | Line 624: | ||
}); | }); | ||
− | + | tabulator.on('tableBuilt', () => { | |
− | + | tabulator.redraw(true); | |
console.log('done') | 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. | // Listen for changes in filter checkbox state. | ||
Line 316: | Line 727: | ||
applyFilters(); | applyFilters(); | ||
}, { passive: true }); | }, { passive: true }); | ||
− | document.getElementById('target-audience- | + | 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(); | applyFilters(); | ||
}, { passive: true }); | }, { passive: true }); | ||
Line 326: | Line 746: | ||
}); | }); | ||
+ | // 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) { | function selectAll(context) { | ||
Line 340: | Line 787: | ||
function clearFilters() { | function clearFilters() { | ||
− | document.querySelectorAll('#gl-filters input[type="checkbox').forEach(checkbox => checkbox.checked = checkbox.defaultChecked); | + | document.querySelectorAll('#gl-filters input[type="checkbox"]').forEach(checkbox => checkbox.checked = checkbox.defaultChecked); |
applyFilters(true); | applyFilters(true); | ||
} | } | ||
Line 348: | Line 795: | ||
} | } | ||
</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> | ||
Line 365: | Line 827: | ||
</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 393: | Line 857: | ||
</div> | </div> | ||
</div> | </div> | ||
+ | <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 407: | Line 870: | ||
<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 418: | Line 881: | ||
</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 428: | Line 893: | ||
</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>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-container"> | ||
<div class="filter-button-wrapper"> | <div class="filter-button-wrapper"> | ||
Line 438: | Line 941: | ||
</div> | </div> | ||
<div class="filter-wrapper"> | <div class="filter-wrapper"> | ||
− | <h4> | + | <h4>Mentions Platforms <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"> | ||
− | <button type="button" onclick="selectAll('# | + | <button type="button" onclick="selectAll('#data-source-filter')">Select all</button> | |
− | <button type="button" onclick="deselectAll('# | + | <button type="button" onclick="deselectAll('#data-source-filter')">Clear all</button> |
</div> | </div> | ||
− | <div class="filter-content" id=" | + | <div class="filter-content" id="data-source-filter"></div> |
</div> | </div> | ||
</div> | </div> | ||
<div class="filter-wrapper"> | <div class="filter-wrapper"> | ||
− | <h4> | + | <h4>Mentions Techologies <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"> | ||
− | <button type="button" onclick="selectAll('# | + | <button type="button" onclick="selectAll('#tech-filter')">Select all</button> | |
− | <button type="button" onclick="deselectAll('# | + | <button type="button" onclick="deselectAll('#tech-filter')">Clear all</button> |
</div> | </div> | ||
− | <div class="filter-content" id=" | + | <div class="filter-content" id="tech-filter"></div> |
</div> | </div> | ||
</div> | </div> |
Latest revision as of 17:08, 24 November 2022
Development version of the List of Guidelines.
Not ready for production!