]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/html/bweb.js
ebl Add volume/pool usage
[bacula/bacula] / gui / bweb / html / bweb.js
1  var even_cell_color = "#FFFFFF";
2  var odd_cell_color  = "#EEEEEE";
3  var header_color    = "#E1E0DA";
4  var rows_per_page   = 20;
5  var up_icon         = "/bweb/up.gif";
6  var down_icon       = "/bweb/down.gif";
7  var prev_icon       = "/bweb/left.gif";
8  var next_icon       = "/bweb/right.gif";
9  var rew_icon        = "/bweb/first.gif";
10  var fwd_icon        = "/bweb/last.gif";
11
12  var jobstatus = {
13  'C': 'created but not yet running',
14  'R': 'running',
15  'B': 'blocked',
16  'T': 'terminated normally',
17  'E': 'Job terminated in error',
18  'e': 'Non-fatal error',
19  'f': 'Fatal error',
20  'D': 'Verify differences',
21  'A': 'canceled by user',
22  'F': 'waiting on File daemon',
23  'S': 'waiting on the Storage daemon',
24  'm': 'waiting for new media',
25  'M': 'waiting for Mount',
26  's': 'Waiting for storage resource',
27  'j': 'Waiting for job resource',
28  'c': 'Waiting for Client resource',
29  'd': 'Waiting for maximum jobs',
30  't': 'Waiting for start time',
31  'p': 'Waiting for higher priority jobs to finish'
32 };
33
34 var joblevel = {
35  'F': 'Full backup',
36  'I': 'Incr (since last backup)',
37  'D': 'Diff (since last full backup)',
38  'C': 'verify from catalog',
39  'V': 'verify save (init DB)',
40  'O': 'verify Volume to catalog entries',
41  'd': 'verify Disk attributes to catalog',
42  'A': 'verify data on volume',
43  'B': 'Base level job'
44 };
45
46
47 var refresh_time = 60000;
48
49 function bweb_refresh() {
50   location.reload(true)
51 }
52 function bweb_add_refresh(){
53         window.setInterval("bweb_refresh()",refresh_time);
54 }
55
56 //
57 // percent_display("row2", [ { nb: 1, name: "Full"   },
58 //                         { nb: 2, name: "Error"  },
59 //                         { nb: 5, name: "Append" },
60 //                         { nb: 2, name: "Purged" },
61 //                         {}                               # last element must be {}
62 //                       ]);
63
64 function percent_get_img(type)
65 {
66    var img=document.createElement('img');
67    if (type) {
68       img.className="pSlice" + type ;
69    } else {
70       img.className="pSlice";
71    }
72    img.src="/bweb/pix.png";
73    img.alt="";
74    return img;
75 }
76
77 var percent_display_nb_slice = 20;
78 var percent_usage_nb_slice = 5;
79
80 function percent_display(hash_values, parent)
81 {
82    var nb_elt=percent_display_nb_slice;
83    var tips= "";
84
85    if (!parent) {
86       parent = document.createElement('DIV');
87    }
88
89    if (typeof parent != "object") {
90       parent = document.getElementById(parent);
91    } 
92
93    if (!parent) {
94        alert("E : display_percent(): Can't find parent " + parent);
95        return;
96    }
97
98    hash_values.pop(); // drop last element {}
99
100    var nb_displayed = 0;
101    var nb_max = 0;
102
103    for(var i=0;i<hash_values.length;i++) {
104         nb_max += hash_values[i]['nb'];
105    }
106
107    for(var i=0;i<hash_values.length;i++) {
108         var elt = hash_values[i];
109         var cur_nb = (elt['nb'] * nb_elt)/nb_max;
110         var cur_name = elt['name'];
111         cur_name.replace(/-/,"_");
112
113         tips = tips + " " + elt['nb'] + " " + cur_name;
114
115         while ((nb_displayed < nb_elt) && (cur_nb >=1)) {
116             nb_displayed++;
117             cur_nb--;
118
119             var img= percent_get_img(cur_name);
120             parent.appendChild(img);
121         }       
122    }
123
124    while (nb_displayed < nb_elt) {
125       nb_displayed++;
126       var img= percent_get_img();
127       parent.appendChild(img);
128   }     
129
130   parent.title = tips;
131
132   return parent;
133 }
134
135 function percent_usage(value, parent)
136 {
137    var nb_elt=percent_usage_nb_slice;
138    var type;
139   
140    if (!parent) {
141       parent = document.createElement('DIV');
142    }   
143
144    if (typeof parent != "object") {
145       parent = document.getElementById(parent);
146    } 
147
148    if (!parent) {
149        alert("E : display_percent(): Can't find parent " + parent);
150        return;
151    }
152
153    if (value <= 0) {
154       type = "Empty";
155       value = 0;      
156    } else if (value <= 40) {
157       type = "Ok";
158    } else if (value <= 75) {
159       type = "Warn";
160    } else if (value <= 85) {
161       type = "Crit";
162    } else {
163       type = "Crit";
164    }
165
166    var nb = parseInt(value*nb_elt/100, 10);
167    parent.title = parseInt(value*100,10)/100 + "% used (approximate)";
168
169    for(var i=0; i<nb; i++) {
170       var img= percent_get_img(type);
171       parent.appendChild(img);
172    }
173
174    for(nb;nb < nb_elt;nb++) {
175       var img= percent_get_img("Empty");
176       parent.appendChild(img);       
177    } 
178
179    return parent;
180 }
181