Difference between revisions of "Widget:DCTList"

From LINKS Community Center
Jump to: navigation, search
Line 5: Line 5:
  
 
     <style>
 
     <style>
         #dct-list-wrapper { font-family: 'Open Sans'; margin-top: 4em; }
+
         #dct-list-wrapper {
         #dct-list-wrapper h1, #dct-list-wrapper h2, #dct-list-wrapper h3 {
+
            font-family: 'Open Sans';
 +
            margin-top: 4em;
 +
        }
 +
 
 +
         #dct-list-wrapper h1,
 +
        #dct-list-wrapper h2,
 +
        #dct-list-wrapper h3 {
 
             font-family: 'Raleway';
 
             font-family: 'Raleway';
 
             font-weight: 300;
 
             font-weight: 300;
 
             letter-spacing: .06em;
 
             letter-spacing: .06em;
 
         }
 
         }
         #dct-list-wrapper h1, #dct-filters h2 {
+
 
 +
         #dct-list-wrapper h1,
 +
        #dct-filters h2 {
 
             color: var(--links-blue);
 
             color: var(--links-blue);
 
             display: flex;
 
             display: flex;
 
             align-items: center;
 
             align-items: center;
 
         }
 
         }
 +
 
         #dct-intro {
 
         #dct-intro {
 
             font-size: larger;
 
             font-size: larger;
 
             margin-bottom: 4em;
 
             margin-bottom: 4em;
 
         }
 
         }
 +
 
         #dct-list-wrapper h1 svg {
 
         #dct-list-wrapper h1 svg {
 
             height: 2.5em;
 
             height: 2.5em;
Line 26: Line 36:
 
             margin-right: .5em;
 
             margin-right: .5em;
 
         }
 
         }
 +
 
         #dct-filters h2 svg {
 
         #dct-filters h2 svg {
 
             height: 1.5em;
 
             height: 1.5em;
Line 33: Line 44:
 
             margin-left: -.2em;
 
             margin-left: -.2em;
 
         }
 
         }
 +
 
         #clear-filters-button {
 
         #clear-filters-button {
 
             border: 1px solid var(--links-blue);
 
             border: 1px solid var(--links-blue);
Line 44: Line 56:
 
             font-variant: small-caps;
 
             font-variant: small-caps;
 
         }
 
         }
 +
 
         #dct-list-wrapper h2 {
 
         #dct-list-wrapper h2 {
 
             margin-bottom: 1em;
 
             margin-bottom: 1em;
 
         }
 
         }
 +
 
         .filter-button-wrapper {
 
         .filter-button-wrapper {
 
             margin: 1.5em 0 1em 0;
 
             margin: 1.5em 0 1em 0;
 
         }
 
         }
 +
 
         .filter-wrapper button {
 
         .filter-wrapper button {
 
             border: 0 none;
 
             border: 0 none;
Line 59: Line 74:
 
             padding: 0;
 
             padding: 0;
 
         }
 
         }
 +
 
         .filter-content {
 
         .filter-content {
 
             font-size: 1.2em;
 
             font-size: 1.2em;
Line 67: Line 83:
 
             align-items: end;
 
             align-items: end;
 
         }
 
         }
 +
 
         .filter-group-header {
 
         .filter-group-header {
 
             grid-column: 1/-1;
 
             grid-column: 1/-1;
Line 75: Line 92:
 
             letter-spacing: .06em;
 
             letter-spacing: .06em;
 
         }
 
         }
         .filter-group-start { grid-column-start: 1; }
+
 
         .filter-content img { width: 2em; height: 2em; margin: 0 .5em; }
+
         .filter-group-start {
         #dct-tabulator.tabulator { border: 0 none; background-color: transparent; font-size: 1.2em; }
+
            grid-column-start: 1;
         #dct-tabulator.tabulator .tabulator-header { border-bottom: 4px double var(--links-blue); background-color: transparent; }
+
        }
         #dct-tabulator.tabulator .tabulator-header .tabulator-col { border-right: 0 none; background: transparent; }
+
 
         #dct-tabulator.tabulator .tabulator-header .tabulator-col-content { padding: .5em 0; }
