Difference between revisions of "Widget:DevGuidelines"

From LINKS Community Center
Jump to: navigation, search
 
(18 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 {
 
         #gl-filters {
 
             position: absolute;
 
             position: absolute;
Line 44: Line 49:
 
             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 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 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 203: Line 214:
 
         }
 
         }
  
         #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;
 +
        }
  
 
         #guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse table {
 
         #guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse table {
Line 218: Line 235:
 
         }
 
         }
  
         #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);
Line 224: Line 241:
  
  
 +
        .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 261:
 
         * @property {string[]} audienceTargets
 
         * @property {string[]} audienceTargets
 
         * @property {string[]} languages
 
         * @property {string[]} languages
         */  
+
        * @property {string[]} dataSources
 +
        * @property {string[]} techs
 +
         */
 
         let table;  // Tabulator instance
 
         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 PHASES = ["Before", "During", "After"];
 
         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 escapeAttr = text => text ? text.replace(/\W/g, '-') : text;
+
         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 251: 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 258: Line 304:
 
             + '|?' + YEAR_PROP
 
             + '|?' + YEAR_PROP
 
             + '|?' + EX_PROP
 
             + '|?' + EX_PROP
             + '|?' + TA_PROP;
+
             + '|?' + TA_PROP
 +
            + '|?' + TECH_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 318:
 
                 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 277: 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;
 
             });
 
             });
 
         }
 
         }
  
 +
 +
        // 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 356:
 
             }
 
             }
  
 
+
             /** @type {FilterState} **/
             /** @type {FilterState} **/  
 
 
             const filterState = {};
 
             const filterState = {};
  
Line 302: Line 366:
 
             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 378:
 
             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;
 +
 +
            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);
 
             table.setFilter(guidelineFilter, filterState);
