Widget: DataExporter: Difference between revisions

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


             const permittedUsers = ['Eschmidt'];
             const permittedUsers = ['Eschmidt'];
            const dat = '/index.php?title=Category:Disaster_Community_Technology&action=raw';
            const dat2 = '/index.php?title=Category:Use_Cases&action=raw';


             async function exportData() {
             async function exportData() {
Line 32: Line 30:
                 const formData = new FormData(document.getElementById('export_form'));
                 const formData = new FormData(document.getElementById('export_form'));
                 const lib = formData.get('library');
                 const lib = formData.get('library');
                 console.log(lib)
                 let schemaUrl;
                if (lib === 'TL') schemaUrl = '/index.php?title=Category:Disaster_Community_Technology&action=raw';
                else if (lib === 'UCL') schemaUrl = '/index.php?title=Category:Use_Cases&action=raw';
                else if (lib === 'GL') schemaUrl = '/index.php?title=Category:Guideline&action=raw';


                 const schema = await fetch(dat2).then(rsp => rsp.text());
                 const schemaXml = await fetch(schemaUrl).then(rsp => rsp.text());
                 const doc = (new DOMParser).parseFromString(schema, 'text/xml');
                 const schema = (new DOMParser).parseFromString(schemaXml, 'text/xml');


                 for (const field of doc.querySelectorAll('Field')) {
                 for (const field of schema.querySelectorAll('Field')) {
                     const prop = field.querySelector('semanticmediawiki_Property')?.getAttribute('name')
                     const prop = field.querySelector('semanticmediawiki_Property')?.getAttribute('name')
                         || field.getAttribute('name');
                         || field.getAttribute('name');

Revision as of 15:11, 15 August 2023