+
         .filter-content img {
         #dct-tabulator.tabulator .tabulator-header .tabulator-col-sorter { right: 1em; }
+
            width: 2em;
         #dct-tabulator.tabulator .tabulator-row { background-color: transparent; }
+
            height: 2em;
         #dct-tabulator.tabulator .tabulator-cell { border-right: 0 none; border-bottom: 1px solid var(--links-blue); padding: .5em 0; }
+
            margin: 0 .5em;
         .data-source-img, .func-img { width: 2em; height: 2em; margin-right: .4em; margin-bottom: .4em; }
+
        }
 +
 
 +
         #dct-tabulator.tabulator {
 +
            border: 0 none;
 +
            background-color: transparent;
 +
            font-size: 1.2em;
 +
        }
 +
 
 +
         #dct-tabulator.tabulator .tabulator-header {
 +
            border-bottom: 4px double var(--links-blue);
 +
            background-color: transparent;
 +
        }
 +
 
 +
         #dct-tabulator.tabulator .tabulator-header .tabulator-col {
 +
            border-right: 0 none;
 +
            background: transparent;
 +
        }
 +
 
 +
         #dct-tabulator.tabulator .tabulator-header .tabulator-col-content {
 +
            padding: .5em 0;
 +
        }
 +
 
 +
         #dct-tabulator.tabulator .tabulator-header .tabulator-col-sorter {
 +
            right: 1em;
 +
        }
 +
 
 +
         #dct-tabulator.tabulator .tabulator-row {
 +
            background-color: transparent;
 +
        }
 +
 
 +
         #dct-tabulator.tabulator .tabulator-cell {
 +
            border-right: 0 none;
 +
            border-top: 1px solid var(--links-blue);
 +
            padding: .5em 0;
 +
        }
 +
 
 +
         .data-source-img,
 +
        .func-img {
 +
            width: 2em;
 +
            height: 2em;
 +
            margin-right: .4em;
 +
            margin-bottom: .4em;
 +
        }
 +
 
 
         #dct-tabulator img.unselected {
 
         #dct-tabulator img.unselected {
 
             filter: grayscale(1);
 
             filter: grayscale(1);
 
             opacity: .25;
 
             opacity: .25;
 
         }
 
         }
 +
 
         .sources-collapse {
 
         .sources-collapse {
 
             display: inline-block;
 
             display: inline-block;
 
         }
 
         }
         .sources-collapse-toggle { display:inline-block; width: 2em; height: 2em; }
+
 
 +
         .sources-collapse-toggle {
 +
            display: inline-block;
 +
            width: 2em;
 +
            height: 2em;
 +
        }
 +
 
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse {
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse {
 
             padding: .5em 0 1.5em 0;
 
             padding: .5em 0 1.5em 0;
 
             border: 0 none;
 
             border: 0 none;
 
         }
 
         }
 +
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse table tr td strong {
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse table tr td strong {
 
             font-family: 'Raleway';
 
             font-family: 'Raleway';
Line 102: Line 170:
 
             display: block;
 
             display: block;
 
         }
 
         }
 +
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse table tr:nth-child(n+2) td strong {
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse table tr:nth-child(n+2) td strong {
 
             margin-top: 1em;
 
             margin-top: 1em;
 
         }
 
         }
 +
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse table tr td {
 
         #dct-tabulator .tabulator-row .tabulator-responsive-collapse table tr td {
 
             display: block;
 
             display: block;
Line 111: Line 181:
  
 
     <script>
 
     <script>
    'use strict';
+
        'use strict';
 +
 
 +
        /**
 +
        * @typedef {Object} DCT
 +
        * @property {string} name
 +
        * @property {string} url
 +
        * @property {string[]} dataSources
 +
        * @property {string[]} functions
 +
        * @property {string} logo
 +
        */
 +
 
 +
        let table;
 +
 
 +
        // 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']
 +
            }
 +
        ];
  
    /**
+
        // Helpers
    * @typedef {Object} DCT
+
        const escapeAttr = text => text ? text.replace(/\W/g, '-') : text;
    * @property {string} name
+
        const getFilePath = title => title ? '/index.php/Special:FilePath/' + title : title;
    * @property {string} url
+
        const getQueryUrl = query => '/api.php?action=ask&format=json&query=' + encodeURIComponent(query);
    * @property {string[]} dataSources
+
        const removePrefix = str => str.substring(str.indexOf(':') + 1);
    * @property {string[]} functions
 
    * @property {string} logo
 
    */
 
  
    let table;
+
        // 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());
  
    // This defines how sources are grouped in the filter.
+
            return Object.keys(sourceResponse.query.results).map(platform => {
    // Any source not listed here will be added to the last group entitled "More platforms".
+
                const img = sourceResponse.query.results[platform].printouts[IMG_KEY][0];
    const sourcesLayout = [
+
                return {
        {
+
                    name: platform,
            title: 'General',
+
                    image: img ? getFilePath(img.fulltext) : undefined
            sources: ['Crowd', 'Web']
+
                };
        },
+
             });
        {
 
             title: 'Platforms',
 
            sources: ['Facebook', 'Twitter', 'Instagram', 'YouTube']
 
 
         }
 
         }
    ];
 
  
    // Helpers
+
        // Fetches DCTs and their functions.
    const escapeAttr = text => text ? text.replace(/\W/g, '-') : text;
