status.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ data['title'] }} Status display</title>
  6. <meta name="description"
  7. content="Status display generated by BORA.">
  8. <link rel="stylesheet" href="{{ static_url("style.css") }}">
  9. <link rel="stylesheet" href="{{ static_url("jquery-ui.min.css") }}">
  10. <!--[if IE]>
  11. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  12. <![endif]-->
  13. </head>
  14. <body>
  15. <div id="page_info">{{ data['title'] }} data monitoring. Last refreshed</div>
  16. <div id="page_title_cache" style="display:none;">{{ data['title'] }}</div>
  17. {% if data['style'] %}
  18. {% for key in data['style'] %}
  19. {% if data['style'][key]['type'] == "calc" %}
  20. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  21. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  22. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
  23. {% if "condition" in data['style'][key] %}
  24. data-cond="{{ data['style'][key]['condition'] }}"
  25. {% else%}position
  26. {% end%}
  27. {% if "formula" in data['style'][key] %}
  28. data-formula="{{ data['style'][key]['formula'] }}" tooltip="{{ data['style'][key]['formula'] }}"
  29. {% else %}
  30. {% end %}
  31. {% if "lesser" in data['style'][key] %}
  32. data-lesser="{{ data['style'][key]['lesser'] }}"
  33. {% else %}
  34. {% end %}
  35. {% if "larger" in data['style'][key] %}
  36. data-larger="{{ data['style'][key]['larger'] }}"
  37. {% else %}
  38. {% end %}
  39. data-type="{{ data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  40. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> --- </span><span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" > {{ data['style'][key]['unit']['title'] }}</span></p>
  41. </div>
  42. {% else %}
  43. {% end %}
  44. {% if data['style'][key]['type'] == "data" %}
  45. {% if "ref" in data['style'][key] %}
  46. <div tooltip="{{ data['style'][key]['ref'] }}"
  47. {% else %}
  48. <div tooltip="{{ key }}"
  49. {% end %}
  50. class="databox" style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;
  51. {% if "background_color" in data['style'][key] %}
  52. background-color:{{ data['style'][key]['background_color'] }};'
  53. {% else%}
  54. {% end%}
  55. {% if "condition" in data['style'][key] %}
  56. data-cond="{{ data['style'][key]['condition'] }}"
  57. {% else%}
  58. {% end%}
  59. {% if "formula" in data['style'][key] %}
  60. data-formula="{{ data['style'][key]['formula'] }}"
  61. {% else %}
  62. {% end %}
  63. {% if "lesser" in data['style'][key] %}
  64. data-lesser="{{ data['style'][key]['lesser'] }}"
  65. {% else %}
  66. {% end %}
  67. {% if "larger" in data['style'][key] %}
  68. data-larger="{{ data['style'][key]['larger'] }}"
  69. {% else %}
  70. {% end %}
  71. {% if "exponential" in data['style'][key] %}
  72. data-exponential="{{ data['style'][key]['exponential'] }}"
  73. {% else %}
  74. {% end %}
  75. {% if "linkhtml" in data['style'][key] %}
  76. {% if data['style'][key]['linkhtml'] == 'true' %}
  77. {% if "server" in data %}
  78. onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');"
  79. {% else %}
  80. {% end %}
  81. {% else %}
  82. {% end %}
  83. {% else %}
  84. {% end %}
  85. {% if "ref" in data['style'][key] %}
  86. data-type="{{ data['style'][key]['type'] }}" id="{{ key }}">
  87. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> --- </span><span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};"> {{ data['style'][key]['unit']['title'] }}</span><span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span></p>
  88. </div>
  89. {% else %}
  90. data-type="{{ data['style'][key]['type'] }}" id="{{ key }}">
  91. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> --- </span><span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};"> {{ data['style'][key]['unit']['title'] }}</span><span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span></p>
  92. </div>
  93. {% end %}
  94. {% else %}
  95. {% end %}
  96. {% if data['style'][key]['type'] == "icon" %}
  97. {% if data['style'][key]['icon'] == "valve" %}
  98. {% if "ref" in data['style'][key] %}
  99. <div tooltip="{{ data['style'][key]['ref'] }}"
  100. {% else %}
  101. <div tooltip="{{ key }}"
  102. {% end %}
  103. style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;'
  104. {% if data['style'][key]['linkhtml'] == 'true' %}
  105. {% if "server" in data %}
  106. onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');"
  107. {% else %}
  108. {% end %}
  109. {% else %}
  110. {% end %}
  111. {% if "ref" in data['style'][key] %}
  112. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  113. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  114. <div class="icon">
  115. <img width='100%' height='100%' src='{{ static_url("valve_inactive.png") }}'></img>
  116. </div>
  117. </div>
  118. {% else %}
  119. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  120. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  121. <div class="icon">
  122. <img width='100%' height='100%' src='{{ static_url("valve_inactive.png") }}'></img>
  123. </div>
  124. </div>
  125. {% end %}
  126. {% else %}
  127. {% end %}
  128. {% if data['style'][key]['icon'] == "commbit" %}
  129. {% if "ref" in data['style'][key] %}
  130. <div tooltip="{{ data['style'][key]['ref'] }}"
  131. {% else %}
  132. <div tooltip="{{ key }}"
  133. {% end %}
  134. style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;'
  135. {% if data['style'][key]['linkhtml'] == 'true' %}
  136. {% if "server" in data %}
  137. onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');"
  138. {% else %}
  139. {% end %}
  140. {% else %}
  141. {% end %}
  142. {% if "ref" in data['style'][key] %}
  143. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  144. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  145. <div class="icon">
  146. <img width='100%' height='100%' src='{{ static_url("commbit_inactive.svg") }}'></img>
  147. </div>
  148. </div>
  149. {% else %}
  150. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  151. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  152. <div class="icon">
  153. <img width='100%' height='100%' src='{{ static_url("commbit_inactive.svg") }}'></img>
  154. </div>
  155. </div>
  156. {% end %}
  157. {% else %}
  158. {% end %}
  159. {% if data['style'][key]['icon'] == "alarm" %}
  160. {% if "ref" in data['style'][key] %}
  161. <div tooltip="{{ data['style'][key]['ref'] }}"
  162. {% else %}
  163. <div tooltip="{{ key }}"
  164. {% end %}
  165. style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;'
  166. {% if data['style'][key]['linkhtml'] == 'true' %}
  167. {% if "server" in data %}
  168. onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');"
  169. {% else %}
  170. {% end %}
  171. {% else %}
  172. {% end %}
  173. {% if "ref" in data['style'][key] %}
  174. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  175. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  176. <div class="icon">
  177. <img width='100%' height='100%' src='{{ static_url("alarm_inactive.svg") }}'></img>
  178. </div>
  179. </div>
  180. {% else %}
  181. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  182. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  183. <div class="icon">
  184. <img width='100%' height='100%' src='{{ static_url("alarm_inactive.svg") }}'></img>
  185. </div>
  186. </div>
  187. {% end %}
  188. {% else %}
  189. {% end %}
  190. {% if data['style'][key]['icon'] == "TMP" %}
  191. {% if "ref" in data['style'][key] %}
  192. <div tooltip="{{ data['style'][key]['ref'] }}"
  193. {% else %}
  194. <div tooltip="{{ key }}"
  195. {% end %}
  196. style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;'
  197. {% if data['style'][key]['linkhtml'] == 'true' %}
  198. {% if "server" in data %}
  199. onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');"
  200. {% else %}
  201. {% end %}
  202. {% else %}
  203. {% end %}
  204. {% if "ref" in data['style'][key] %}
  205. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  206. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  207. <div class="icon">
  208. <img width='100%' height='100%' src='{{ static_url("TMP_inactive.svg") }}'></img>
  209. </div>
  210. </div>
  211. {% else %}
  212. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  213. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  214. <div class="icon">
  215. <img width='100%' height='100%' src='{{ static_url("TMP_inactive.svg") }}'></img>
  216. </div>
  217. </div>
  218. {% end %}
  219. {% else %}
  220. {% end %}
  221. {% if data['style'][key]['icon'] == "bottle" %}
  222. {% if "ref" in data['style'][key] %}
  223. <div tooltip="{{ data['style'][key]['ref'] }}"
  224. {% else %}
  225. <div tooltip="{{ key }}"
  226. {% end %}
  227. style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;'
  228. {% if data['style'][key]['linkhtml'] == 'true' %}
  229. {% if "server" in data %}
  230. onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');"
  231. {% else %}
  232. {% end %}
  233. {% else %}
  234. {% end %}
  235. {% if "ref" in data['style'][key] %}
  236. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  237. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  238. <div class="icon">
  239. <img width='100%' height='100%' src='{{ static_url("bottle_inactive.svg") }}'></img>
  240. </div>
  241. </div>
  242. {% else %}
  243. data-type="{{ data['style'][key]['type'] }}" data-icon="{{ data['style'][key]['icon'] }}" data-off="{{ data['style'][key]['off'] }}" data-offexpression="{{ data['style'][key]['off_condition'] }}" data-on="{{ data['style'][key]['on'] }}" data-onexpression="{{ data['style'][key]['on_condition'] }}" class='databox' id="{{ key }}">
  244. <span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span>
  245. <div class="icon">
  246. <img width='100%' height='100%' src='{{ static_url("bottle_inactive.svg") }}'></img>
  247. </div>
  248. </div>
  249. {% end %}
  250. {% else %}
  251. {% end %}
  252. {% else %}
  253. {% end %}
  254. {% if data['style'][key]['type'] == "integer-to-string" %}
  255. <div tooltip="{{ key }}" style='position: absolute; top: {{
  256. data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }};
  257. width:{{ data['style'][key]['width'] }}px; height:{{
  258. data['style'][key]['height'] }}px;
  259. {% if "background_color" in data['style'][key] %}
  260. background-color:{{ data['style'][key]['background_color'] }};'
  261. {% else%}
  262. '
  263. {% end%}
  264. {% if "cond" in data['style'][key] %}
  265. data-cond="{{ data['style'][key]['cond'] }}"
  266. {% else %}
  267. {% end %}
  268. {% if "linkhtml" in data['style'][key] %}
  269. {% if data['style'][key]['linkhtml'] == 'true' %}
  270. {% if "server" in data %}
  271. onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data['style'][key]['ref']] }}&experiment=-&window=86400&module=graph&virtual=srctree&srctree=&infomod=legend', '_blank');"
  272. {% else %}
  273. {% end %}
  274. {% else %}
  275. {% end %}
  276. {% else %}
  277. {% end %}
  278. data-dict="{{ data['style'][key]['dict'] }}" data-type="{{ data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  279. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><br /><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval">--- </span><span><img src="static/dataimage/{{data['style'][key]['ref']}}.png" alt="" class="popup"></span></p>
  280. </div>
  281. {% else %}
  282. {% end %}
  283. {% if data['style'][key]['type'] == "header" %}
  284. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  285. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  286. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' data-type="{{
  287. data['style'][key]['type'] }}" class='databox' id="{{ key }}">
  288. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span></p>
  289. </div>
  290. {% else %}
  291. {% end %}
  292. {% end %}
  293. {% else %}
  294. {% end %}
  295. {% if "background" in data %}
  296. <img src="{{ static_url( data['background'] ) }}"></img>
  297. {% else %}
  298. <img src="{{ static_url( 'background.png' ) }}"></img>
  299. {% end %}
  300. <!-- java script -->
  301. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  302. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  303. <script src="{{ static_url("math.min.js") }}"></script>
  304. <script>
  305. jQuery(window).load(function () {
  306. myTimer();
  307. var myVar = setInterval(myTimer, 10000);
  308. function myTimer() {
  309. var dataToSend = {};
  310. $.ajax({
  311. url: '/getdata/',
  312. type: 'GET',
  313. data: dataToSend,
  314. success: function (response) {
  315. //var objresponse = JSON.parse(response);
  316. console.log(response);
  317. for (var key in response) {
  318. //console.log(key, response[key]);
  319. data_type = $("#" + key).attr('data-type');
  320. if($("#" + key).length > 0) {
  321. if (data_type == "data") {
  322. //console.log("data");
  323. var datavalue, set_color, formula;
  324. var formula_attr = $("#" + key).attr('data-formula');
  325. if (response[key]) {
  326. if (formula_attr) {
  327. datavalue = parseFloat(response[key]).toFixed(2);
  328. formula = formula_attr.replace("x", datavalue.toString());
  329. datavalue = math.round(math.eval(formula),2);
  330. datavalue = datavalue.toFixed(2);
  331. } else {
  332. if ( ($("#" + key).attr('data-exponential')) == "True" || ($("#" + key).attr('data-exponential')) == "true" ) {
  333. datavalue = parseFloat(response[key]);
  334. datavalue = datavalue.toExponential(2)
  335. } else {
  336. datavalue = parseFloat(response[key]).toFixed(2);
  337. }
  338. }
  339. set_color = "green";
  340. } else {
  341. datavalue = "---";
  342. set_color = "black";
  343. }
  344. $(".varval", "#" + key).text(datavalue);
  345. var condition_attr = $("#" + key).attr('data-cond');
  346. var lesser_attr = $("#" + key).attr('data-lesser');
  347. var larger_attr = $("#" + key).attr('data-larger');
  348. //console.log(condition_attr);
  349. if (condition_attr) {
  350. if (response[key] == condition_attr) {
  351. set_color = "red";
  352. }
  353. }
  354. if (lesser_attr) {
  355. if (parseFloat(response[key]) < parseFloat(lesser_attr)) {
  356. set_color = "red";
  357. }
  358. }
  359. if (larger_attr) {
  360. if (parseFloat(response[key]) > parseFloat(larger_attr)) {
  361. set_color = "red";
  362. }
  363. }
  364. $(".varval", "#" + key).css("color", set_color);
  365. $(".unit_title", "#" + key).css("color", set_color);
  366. } else if (data_type == "icon") {
  367. //console.log("ventil");
  368. var on_attr = $("#" + key).attr('data-on');
  369. var off_attr = $("#" + key).attr('data-off');
  370. var on_condition = $("#" + key).attr('data-onexpression');
  371. var off_condition = $("#" + key).attr('data-offexpression');
  372. if (on_condition == 'onequal'){
  373. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  374. $("img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_green.svg");
  375. }
  376. } else if (on_condition == 'onsmaller'){
  377. if (parseFloat(response[key]) < parseFloat(on_attr)) {
  378. $(".icon img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_green.svg");
  379. }
  380. } else if (on_condition == 'ongreater'){
  381. if (parseFloat(response[key]) > parseFloat(on_attr)) {
  382. $(".icon img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_green.svg");
  383. }
  384. }
  385. if (off_condition == 'offequal'){
  386. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  387. $(".icon img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_red.svg");
  388. }
  389. } else if (off_condition == 'offsmaller'){
  390. if (parseFloat(response[key]) < parseFloat(off_attr)) {
  391. $(".icon img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_red.svg");
  392. }
  393. } else if (off_condition == 'offgreater'){
  394. if (parseFloat(response[key]) > parseFloat(off_attr)) {
  395. $(".icon img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_red.svg");
  396. }
  397. }
  398. /*
  399. } else if (data_type == "commbit") {
  400. //console.log("commbit");
  401. var on_attr = $("#" + key).attr('data-on');
  402. var off_attr = $("#" + key).attr('data-off');
  403. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  404. $("img", "#" + key).attr("src", "{{ static_url('commbit_green.svg') }}");
  405. }
  406. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  407. $("img", "#" + key).attr("src", "{{ static_url('commbit_red.svg') }}");
  408. }
  409. } else if (data_type == "alarm") {
  410. //console.log("alarm");
  411. var on_attr = $("#" + key).attr('data-on');
  412. var off_attr = $("#" + key).attr('data-off');
  413. if (parseFloat(response[key]) == parseFloat(on_attr)) {
  414. $("img", "#" + key).attr("src", "{{ static_url('alarm_active.svg') }}");
  415. }
  416. if (parseFloat(response[key]) == parseFloat(off_attr)) {
  417. $("img", "#" + key).attr("src", "{{ static_url('alarm_inactive.svg') }}");
  418. }*/
  419. } else if (data_type == "integer-to-string") {
  420. //console.log("integer-to-string");
  421. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  422. var dict_cond;
  423. if ($("#"+key).attr("data-cond")) {
  424. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  425. } else {
  426. dict_cond = {};
  427. }
  428. var dict_color = "";
  429. if (key in response) {
  430. var token = response[key];
  431. if (token in dict_cond) {
  432. dict_color = dict_cond[token];
  433. }
  434. }
  435. $(".varval", "#" + key).css("color", dict_color);
  436. $(".varval", "#" + key).text(dict_attr[response[key]]);
  437. }
  438. }
  439. }
  440. $('[id^=virtual_]').each(function( index ) {
  441. var key = this.id;
  442. var ref = key.split("_");
  443. ref.shift();
  444. ref.pop();
  445. ref = ref.join("_");
  446. //ref = ref[1];
  447. console.log(ref, key);
  448. data_type = $("#" + key).attr('data-type');
  449. if($("#" + key).length > 0) {
  450. if (data_type == "data") {
  451. console.log(key);
  452. var datavalue, set_color, formula;
  453. var formula_attr = $("#" + key).attr('data-formula');
  454. if (response[ref]) {
  455. if (formula_attr) {
  456. datavalue = parseFloat(response[ref]).toFixed(2);
  457. formula = formula_attr.replace("x", datavalue.toString());
  458. datavalue = math.round(math.eval(formula),2);
  459. datavalue = datavalue.toFixed(2);
  460. } else {
  461. datavalue = parseFloat(response[ref]).toFixed(2);
  462. }
  463. set_color = "green";
  464. } else {
  465. datavalue = "---";
  466. set_color = "black";
  467. }
  468. $(".varval", "#" + key).text(datavalue);
  469. var condition_attr = $("#" + key).attr('data-cond');
  470. var lesser_attr = $("#" + key).attr('data-lesser');
  471. var larger_attr = $("#" + key).attr('data-larger');
  472. //console.log(condition_attr);
  473. if (condition_attr) {
  474. if (response[ref] == condition_attr) {
  475. set_color = "red";
  476. }
  477. }
  478. if (lesser_attr) {
  479. if (parseFloat(response[ref]) < parseFloat(lesser_attr)) {
  480. set_color = "red";
  481. }
  482. }
  483. if (larger_attr) {
  484. if (parseFloat(response[ref]) > parseFloat(larger_attr)) {
  485. set_color = "red";
  486. }
  487. }
  488. $(".varval", "#" + key).css("color", set_color);
  489. $(".unit_title", "#" + key).css("color", set_color);
  490. } else if (data_type == "icon") {
  491. var on_attr = $("#" + key).attr('data-on');
  492. var off_attr = $("#" + key).attr('data-off');
  493. var on_condition = $("#" + key).attr('data-onexpression');
  494. var off_condition = $("#" + key).attr('data-offexpression');
  495. if (on_condition == 'onequal'){
  496. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  497. $("img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_green.svg");
  498. }
  499. } else if (on_condition == 'onsmaller'){
  500. if (parseFloat(response[ref]) < parseFloat(on_attr)) {
  501. $("img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_green.svg");
  502. }
  503. } else if (on_condition == 'ongreater'){
  504. if (parseFloat(response[ref]) > parseFloat(on_attr)) {
  505. $("img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_green.svg");
  506. }
  507. }
  508. if (off_condition == 'offequal'){
  509. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  510. $("img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_red.svg");
  511. }
  512. } else if (off_condition == 'offsmaller'){
  513. if (parseFloat(response[ref]) < parseFloat(off_attr)) {
  514. $("img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_red.svg");
  515. }
  516. } else if (off_condition == 'offgreater'){
  517. if (parseFloat(response[ref]) > parseFloat(off_attr)) {
  518. $("img", "#" + key).attr("src", "/static/" + $("#" + key).attr('data-icon') + "_red.svg");
  519. }
  520. }
  521. /*
  522. } else if (data_type == "commbit") {
  523. var on_attr = $("#" + key).attr('data-on');
  524. var off_attr = $("#" + key).attr('data-off');
  525. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  526. $("img", "#" + key).attr("src", "{{ static_url('commbit_green.svg') }}");
  527. }
  528. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  529. $("img", "#" + key).attr("src", "{{ static_url('commbit_red.svg') }}");
  530. }
  531. } else if (data_type == "alarm") {
  532. var on_attr = $("#" + key).attr('data-on');
  533. var off_attr = $("#" + key).attr('data-off');
  534. if (parseFloat(response[ref]) == parseFloat(on_attr)) {
  535. $("img", "#" + key).attr("src", "{{ static_url('alarm_active.svg') }}");
  536. }
  537. if (parseFloat(response[ref]) == parseFloat(off_attr)) {
  538. $("img", "#" + key).attr("src", "{{ static_url('alarm_inactive.svg') }}");
  539. }*/
  540. } else if (data_type == "integer-to-string") {
  541. var dict_attr = JSON.parse($("#" + key).attr('data-dict'));
  542. var dict_cond;
  543. if ($("#"+key).attr("data-cond")) {
  544. dict_cond = JSON.parse($("#" + key).attr('data-cond'));
  545. } else {
  546. dict_cond = {};
  547. }
  548. var dict_color = "";
  549. if (ref in response) {
  550. var token = response[ref];
  551. if (token in dict_cond) {
  552. dict_color = dict_cond[token];
  553. }
  554. }
  555. $(".varval", "#" + key).css("color", dict_color);
  556. $(".varval", "#" + key).text(dict_attr[response[ref]]);
  557. }
  558. }
  559. });
  560. $('[id^=calc_]').each(function( index ) {
  561. console.log(this.id);
  562. console.log($(this).attr('data-formula'));
  563. var myformula = $(this).attr('data-formula').trim();
  564. /*
  565. myformula = myformula.replace(/\[.*?\]/g, '__');
  566. console.log(myformula);
  567. */
  568. var data = myformula;
  569. var re= /\[(.*?)\]/g;
  570. var buffer = []
  571. for(m = re.exec(data); m; m = re.exec(data)){
  572. buffer.push(m[1]);
  573. }
  574. console.log("Debug:");
  575. console.log(buffer);
  576. var finalstring = "";
  577. var pattern = /\[(.*?)\]/g;
  578. var teststring = myformula.split(/[\[\]]+/);
  579. console.log(teststring);
  580. console.log(finalstring);
  581. for (var i = 0; i < teststring.length; i++) {
  582. var val = "";
  583. if (teststring[i] in response) {
  584. val = response[teststring[i]];
  585. } else {
  586. val = teststring[i];
  587. }
  588. finalstring += val;
  589. finalstring += " ";
  590. }
  591. finalstring = finalstring.trim();
  592. console.log(finalstring);
  593. var myvalue = math.round(math.eval(finalstring),2);
  594. myvalue = myvalue.toFixed(2);
  595. set_color = "green";
  596. console.log(myvalue);
  597. $(".varval", "#" + this.id).text(myvalue);
  598. var condition_attr = $("#" + this.id).attr('data-cond');
  599. var lesser_attr = $("#" + this.id).attr('data-lesser');
  600. var larger_attr = $("#" + this.id).attr('data-larger');
  601. //console.log(condition_attr);
  602. if (condition_attr) {
  603. if (myvalue == condition_attr) {
  604. set_color = "red";
  605. }
  606. }
  607. if (lesser_attr) {
  608. if (parseFloat(myvalue) < parseFloat(lesser_attr)) {
  609. set_color = "red";
  610. }
  611. }
  612. if (larger_attr) {
  613. if (parseFloat(myvalue) > parseFloat(larger_attr)) {
  614. set_color = "red";
  615. }
  616. }
  617. $(".varval", "#" + this.id).css("color", set_color);
  618. $(".unit_title", "#" + this.id).css("color", set_color);
  619. });
  620. var page_title_cache = $("#page_title_cache").text();
  621. var datetime = page_title_cache + " data monitoring page. Last Sync: " + response["time"];
  622. $("#page_info").text(datetime);
  623. console.log(datetime);
  624. },
  625. error: function () {
  626. console.log("Error.")
  627. }
  628. });
  629. }
  630. });
  631. </script>
  632. </body>
  633. </html>