designer.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Designer</title>
  6. <meta name="description"
  7. content="Designer Drawing Block.">
  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">Designer Block. Generated by BORA 0.0.1</div>
  16. <img src="{{ static_url('background.png') }}"></img>
  17. <button class="button showhide" onclick="showhide()">Show/Hide</button>
  18. {% if data['style'] %}
  19. {% for key in data['style'] %}
  20. {% if data['style'][key]['type'] == "data" %}
  21. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  22. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  23. height:{{ data['style'][key]['height'] }}px;'
  24. {% if "formula" in data['style'][key] %}
  25. data-formula="{{ data['style'][key]['formula'] }}"
  26. {% else %}
  27. {% end %}
  28. data-cond="{{ data['style'][key]['condition'] }}" data-lesser="{{ data['style'][key]['lesser'] }}" data-type="{{ data['style'][key]['type'] }}" data-larger="{{ data['style'][key]['larger'] }}" class='varbox' id="{{ key }}">
  29. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; 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'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX <span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};" > {{ data['style'][key]['unit']['title'] }}</span></span></p>
  30. </div>
  31. {% else %}
  32. {% end %}
  33. {% if data['style'][key]['type'] == "ventil" %}
  34. <div 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;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  35. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  36. </div>
  37. {% else %}
  38. {% end %}
  39. {% if data['style'][key]['type'] == "integer-to-string" %}
  40. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  41. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  42. height:{{ data['style'][key]['height'] }}px;' data-cond="{{data['style'][key]['cond']}}" data-dict="{{ data['style'][key]['dict'] }}" data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  43. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; 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'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval">??? </span></p>
  44. </div>
  45. {% else %}
  46. {% end %}
  47. {% if data['style'][key]['type'] == "header" %}
  48. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  49. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  50. height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  51. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span></p>
  52. </div>
  53. {% else %}
  54. {% end %}
  55. {% end %}
  56. {% else %}
  57. {% end %}
  58. <div id="tool-btn">
  59. <span class="info">Variable</span>
  60. <select id="varname" style="font-size:16pt;">
  61. {% if data['cache'] %}
  62. {% for key in data['cache'] %}
  63. {% if key != "time" %}
  64. <option value={{data['cache'][key]}}>{{key}}</option>
  65. {% else %}
  66. {% end %}
  67. {% end %}
  68. {% else %}
  69. {% end %}
  70. </select>
  71. <span class="info">Type</span>
  72. <select id="vartype" style="font-size:16pt;">
  73. <option value="data">data</option>
  74. <option value="ventil">ventil</option>
  75. <option value="integer-to-string">integer-to-string</option>
  76. <option value="header">header</option>
  77. </select>
  78. <br /><br />
  79. <span class="info">Title</span>
  80. <input type="text" id="elem_title_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  81. <input type="text" id="elem_title_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  82. <input type="text" id="elem_lesser_range" placeholder="smaller than (red)" style="font-size:16pt; width=100px;"/>
  83. <input type="text" id="elem_larger_range" placeholder="larger than (red)" style="font-size:16pt; width=100px;"/>
  84. <select id="elem_title_style" style="font-size:16pt;">
  85. <option value="400">normal</option>
  86. <option value="700">bold</option>
  87. </select>
  88. <br /><br />
  89. <span class="info">Value</span>
  90. <input type="text" id="elem_unit_text" placeholder="unit" style="font-size:16pt; width=100px;"/>
  91. <input type="text" id="elem_unit_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  92. <input type="text" id="elem_condition_range" placeholder="condition (red)" style="font-size:16pt; width=100px;"/>
  93. <input type="text" id="elem_formula" placeholder="Equation" style="font-size:16pt; width=100px;"/>
  94. <select id="elem_unit_style" style="font-size:16pt;">
  95. <option value="400">normal</option>
  96. <option value="700">bold</option>
  97. </select>
  98. <br /><br />
  99. <button class="button save" onclick="backup()">Backup</button>
  100. <button class="button highlight" onclick="highlight()">Highlight</button>
  101. <button class="button add" onclick="add()">Add</button>
  102. <button class="button remove" onclick="myremove()">Remove</button>
  103. <button class="button save" onclick="mysave({{ data['cache'] }})">Save</button>
  104. </div>
  105. <!-- java script -->
  106. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  107. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  108. <script>
  109. function backup() {
  110. $.ajax({
  111. url: '/backup/',
  112. type: 'POST',
  113. success: function (response) {
  114. alert("Backup success!");
  115. },
  116. error: function () {
  117. console.log("Error.")
  118. }
  119. });
  120. }
  121. function showhide() {
  122. console.log("Show or Hide");
  123. $("#tool-btn").toggle();
  124. }
  125. function add() {
  126. console.log("add element");
  127. title_text = $("#elem_title_text").val();
  128. title_text = title_text.trim();
  129. title_color = "#000000";
  130. //title_color = $("#elem_title_color").val();
  131. title_size = $("#elem_title_size").val();
  132. title_style = $("#elem_title_style option:selected").val();
  133. unit_text = $("#elem_unit_text").val();
  134. unit_text = unit_text.trim();
  135. unit_color = "#000";
  136. //unit_color = $("#elem_unit_color").val();
  137. unit_size = $("#elem_unit_size").val();
  138. unit_style = $("#elem_unit_style option:selected").val();
  139. data_condition = $("#elem_condition_range").val();
  140. //data_max = $("#elem_max_range").val();
  141. data_formula = $("#elem_formula").val();
  142. data_lesser = $("#elem_lesser_range").val();
  143. data_larger = $("#elem_larger_range").val();
  144. varval = $( "#varname option:selected").val();
  145. varname = $("#varname option:selected").text();
  146. vartype = $("#vartype option:selected").val();
  147. console.log("Selected");
  148. console.log(vartype);
  149. console.log(title_text, unit_text, varname, varval, vartype);
  150. if(($("#" + varname).length == 0) || (vartype=="header")) {
  151. console.log("Must enter here");
  152. console.log(vartype);
  153. if (vartype == "data") {
  154. console.log("Data");
  155. html_text = "<div " +
  156. "style='position: absolute; " +
  157. "top:0; " +
  158. "left:0;' " +
  159. "class='varbox' " +
  160. "id='" + varname +
  161. "' data-type='" + vartype +
  162. "' data-cond='" + data_condition +
  163. "' data-formula='" + data_formula +
  164. "' data-lesser='" + data_lesser +
  165. "' data-larger='" + data_larger +
  166. "'>" +
  167. "<p>" +
  168. "<span style='color: " + title_color + ";" +
  169. "font-size:" + title_size + "px; " +
  170. "font-weight: " + title_style + ";' " +
  171. "class='title'>" + title_text +
  172. " </span>" +
  173. "<span style='color: " + unit_color + "; " +
  174. "font-size:" + unit_size + "px; " +
  175. "font-weight: " + unit_style + ";' " +
  176. "class='varval'>" + parseFloat(varval).toFixed(2) + " </span>" +
  177. "<span class='unit_title'>" + unit_text + "</span></p>" +
  178. "</div>";
  179. } else if (vartype == "header") {
  180. console.log("Header");
  181. varname = "header_" + title_text.replace(/\s+/g, '-').toLowerCase();
  182. html_text = "<div " +
  183. "style='position: absolute; " +
  184. "top:0; " +
  185. "left:0;' " +
  186. "class='varbox' " +
  187. "id='" + varname +
  188. "' data-type='" + vartype +
  189. "' data-cond='" + data_condition +
  190. "' data-lesser='" + data_lesser +
  191. "' data-larger='" + data_larger +
  192. "'>" +
  193. "<p>" +
  194. "<span style='color: " + title_color + ";" +
  195. "font-size:" + title_size + "px; " +
  196. "font-weight: " + title_style + ";' " +
  197. "class='title'>" + title_text +
  198. " </span></p>" +
  199. "</div>";
  200. } else if (vartype == "ventil") {
  201. console.log("Ventil");
  202. var token = JSON.parse(unit_text);
  203. data_on = token["on"];
  204. data_off = token["off"];
  205. html_text = "<div " +
  206. "style='position: absolute; " +
  207. "top:0; " +
  208. "left:0;' " +
  209. "class='varbox' " +
  210. "id='" + varname +
  211. "' data-type='" + vartype +
  212. "' data-cond='" + data_condition +
  213. "' data-lesser='" + data_lesser +
  214. "' data-larger='" + data_larger +
  215. "' data-on='" + data_on +
  216. "' data-off='" + data_off +
  217. "'>" +
  218. "<img width='100%' height='100%' " +
  219. "src='{{ static_url("ventil_inactive.png") }}'></img>" +
  220. "</div>";
  221. } else if (vartype == "integer-to-string") {
  222. console.log("Integer2String");
  223. html_text = "<div " +
  224. "style='position: absolute; " +
  225. "top:0; " +
  226. "left:0;' " +
  227. "class='varbox' " +
  228. "id='" + varname +
  229. "' data-type='" + vartype +
  230. "' data-dict='" + unit_text +
  231. "' data-cond='" + data_condition +
  232. "'>" +
  233. "<p>" +
  234. "<span style='color: " + title_color + ";" +
  235. "font-size:" + title_size + "px; " +
  236. "font-weight: " + title_style + ";' " +
  237. "class='title'>" + title_text +
  238. " </span><br />" +
  239. "<span style='color: " + unit_color + "; " +
  240. "font-size:" + unit_size + "px; " +
  241. "font-weight: " + unit_style + ";' " +
  242. "class='varval'>Standard Operation </span>" +
  243. "</p>" +
  244. "</div>";
  245. }
  246. console.log("Adding element");
  247. console.log(html_text);
  248. $( "body" ).append(html_text);
  249. $("#"+varname).draggable();
  250. $("#"+varname).resizable();
  251. }
  252. }
  253. function myremove() {
  254. varname = $("#varname option:selected").text();
  255. vartype = $("#vartype option:selected").val();
  256. if (vartype != "header") {
  257. if($("#" + varname).length > 0) {
  258. $("#"+varname).remove();
  259. console.log(varname +" removed.");
  260. }
  261. } else {
  262. title_text = $("#elem_title_text").val();
  263. title_text = title_text.trim();
  264. varname = "header_" + title_text.replace(/\s+/g, '-').toLowerCase();
  265. $("#"+varname).remove();
  266. console.log(varname +" removed.");
  267. }
  268. }
  269. function mysave(data) {
  270. console.log("saving...");
  271. console.log(data);
  272. var position = {};
  273. for(key in data) {
  274. var tmp = {};
  275. console.log(key);
  276. if($("#" + key).length > 0 ) {
  277. tmp["left"] = $("#"+key).css("left");
  278. tmp["top"] = $("#"+key).css("top");
  279. tmp["width"] = $("#"+key).width();
  280. tmp["height"] = $("#"+key).height();
  281. tmp["type"] = $("#vartype option:selected").val();
  282. if ( $("#"+key).attr("data-type") == "data" ) {
  283. tmp["condition"] = $("#elem_condition_range").val();
  284. tmp["formula"] = $("#elem_formula").val();
  285. tmp["lesser"] = $("#elem_lesser_range").val();
  286. tmp["larger"] = $("#elem_larger_range").val();
  287. //tmp["min"] = $("#"+key).attr("min");
  288. //tmp["max"] = $("#"+key).attr("max");
  289. header = {};
  290. header["title"] = $("#elem_title_text").val().trim();
  291. //header["color"] = $(".title", "#"+key).css("color");
  292. header["size"] = $("#elem_title_size").val();
  293. header["weight"] = $("#elem_title_style option:selected").val();
  294. unit = {};
  295. unit["title"] = $("#elem_unit_text").val().trim();
  296. //unit["color"] = $(".varval", "#"+key).css("color");
  297. unit["size"] = $("#elem_unit_size").val();
  298. unit["weight"] = $("#elem_unit_style option:selected").val();
  299. tmp["header"] = header;
  300. tmp["unit"] = unit;
  301. } else if ( $("#"+key).attr("data-type") == "header" ) {
  302. //tmp["condition"] = $("#"+key).attr("data-cond");
  303. //tmp["lesser"] = $("#"+key).attr("data-lesser");
  304. //tmp["larger"] = $("#"+key).attr("data-larger");
  305. //tmp["min"] = $("#"+key).attr("min");
  306. //tmp["max"] = $("#"+key).attr("max");
  307. header = {};
  308. header["title"] = $(".title", "#"+key).text();
  309. //header["color"] = $(".title", "#"+key).css("color");
  310. header["size"] = $(".title", "#"+key).css("font-size");
  311. header["weight"] = $(".title", "#"+key).css("font-weight");
  312. //unit = {};
  313. //unit["title"] = $(".unit_title", "#"+key).text();
  314. //unit["color"] = $(".varval", "#"+key).css("color");
  315. //unit["size"] = $(".varval", "#"+key).css("font-size");
  316. //unit["weight"] = $(".varval", "#"+key).css("font-weight");
  317. tmp["header"] = header;
  318. //tmp["unit"] = unit;
  319. } else if ( $("#"+key).attr("data-type") == "ventil" ) {
  320. tmp["on"] = $("#"+key).attr("data-on");
  321. tmp["off"] = $("#"+key).attr("data-off");
  322. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  323. tmp["dict"] = $("#"+key).attr("data-dict");
  324. tmp["cond"] = $("#"+key).attr("data-cond");
  325. header = {};
  326. header["title"] = $(".title", "#"+key).text();
  327. //header["color"] = $(".title", "#"+key).css("color");
  328. header["size"] = $(".title", "#"+key).css("font-size");
  329. header["weight"] = $(".title", "#"+key).css("font-weight");
  330. unit = {};
  331. unit["title"] = $(".unit_title", "#"+key).text();
  332. //unit["color"] = $(".varval", "#"+key).css("color");
  333. unit["size"] = $(".varval", "#"+key).css("font-size");
  334. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  335. tmp["header"] = header;
  336. tmp["unit"] = unit;
  337. }
  338. position[key] = tmp;
  339. }
  340. }
  341. $('[id^=header_]').each(function( index ) {
  342. tmp = {};
  343. var hkey = $( this ).attr('id');
  344. tmp["left"] = $("#"+hkey).css("left");
  345. tmp["top"] = $("#"+hkey).css("top");
  346. tmp["width"] = $("#"+hkey).width();
  347. tmp["height"] = $("#"+hkey).height();
  348. tmp["type"] = $("#"+hkey).attr("data-type");
  349. //tmp["condition"] = $("#"+hkey).attr("data-cond");
  350. //tmp["lesser"] = $("#"+hkey).attr("data-lesser");
  351. //tmp["larger"] = $("#"+hkey).attr("data-larger");
  352. //tmp["min"] = $("#"+hkey).attr("min");
  353. //tmp["max"] = $("#"+hkey).attr("max");
  354. header = {};
  355. header["title"] = $(".title", "#"+hkey).text();
  356. //header["color"] = $(".title", "#"+hkey).css("color");
  357. header["size"] = $(".title", "#"+hkey).css("font-size");
  358. header["weight"] = $(".title", "#"+hkey).css("font-weight");
  359. tmp["header"] = header;
  360. position[hkey] = tmp;
  361. //console.log( index + ": " + $( this ).text() );
  362. });
  363. //console.log("Check here");
  364. //console.log(position);
  365. var dataToSend = JSON.stringify(position);
  366. //console.log(dataToSend);
  367. $.ajax({
  368. url: '/save/',
  369. type: 'POST',
  370. data: dataToSend,
  371. success: function (response) {
  372. var objresponse = JSON.parse(response);
  373. console.log(objresponse);
  374. },
  375. error: function () {
  376. console.log("Error.")
  377. }
  378. });
  379. }
  380. function highlight() {
  381. varname = $("#varname option:selected").text();
  382. console.log(varname);
  383. vartype = $("#vartype option:selected").val();
  384. if (vartype == "header") {
  385. title_text = $("#elem_title_text").val();
  386. title_text = title_text.trim();
  387. varname = "header_" + title_text.replace(/\s+/g, '-').toLowerCase();
  388. } else if (vartype == "data") {
  389. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  390. $("#elem_title_size").val("");
  391. if ($("#"+varname + " .title").css("font-size")) {
  392. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  393. }
  394. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  395. $("#elem_unit_size").val("");
  396. if ($("#"+varname + " .varval").css("font-size")) {
  397. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  398. }
  399. $("#elem_lesser_range").val("");
  400. if ($("#"+varname).attr("data-lesser") ) {
  401. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  402. }
  403. $("#elem_larger_range").val("");
  404. if ($("#"+varname).attr("data-larger") ) {
  405. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  406. }
  407. $("#elem_condition_range").val("");
  408. if ($("#"+varname).attr("data-cond") ) {
  409. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  410. }
  411. $("#elem_formula").val("");
  412. if ($("#"+varname).attr("data-formula") ) {
  413. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  414. }
  415. /*
  416. title_text = title_text.trim();
  417. title_color = "#000000";
  418. //title_color = $("#elem_title_color").val();
  419. title_size = $("#elem_title_size").val();
  420. title_style = $("#elem_title_style option:selected").val();
  421. unit_text = $("#elem_unit_text").val();
  422. unit_text = unit_text.trim();
  423. unit_color = "#000";
  424. //unit_color = $("#elem_unit_color").val();
  425. unit_size = $("#elem_unit_size").val();
  426. unit_style = $("#elem_unit_style option:selected").val();
  427. data_condition = $("#elem_condition_range").val();
  428. //data_max = $("#elem_max_range").val();
  429. data_formula = $("#elem_formula").val();
  430. data_lesser = $("#elem_lesser_range").val();
  431. data_larger = $("#elem_larger_range").val();
  432. varval = $( "#varname option:selected").val();
  433. varname = $("#varname option:selected").text();
  434. vartype = $("#vartype option:selected").val();
  435. console.log("Selected");
  436. console.log(vartype);
  437. */
  438. }
  439. if ($("#"+varname).hasClass("box_highlight")) {
  440. $("#"+varname).removeClass("box_highlight");
  441. } else {
  442. $("#"+varname).addClass("box_highlight");
  443. }
  444. }
  445. jQuery(window).load(function () {
  446. $("#varname > option").each(function() {
  447. if ($('#'+this.text).length){
  448. $('#'+this.text).draggable();
  449. $('#'+this.text).resizable();
  450. }
  451. //console.log(this.text + ' ' + this.value);
  452. });
  453. $('[id^=header_]').each(function( index ) {
  454. $(this).draggable();
  455. $(this).resizable();
  456. });
  457. });
  458. </script>
  459. </body>
  460. </html>