+
        async function getDcts() {
    const getFilePath = title => title ? '/index.php/Special:FilePath/' + title : title;
+
            const FUNC_KEY = 'functions';
    const getQueryUrl = query => '/api.php?action=ask&format=json&query=' + encodeURIComponent(query);
+
            const DESC_KEY = 'description';
    const removePrefix = str => str.substring(str.indexOf(':') + 1);
 
  
    // Fetches platform / data source information.
+
            /** @type Map<string, { [DESC_KEY]: string, [FUNC_KEY]: string[] } */
    async function getSources() {
+
            const functionsData = new Map();
        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 functionsQuery = '[[Category:Function_category]]'
             const img = sourceResponse.query.results[platform].printouts[IMG_KEY][0];
+
                                + '|?-Subproperty_of=' + FUNC_KEY
             return {
+
                                + '|?Has_description=' + DESC_KEY;
                name: platform,
+
             const functionsQueryResponse = await fetch(getQueryUrl(functionsQuery)).then(response => response.json());
                image: img ? getFilePath(img.fulltext) : undefined
 
            };
 
        });
 
    }
 
  
    // Fetches DCTs and their functions.
+
            Object.keys(functionsQueryResponse.query.results).forEach(key => {
    async function getDcts() {
+
                const functionCategory = functionsQueryResponse.query.results[key];
        const FUNC_KEY = 'functions';
+
                functionsData.set(
        const DESC_KEY = 'description';
+
                    removePrefix(functionCategory.fulltext),
       
+
                    {
        /** @type Map<string, { [DESC_KEY]: string, [FUNC_KEY]: string[] } */
+
                        [DESC_KEY]: functionCategory.printouts[DESC_KEY][0],
        const functionsData = new Map();
+
                        [FUNC_KEY]: functionCategory.printouts[FUNC_KEY].map(func => removePrefix(func.fulltext))
 +
                    }
 +
                );
 +
            });
  
        const functionsQuery = '[[Category:Function_category]]'
+
            // TODO: Remove properties that are not relevant for the filter? (e.g. 'Supported content types')
                            + '|?-Subproperty_of=' + FUNC_KEY
+
             const allFunctions = Array.from(functionsData.values(), entry => entry[FUNC_KEY]).flat();
                            + '|?Has_description=' + DESC_KEY;
 
        const functionsQueryResponse = await fetch(getQueryUrl(functionsQuery)).then(response => response.json());
 
       
 
        Object.keys(functionsQueryResponse.query.results).forEach(key => {
 
             const functionCategory = functionsQueryResponse.query.results[key];
 
            functionsData.set(
 
                removePrefix(functionCategory.fulltext),
 
                {
 
                    [DESC_KEY]: functionCategory.printouts[DESC_KEY][0],
 
                    [FUNC_KEY]: functionCategory.printouts[FUNC_KEY].map(func => removePrefix(func.fulltext))
 
                }
 
            );
 
        });
 
  
        // TODO: Remove properties that are not relevant for the filter? (e.g. 'Supported content types')
+
            const DATASRC_PROP = 'Data Sources';
        const allFunctions = Array.from(functionsData.values(), entry => entry[FUNC_KEY]).flat();
+
            const IMG_PROP = 'Image';
 +
            const dctQuery = '[[Category:Disaster Community Technology]]'
 +
                          + '[[Is Archived::No]]'
 +
                          + '|limit=500'
 +
                          + '|?' + IMG_PROP
 +
                          + '|?' + DATASRC_PROP
 +
                          + '|?' + allFunctions.join('|?');
  
        const DATASRC_PROP = 'Data Sources';
+
            const dctResponse = await fetch(getQueryUrl(dctQuery)).then(response => response.json());
        const IMG_PROP = 'Image';
+
            const dctList = Object.keys(dctResponse.query.results).map(dctName => {
        const dctQuery = '[[Category:Disaster Community Technology]]'
+
                const dctResult = dctResponse.query.results[dctName];
                      + '[[Is Archived::No]]'
 
                      + '|limit=500'
 
                      + '|?' + IMG_PROP
 
                      + '|?' + DATASRC_PROP
 
                      + '|?' + allFunctions.join('|?');
 
  
        const dctResponse = await fetch(getQueryUrl(dctQuery)).then(response => response.json());
+
                /** @type {DCT} */
        const dctList = Object.keys(dctResponse.query.results).map(dctName => {
+
                const dct = {};
            const dctResult = dctResponse.query.results[dctName];
+
                dct.name = dctName;
 +
                dct.url = dctResult.fullurl;
 +
                dct.dataSources = dctResult.printouts[DATASRC_PROP].map(source => source.fulltext).sort();
 +
                dct.logo = dctResult.printouts[IMG_PROP][0] ? getFilePath(dctResult.printouts[IMG_PROP][0].fulltext) : undefined;
  
            /** @type {DCT} */
+
                dct.functions = [];
            const dct = {};
+
                functionsData.forEach((value, key) => {
            dct.name = dctName;
+
                    if (value[FUNC_KEY].some(
            dct.url = dctResult.fullurl;
+
                        func => dctResult.printouts[func][0] && dctResult.printouts[func][0].fulltext.toLowerCase() === 'yes'
            dct.dataSources = dctResult.printouts[DATASRC_PROP].map(source => source.fulltext).sort();
+
                    )) {
            dct.logo = dctResult.printouts[IMG_PROP][0] ? getFilePath(dctResult.printouts[IMG_PROP][0].fulltext) : undefined;
+
                        dct.functions.push(key);
 +
                    }
 +
                });
  
            dct.functions = [];
+
                 return dct;
            functionsData.forEach((value, key) => {
 
                if (value[FUNC_KEY].some(
 
                    func => dctResult.printouts[func][0] && dctResult.printouts[func][0].fulltext.toLowerCase() === 'yes'
 
                 )) {
 
                    dct.functions.push(key);
 
                }
 
 
             });
 
             });
  
             return dct;
+
             return { dcts: dctList, funcData: functionsData };
         });
+
         }
  
         return { dcts: dctList, funcData: functionsData };
