Blame view

src/misc/static/js/observation_status.js 3.31 KB
76dfa189   Unknown   Adding devices lo...
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
var LOGS_REFRESH_FREQUENCE = 2000; //in milliseconds

var show_cagire = false;
var show_telescope = false;
var show_ddrago_b = false;
var show_ddrago_r = false;
var interval_cagire =-1;
var interval_ddrago_r=-1;
var interval_ddrago_b=-1;
var interval_telescope=-1;

jQuery(document).ready(function(){

$("#Telescope_button").click(function () {
  show_telescope= !show_telescope;

  if (show_telescope)
  {
    $("#telescope_list").show();
    interval_telescope = setInterval(function() {ajax_request("telescope", "telescope_list");}, LOGS_REFRESH_FREQUENCE);
  }
  else { $("#telescope_list").hide();
  if (interval_telescope !== -1){clearInterval(interval_telescope);}
  }

});

$("#Cagire_button").click(function () {
  show_cagire = !show_cagire;


  if (show_cagire)
  {
    $("#cagire_list").show();
    interval_cagire = setInterval(function() {ajax_request("cagire", "cagire_list");}, LOGS_REFRESH_FREQUENCE);
  }
  else {
      $("#cagire_list").hide();
      if (interval_cagire !== -1){clearInterval(interval_cagire);}
  }

});

$("#ddrago_r_button").click(function () {
  show_ddrago_r= !show_ddrago_r;

  if (show_ddrago_r)
  {
    $("#ddrago_r_list").show();
    interval_ddrago_r = setInterval(function() {ajax_request("ddrago_r", "ddrago_r_list");}, LOGS_REFRESH_FREQUENCE);
  }
  else {
      $("#ddrago_r_list").hide();
      if (interval_ddrago_r !== -1){clearInterval(interval_ddrago_r);}
  }
});

$("#ddrago_b_button").click(function () {
  show_ddrago_b= !show_ddrago_b;

  if (show_ddrago_b)
  {
    $("#ddrago_b_list").show();
    interval_ddrago_b = setInterval(function() {ajax_request("ddrago_b", "ddrago_b_list");}, LOGS_REFRESH_FREQUENCE);
  }
  else { $("#ddrago_b_list").hide();
    if (interval_ddrago_b !== -1){clearInterval(interval_ddrago_b);}
  }
});

    /*
        function retriving logs for tools with show variable equal True, called every LOGS_REFRESH_FREQUENCE
    */

function ajax_request(cam, id_list){
      var cagire_url ="/devices/update_cagire_logs";
      var telescope_url ="/devices/update_telescope_logs";
      var ddrago_r_url ="/devices/update_ddrago_r_logs";
      var ddrago_b_url ="/devices/update_ddrago_b_logs";
      var url_txt = "";
      if (cam === 'cagire')
        url_txt = cagire_url;
      else if (cam === "telescope")
          url_txt = telescope_url;
      else if (cam === "ddrago_r")
          url_txt = ddrago_r_url;
      else if (cam === "ddrago_b")
          url_txt = ddrago_b_url;
      $.ajax({
        url: url_txt,
        type: 'get',
        dataType: 'text',
        success: function(data)
        {
          var obj = JSON.parse(data);
          if (obj) {
              var listDiv = document.getElementById(id_list);
              listDiv.innerHTML = '';
              for (var tmp in obj) {
                  var li = document.createElement('li');
                  li.innerHTML = obj[tmp]['fields']['created'] + ":     " + obj[tmp]['fields']['message'];   // Use innerHTML to set the text
                  listDiv.appendChild(li);
              }
          }
        },
        error: function()
        {
          console.log('Ajax error: GET request failed\n');
        }

      });

    }


});

 $(window).unload(function(){
        alert("bye")
  if (interval_cagire != -1){clearInterval(interval_cagire);}
  if (interval_telescope !== -1){clearInterval(interval_telescope);}
});