File size: 3,384 Bytes
98848b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fd2614
 
7dbf557
98848b5
7fd2614
 
457e395
7fd2614
 
 
 
 
98848b5
 
7dbf557
b14f316
7dbf557
7fd2614
7dbf557
98848b5
 
 
 
 
 
 
 
 
 
7dbf557
7fd2614
 
 
 
 
 
98848b5
 
 
 
 
 
 
7dbf557
 
98848b5
 
7fd2614
 
 
 
 
98848b5
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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();

//         }
//       })
//     }