Line 323: Line 395:
 
         * @param {FilterState} filterState
 
         * @param {FilterState} filterState
 
         */
 
         */
        function guidelineFilter(guideline, 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 341: Line 413:
 
                 ? guideline[LANG_PROP].some(lang => filterState.languages.includes(lang))
 
                 ? guideline[LANG_PROP].some(lang => filterState.languages.includes(lang))
 
                 : true;
 
                 : 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;
+
             return phaseCheck && thematicCheck && audienceExperiencesCheck && audienceTargetCheck && langCheck && sourcesCheck & techCheck;
 
         }
 
         }
  
         Promise.all([getGuidelines()]).then(data => {
+
         Promise.all([getSources(), getGuidelines()]).then(data => {
             const guidelines = data[0];
+
 
            console.log(guidelines);
+
             const [dataSources, guidelines] = data;
  
             let COVERS_THEMATIC_VALUES = []
+
             let COVERS_THEMATIC_VALUES = []
 
             let LANGUAGES_VALUES = [];
 
             let LANGUAGES_VALUES = [];
 
             let TARGET_AUDIENCE_VALUES = [];
 
             let TARGET_AUDIENCE_VALUES = [];
Line 355: Line 433:
 
             let YEAR_LEVEL_VALUES = [];
 
             let YEAR_LEVEL_VALUES = [];
 
             let PHASE_VALUES = [];
 
             let PHASE_VALUES = [];
 +
            let MENTIONS_TECHNOLOGIES_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.concat(guideline[YEAR_PROP])
+
                 YEAR_LEVEL_VALUES = YEAR_LEVEL_VALUES.concat(guideline[YEAR_PROP]);
 +
                MENTIONS_TECHNOLOGIES_VALUES = MENTIONS_TECHNOLOGIES_VALUES.concat(guideline[TECH_PROP]);
 
             }
 
             }
  
Line 367: Line 447:
 
             COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.sort();
 
             COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.sort();
 
             TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.sort();
 
             TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.sort();
 +
            MENTIONS_TECHNOLOGIES_VALUES = MENTIONS_TECHNOLOGIES_VALUES.sort();
  
 
             LANGUAGES_VALUES = new Set(LANGUAGES_VALUES);
 
             LANGUAGES_VALUES = new Set(LANGUAGES_VALUES);
Line 372: Line 453:
 
             TARGET_AUDIENCE_VALUES = new Set(TARGET_AUDIENCE_VALUES);
 
             TARGET_AUDIENCE_VALUES = new Set(TARGET_AUDIENCE_VALUES);
 
             YEAR_LEVEL_VALUES = new Set(YEAR_LEVEL_VALUES);
 
             YEAR_LEVEL_VALUES = new Set(YEAR_LEVEL_VALUES);
 +
            MENTIONS_TECHNOLOGIES_VALUES = new Set(MENTIONS_TECHNOLOGIES_VALUES);
 
             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 392: Line 502:
 
             }, '');
 
             }, '');
 
             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 401: Line 511:
 
             }, '');
 
             }, '');
 
             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 419: Line 529:
 
             }, '');
 
             }, '');
 
             document.getElementById('audience-experience-filter').innerHTML = targetAudienceExperienceHtml;
 
             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', {
 
             const tabulator = new Tabulator('#guideline-tabulator', {
 
                 data: guidelines,
 
                 data: guidelines,
Line 459: Line 579:
 
                         field: PHASE_PROP,
 
                         field: PHASE_PROP,
 
                         formatter: cell => cell.getValue().join(', ')
 
                         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 475: Line 632:
 
             tabulator.on('dataFiltered', (filters, rows) => {
 
             tabulator.on('dataFiltered', (filters, rows) => {
 
                 const summary = document.getElementById('filter-summary');
 
                 const summary = document.getElementById('filter-summary');
 +
 +
                /** @type {FilterState}  **/
 +
 
                 const filter = filters[0];
 
                 const filter = filters[0];
  
                console.log("Filtesr", filter);
 
                   
 
 
                 // Set result counter
 
                 // Set result counter
 
                 document.getElementById('result-count').textContent = rows.length;
 
                 document.getElementById('result-count').textContent = rows.length;
Line 485: Line 643:
 
                 if (!(filter && filter.type)) { summary.textContent = 'No filter. Showing all results.'; return; }
 
                 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.
 
             });
 
             });
  
Line 503: Line 731:
 
             }, { passive: true });
 
             }, { passive: true });
 
             document.getElementById('target-audience-filter').addEventListener('change', event => {
 
             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 512: Line 746:
 
             });
 
             });
  
              // Close filter pane when clicked outside of it.
+
            // 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 521: Line 755:
 
                 ) { filterPane.classList.remove('open'); }
 
                 ) { filterPane.classList.remove('open'); }
 
             }, { 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.
 +
                // 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
 
         });
 
         });
  
Line 542: Line 795:
 
         }
 
         }
 
     </script>
 
     </script>
  <!-- Icon definitons -->
+
    <!-- Icon definitons -->
  <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" style="display:none;">
+
    <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" style="display:none;">
    <defs>
+
        <defs>
        <symbol id="chevron-down" viewBox="0 0 96 96">
+
            <symbol id="chevron-down" viewBox="0 0 96 96">
            <clipPath id="chev">
+
                <clipPath id="chev">
                <path d="M592 312h96v96h-96z" />
+
                    <path d="M592 312h96v96h-96z" />
            </clipPath>
+
                </clipPath>
            <g clip-path="url(#chev)" transform="translate(-592 -312)">
+
                <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" />
+
                    <path
            </g>
+
                        d="m640 370.586-25.293-25.293-1.414 1.414L640 373.414l26.707-26.707-1.414-1.414L640 370.586Z" />
        </symbol>
+
                </g>
    </defs>
+
            </symbol>
</svg>
+
        </defs>
 
+
    </svg>
  
 
     <div id="guideline-list-wrapper">
 
     <div id="guideline-list-wrapper">
Line 574: 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 602: Line 857:
 
             </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 616: 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" />
+
                                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 627: 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 637: Line 893:
 
             </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 647: Line 905:
 
             </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 657: Line 917:
 
             </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 667: Line 929:
 
             </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 674: Line 938:
 
                     </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>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>

Latest revision as of 17:08, 24 November 2022

Development version of the List of Guidelines.
Not ready for production!