Spaces:
Sleeping
Sleeping
Upload API_Refresh_workerJS.js
Browse files
static/API_Refresh_workerJS.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
getRefreshAPIAjax()
|
| 2 |
+
intervalBegin()
|
| 3 |
+
|
| 4 |
+
function intervalBegin(){
|
| 5 |
+
// minutes= min *60*1000
|
| 6 |
+
intervalAPI= setInterval( getRefreshAPIAjax ,300000) // 60*60*1000
|
| 7 |
+
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
function getRefreshAPIAjax(){
|
| 11 |
+
ajax("/refreshAPI")
|
| 12 |
+
.then(function(data) {
|
| 13 |
+
var data1=JSON.parse(data);
|
| 14 |
+
self.postMessage(data); // Code depending on result
|
| 15 |
+
})
|
| 16 |
+
|
| 17 |
+
}
|
| 18 |
+
function ajax(url) {
|
| 19 |
+
return new Promise(function(resolve, reject) {
|
| 20 |
+
var xhr = new XMLHttpRequest();
|
| 21 |
+
xhr.onload = function() {
|
| 22 |
+
resolve(this.responseText);
|
| 23 |
+
};
|
| 24 |
+
xhr.onerror = reject;
|
| 25 |
+
xhr.open('GET', url);
|
| 26 |
+
xhr.send();
|
| 27 |
+
});
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
function appendtotables(data){
|
| 32 |
+
ajax('/refreshAPIAppendNewTables?keyword=' + data, true)
|
| 33 |
+
.then(function(data) {
|
| 34 |
+
console.log('ok')
|
| 35 |
+
// self.postMessage('appended'); // Code depending on result
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
// $.ajax({
|
| 42 |
+
// type: "POST",
|
| 43 |
+
// url: '/refreshAPIAppendNewTables',
|
| 44 |
+
// // set content type header to use Flask response.get_json()
|
| 45 |
+
// contentType: "application/json",
|
| 46 |
+
// // convert data/object to JSON to send
|
| 47 |
+
// data: JSON.stringify({value:data[1]}),
|
| 48 |
+
// // expect JSON data in return (e.g. Flask jsonify)
|
| 49 |
+
// dataType: "json",
|
| 50 |
+
// // handle response
|
| 51 |
+
// success: function(response) {
|
| 52 |
+
// self.addEventListener('message', function(e) {
|
| 53 |
+
|
| 54 |
+
// self.postMessage('heeeeyyyy');
|
| 55 |
+
// }, false);
|
| 56 |
+
// if (data[1].toString()==='projectsection')
|
| 57 |
+
// {
|
| 58 |
+
// displayprjnames();
|
| 59 |
+
// displayprojsections();
|
| 60 |
+
// }
|
| 61 |
+
// if (data[1].toString()==='project')
|
| 62 |
+
// displayprjnames();
|
| 63 |
+
// if (data[1].toString()==='part')
|
| 64 |
+
// displayprojparts();
|
| 65 |
+
// if (data[1].toString()==='section')
|
| 66 |
+
// displayprojsections();
|
| 67 |
+
// if (data[1].toString()==='projectpart')
|
| 68 |
+
// {
|
| 69 |
+
// displayprjnames();
|
| 70 |
+
// displayprojparts();
|
| 71 |
+
// }
|
| 72 |
+
// if (data[1].toString()==='partsection')
|
| 73 |
+
// {
|
| 74 |
+
// displayprojparts();
|
| 75 |
+
// displayprojsections();
|
| 76 |
+
// }
|
| 77 |
+
|
| 78 |
+
// },
|
| 79 |
+
// error: function(err) {
|
| 80 |
+
// PopupElement.textContent='Error occured. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
|
| 81 |
+
// ShowPopUp();
|
| 82 |
+
|
| 83 |
+
// }
|
| 84 |
+
// })
|
| 85 |
+
// }
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|