+
         /**
    }
+
        * @param {DCT} dct
 +
        * @param {Partial<DCT>} filterState
 +
        */
 +
        function dctFilter(dct, 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 sourcesCheck = filterState.dataSources
 +
                ? dct.dataSources.some(source => filterState.dataSources.includes(source))
 +
                : true;
 +
            const functionsCheck = filterState.functions
 +
                ? dct.functions.some(func => filterState.functions.includes(func))
 +
                : true;
 +
            return sourcesCheck && functionsCheck;
 +
        }
  
    /**
+
        function applyFilters(clear) {
    * @param {DCT} dct
+
            if (!table) return;
    * @param {Partial<DCT>} filterState
 
    */
 
    function dctFilter(dct, 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 sourcesCheck = filterState.dataSources
 
            ? dct.dataSources.some(source => filterState.dataSources.includes(source))
 
            : true;
 
        const functionsCheck = filterState.functions
 
            ? dct.functions.some(func => filterState.functions.includes(func))
 
            : true;
 
        return sourcesCheck && functionsCheck;
 
    }
 
  
    function applyFilters(clear) {
+
            // If clear=true, pass empty object to the filter to disable it.
        if (!table) return;
+
            if (clear) {
 +
                table.setFilter(dctFilter, {});
 +
                return;
 +
            }
  
        // If clear=true, pass empty object to the filter to disable it.
+
            /** @type {Partial<DCT>} */
        if (clear) {
+
             const filterState = {};
             table.setFilter(dctFilter, {});
 
            return;
 
        }
 
  
        /** @type {Partial<DCT>} */
+
            const functionOptions = Array.from(document.querySelectorAll('#functions-filter input[type="checkbox"]'));
        const filterState = {};
+
            const selectedFunctions = functionOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value);
  
        const functionOptions = Array.from(document.querySelectorAll('#functions-filter input[type="checkbox"]'));
+
            // If all checkboxes are checked, disable the filter property.
        const selectedFunctions = functionOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value);
+
            filterState.functions = selectedFunctions.length === functionOptions.length ? undefined : selectedFunctions;
  
        // If all checkboxes are checked, disable the filter property.
+
            const sourceOptions = Array.from(document.querySelectorAll('#data-source-filter input[type="checkbox"]'));
        filterState.functions = selectedFunctions.length === functionOptions.length ? undefined : selectedFunctions;
+
            const selectedSources = sourceOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value);
  
        const sourceOptions = Array.from(document.querySelectorAll('#data-source-filter input[type="checkbox"]'));
+
            // If all checkboxes are checked, disable the filter property.
        const selectedSources = sourceOptions.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value);
+
            filterState.dataSources = selectedSources.length === sourceOptions.length ? undefined : selectedSources;
  
        // If all checkboxes are checked, disable the filter property.
+
            table.setFilter(dctFilter, filterState);
         filterState.dataSources = selectedSources.length === sourceOptions.length ? undefined : selectedSources;
+
         }
  
         table.setFilter(dctFilter, filterState);
+
         // Load data and build page.
    }
