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 86: Line 86:
         return text ? text.replace(/\s/g, '-') : text;
         return text ? text.replace(/\s/g, '-') : text;
     }
     }
    const hasFunction = (dctResult, subfunctions) => subfunctions.some(func => {
        const printoutValue = dctResult.printouts[func][0];
        return printoutValue && printoutValue.fulltext.toLowerCase() === 'yes';
    });


     async function getSources() {
     async function getSources() {
Line 130: Line 135:


         const results = dctResponse.query.results;
         const results = dctResponse.query.results;
       
        const testFunc = (dct, subfunctions) => subfunctions.some(func => {
                const printoutValue = dct.printouts[func][0];
                if (printoutValue) console.log(dct.fulltext, func, printoutValue.fulltext);
                return printoutValue && printoutValue.fulltext.toLowerCase() === 'yes';
            })
         const dctList = Object.getOwnPropertyNames(results).map(dctKey => {
         const dctList = Object.getOwnPropertyNames(results).map(dctKey => {
            const dctResult = results[dctKey];
             /** @type {DCT} */
             /** @type {DCT} */
             const dct = {};
             const dct = {};
             dct.name = dctKey;
             dct.name = dctKey;
             dct.url = results[dctKey].fullurl;
             dct.url = dctResult.fullurl;
             dct.dataSources = results[dctKey].printouts['Data Sources'].map(source => source.fulltext).sort();
             dct.dataSources = dctResult.printouts['Data Sources'].map(source => source.fulltext).sort();
             dct.logo = results[dctKey].printouts['Image'][0] ? getUrl(results[dctKey].printouts['Image'][0].fulltext) : void 0;
             dct.logo = dctResult.printouts['Image'][0] ? getUrl(dctResult.printouts['Image'][0].fulltext) : void 0;
             dct.functions = [];
             dct.functions = [];


            if (hasFunction(dctResult, searchFunctions)) dct.functions.push(FN_SEARCH);
            if (hasFunction(dctResult, postFunctions)) dct.functions.push(FN_POST);


            console.log('result for', dctKey, testFunc(results[dctKey], searchFunctions))
             return dct;
             return dct;
         })
         })
Line 212: Line 210:
                         return '<a href="' + dct.url + '">' + dct.name + '</a>';
                         return '<a href="' + dct.url + '">' + dct.name + '</a>';
                     }
                     }
                },
                {
                    title: 'Functions',
                    field: 'functions',
                    // formatter: function (cell) {
                    //    /** @type {DCT} */
                    //    const dct = cell.getData();
                    //    return '<a href="' + dct.url + '">' + dct.name + '</a>';
                    // }
                 },
                 },
                 {
                 {

Revision as of 15:47, 9 June 2022

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