Widget: DCTList: Difference between revisions

From LINKS Community Center
Jump to: navigation, search
Eschmidt (talk | contribs)
No edit summary
Eschmidt (talk | contribs)
No edit summary
Line 175: Line 175:


     async function getDcts() {
     async function getDcts() {
        // TEST TEST TEST TEST TEST TEST TEST
         const removePrefix = str => str.substring(str.indexOf(':') + 1);
         const CKEY = 'children'
        const DKEY = 'desc'
        const fq = '[[Category:Function_category]]' +
                  '|?-Subproperty_of=' + CKEY +
                  '|?Has_description=' + DKEY;


         const qUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(fq);
         const FUNC_KEY = 'functions';
         const fRes = await fetch(qUrl).then(response => response.json());
         const DESC_KEY = 'description'


         const data = fRes.query.results;
         const queryBaseUrl = '/api.php?action=ask&format=json&query=';
         console.log(data)
         const functionsQuery = '[[Category:Function_category]]' +
        const xxx = new Map();
                              '|?-Subproperty_of=' + FUNC_KEY +
                              '|?Has_description=' + DESC_KEY;


         const removePrefix = str => str.substring(str.indexOf(':') + 1);
         const functionsQueryResponse = await fetch(
            queryBaseUrl + encodeURIComponent(functionsQuery)
        ).then(response => response.json());
        const functionsQueryResults = functionsQueryResponse.query.results;
       
        const functionsData = new Map();


         Object.keys(data).forEach(key => {
         Object.keys(functionsQueryResults).forEach(key => {
             xxx.set(
             const functionCategory = functionsQueryResults[key];
                 removePrefix(data[key].fulltext),
            functionsData.set(
                 {  
                // Key: Name of the Function Category.
                     [DKEY]: data[key].printouts[DKEY][0],  
                 removePrefix(functionCategory.fulltext),
                     [CKEY]: data[key].printouts[CKEY].map(func => removePrefix(func.fulltext))
                // Value: Description and subfunctions.
                 }  
                 {
                )
                     [DESC_KEY]: functionCategory.printouts[DESC_KEY][0],
                     [FUNC_KEY]: functionCategory.printouts[FUNC_KEY].map(subfunction => removePrefix(subfunction.fulltext))
                 }
            )
         })
         })
         console.log('Func result', xxx);
         console.log('Func result', functionsData);
 
        const re = /^.+:(.+)$/;
        // TEST TEST TEST TEST TEST TEST TEST
 


         const searchFunctions = [
         const searchFunctions = [

Revision as of 13:07, 30 August 2022

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