Difference between revisions of "Widget:GuidelinesList"

From LINKS Community Center
Jump to: navigation, search
 
(23 intermediate revisions by one other user not shown)
Line 1: Line 1:
<noinclude>Development version of the List of Guidelines.<br><strong style="color:red;">Not ready for production!</strong></noinclude>
+
<noinclude>Current version of the List of Guidelines.<br><strong style="color:red;">Currently in use &ndash; do not modify!</strong></noinclude>
 
<includeonly>
 
<includeonly>
     <link href="/resources/assets/tabulator.min.css" rel="stylesheet">
+
     <link href="/resources/assets/tabulator/dist/css/tabulator.min.css" rel="stylesheet">
     <script type="text/javascript" src="/resources/assets/tabulator.min.js"></script>
+
     <script type="text/javascript" src="/resources/assets/tabulator/dist/js/tabulator.min.js"></script>
     <style>
+
      
        #guideline-list-wrapper {
+
  <!-- STYLES BEGIN -->
            font-family: 'Open Sans';
+
<link rel="stylesheet" href="https://www.safetyinnovation.center/lcc/gl_list/styles.css">
            margin-top: 4em;
+
<!-- STYLES END -->
        }
 
 
 
        #guideline-list-wrapper h1,
 
        #guideline-list-wrapper h2,
 
        #guideline-list-wrapper h3,
 
        #guideline-list-wrapper h4 {
 
            font-family: 'Raleway';
 
            font-weight: 300;
 
            letter-spacing: .06em;
 
        }
 
 
 
        #guideline-list-wrapper h1,
 
        #guideline-filters h2 {
 
            color: var(--links-orange);
 
            display: flex;
 
            align-items: center;
 
        }
 
 
 
        #guideline-list-wrapper h1 svg {
 
            height: 2.5em;
 
            width: 2.5em;
 
            fill: var(--links-orange);
 
            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 .filter-toggle {
 
            cursor: pointer;
 
        }
 
 
 
        .filter-wrapper.open .plus.icon::after {
 
            transform: rotate(0);
 
        }
 
 
 
        .filter-content {
 
            font-size: 1.2em;
 
            margin-bottom: 2em;
 
            display: grid;
 
            grid-template-columns: repeat(auto-fit, minmax(14em, 1fr));
 
            align-items: start;
 
        }
 
       
 
        .filter-content.loose {
 
            gap: .5em .5em;
 
        }
 
 
 
        .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;
 
        }
 
 
 
        .filter-content label {
 
            display: inline;
 
        }
 
 
 
        #guideline-intro {
 
            font-size: larger;
 
            margin-bottom: 4em;
 
        }
 
 
 
        #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>
 
    <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;
 
            });
 
        }
 
  
 +
    <!-- SCRIPT BEGIN -->
 +
    <script type="text/javascript" src="https://www.safetyinnovation.center/lcc/gl_list/script.js"></script>
 +
    <!-- SCRIPT END -->
  
        // 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>
 
 
     <!-- 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;">
Line 855: Line 73:
 
                     <div id="filter-summary">No filter. Showing all results.</div>
 
                     <div id="filter-summary">No filter. Showing all results.</div>
 
                 </div>
 
                 </div>
                 <div style="flex: 0 0;">
+
                 <div>
                     <button class="large-button" type="button" onclick="toggleFilter()">Filters</button>
+
                     <button class="large-button" type="button" onclick="toggleFilter()">Open Filters</button>
 
                 </div>
 
                 </div>
 
             </div>
 
             </div>
             <h2 style="margin-top: 2.5rem; margin-bottom: 0;">Results: <span id="result-count"></span></h2>
+
 
 +
             <div style="display: flex; justify-content: space-between; align-items: center; margin-top: 2.5rem;">
 +
                <h2 style="margin-bottom: 0;">Results: <span id="result-count"></span></h2>
 +
                <div><a href="/index.php/Form:Guideline" style="font-size: 1.5em; font-variant:small-caps; color: var(--links-orange)">Add new guideline</a></div>
 +
            </div>
 
      
 
      
 
             <div id="gl-filters">
 
             <div id="gl-filters">
Line 880: Line 102:
 
                 </h2>
 
                 </h2>
 
                 <div style="text-align: center;">
 
                 <div style="text-align: center;">
                     <button class="large-button" type="button" onclick="clearFilters()">Show All</button>
+
                     <button class="large-button" type="button" onclick="clearFilters()">Clear Filters</button>
 
                 </div>
 
                 </div>
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
Line 932: Line 154:
 
                     </div>
 
                     </div>
 
                 </div>
 
                 </div>
                 <div class="filter-wrapper">
+
                 <!-- <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Mentions Platforms <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Mentions Platforms <div class="plus icon"></div></h4>
 
                     <div class="filter-container">
 
                     <div class="filter-container">
Line 941: Line 163:
 
                         <div class="filter-content loose" id="data-source-filter"></div>
 
                         <div class="filter-content loose" id="data-source-filter"></div>
 
                     </div>
 
                     </div>
                 </div>
+
                 </div> -->
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Mentions Technologies <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Mentions Technologies <div class="plus icon"></div></h4>

Latest revision as of 20:49, 10 May 2024

Current version of the List of Guidelines.
Currently in use – do not modify!