File size: 2,632 Bytes
7fd2614
 
7dbf557
7fd2614
 
457e395
7fd2614
 
 
 
 
7dbf557
 
b14f316
7dbf557
7fd2614
7dbf557
 
 
7fd2614
 
 
 
 
 
7dbf557
 
 
 
7fd2614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
intervalBegin()


function intervalBegin(){
    // minutes= min *60*1000
    intervalAPI= setInterval( getRefreshAPIAjax ,1800000) // 30*60*1000 // every 30 min 

}

function getRefreshAPIAjax(){

        ajax("/refreshAPI")//, sectionData)
        .then(function(data) {
              self.postMessage(data); // Code depending on result  
        })
}

function ajax(url , sectionData) {

    return new Promise(function(resolve, reject) {
      var xhr = new XMLHttpRequest();
      xhr.onload = function() {
        resolve(this.responseText);
      };
      xhr.onerror = reject;
      
      // xhr.open('POST', url, true);
      // xhr.send("sectionData=" + sectionData);
      xhr.open('GET', url)//+'?sectionData=' + sectionData);
      xhr.send();
    });
}


function appendtotables(data){
    ajax('/refreshAPIAppendNewTables?keyword=' + data, 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();

//         }
//       })
//     }