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 7: Line 7:
             'use strict';
             'use strict';


             const usr = '/api.php?action=query&meta=userinfo&format=json';
             const permittedUsers = ['Eschmidt'];
             const dat = '/index.php?title=Category:Disaster_Community_Technology&action=raw';
             const dat = '/index.php?title=Category:Disaster_Community_Technology&action=raw';
 
             const dat2 = '/index.php?title=Category:Use_Cases&action=raw';
             const permittedUsers = ['Eschmidt'];


             async function exportData() {
             async function exportData() {
                 const output = document.getElementById('output');
                 const output = document.getElementById('output');


                 const usrData = await fetch(usr).then(rsp => rsp.json());
                // Check user.
                 const usrData = await fetch('/api.php?action=query&meta=userinfo&format=json').then(rsp => rsp.json());
                 if (!permittedUsers.includes(usrData?.query?.userinfo?.name)) {
                 if (!permittedUsers.includes(usrData?.query?.userinfo?.name)) {
                     output.innerHTML = '<span style="color:red; font-size:large">Access Denied</span>';
                     output.innerHTML = '<span style="color:red; font-size:large">Access Denied</span>';
Line 21: Line 21:
                 }
                 }


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


Line 29: Line 29:
                     output.innerHTML += prop + ' | ' + label + '<br>';
                     output.innerHTML += prop + ' | ' + label + '<br>';
                 }
                 }
                // output.innerText = schema;
             }
             }
         </script>
         </script>

Revision as of 13:16, 15 August 2023