Widget: DCTList: Difference between revisions

From LINKS Community Center
Jump to: navigation, search
Eschmidt (talk | contribs)
No edit summary
Marterer (talk | contribs)
No edit summary
(504 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<noinclude>Development verstion of the DCT List.<br><span style="color: red; font-weight: bold;">Not ready for production!</span></noinclude>
<noinclude>DCT list widget.<br><span style="color: red; font-weight: bold;">Currently in use &ndash; do not modify!</span></noinclude>
 
<includeonly>
<includeonly>
     <link href="https://unpkg.com/tabulator-tables@5.2.7/dist/css/tabulator.min.css" rel="stylesheet">
     <link href="/resources/assets/tabulator/dist/css/tabulator.min.css" rel="stylesheet">
     <script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.2.7/dist/js/tabulator.min.js"></script>
     <script type="text/javascript" src="/resources/assets/tabulator/dist/js/tabulator.min.js"></script>


     <style>
     <!-- STYLES BEGIN -->
        #dct-list-wrapper { font-family: 'Open Sans'; }
<link rel="stylesheet" href="https://www.safetyinnovation.center/lcc/dct_list/styles.css">
        #dct-list-wrapper h1, #dct-list-wrapper h2, #dct-list-wrapper h3 {
<!-- STYLES END -->
            font-family: 'Raleway';
            font-weight: 300;
            letter-spacing: .06em;
        }
        #dct-list-wrapper h1 {
            margin-bottom: 2em;
            color: var(--links-blue);
        }
        #dct-list-wrapper h1 svg {
            height: 2.5em;
            width: 2.5em;
            fill: var(--links-blue);
            margin-right: .5em;
        }
        #dct-list-wrapper h2 {
            margin-bottom: 1em;
        }
        #data-source-button-wrapper {
            margin: .5em 0;
        }
        #data-source-filter-wrapper button {
            border: 0 none;
            color: var(--links-blue);
            background-color: transparent;
            font-variant: small-caps;
            font-size: 1.2em;
            text-decoration: underline;
        }
        #data-source-filter {
            font-size: 1.2em;
            margin-bottom: 4em;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(14em, 1fr));
            gap: 1em 1em;
        }
        #data-source-filter img { width: 2em; height: 2em; margin: 0 .5em; }
        #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-bottom: 1px solid var(--links-blue); padding: .5em 0; }
        .data-source-img { width: 2em; height: 2em; }
        .data-source-img.unselected {
            filter: grayscale(1);
            opacity: .25;
        }
    </style>


     <script>
    <!-- SCRIPT BEGIN -->
     'use strict';
     <script type="text/javascript" src="https://www.safetyinnovation.center/lcc/dct_list/script.js"></script>
     <!-- SCRIPT END -->


     /**
     <!-- Icon definitons -->
    * @typedef {Object} DCT
    <img src="https://www.safetyinnovation.center/lcc/dct_list/img/unknown.svg">
    * @property {string} name
    * @property {string} url
    * @property {string[]} dataSources
    * @property {string} logo
    */


     let table;
     <div id="dct-list-wrapper">
        <h1>
            <img src="https://www.safetyinnovation.center/lcc/dct_list/img/1-dct.svg">
            <div>
                <div>Technologies</div>
                <div style="font-size:small; letter-spacing:.03em; margin-left: .6em;">Social Media and Crowdsourcing Library</div>
            </div>
        </h1>
        <div id="dct-intro">
            <p>The overall goal of the Social Media and Crowdsourcing (SMCS) Technologies Library is to face the growing
                heterogeneous use of technologies in disasters and the overwhelming number of technologies on the
                market. It gathers and structures information about existing technologies to provide an up-to-date overview and
                thus support the selection of suitable technologies.
            </p>
            <p>
                You can use the filters to identify relevant technologies according to your needs and then click on the
                name of the technology to get further information.
            </p>
        </div>


    /** @param {string} title */
        <div id="filter-bar">
    function getUrl(title) {
            <div style="display: flex; justify-content: space-between;">
        return title ? '/index.php/Special:FilePath/' + title : title;
                <div style="flex: 1 1;">
    }
                    <h2 style="margin-bottom: 1rem;">Selected Filters</h2>
                    <div id="filter-summary">No filter. Showing all results.</div>
                </div>
                <div>
                    <button class="large-button open-filters" type="button" onclick="toggleFilter()">Open Filters</button>
                </div>
            </div>


    /** @param {string} text */
            <div style="display: flex; justify-content: space-between; align-items: center; margin-top: 2.5rem;">
    function escapeAttr(text) {
                <h2 style="margin-bottom: 0;">Results: <span id="result-count"></span></h2>
        return text ? text.replace(/\s/g, '-') : text;
                <div><a href="/index.php/Form:Disaster_Community_Technology" style="color: var(--links-blue); font-size: 1.5em; font-variant:small-caps">Add new technology</a></div>
    }
             </div>
 
    async function getSources() {
        const sourceQuery = '/api.php?action=ask&format=json&query=' + encodeURIComponent('[[Category:Social media platform]]|?IMAGE');
        const sourceResponse = await fetch(sourceQuery).then(response => response.json());
 
        const results = sourceResponse.query.results;
        const sources = Object.getOwnPropertyNames(results).map(platformName => ({
            name: platformName,
            image: getUrl(results[platformName].printouts['IMAGE'][0].fulltext.replace('PAGENAME:', ''))
        }));
 
        return sources;
    }
 
    async function getDcts() {
        const dctQuery = '[[Category:Disaster Community Technology]]' +
                        '|?Image' +
                        '|?Data Sources';
        const dctQueryUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(dctQuery);
        const dctResponse = await fetch(dctQueryUrl).then(response => response.json());
 
        const results = dctResponse.query.results;
        const dctList = Object.getOwnPropertyNames(results).map(dctKey => {
            /** @type {DCT} */
            const dct = {};
            dct.name = dctKey;
            dct.url = results[dctKey].fullurl;
            dct.dataSources = results[dctKey].printouts['Data Sources'].map(source => source.fulltext).sort();
            dct.logo = results[dctKey].printouts['Image'][0] ? getUrl(results[dctKey].printouts['Image'][0].fulltext) : void 0;
            return dct;
        })
 
        return dctList;
    }
 
    /**
    * @param {DCT} dct
    * @param {Partial<DCT>} filterState
    */
    function dctFilter(dct, filterState) {
        // if the property is empty, don't apply the filter (return true)
        const sourcesCheck = filterState.dataSources
            ? dct.dataSources.some(source => filterState.dataSources.includes(source))
             : true;
        return sourcesCheck;
    }
 
    function applyFilters() {
        if (!table) return;
 
        /** @type {Partial<DCT>} */
        const filterState = {};
 
        // Build filter from the current filter form state
        // Alternative: keep a copy and update


        const selectedSources = Array.from(document.querySelectorAll('#data-source-filter input[type="checkbox"]:checked')).map(checkbox => checkbox.value);
            <div id="dct-filters">
        filterState.dataSources = selectedSources;
                <h2 style="display: flex; justify-content: space-between;">
 
                    <div>
        table.setFilter(dctFilter, filterState);
                        <img src="filters.svg">
    }
                        <span>Filters</span>
 
                    </div>
    // Load data and build page.
                    <a onclick="toggleFilter()" id="close-filter-button">&times;</a>
    Promise.all([getSources(), getDcts()]).then(data => {
                </h2>
        const dataSources = data[0];
                <div style="text-align: center;">
        const dcts = data[1];
                    <button class="large-button" type="button" onclick="clearFilters()">Clear Filters</button>
 
                </div>
        dataSources.unshift(dataSources.splice(dataSources.findIndex(src => src.name === 'Web'), 1)[0]);
                <div class="filter-wrapper">
        dataSources.unshift(dataSources.splice(dataSources.findIndex(src => src.name === 'Crowd'), 1)[0]);
                    <h4 class="filter-toggle">Functions <div class="plus icon"></div>
 
                    </h4>
        // Set up filters.
                    <div class="filter-container">
        const filterHtml = dataSources.reduce((prev, curr, idx) => {
                        <div class="filter-button-wrapper">
            const identifier = escapeAttr(curr.name);
                            <button type="button" onclick="selectAll('#functions-filter')">Select all</button> |
            return prev + '<div>' + (curr.name === 'Web' ? ' style="grid-column: "' + (idx + 1) + '/-1' : '') +
                            <button type="button" onclick="deselectAll('#functions-filter')">Clear all</button>
                '<input type="checkbox" id="filter-' + identifier + '" value="' + curr.name + '" checked>' +
                         </div>
                '<label for="filter-' + identifier + '"><img src="' + curr.image + '"> ' + curr.name + '</label></div>'
                         <div class="filter-content loose" id="functions-filter"></div>
        }, '');
                     </div>
        document.getElementById('data-source-filter').innerHTML = filterHtml;
                 </div>
 
                 <div class="filter-wrapper">
        // Set up table.
                     <h4 class="filter-toggle">Supported Platforms <div class="plus icon"></div>
        const tabulator = new Tabulator("#dct-tabulator", {
                    </h4>
            layout: 'fitColumns',
                    <div class="filter-container">
            columns: [
                        <div class="filter-button-wrapper">
                {
                            <button type="button" onclick="selectAll('#data-source-filter')">Select all</button> |
                    title: 'Name',
                            <button type="button" onclick="deselectAll('#data-source-filter')">Clear all</button>
                    field: 'name',
                        </div>
                    formatter: function (cell) {
                        <div class="filter-content loose" id="data-source-filter"></div>
                         /** @type {DCT} */
                     </div>
                         const dct = cell.getData();
                 </div>
                        return '<a href="' + dct.url + '">' + dct.name + '</a>';
                 <div class="filter-wrapper">
                     }
                    <h4 class="filter-toggle">Pricing <div class="plus icon"></div>
                 },
                    </h4>
                 {
                    <div class="filter-container">
                    title: 'Data Sources',
                        <div class="filter-button-wrapper">
                    field: 'dataSources',
                            <button type="button" onclick="selectAll('#business-model-filter')">Select all</button> |
                    cssClass: 'data-source-cell',
                            <button type="button" onclick="deselectAll('#business-model-filter')">Clear all</button>
                     formatter: function (cell) {
                        </div>
                        const output = cell.getValue().reduce((prev, curr) => {
                        <div class="filter-content" id="business-model-filter"></div>
                            const src = dataSources.find(src => src.name === curr);
                    </div>
                            const url = src ? src.image : '';
                </div>
                            return url ? prev + '<img class="data-source-img" data-value="' + curr + '" src="' + url + '">' : prev + ' ' + curr;
                <!-- <div class="filter-wrapper">
                        }, '');
                    <h4 class="filter-toggle">Used by Practitioners <div class="plus icon"></div>
                        return output;
                    </h4>
                    }
                    <div class="filter-container">
                }
                        <div class="filter-button-wrapper">
            ]
                            <button type="button" onclick="selectAll('#dm-use-filter')">Select all</button> |
        });
                            <button type="button" onclick="deselectAll('#dm-use-filter')">Clear all</button>
 
                        </div>
        tabulator.on('tableBuilt', () => {
                        <div class="filter-content" id="dm-use-filter"></div>
            tabulator.setData(dcts);
                    </div>
            table = tabulator;
                </div> -->
        });
                <div id="bool-filters"
 
                    style="border-top: 1px solid var(--links-blue); margin-top: 1em; padding-top: 1em;">
        tabulator.on('dataFiltered', (filters, rows) => {
                    <div>
            if (!(filters[0] && filters[0].type)) { return; }
                        <input type="checkbox" id="used-by-practitioners" value="yes">
 
                        <label for="used-by-practitioners">Used by practitioners</label>
            const markDeselectedDataSources = () => {
                    </div>
                const selectedSources = filters[0].type.dataSources;
                    <div>
                document.querySelectorAll('.data-source-cell .data-source-img').forEach(img => {
                        <input type="checkbox" id="has-use-case" value="yes">
                     if (selectedSources.includes(img.dataset.value)) { img.classList.remove('unselected'); }
                        <label for="has-use-case">Use case available</label>
                    else { img.classList.add('unselected'); }
                    </div>
                 });
                    <div>
                 tabulator.off('renderComplete', markDeselectedDataSources);
                        <input type="checkbox" id="show-archived" value="yes">
            }
                        <label for="show-archived">Show archived</label>
            tabulator.on('renderComplete', markDeselectedDataSources);
                    </div>
        });
                </div>
 
        document.getElementById('data-source-filter').addEventListener('change', event => {
            applyFilters();
        }, { passive: true });
    });
 
    function selectAllSources() {
        document.querySelectorAll('#data-source-filter input[type="checkbox"]').forEach(checkbox => checkbox.checked = true);
        applyFilters();
    }
 
    function deselectAllSources() {
        document.querySelectorAll('#data-source-filter input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
        applyFilters();
    }
    </script>
 
    <div id="dct-list-wrapper">
        <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>
            Social Media and Crowdsourcing Technologies
        </h1>
        <h2>Filters</h2>
        <div id="data-source-filter-wrapper">
            <h3>Data Sources</h3>
            <div id="data-source-button-wrapper">
                <button type="button" onclick="selectAllSources()">Select all</button>
                <button type="button" onclick="deselectAllSources()">Deselect all</button>
             </div>
             </div>
            <div id="data-source-filter"></div>
         </div>
         </div>
         <div id="dct-tabulator"></div>
         <div id="dct-tabulator"></div>
     </div>
     </div>
</includeonly>
</includeonly>

Revision as of 22:22, 10 May 2024

DCT list widget.
Currently in use – do not modify!