+
        Promise.all([getSources(), getDcts()]).then(data => {
 +
            const dataSources = data[0];
 +
            const { dcts, funcData } = data[1];
  
    // Load data and build page.
+
            console.log(funcData)
    Promise.all([getSources(), getDcts()]).then(data => {
 
        const dataSources = data[0];
 
        const {dcts, funcData} = data[1];
 
  
        console.log(funcData)
+
            // The keys of this object must match function category names EXACTLY.
 +
            // This also defines the sort order of function categories.
 +
            // TODO: Link images to categories directly.
 +
            const fnImages = {
 +
                'Search and Monitor': '/index.php/Special:FilePath/File:Func_search.svg',
 +
                'Post and Schedule':  '/index.php/Special:FilePath/File:Func_post.svg',
 +
                'Analysis':          '/index.php/Special:FilePath/File:Func_analysis.svg',
 +
                'Metrics':            '/index.php/Special:FilePath/File:Func_metrics.svg',
 +
                'Report':            '/index.php/Special:FilePath/File:Func_report.svg',
 +
                'Collaboration':      '/index.php/Special:FilePath/File:Func_collaboration.svg',
 +
                'Interoperability':  '/index.php/Special:FilePath/File:Func_interoperability.svg',
 +
                'Meta':              '/index.php/Special:FilePath/File:Func_meta.svg',
 +
            };
  
        // The keys of this object must match function category names EXACTLY.
+
            // Set up filters.
        // TODO: Link images to categories directly.
+
            const functionFilterHtml = Object.keys(fnImages).reduce((acc, funcName) => {
        const fnImages = {
+
                const identifier = escapeAttr(funcName);
            'Search and Monitor':  '/index.php/Special:FilePath/File:Func_search.svg',
+
                return acc
            'Post and Schedule':    '/index.php/Special:FilePath/File:Func_post.svg',
+
                    + '<div><input type="checkbox" checked id="func-filter-' + identifier
            'Analysis':            '/index.php/Special:FilePath/File:Func_analysis.svg',
+
                    + '" value="' + funcName + '">'
            'Metrics':              '/index.php/Special:FilePath/File:Func_metrics.svg',
+
                    + '<label for="func-filter-' + identifier
             'Report':              '/index.php/Special:FilePath/File:Func_report.svg',
+
                    + '"><img src="' + fnImages[funcName] + '"> ' + funcName + '</label></div>'
            'Collaboration':        '/index.php/Special:FilePath/File:Func_collaboration.svg',
+
             }, '');
             'Interoperability':    '/index.php/Special:FilePath/File:Func_interoperability.svg',
+
             document.getElementById('functions-filter').innerHTML = functionFilterHtml;
            'Meta':                '/index.php/Special:FilePath/File:Func_meta.svg',
 
        };
 
  
        // Set up filters.
+
             const groupedSources = [];
        const functionFilterHtml = Object.keys(fnImages).reduce((acc, funcName) => {
+
            const sourcesCopy = Array.from(dataSources);
            const identifier = escapeAttr(funcName);
+
            for (const layoutGroup of sourcesLayout) {
             return acc
+
                const group = [];
                + '<div><input type="checkbox" checked id="func-filter-' + identifier
+
                for (const source of layoutGroup.sources) {
                + '" value="' + funcName + '">'
+
                    let idx = sourcesCopy.findIndex(src => src.name === source);
                + '<label for="func-filter-' + identifier
+
                    if (idx !== -1) { group.push(sourcesCopy.splice(idx, 1)[0]); }
                + '"><img src="' + fnImages[funcName] + '"> ' + funcName + '</label></div>'
+
                }
        }, '');
+
                if (group.length > 0) { groupedSources.push({ title: layoutGroup.title, sources: group }); }
        document.getElementById('functions-filter').innerHTML = functionFilterHtml;
 
 
 
        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 });
        }
 
        groupedSources.push({ title: 'More platforms', sources: sourcesCopy });
 
  
        let dataSourceFilterHtml = '';
+
            let dataSourceFilterHtml = '';
        groupedSources.forEach(group => {
+
            groupedSources.forEach(group => {
            dataSourceFilterHtml += '<div class="filter-group-header">' + group.title + '</div>';
+
                dataSourceFilterHtml += '<div class="filter-group-header">' + group.title + '</div>';
            dataSourceFilterHtml += group.sources.reduce((acc, curr, idx) => {
+
                dataSourceFilterHtml += group.sources.reduce((acc, curr, idx) => {
                const identifier = escapeAttr(curr.name);
+
                    const identifier = escapeAttr(curr.name);
                return acc +
+
                    return acc +
                '<div ' + (idx === 0 ? ' class="filter-group-start">' : '>') +
+
                        '<div ' + (idx === 0 ? ' class="filter-group-start">' : '>') +
                '<input type="checkbox" id="filter-' + identifier + '" value="' + curr.name + '" checked>' +
+
                        '<input type="checkbox" id="filter-' + identifier + '" value="' + curr.name + '" checked>' +
                '<label for="filter-' + identifier + '"><img src="' + curr.image + '"> ' + curr.name + '</label></div>'
+
                        '<label for="filter-' + identifier + '"><img src="' + curr.image + '"> ' + curr.name + '</label></div>'
            }, '');
+
                }, '');
        })
+
            })
        document.getElementById('data-source-filter').innerHTML = dataSourceFilterHtml;
+
            document.getElementById('data-source-filter').innerHTML = dataSourceFilterHtml;
  
        // Set up table.
+
            // Set up table.
        const tabulator = new Tabulator("#dct-tabulator", {
+
            const tabulator = new Tabulator("#dct-tabulator", {
            layout: 'fitColumns',
+
                layout: 'fitColumns',
            responsiveLayout: 'collapse',
+
                responsiveLayout: 'collapse',
            columns: [
+
                columns: [
                {
+
                    {
                    title: 'Name',
+
                        title: 'Name',
                    field: 'name',
+
                        field: 'name',
                    minWidth: 300, // required for responsiveness when using fitColumns
+
                        minWidth: 300, // required for responsiveness when using fitColumns
                    formatter: function (cell) {
+
                        formatter: function (cell) {
                        /** @type {DCT} */
+
                            /** @type {DCT} */
                        const dct = cell.getData();
+
                            const dct = cell.getData();
                        return '<a href="' + dct.url + '">' + dct.name + '</a>';
+
                            return '<a href="' + dct.url + '">' + dct.name + '</a>';
                    }
+
                        }
                },
+
                    },
                {
+
                    {
                    title: 'Functions',
+
                        title: 'Functions',
                    field: 'functions',
+
                        field: 'functions',
                    minWidth: 300, // required for responsiveness when using fitColumns
+
                        minWidth: 300, // required for responsiveness when using fitColumns
                    cssClass: 'functions-cell',
+
                        cssClass: 'functions-cell',
                    formatter: function (cell) {
+
                        formatter: function (cell) {
                        const order = Object.keys(fnImages);
+
                            const order = Object.keys(fnImages);
                        const output = cell.getValue()
+
                            const output = cell.getValue()
                            .sort((a, b) => order.indexOf(a) - order.indexOf(b))
+
                                .sort((a, b) => order.indexOf(a) - order.indexOf(b))
                            .map(func => '<img class="func-img" src="' + fnImages[func] +
+
                                .map(func => '<img class="func-img" src="' + fnImages[func] +
                                '" data-value="' + func +
+
                                    '" data-value="' + func +
                                '" alt="' + func +
+
                                    '" alt="' + func +
                                '" title="' + func +
+
                                    '" title="' + func +
                                '">')
+
                                    '">')
                            .join('');
+
                                .join('');
                        return output;
+
                            return output;
                    }
+
                        }
                },
+
                    },
                {
+
                    {
                    title: 'Supported Platforms',
+
                        title: 'Supported Platforms',
                    field: 'dataSources',
+
                        field: 'dataSources',
                    minWidth: 300, // required for responsiveness when using fitColumns
+
                        minWidth: 300, // required for responsiveness when using fitColumns
                    cssClass: 'data-sources-cell',
+
                        cssClass: 'data-sources-cell',
                    formatter: function (cell) {
+
                        formatter: function (cell) {
                        const val = cell.getValue();
+
                            const val = cell.getValue();
                        let out = '';
+
                            let out = '';
  
                        groupedSources.forEach((group, gIndex) => {
+
                            groupedSources.forEach((group, gIndex) => {
                            if (gIndex === groupedSources.length - 1) { out += '<div class="sources-collapse">'; }
+
                                if (gIndex === groupedSources.length - 1) { out += '<div class="sources-collapse">'; }
                            out += group.sources.reduce((prev, curr) => {
+
                                out += group.sources.reduce((prev, curr) => {
                                const idx = val.findIndex(src => src === curr.name);
+
                                    const idx = val.findIndex(src => src === curr.name);
                                if (idx === -1) {
+
                                    if (idx === -1) {
                                    return prev;
+
                                        return prev;
                                } else {
+
                                    } else {
                                    return curr.image
+
                                        return curr.image
                                        ? prev + '<img class="data-source-img" data-value="' + curr.name
+
                                            ? prev + '<img class="data-source-img" data-value="' + curr.name
                                              + '" src="' + curr.image  
+
                                            + '" src="' + curr.image
                                              + '" alt="' + curr.name  
+
                                            + '" alt="' + curr.name
                                              +'" title="' + curr.name + '">'
+
                                            + '" title="' + curr.name + '">'
                                        : prev + ' ' + curr.name;
+
                                            : prev + ' ' + curr.name;
 +
                                    }
 +
                                }, '');
 +
                                if (gIndex === groupedSources.length - 1) {
 +
                                    // out += '<span class="sources-collapse-toggle"></span>';
 +
                                    out += '</div>';
 
                                 }
 
                                 }
                             }, '');
+
                             });
                             if (gIndex === groupedSources.length - 1) {
+
                             return out;
                                // out += '<span class="sources-collapse-toggle"></span>';
+
                         }
                                out += '</div>';
 
                            }
 
                         });
 
                        return out;
 
 
                     }
 
                     }
                 }
+
                 ]
             ]
+
             });
        });
 
  
        tabulator.on('tableBuilt', () => {
+
            tabulator.on('tableBuilt', () => {
            tabulator.setData(dcts);
+
                tabulator.setData(dcts);
            table = tabulator;
+
                table = tabulator;
        });
+
            });
  
        tabulator.on('dataFiltered', (filters, rows) => {
+
            tabulator.on('dataFiltered', (filters, rows) => {
            if (!(filters[0] && filters[0].type)) { return; }
+
                if (!(filters[0] && filters[0].type)) { return; }
  
            const markImages = () => {
+
                const markImages = () => {
                const selectedSources = filters[0].type.dataSources;
+
                    const selectedSources = filters[0].type.dataSources;
                const selectedFunctions = filters[0].type.functions;
+
                    const selectedFunctions = filters[0].type.functions;
  
                // Mark data source images
+
                    // Mark data source images
                document.querySelectorAll('.data-sources-cell .data-source-img, .tabulator-responsive-collapse .data-source-img')
+
                    document.querySelectorAll('.data-sources-cell .data-source-img, .tabulator-responsive-collapse .data-source-img')
                     .forEach(img => {
+
                        .forEach(img => {
                         if (!selectedSources || selectedSources.includes(img.dataset.value)) { img.classList.remove('unselected'); }
+
                            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'); }
 
                         else { img.classList.add('unselected'); }
 
                     });
 
                     });
  
                // Mark functions images
+
                     tabulator.off('renderComplete', markImages);
                document.querySelectorAll('.functions-cell .func-img').forEach(img => {
+
                }
                     if (!selectedFunctions || selectedFunctions.includes(img.dataset.value)) { img.classList.remove('unselected'); }
+
                tabulator.on('renderComplete', markImages);
                    else { img.classList.add('unselected'); }
+
            });
                });
 
  
                tabulator.off('renderComplete', markImages);
+
            document.getElementById('data-source-filter').addEventListener('change', event => {
             }
+
                applyFilters();
             tabulator.on('renderComplete', markImages);
+
             }, { passive: true });
 +
             document.getElementById('functions-filter').addEventListener('change', event => {
 +
                applyFilters();
 +
            }, { passive: true });
 
         });
 
         });
  
         document.getElementById('data-source-filter').addEventListener('change', event => {
+
         function selectAll(context) {
 +
            document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = true);
 
             applyFilters();
 
             applyFilters();
         }, { passive: true });
