Spaces:
Sleeping
Sleeping
| var prjname='' | |
| var prjpart='' | |
| self.onmessage = function(event) { | |
| console.log('Message received from main script:', event.data); | |
| console.log(typeof event.data) | |
| if (typeof event.data === 'object') | |
| { | |
| prjname=event.data[0] | |
| prjpart=event.data[1] | |
| console.log(prjname,prjpart) | |
| } | |
| else | |
| prjname=event.data | |
| } | |
| intervalBegin() | |
| function intervalBegin(){ | |
| // minutes= min *60*1000 | |
| intervalAPI= setInterval( getRefreshAPIAjax ,1800000) // 30*60*1000 // every 30 min | |
| } | |
| function getRefreshAPIAjax(){ | |
| console.log(prjname,'jgjk') | |
| ajax("/refreshAPI",prjname,prjpart)//, sectionData) | |
| .then(function(data) { | |
| self.postMessage(data); // Code depending on result | |
| }) | |
| } | |
| // function getRefreshAPIPartAjax(prjname){ | |
| // ajax("/getnewparts",prjname)//, sectionData) | |
| // .then(function(data) { | |
| // self.postMessage(data); // Code depending on result ['parts',data] | |
| // }) | |
| // } | |
| function ajax(url , prjname=0) { | |
| return new Promise(function(resolve, reject) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.onload = function() { | |
| resolve(this.responseText); | |
| }; | |
| xhr.onerror = reject; | |
| if (prjname){ | |
| console.log('gss',prjname,prjpart) | |
| xhr.open('GET', url+'?prjname=' + prjname+'&prjpart=' + prjpart ); | |
| xhr.send(); | |
| } | |
| else | |
| {// xhr.open('POST', url, true); | |
| // xhr.send("sectionData=" + sectionData); | |
| xhr.open('GET', url)//+'?sectionData=' + sectionData); | |
| xhr.send();} | |
| }); | |
| } | |
| function appendtotables(data){ | |
| ajax('/refreshAPIAppendNewTables', true) | |
| .then(function(data) { | |
| console.log('ok') | |
| // self.postMessage('appended'); // Code depending on result | |
| }); | |
| } | |
| // $.ajax({ | |
| // type: "POST", | |
| // url: '/refreshAPIAppendNewTables', | |
| // // set content type header to use Flask response.get_json() | |
| // contentType: "application/json", | |
| // // convert data/object to JSON to send | |
| // data: JSON.stringify({value:data[1]}), | |
| // // expect JSON data in return (e.g. Flask jsonify) | |
| // dataType: "json", | |
| // // handle response | |
| // success: function(response) { | |
| // self.addEventListener('message', function(e) { | |
| // self.postMessage('heeeeyyyy'); | |
| // }, false); | |
| // if (data[1].toString()==='projectsection') | |
| // { | |
| // displayprjnames(); | |
| // displayprojsections(); | |
| // } | |
| // if (data[1].toString()==='project') | |
| // displayprjnames(); | |
| // if (data[1].toString()==='part') | |
| // displayprojparts(); | |
| // if (data[1].toString()==='section') | |
| // displayprojsections(); | |
| // if (data[1].toString()==='projectpart') | |
| // { | |
| // displayprjnames(); | |
| // displayprojparts(); | |
| // } | |
| // if (data[1].toString()==='partsection') | |
| // { | |
| // displayprojparts(); | |
| // displayprojsections(); | |
| // } | |
| // }, | |
| // error: function(err) { | |
| // PopupElement.textContent='Error occured. Refresh and try again. If the error continues, please contact the ADR team to fix it. '; | |
| // ShowPopUp(); | |
| // } | |
| // }) | |
| // } | |