Difference between revisions of "Widget:DCTList"

From LINKS Community Center
Jump to: navigation, search
Line 252: Line 252:
 
     <script>
 
     <script>
 
         'use strict';
 
         'use strict';
 +
 +
        const FUNC_KEY = 'functions';
 +
        const DESC_KEY = 'description';
 +
 +
        /** @typedef {Map<string, { [DESC_KEY]: string, [FUNC_KEY]: string[] }>} FuncData */
 +
 +
        /** @type FuncData */
 +
        const functionsData = new Map();
  
 
         /**
 
         /**
Line 315: Line 323:
 
         // Fetches DCTs and their functions.
 
         // Fetches DCTs and their functions.
 
         async function getDcts() {
 
         async function getDcts() {
            const FUNC_KEY = 'functions';
 
            const DESC_KEY = 'description';
 
 
            /** @type Map<string, { [DESC_KEY]: string, [FUNC_KEY]: string[] } */
 
            const functionsData = new Map();
 
 
 
             const functionsQuery = '[[Category:Function_category]]'
 
             const functionsQuery = '[[Category:Function_category]]'
 
                                 + '|?-Subproperty_of=' + FUNC_KEY
 
                                 + '|?-Subproperty_of=' + FUNC_KEY
Line 370: Line 372:
  
 
                 dct.functions = [];
 
                 dct.functions = [];
                 functionsData.forEach((value, key) => {
+
                 functionsData.forEach((categoryData, funcCategory) => {
                     if (value[FUNC_KEY].some(
+
                     if (categoryData[FUNC_KEY].some(
 
                         func => dctResult.printouts[func][0] && dctResult.printouts[func][0].fulltext.toLowerCase() === 'yes'
 
                         func => dctResult.printouts[func][0] && dctResult.printouts[func][0].fulltext.toLowerCase() === 'yes'
 
                     )) {
 
                     )) {
                         dct.functions.push(key);
+
                         dct.functions.push(funcCategory);
 
                     }
 
                     }
 
                 });
 
                 });
Line 381: Line 383:
 
             });
 
             });
  
             return { dcts: dctList, funcData: functionsData };
+
             return dctList;
 
         }
 
         }
  
Line 439: Line 441:
 
         // Load data and build page.
 
         // Load data and build page.
 
         Promise.all([getSources(), getDcts()]).then(data => {
 
         Promise.all([getSources(), getDcts()]).then(data => {
             const dataSources = data[0];
+
             const [dataSources, dcts] = data;
            const { dcts, funcData } = data[1];
 
  
 
             // Set up functions filter
 
             // Set up functions filter
 
             let funcFilterHtml = '';
 
             let funcFilterHtml = '';
             Array.from(funcData).forEach(([fnCat, fnInfo], index) => {
+
             Array.from(functionsData).forEach(([fnCat, fnInfo], index) => {
 
                 const identifier = 'func-filter-' + escapeAttr(fnCat);
 
                 const identifier = 'func-filter-' + escapeAttr(fnCat);
 
                 funcFilterHtml +=
 
                 funcFilterHtml +=

Revision as of 16:15, 17 November 2022

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