Difference between revisions of "Widget:DCTList"

From LINKS Community Center
Jump to: navigation, search
(562 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 {
+
<!-- STYLES END -->
            font-family: 'Raleway';
 
            font-weight: 300;
 
            letter-spacing: .06em;
 
        }
 
        #dct-list-wrapper h1 {
 
            margin-bottom: 2em;
 
            color: var(--links-blue);
 
        }
 
        #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; }
 
    </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
 
    */
 
  
    /** @param {string} title */
+
     <div id="dct-list-wrapper">
     function getUrl(title) {
+
         <h1>
         return title ? '/index.php/Special:FilePath/' + title : title;
+
            <img src="https://www.safetyinnovation.center/lcc/dct_list/img/1-dct.svg">
    }
+
            <div>
 
+
                <div>Technologies</div>
    /** @param {string} text */  
+
                <div style="font-size:small; letter-spacing:.03em; margin-left: .6em;">Social Media and Crowdsourcing Library</div>
    function escapeAttr(text) {
+
            </div>
        return text ? text.replace(/\s/g, '-') : text;
+
         </h1>
    }
+
         <div id="dct-intro">
 
+
             <p>The overall goal of the Social Media and Crowdsourcing (SMCS) Technologies Library is to face the growing
    async function getSources() {
+
                heterogeneous use of technologies in disasters and the overwhelming number of technologies on the
        const sourceQuery = '/api.php?action=ask&format=json&query=' + encodeURIComponent('[[Category:Social media platform]]|?IMAGE');
+
                market. It gathers and structures information about existing technologies to provide an up-to-date overview and
        const sourceResponse = await fetch(sourceQuery).then(response => response.json());
+
                thus support the selection of suitable technologies.
 
+
            </p>
         const results = sourceResponse.query.results;
+
            <p>
         const sources = Object.getOwnPropertyNames(results).map(platformName => ({
+
                You can use the filters to identify relevant technologies according to your needs and then click on the
             name: platformName,
+
                name of the technology to get further information.
            image: getUrl(results[platformName].printouts.IMAGE[0].fulltext.replace('PAGENAME:', ''))
+
            </p>
        }));
+
         </div>
 
 
        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;
+
         <div id="filter-bar">
        const dctList = Object.getOwnPropertyNames(results).map(dctKey => {
+
             <div style="display: flex; justify-content: space-between;">
            /** @type {DCT} */
+
                <div style="flex: 1 1;">
             const dct = {};
+
                    <h2 style="margin-bottom: 1rem;">Selected Filters</h2>
            dct.name = dctKey;
+
                    <div id="filter-summary">No filter. Showing all results.</div>
            dct.url = results[dctKey].fullurl;
+
                </div>
            dct.dataSources = results[dctKey].printouts['Data Sources'].map(source => source.fulltext).sort();
+
                <div>
            dct.logo = results[dctKey].printouts['Image'][0] ? getUrl(results[dctKey].printouts['Image'][0].fulltext) : void 0;
+
                    <button class="large-button open-filters" type="button" onclick="toggleFilter()">Open Filters</button>
             return dct;
+
                </div>
        })
+
             </div>
  
        return dctList;
+
            <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:Disaster_Community_Technology" style="color: var(--links-blue); font-size: 1.5em; font-variant:small-caps">Add new technology</a></div>
 +
            </div>
  
    /**
+
            <div id="dct-filters">
    * @param {DCT} dct
+
                <h2 style="display: flex; justify-content: space-between;">
    * @param {Partial<DCT>} params
+
                    <div>
    */
+
                        <img src="filters.svg">
    function dctFilter(dct, params) {
+
                        <span>Filters</span>
        return true;
+
                    </div>
    }
+
                    <a onclick="toggleFilter()" id="close-filter-button">&times;</a>
 
+
                </h2>
    // Load data and build page.
+
                <div style="text-align: center;">
    Promise.all([getSources(), getDcts()]).then(data => {
+
                    <button class="large-button" type="button" onclick="clearFilters()">Clear Filters</button>
        const dataSources = data[0];
+
                </div>
        const dcts = data[1];
+
                <div class="filter-wrapper">
 
+
                    <h4 class="filter-toggle">Functions <div class="plus icon"></div>
        // Set up filters.
+
                    </h4>
        const filterHtml = dataSources.reduce((prev, curr) => {
+
                    <div class="filter-container">
            const identifier = escapeAttr(curr.name);
+
                        <div class="filter-button-wrapper">
            return prev +
+
                            <button type="button" onclick="selectAll('#functions-filter')">Select all</button> |
                '<div><input type="checkbox" id="filter-' + identifier + '" value="' + curr.name + '" checked>' +
+
                            <button type="button" onclick="deselectAll('#functions-filter')">Clear all</button>
                '<label for="filter-' + identifier + '"><img src="' + curr.image + '"> ' + curr.name + '</label></div>'
+
                        </div>
        }, '');
+
                        <div class="filter-content loose" id="functions-filter"></div>
        document.getElementById('data-source-filter').innerHTML = filterHtml;
+
                    </div>
 
+
                </div>
        // Set up table.
+
                <div class="filter-wrapper">
        const table = new Tabulator("#dct-tabulator", {
+
                    <h4 class="filter-toggle">Supported Platforms <div class="plus icon"></div>
            layout: 'fitColumns',
+
                    </h4>
            columns: [
+
                    <div class="filter-container">
                 {
+
                        <div class="filter-button-wrapper">
                     title: 'Name',
+
                            <button type="button" onclick="selectAll('#data-source-filter')">Select all</button> |
                     field: 'name',
+
                            <button type="button" onclick="deselectAll('#data-source-filter')">Clear all</button>
                     formatter: function (cell) {
+
                        </div>
                         /** @type {DCT} */
+
                        <div class="filter-content loose" id="data-source-filter"></div>
                        const dct = cell.getData();
+
                    </div>
                         return '<a href="' + dct.url + '">' + dct.name + '</a>';
+
                </div>
                     }
+
                 <div class="filter-wrapper">
                 },
+
                     <h4 class="filter-toggle">Pricing <div class="plus icon"></div>
                 {
+
                     </h4>
                     title: 'Data Sources',
+
                     <div class="filter-container">
                     field: 'dataSources',
+
                         <div class="filter-button-wrapper">
                     formatter: function (cell) {
+
                            <button type="button" onclick="selectAll('#business-model-filter')">Select all</button> |
                         const output = cell.getValue().reduce((prev, curr) => {
+
                            <button type="button" onclick="deselectAll('#business-model-filter')">Clear all</button>
                             const src = dataSources.find(src => src.name === curr);
+
                        </div>
                            const url = src ? src.image : '';
+
                         <div class="filter-content" id="business-model-filter"></div>
                             return url ? prev + '<img class="data-source-img" src="' + url + '">' : prev + ' ' + curr;
+
                     </div>
                         }, '');
+
                 </div>
                         return output;
+
                 <!-- <div class="filter-wrapper">
                     }
+
                     <h4 class="filter-toggle">Used by Practitioners <div class="plus icon"></div>
                 }
+
                     </h4>
            ]
+
                     <div class="filter-container">
        });
+
                         <div class="filter-button-wrapper">
 
+
                             <button type="button" onclick="selectAll('#dm-use-filter')">Select all</button> |
        table.on("tableBuilt", () => {
+
                             <button type="button" onclick="deselectAll('#dm-use-filter')">Clear all</button>
            table.setData(dcts);  
+
                         </div>
            table.setFilter(dctFilter, { foo:3 });
+
                         <div class="filter-content" id="dm-use-filter"></div>
            console.log('Filter 1', table.getFilters())
+
                     </div>
            table.setFilter(dctFilter, { foo:666 });
+
                 </div> -->
            console.log('Filter 2', table.getFilters())
+
                <div id="bool-filters"
            const chk = Array.from(document.querySelectorAll('#data-source-filter input[type="checkbox"]:checked')).map(el => el.value);
+
                    style="border-top: 1px solid var(--links-blue); margin-top: 1em; padding-top: 1em;">
            console.log(chk)
+
                    <div>
        });
+
                        <input type="checkbox" id="used-by-practitioners" value="yes">
    })
+
                        <label for="used-by-practitioners">Used by practitioners</label>
 
+
                    </div>
    $(document).ready(function () {
+
                    <div>
                const checked1 =  $('#data-source-filter input[type="checkbox"]:checked').map((idx, el) => el.value)
+
                        <input type="checkbox" id="has-use-case" value="yes">
                console.log(checked1)
+
                        <label for="has-use-case">Use case available</label>
            //your code here
+
                    </div>
            });
+
                    <div>
    </script>
+
                        <input type="checkbox" id="show-archived" value="yes">
 
+
                        <label for="show-archived">Show archived</label>
    <div id="dct-list-wrapper">
+
                    </div>
        <h1>Social Media and Crowdsourcing Technologies</h1>
+
                </div>
        <h2>Filters</h2>
+
            </div>
        <div id="data-source-filter"></div>
+
        </div>
 
         <div id="dct-tabulator"></div>
 
         <div id="dct-tabulator"></div>
 
     </div>
 
     </div>
 +
 
</includeonly>
 
</includeonly>

Revision as of 23:22, 10 May 2024

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