+
         }
        document.getElementById('functions-filter').addEventListener('change', event => {
+
 
 +
        function deselectAll(context) {
 +
            document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
 
             applyFilters();
 
             applyFilters();
         }, { passive: true });
+
         }
    });
 
  
    function selectAll(context) {
+
         function clearFilters() {
         document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = true);
+
            document.querySelectorAll('#dct-filters input[type="checkbox').forEach(checkbox => checkbox.checked = checkbox.defaultChecked);
        applyFilters();
+
            applyFilters(true);
    }
+
        }
 
 
    function deselectAll(context) {
 
        document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
 
        applyFilters();
 
    }
 
 
 
    function clearFilters() {
 
        document.querySelectorAll('#dct-filters input[type="checkbox').forEach(checkbox => checkbox.checked = checkbox.defaultChecked);
 
        applyFilters(true);
 
    }
 
 
     </script>
 
     </script>
  
 
     <div id="dct-list-wrapper">
 
     <div id="dct-list-wrapper">
 
         <h1>
 
         <h1>
             <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96"><defs><clipPath id="a"><path d="M65 334h96v96H65z"/></clipPath></defs><g clip-path="url(#a)" transform="translate(-65 -334)"><path d="m142 395.981.004-35.993H84.001v36.01Zm-55.999-33.993h54.003L140 393.981l-53.999.017Z"/><path d="M81.001 358.987a2.002 2.002 0 0 1 2-2h60.003a2.002 2.002 0 0 1 2 2V400h2v-41.013a4.003 4.003 0 0 0-4-4H83.001a4.003 4.003 0 0 0-4 4V400h2ZM118.003 402.981v2h-10.001v-2H67v1.999a5.006 5.006 0 0 0 5 5.001h82.004a5.006 5.006 0 0 0 5.001-5.001v-1.999Zm36.001 5H72a3.004 3.004 0 0 1-3-3h37.002a1.934 1.934 0 0 0 2 2h10.001a1.934 1.934 0 0 0 2-2h37.002a3.005 3.005 0 0 1-3.001 3Z"/><path d="M113 365c-7.18 0-13 5.82-13 13s5.82 13 13 13 13-5.82 13-13c-.008-7.176-5.824-12.992-13-13Zm10.949 12h-3.518a14.167 14.167 0 0 0-4.176-9.508 11.023 11.023 0 0 1 7.694 9.508ZM112 368.226V377h-4.426c.254-3.771 1.929-7.06 4.426-8.774ZM112 379v8.775c-2.494-1.717-4.17-5.017-4.425-8.775Zm2 8.774V379h4.425c-.255 3.754-1.932 7.056-4.425 8.774ZM114 377v-8.773c2.492 1.718 4.17 5.019 4.425 8.773Zm-4.273-9.502a14.124 14.124 0 0 0-4.158 9.502h-3.518a11.02 11.02 0 0 1 7.676-9.502ZM102.051 379h3.518a14.157 14.157 0 0 0 4.173 9.507 11.022 11.022 0 0 1-7.691-9.507Zm14.205 9.508a14.168 14.168 0 0 0 4.175-9.508h3.518a11.023 11.023 0 0 1-7.693 9.508Z"/></g></svg>
+
             <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96">
 +
                <defs>
 +
                    <clipPath id="a">
 +
                        <path d="M65 334h96v96H65z" />
 +
                    </clipPath>
 +
                </defs>
 +
                <g clip-path="url(#a)" transform="translate(-65 -334)">
 +
                    <path d="m142 395.981.004-35.993H84.001v36.01Zm-55.999-33.993h54.003L140 393.981l-53.999.017Z" />
 +
                    <path
 +
                        d="M81.001 358.987a2.002 2.002 0 0 1 2-2h60.003a2.002 2.002 0 0 1 2 2V400h2v-41.013a4.003 4.003 0 0 0-4-4H83.001a4.003 4.003 0 0 0-4 4V400h2ZM118.003 402.981v2h-10.001v-2H67v1.999a5.006 5.006 0 0 0 5 5.001h82.004a5.006 5.006 0 0 0 5.001-5.001v-1.999Zm36.001 5H72a3.004 3.004 0 0 1-3-3h37.002a1.934 1.934 0 0 0 2 2h10.001a1.934 1.934 0 0 0 2-2h37.002a3.005 3.005 0 0 1-3.001 3Z" />
 +
                    <path
 +
                        d="M113 365c-7.18 0-13 5.82-13 13s5.82 13 13 13 13-5.82 13-13c-.008-7.176-5.824-12.992-13-13Zm10.949 12h-3.518a14.167 14.167 0 0 0-4.176-9.508 11.023 11.023 0 0 1 7.694 9.508ZM112 368.226V377h-4.426c.254-3.771 1.929-7.06 4.426-8.774ZM112 379v8.775c-2.494-1.717-4.17-5.017-4.425-8.775Zm2 8.774V379h4.425c-.255 3.754-1.932 7.056-4.425 8.774ZM114 377v-8.773c2.492 1.718 4.17 5.019 4.425 8.773Zm-4.273-9.502a14.124 14.124 0 0 0-4.158 9.502h-3.518a11.02 11.02 0 0 1 7.676-9.502ZM102.051 379h3.518a14.157 14.157 0 0 0 4.173 9.507 11.022 11.022 0 0 1-7.691-9.507Zm14.205 9.508a14.168 14.168 0 0 0 4.175-9.508h3.518a11.023 11.023 0 0 1-7.693 9.508Z" />
 +
                </g>
 +
            </svg>
 
             <span>Technologies</span>
 
             <span>Technologies</span>
 
         </h1>
 
         </h1>
 
         <div id="dct-intro">
 
         <div id="dct-intro">
  
        <p>This page provides an&nbsp;overview of&nbsp;various Technologies related to Social Media and Crowdsourcing. You can use the&nbsp;filters to&nbsp;identify
+
            <p>This page provides an&nbsp;overview of&nbsp;various Technologies related to Social Media and
            relevant technologies according to your needs and then click on the name of a&nbsp;tool to&nbsp;get further information.</p>
+
                Crowdsourcing. You can use the&nbsp;filters to&nbsp;identify
 +
                relevant technologies according to your needs and then click on the name of a&nbsp;tool to&nbsp;get
 +
                further information.</p>
 
         </div>
 
         </div>
 
         <div id="dct-filters">
 
         <div id="dct-filters">
 
             <h2>
 
             <h2>
                 <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96"><defs><clipPath id="b"><path d="M592 312h96v96h-96z"/></clipPath></defs><g clip-path="url(#b)" transform="translate(-592 -312)"><path d="M636 356.012v38.011l8-8v-30.011L674 326h-68Zm6.588-1.412-.588.584v30.008l-4 4v-34.008l-.585-.586L610.828 328h58.348Z"/></g></svg>
+
                 <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96">
 +
                    <defs>
 +
                        <clipPath id="b">
 +
                            <path d="M592 312h96v96h-96z" />
 +
                        </clipPath>
 +
                    </defs>
 +
                    <g clip-path="url(#b)" transform="translate(-592 -312)">
 +
                        <path
 +
                            d="M636 356.012v38.011l8-8v-30.011L674 326h-68Zm6.588-1.412-.588.584v30.008l-4 4v-34.008l-.585-.586L610.828 328h58.348Z" />
 +
                    </g>
 +
                </svg>
 
                 <span>Filters</span>
 
                 <span>Filters</span>
 
             </h2>
 
             </h2>
Line 466: Line 562:
 
                     <button type="button" onclick="deselectAll('#functions-filter')">Deselect all</button>
 
                     <button type="button" onclick="deselectAll('#functions-filter')">Deselect all</button>
 
                 </div>
 
                 </div>
                 <div class="filter-content" id="functions-filter" ></div>
+
                 <div class="filter-content" id="functions-filter"></div>
 
             </div>
 
             </div>
 
             <div class="filter-wrapper">
 
             <div class="filter-wrapper">

Revision as of 11:34, 6 September 2022

Development verstion of the DCT List.
Not ready for production!