dry_block.html 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ title }}</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  8. <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  11. <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
  12. <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  15. <!--可用來建立使用者小圖示-->
  16. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  17. <script language="JavaScript">
  18. // 指定 秒 刷新網頁一次
  19. var dtn = '{{tid}}';
  20. var status = '{{status}}';
  21. console.log('dtn:' + dtn)
  22. $(function(){
  23. $("#coffee_title_pc").text("乾燥槽積木程式介面");
  24. $("#coffee_title_phone").text("乾燥槽積木");
  25. if (status == 2) {
  26. $('input').prop('disabled', true);
  27. $('button').prop('disabled', true);
  28. } else if ( (status == 0) || (status == 1) ) {
  29. $('input').prop('disabled', false);
  30. $('button').prop('disabled', false);
  31. }
  32. });
  33. </script>
  34. <style>
  35. .newcondition_css {
  36. padding: 10px;
  37. margin-top: 10px;
  38. background-color:honeydew;
  39. }
  40. hr {
  41. margin-top: 5px;
  42. margin-bottom: 5px;
  43. }
  44. .input-cond-delete {
  45. background: #E43030;
  46. border: 1px solid #CFCFCF;
  47. box-sizing: border-box;
  48. border-radius: 5px;
  49. margin-left: 5px;
  50. width: 65px;
  51. height: 33px;
  52. font-size: 16px;
  53. text-align: center;
  54. line-height: 16px;
  55. color: #FFFFFF;
  56. }
  57. .input-cond-add {
  58. background: #008CBA;
  59. border: 1px solid #CFCFCF;
  60. box-sizing: border-box;
  61. border-radius: 5px;
  62. margin-left: 5px;
  63. width: 65px;
  64. height: 33px;
  65. font-size: 16px;
  66. text-align: center;
  67. line-height: 16px;
  68. color: #FFFFFF;
  69. }
  70. .input-act-add {
  71. background: #008CBA;
  72. border: 1px solid #CFCFCF;
  73. box-sizing: border-box;
  74. border-radius: 5px;
  75. margin-left: 5px;
  76. width: 100px;
  77. height: 33px;
  78. font-size: 16px;
  79. text-align: center;
  80. line-height: 16px;
  81. color: #FFFFFF;
  82. }
  83. .input-act-delete {
  84. background: #E43030;
  85. border: 1px solid #CFCFCF;
  86. box-sizing: border-box;
  87. border-radius: 5px;
  88. margin-left: 5px;
  89. width: 100px;
  90. height: 33px;
  91. font-size: 16px;
  92. text-align: center;
  93. line-height: 16px;
  94. color: #FFFFFF;
  95. }
  96. .input-add {
  97. background: #008CBA;
  98. border: 1px solid #CFCFCF;
  99. box-sizing: border-box;
  100. border-radius: 5px;
  101. margin-left: 5px;
  102. margin-top: 5px;
  103. width: 150px;
  104. height: 40px;
  105. font-size: 18px;
  106. text-align: center;
  107. line-height: 16px;
  108. color: #FFFFFF;
  109. }
  110. .input-delete {
  111. background: #E43030;
  112. border: 1px solid #CFCFCF;
  113. box-sizing: border-box;
  114. border-radius: 5px;
  115. margin-left: 5px;
  116. margin-top: 5px;
  117. width: 150px;
  118. height: 40px;
  119. font-size: 18px;
  120. text-align: center;
  121. line-height: 16px;
  122. color: #FFFFFF;
  123. }
  124. select {
  125. font-size: 24px;
  126. height: 30px;
  127. padding: 2px 5px;
  128. margin-left: 5px;
  129. }
  130. </style>
  131. </head>
  132. <body style="font-size: 18px;">
  133. <div id="wrapper">
  134. <div id="coffee_header">
  135. <!-- 匯入共同使用的 header.html 內容 -->
  136. {% include 'header.html' %}
  137. </div>
  138. <!-- [物件]文字輸入框 選擇後連結 [動作]文字輸入框 -->
  139. <script>
  140. dry_object = new Array();
  141. dry_object[0] = ["-"]; // 制動器 / 感測器
  142. dry_object[1] = ["on", "off"]; // 入料真空吸料機
  143. dry_object[2] = ["on", "off"]; // 真空吸料機
  144. dry_object[3] = ["ON 吸料", "OFF 排氣"]; // 入料三通閥
  145. dry_object[4] = ["0", "10", "20", "30", "40", "50"]; // 馬達
  146. dry_object[5] = ["on", "off"]; // 鼓風機
  147. dry_object[6] = ["on", "off"]; // 加熱器 1
  148. dry_object[7] = ["on", "off"]; // 加熱器 2
  149. dry_object[8] = ["on", "off"]; // 蝴蝶閥
  150. dry_object[9] = ["on", "off"]; // 消毒電磁閥
  151. dry_object[10] = ["on", "off"]; // 排水電磁閥
  152. dry_object[11] = ["on", "off"]; // 夾層進水電磁閥
  153. dry_object[12] = ["on", "off"]; // 溫控開關
  154. dry_object[13] = ["0.0", "28.0", "30.0", "32.0", "34.0", "36.0", "38.0", "40.0", "42.0", "44.0", "46.0", "48.0", "50.0"]; // 設定溫度
  155. dry_object[14] = ["on", "off"]; // 出料真空吸料機
  156. dry_object[15] = ["1", "5", "10", "30", "60"]; // 暫停秒數
  157. dry_object[16] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // 入料儲豆槽_液位計
  158. dry_object[17] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // 液位計
  159. dry_object[18] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // SHT11_溫度
  160. dry_object[19] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // SHT11_濕度
  161. dry_object[20] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // 土壤三合一_溫度
  162. dry_object[21] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // 土壤三合一_濕度
  163. dry_object[22] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // 土壤三合一_EC
  164. dry_object[23] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // 氣壓
  165. dry_object[24] = ["off", "1s", "5s", "10s", "30s", "1min", "5min", "10min", "30min", "1hr", "2hr"]; // 出料儲豆槽_液位計
  166. function renew(obj_num, index) {
  167. var Value="";
  168. for(var i=0; i<dry_object[index].length; i++){
  169. Value = Value + '<option value=' + dry_object[index][i] + '> ' + dry_object[index][i] + '</option>';
  170. }
  171. var sectorSelect = document.getElementById("do_act" + obj_num);
  172. // console.log("sectorSelect: " + sectorSelect)
  173. sectorSelect.innerHTML = Value;
  174. }
  175. </script>
  176. <div id="box">
  177. <div id="newcondition_1" class="newcondition_css">
  178. <!-- 總 條件 -->
  179. <div id="condition1">
  180. <!-- 子條件 1_1-->
  181. <div id="condition1_1">
  182. 條件
  183. <select id="cond_z1_1">
  184. <option value="if">if</option>
  185. <option value="while">while</option>
  186. </select>
  187. <select id="cond_tank1_1">
  188. <option value="D1">乾燥桶 D1</option>
  189. <option value="D2">乾燥桶 D2</option>
  190. <option value="D3">乾燥桶 D3</option>
  191. <option value="D4">乾燥桶 D4</option>
  192. <option value="D5">乾燥桶 D5</option>
  193. <option value="D6">乾燥桶 D6</option>
  194. <option value="D7">乾燥桶 D7</option>
  195. <option value="D8">乾燥桶 D8</option>
  196. <option value="D9">乾燥桶 D9</option>
  197. <option value="D10">乾燥桶 D10</option>
  198. <option value="D11">乾燥桶 D11</option>
  199. <option value="D12">乾燥桶 D12</option>
  200. </select>
  201. <select id="cond_a1_1">
  202. <option value="">制動器 / 感測器</option>
  203. <optgroup label="制動器">
  204. <option value="input_vacuum_status">入料真空吸料機</option>
  205. <option value="tank_vacuum_status">真空吸料機</option>
  206. <option value="tank_threewayvalve_input_status">入料三通閥</option>
  207. <option value="tank_motor_status">馬達</option>
  208. <option value="tank_blower_status">鼓風機</option>
  209. <option value="tank_heater1_status">加熱器 1</option>
  210. <option value="tank_heater2_status">加熱器 2</option>
  211. <option value="tank_diskvalve_status">蝴蝶閥</option>
  212. <option value="tank_solenoid_disinfect_status">消毒電磁閥</option>
  213. <option value="tank_solenoid_water_out_status">排水電磁閥</option>
  214. <option value="outer_solenoid_water_status">夾層進水電磁閥</option>
  215. <option value="tank_temp_enable">溫控開關</option>
  216. <option value="tank_temp">設定溫度</option>
  217. <option value="output_vacuum">出料真空吸料機</option>
  218. </optgroup>
  219. <optgroup label="感測器數值">
  220. <option value="input_UltraSonic">入料儲豆槽_液位計(cm)</option>
  221. <option value="tank_UltraSonic">液位計(cm)</option>
  222. <option value="tank_SHT11_Temp">SHT11_溫度(℃)</option>
  223. <option value="tank_SHT11_Humidity">SHT11_濕度(%)</option>
  224. <option value="tank_soil_Temp">土壤三合一_溫度(℃)</option>
  225. <option value="tank_soil_Humidity">土壤三合一_濕度(%)</option>
  226. <option value="tank_soil_EC">土壤三合一_EC(%)</option>
  227. <option value="tank_PA">氣壓(PA)</option>
  228. <option value="output_UltraSonic">出料儲豆槽_液位計(cm)</option>
  229. </optgroup>
  230. </select>
  231. <select id="cond_b1_1">
  232. <option value="equal">==</option>
  233. <option value="morethan">&gt;=</option>
  234. <option value="lessthan">&lt;=</option>
  235. </select>
  236. <input list="cond_list_c1_1" id="cond_c1_1">
  237. <datalist id="cond_list_c1_1">
  238. <option value="on">
  239. <option value="off">
  240. <option value="(或請自行輸入數值)">
  241. </datalist>
  242. <input type="button" class="input-cond-add" id="cond_add1_1" value="條件++" onclick="cond_add(cond_add1_1);"><br>
  243. <script>
  244. var cond_add_child_i = 1 // 這是子條件
  245. function cond_add(evt) { // cond_add1_1 下一個是 cond_add1(條件)_2(子條件)
  246. evt.style.display = "none"; // 不顯示原按鈕
  247. var condadd_parent_num = String(evt.id).split('_')[1].slice(3, ) // 把第一個條件的編號記下
  248. // console.log("condadd_parent_num: " + condadd_parent_num)
  249. cond_add_child_i++
  250. var html = '';
  251. html +=
  252. '<div id="condition' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  253. '<select id="cond_d' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  254. '<option value="and">and</option>' +
  255. '<option value="or">or</option>' +
  256. '</select> ' +
  257. '<select id="cond_a' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  258. '<option value="">制動器 / 感測器</option>' +
  259. '<optgroup label="制動器">' +
  260. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  261. '<option value="tank_vacuum_status">真空吸料機</option>' +
  262. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  263. '<option value="tank_motor_status">馬達</option>' +
  264. '<option value="tank_blower_status">鼓風機</option>' +
  265. '<option value="tank_heater1_status">加熱器 1</option>' +
  266. '<option value="tank_heater2_status">加熱器 2</option>' +
  267. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  268. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  269. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  270. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  271. '<option value="tank_temp_enable">溫控開關</option>' +
  272. '<option value="tank_temp">設定溫度</option>' +
  273. '<option value="output_vacuum_status">出料真空吸料機</option>' +
  274. '</optgroup>' +
  275. '<optgroup label="感測器數值">' +
  276. '<option value="input_UltraSonic">入料儲豆槽_液位計(cm)</option>' +
  277. '<option value="tank_UltraSonic">液位計(cm)</option>' +
  278. '<option value="tank_SHT11_Temp">SHT11_溫度(℃)</option>' +
  279. '<option value="tank_SHT11_Humidity">SHT11_濕度(%)</option>' +
  280. '<option value="tank_soil_Temp">土壤三合一_溫度(℃)</option>' +
  281. '<option value="tank_soil_Humidity">土壤三合一_濕度(%)</option>' +
  282. '<option value="tank_soil_EC">土壤三合一_EC(%)</option>' +
  283. '<option value="tank_PA">氣壓(PA)</option>' +
  284. '<option value="output_UltraSonic">出料儲豆槽_液位計(cm)</option>' +
  285. '</optgroup>' +
  286. '</select> ' +
  287. '<select id="cond_b' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  288. '<option value="equal">==</option>' +
  289. '<option value="morethan">&gt;=</option>' +
  290. '<option value="lessthan">&lt;=</option>' +
  291. '</select> ' +
  292. '<input list="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '" id="cond_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  293. '<datalist id="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  294. '<option value="on">' +
  295. '<option value="off">' +
  296. '<option value="(或請自行輸入數值)">' +
  297. '</datalist> ' +
  298. '<input type="button" class="input-cond-delete" id="cond_del' + condadd_parent_num + '_' + cond_add_child_i + '" value="條件--" onclick="cond_del(\'' + condadd_parent_num + '_' + cond_add_child_i + '\');">' +
  299. '<input type="button" class="input-cond-add" id="cond_add' + condadd_parent_num + '_' + cond_add_child_i + '" value="條件++" onclick="cond_add(cond_add' + condadd_parent_num + '_' + cond_add_child_i + ');"><br>' +
  300. '</div>';
  301. var divbox = document.getElementById('condition' + condadd_parent_num);
  302. divbox.insertAdjacentHTML('beforeend', html);
  303. }
  304. function cond_del(evt) {
  305. // console.log('evt: ' + evt)
  306. var del_cond_child = document.getElementById('condition' + evt);
  307. // console.log("del_cond_child: " + del_cond_child)
  308. del_cond_child.innerHTML = ""
  309. var parentObj = del_cond_child.parentNode; // 取得欲刪除 div 的父類別
  310. parentObj.removeChild(del_cond_child) // 刪除 div
  311. // 上一個按鈕要顯示出來
  312. var del_cond_parent_num = String(evt).split('_')[0]
  313. var del_cond_child_num = String(evt).split('_')[1]
  314. // console.log('del_cond_parent_num: ' + del_cond_parent_num)
  315. // console.log('del_cond_child_num: ' + del_cond_child_num)
  316. var button_return_id = document.getElementById('cond_add' + del_cond_parent_num + '_' + String(parseInt(del_cond_child_num)-1));
  317. // console.log("test: " + 'cond_add' + del_cond_parent_num + '_' + String(parseInt(del_cond_child_num)-1))
  318. // console.log("button_return_id: " + button_return_id) // null
  319. if (button_return_id == null) {
  320. var button_return_id = document.getElementById('cond_add' + del_cond_parent_num + '_1');
  321. }
  322. button_return_id.style.display = "inline";
  323. }
  324. </script>
  325. </div>
  326. </div>
  327. <div id="action1">
  328. <div id="action1_1">
  329. 物件
  330. <select id="do_obj1_1" onChange="renew('1_1', this.selectedIndex);">
  331. <option value="">制動器 / 感測器</option>
  332. <optgroup label="制動器">
  333. <option value="input_vacuum_status">入料真空吸料機</option>
  334. <option value="tank_vacuum_status">真空吸料機</option>
  335. <option value="tank_threewayvalve_input_status">入料三通閥</option>
  336. <option value="tank_motor_status">馬達</option>
  337. <option value="tank_blower_status">鼓風機</option>
  338. <option value="tank_heater1_status">加熱器 1</option>
  339. <option value="tank_heater2_status">加熱器 2</option>
  340. <option value="tank_diskvalve_status">蝴蝶閥</option>
  341. <option value="tank_solenoid_disinfect_status">消毒電磁閥</option>
  342. <option value="tank_solenoid_water_out_status">排水電磁閥</option>
  343. <option value="outer_solenoid_water_status">夾層進水電磁閥</option>
  344. <option value="tank_temp_enable">溫控開關</option>
  345. <option value="tank_temp">設定溫度</option>
  346. <option value="output_vacuum">出料真空吸料機</option>
  347. <option value="time.sleep">暫停秒數</option>
  348. </optgroup>
  349. <optgroup label="感測器回傳值頻率">
  350. <option value="input_ultrasonic_status">入料儲豆槽_液位計(cm)</option>
  351. <option value="tank_ultrasonic_status">液位計(cm)</option>
  352. <option value="tank_sht11_temp_status">SHT11_溫度(℃)</option>
  353. <option value="tank_sht11_humidity_status">SHT11_濕度(%)</option>
  354. <option value="tank_soil_temp_status">土壤三合一_溫度(℃)</option>
  355. <option value="tank_soil_humidity_status">土壤三合一_濕度(%)</option>
  356. <option value="tank_soil_ec_status">土壤三合一_EC(%)</option>
  357. <option value="tank_pa_status">氣壓(PA)</option>
  358. <option value="output_ultrasonic_status">出料儲豆槽_液位計(cm)</option>
  359. </optgroup>
  360. </select>
  361. 動作
  362. <select id="do_act1_1">
  363. <option value="">請由左方選取物件
  364. </select>
  365. <input type="button" class="input-act-add" id="act_add1_1" value="物件動作++" onclick="act_add(act_add1_1);"><br>
  366. </div>
  367. <script>
  368. var act_add_child_i = 1
  369. function act_add(evt) {
  370. evt.style.display = "none";
  371. var actadd_parent_num = String(evt.id).split('_')[1].slice(3, )
  372. // console.log("actadd_parent_num: " + actadd_parent_num)
  373. act_add_child_i++;
  374. var html = '';
  375. html +=
  376. '<div id="action' + actadd_parent_num + '_' + act_add_child_i + '">' +
  377. '物件 ' +
  378. '<select id="do_obj' + actadd_parent_num + '_' + act_add_child_i + '" onChange="renew(\'' + actadd_parent_num + '_' + act_add_child_i + '\', this.selectedIndex);">' +
  379. '<option value="">制動器 / 感測器</option>' +
  380. '<optgroup label="制動器">' +
  381. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  382. '<option value="tank_vacuum_status">真空吸料機</option>' +
  383. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  384. '<option value="tank_motor_status">馬達</option>' +
  385. '<option value="tank_blower_status">鼓風機</option>' +
  386. '<option value="tank_heater1_status">加熱器 1</option>' +
  387. '<option value="tank_heater2_status">加熱器 2</option>' +
  388. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  389. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  390. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  391. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  392. '<option value="tank_temp_enable">溫控開關</option>' +
  393. '<option value="tank_temp">設定溫度</option>' +
  394. '<option value="output_vacuum">出料真空吸料機</option>' +
  395. '<option value="time.sleep">暫停秒數</option>' +
  396. '</optgroup>' +
  397. '<optgroup label="感測器回傳值頻率">' +
  398. '<option value="input_ultrasonic_status">入料儲豆槽_液位計(cm)</option>' +
  399. '<option value="tank_ultrasonic_status">液位計(cm)</option>' +
  400. '<option value="tank_sht11_temp_status">SHT11_溫度(℃)</option>' +
  401. '<option value="tank_sht11_humidity_status">SHT11_濕度(%)</option>' +
  402. '<option value="tank_soil_temp_status">土壤三合一_溫度(℃)</option>' +
  403. '<option value="tank_soil_humidity_status">土壤三合一_濕度(%)</option>' +
  404. '<option value="tank_soil_ec_status">土壤三合一_EC(%)</option>' +
  405. '<option value="tank_pa_status">氣壓(PA)</option>' +
  406. '<option value="output_ultrasonic_status">出料儲豆槽_液位計(cm)</option>' +
  407. '</optgroup>' +
  408. '</select> ' +
  409. '動作 ' +
  410. '<select id="do_act' + actadd_parent_num + '_' + act_add_child_i + '">' +
  411. '<option value="">請由左方選取物件</option>' +
  412. '</select> ' +
  413. '<input type="button" class="input-act-delete" id="act_del' + actadd_parent_num + '_' + act_add_child_i + '" value="物件動作--" onclick="act_del(\'' + actadd_parent_num + '_' + act_add_child_i + '\');">' +
  414. '<input type="button" class="input-act-add" id="act_add' + actadd_parent_num + '_' + act_add_child_i + '" value="物件動作++" onclick="act_add(act_add' + actadd_parent_num + '_' + act_add_child_i + ');"><br>' +
  415. '</div>';
  416. var divbox = document.getElementById('action' + actadd_parent_num);
  417. divbox.insertAdjacentHTML('beforeend', html);
  418. }
  419. function act_del(evt) {
  420. var del_action = document.getElementById('action' + evt);
  421. del_action.innerHTML = ""
  422. var parentObj = del_action.parentNode; // 取得欲刪除 div 的父類別
  423. parentObj.removeChild(del_action) // 刪除 div
  424. var del_act_parent_num = String(evt).split('_')[0]
  425. var del_act_child_num = String(evt).split('_')[1]
  426. // console.log('del_act_parent_num: ' + del_act_parent_num)
  427. // console.log('del_act_child_num: ' + del_act_child_num)
  428. var button_return_id = document.getElementById('act_add' + del_act_parent_num + '_' + String(parseInt(del_act_child_num)-1));
  429. // console.log("test: " + 'cond_add' + del_act_parent_num + '_' + String(parseInt(del_act_child_num)-1))
  430. // console.log("button_return_id: " + button_return_id) // null
  431. if (button_return_id == null) {
  432. var button_return_id = document.getElementById('act_add' + del_act_parent_num + '_1');
  433. }
  434. button_return_id.style.display = "inline";
  435. }
  436. </script>
  437. </div>
  438. <input type="button" class="input-add" id="add1" value="條件物件動作++" onclick="Add(add1);">
  439. </div>
  440. <script>
  441. var new_condition_i = 1
  442. function Add(evt) { // 網頁初始按鈕 onclick="Add(add1);
  443. evt.style.display = "none"; // 元素不顯示。將 add1 的 input-button 不顯示
  444. new_condition_i++; // 設定編號用
  445. // var div = document.createElement('div'); // 輸出 <div></div>。此時並不會顯示,
  446. // 需透過 appendChild()、insertBefore() 或 replaceChild() 等方法將新元素加入至指定的位置之後才會顯示。
  447. // var cond_number = String(evt).slice(3, ) // 目前的 condition 條件物件動作 數 (最外層)
  448. // var cond_a = 'cond_a' + cond_number + '_' + new_condition_i; // [條件] 左方 : 制動器感測器
  449. // var cond_b = 'cond_b' + cond_number + '_' + new_condition_i; // [條件] 中間 : > / = / <
  450. // var cond_c = 'cond_c' + cond_number + '_' + new_condition_i; // [條件] 右方 : ON / OFF / 數值
  451. // var cond_d = 'cond_d' + cond_number + '_' + new_condition_i; // 條件] 最左方條件連接 : and / or
  452. // div.id = 'newcondition_' + new_condition_i; // 設定 div 的 id
  453. // div.style.marginTop = "10px"; // 新增的 div 設定 marginTop 屬性值
  454. var html = ''
  455. // 新增的條件
  456. html +=
  457. '<div id="newcondition_' + new_condition_i + '" class="newcondition_css">' +
  458. // 新增的分隔線
  459. // '<hr size="50" width="100%">' +
  460. '<div id="condition' + new_condition_i + '">' +
  461. '<div id="condition' + new_condition_i + '_1">' +
  462. '條件 ' +
  463. '<select id="cond_z' + new_condition_i + '_1">' +
  464. '<option value="if">if</option>' +
  465. '<option value="while">while</option>' +
  466. '</select> ' +
  467. '<select id="cond_tank' + new_condition_i + '_1">' +
  468. '<option value="D1">乾燥桶 D1</option>' +
  469. '<option value="D2">乾燥桶 D2</option>' +
  470. '<option value="D3">乾燥桶 D3</option>' +
  471. '<option value="D4">乾燥桶 D4</option>' +
  472. '<option value="D5">乾燥桶 D5</option>' +
  473. '<option value="D6">乾燥桶 D6</option>' +
  474. '<option value="D7">乾燥桶 D7</option>' +
  475. '<option value="D8">乾燥桶 D8</option>' +
  476. '<option value="D9">乾燥桶 D9</option>' +
  477. '<option value="D10">乾燥桶 D10</option>' +
  478. '<option value="D11">乾燥桶 D11</option>' +
  479. '<option value="D12">乾燥桶 D12</option>' +
  480. '</select> ' +
  481. '<select id="cond_a' + new_condition_i + '_1">' +
  482. '<option value="">制動器 / 感測器</option>' +
  483. '<optgroup label="制動器">' +
  484. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  485. '<option value="tank_vacuum_status">真空吸料機</option>' +
  486. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  487. '<option value="tank_motor_status">馬達</option>' +
  488. '<option value="tank_blower_status">鼓風機</option>' +
  489. '<option value="tank_heater1_status">加熱器 1</option>' +
  490. '<option value="tank_heater2_status">加熱器 2</option>' +
  491. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  492. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  493. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  494. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  495. '<option value="tank_temp_enable">溫控開關</option>' +
  496. '<option value="tank_temp">設定溫度</option>' +
  497. '<option value="output_vacuum_status">出料真空吸料機</option>' +
  498. '</optgroup>' +
  499. '<optgroup label="感測器數值">' +
  500. '<option value="input_UltraSonic">入料儲豆槽_液位計(cm)</option>' +
  501. '<option value="tank_UltraSonic">液位計(cm)</option>' +
  502. '<option value="tank_SHT11_Temp">SHT11_溫度(℃)</option>' +
  503. '<option value="tank_SHT11_Humidity">SHT11_濕度(%)</option>' +
  504. '<option value="tank_soil_Temp">土壤三合一_溫度(℃)</option>' +
  505. '<option value="tank_soil_Humidity">土壤三合一_濕度(%)</option>' +
  506. '<option value="tank_soil_EC">土壤三合一_EC(%)</option>' +
  507. '<option value="tank_PA">氣壓(PA)</option>' +
  508. '<option value="output_UltraSonic">出料儲豆槽_液位計(cm)</option>' +
  509. '</optgroup>' +
  510. '</select> ' +
  511. '<select id="cond_b' + new_condition_i + '_1">' +
  512. '<option value="equal">==</option>' +
  513. '<option value="morethan">&gt;=</option>' +
  514. '<option value="lessthan">&lt;=</option>' +
  515. '</select> ' +
  516. '<input list="cond_list_c' + new_condition_i + '_1" id="cond_c' + new_condition_i + '_1">' +
  517. '<datalist id="cond_list_c' + new_condition_i + '_1">' +
  518. '<option value="on">' +
  519. '<option value="off">' +
  520. '<option value="(或請自行輸入數值)">' +
  521. '</datalist> ' +
  522. '<input type="button" class="input-cond-add" id="cond_add' + new_condition_i + '_1" value="條件++" onclick="cond_add(cond_add' + new_condition_i + '_1)"><br>' +
  523. '</div></div>';
  524. // 新增的物件動作
  525. html +=
  526. '<div id="action' + new_condition_i + '">' +
  527. '<div id="action' + new_condition_i + '_1">' +
  528. '物件 ' +
  529. '<select id="do_obj' + new_condition_i + '_1" onChange="renew(\''+ new_condition_i + '_1\', this.selectedIndex);">' +
  530. '<option value="">制動器 / 感測器</option>' +
  531. '<optgroup label="制動器">' +
  532. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  533. '<option value="tank_vacuum_status">真空吸料機</option>' +
  534. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  535. '<option value="tank_motor_status">馬達</option>' +
  536. '<option value="tank_blower_status">鼓風機</option>' +
  537. '<option value="tank_heater1_status">加熱器 1</option>' +
  538. '<option value="tank_heater2_status">加熱器 2</option>' +
  539. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  540. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  541. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  542. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  543. '<option value="tank_temp_enable">溫控開關</option>' +
  544. '<option value="tank_temp">設定溫度</option>' +
  545. '<option value="output_vacuum">出料真空吸料機</option>' +
  546. '<option value="time.sleep">暫停秒數</option>' +
  547. '</optgroup>' +
  548. '<optgroup label="感測器回傳值頻率">' +
  549. '<option value="input_ultrasonic_status">入料儲豆槽_液位計(cm)</option>' +
  550. '<option value="tank_ultrasonic_status">液位計(cm)</option>' +
  551. '<option value="tank_sht11_temp_status">SHT11_溫度(℃)</option>' +
  552. '<option value="tank_sht11_humidity_status">SHT11_濕度(%)</option>' +
  553. '<option value="tank_soil_temp_status">土壤三合一_溫度(℃)</option>' +
  554. '<option value="tank_soil_humidity_status">土壤三合一_濕度(%)</option>' +
  555. '<option value="tank_soil_ec_status">土壤三合一_EC(%)</option>' +
  556. '<option value="tank_pa_status">氣壓(PA)</option>' +
  557. '<option value="output_ultrasonic_status">出料儲豆槽_液位計(cm)</option>' +
  558. '</optgroup>' +
  559. '</select>' +
  560. ' 動作 ' +
  561. '<select id="do_act' + new_condition_i + '_1">' +
  562. '<option value="">請由左方選取物件' +
  563. '</select> ' +
  564. '<input type="button" class="input-act-add" id="act_add' + new_condition_i + '_1" value="物件動作++" onclick="act_add(act_add' + new_condition_i + '_1);"><br>' +
  565. '</div>' +
  566. '</div>' +
  567. // 新增的 條件物件動作++ 條件物件動作-- 按鈕
  568. '<input type="button" class="input-delete" id="del' + new_condition_i + '" value="條件物件動作--" onclick="Delete(' + new_condition_i + ');"><br>' +
  569. '<input type="button" class="input-add" id="add' + new_condition_i + '" value="條件物件動作++" onclick="Add(add' + new_condition_i + ');">' +
  570. '</div>' ;
  571. var divbox = document.getElementById('box');
  572. divbox.insertAdjacentHTML('beforeend', html);
  573. };
  574. function Delete(evt) {
  575. var del_condition = document.getElementById('newcondition_' + evt);
  576. del_condition.innerHTML = ""
  577. var parentObj = del_condition.parentNode; // 取得欲刪除 div 的父類別
  578. parentObj.removeChild(del_condition) // 刪除 div
  579. // 上一個按鈕要顯示出來
  580. var button_return_id = document.getElementById('add' + String(parseInt(evt)-1));
  581. if (button_return_id == null) {
  582. var button_return_id = document.getElementById('add1');
  583. }
  584. // console.log('button_return_id: ' + button_return_id)
  585. button_return_id.style.display = "block"; // 元素顯示。顯示前一個 input-button
  586. };
  587. </script>
  588. <!-- 新增加的 newcondition_(編號) 會加在這裡 -->
  589. </div>
  590. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  591. <br>
  592. <input type="button" id="test" value="取值測試" onclick="test();"><br>
  593. <span id="value_test"> ( 取值測試 ) </span><br>
  594. <span id="command_test"> ( command 測試 ) </span><br>
  595. <input type="button" id="test" value="ajax 測試" onclick="AJAXtest();">
  596. <script>
  597. var set_Schedule = '';
  598. function test(){
  599. // console.log("new_condition_i: " + new_condition_i) // 總數 : 條件物件動作
  600. // console.log("cond_add_child_i: " + cond_add_child_i) // 總數 : 子 條件
  601. // console.log("act_add_child_i: " + act_add_child_i) // 總數 : 子 物件動作
  602. // set_Schedule += 'set_Schedule = { ';
  603. set_Schedule = '{ ';
  604. var command_test = '';
  605. // 條件物件動作 取值
  606. for (let z = 1; z <= new_condition_i; z++) {
  607. // if-while 取值
  608. try {
  609. var cond_z_value = document.getElementById("cond_z" + z + "_1").value;
  610. // console.log("cond_z" + z + "_1: " + cond_z_value)
  611. set_Schedule += '"cond_z' + z + '_1": "' + cond_z_value + '", ' ;
  612. } catch (error) {
  613. if (error.name == 'TypeError') {
  614. console.log("cond_z" + z + "_1: null")
  615. } else {
  616. alert("cond_z" + z + "_1: " + error.name)
  617. break
  618. }
  619. }
  620. // 桶槽號碼 取值
  621. try {
  622. var cond_tank_value = document.getElementById("cond_tank" + z + "_1").value;
  623. // console.log("cond_tank" + z + "_1: " + cond_tank_value)
  624. set_Schedule += '"cond_tank' + z + '_1": "' + cond_tank_value + '", ' ;
  625. } catch (error) {
  626. if (error.name == 'TypeError') {
  627. console.log("cond_tank" + z + "_1: null")
  628. } else {
  629. alert("cond_tank" + z + "_1: " + error.name)
  630. break
  631. }
  632. }
  633. // 子 條件 取值
  634. for (let x = 1; x <= cond_add_child_i; x++) {
  635. // 子條件取值 : 條件連接 and or
  636. if (x > 1) {
  637. try {
  638. var cond_d_value = document.getElementById("cond_d" + z + "_" + x).value;
  639. // console.log("cond_d" + z + "_" + x + ": " + cond_d_value)
  640. set_Schedule += '"cond_d' + z + '_' + x + '": "' + cond_d_value + '", ' ;
  641. } catch (error) {
  642. if (error.name == 'TypeError') {
  643. // console.log("cond_d" + z + "_" + x + ": null")
  644. } else {
  645. alert("cond_d" + z + "_" + x + ": " + error.name)
  646. break
  647. }
  648. }
  649. }
  650. try {
  651. var cond_a_value = document.getElementById("cond_a" + z + "_" + x).value;
  652. // console.log("cond_a" + z + "_" + x + ": " + cond_a_value)
  653. set_Schedule += '"cond_a' + z + '_' + x + '": "' + cond_a_value + '", ' ;
  654. if (cond_a_value == '') {
  655. alert('條件欄位輸入有誤, 請再次確認')
  656. break
  657. }
  658. } catch (error) {
  659. if (error.name == 'TypeError') {
  660. // console.log("cond_a" + z + "_" + x + ": null")
  661. } else {
  662. alert("cond_a" + z + "_" + x + ": " + error.name)
  663. break
  664. }
  665. }
  666. // 子條件取值 : 條件中 > = <
  667. try {
  668. var cond_b_value = document.getElementById("cond_b" + z + "_" + x).value;
  669. // console.log("cond_b" + z + "_" + x + ": " + cond_b_value)
  670. set_Schedule += '"cond_b' + z + '_' + x + '": "' + cond_b_value + '", ' ;
  671. if (cond_b_value == '') {
  672. alert('條件欄位輸入有誤, 請再次確認')
  673. break
  674. }
  675. } catch (error) {
  676. if (error.name == 'TypeError') {
  677. // console.log("cond_b" + z + "_" + x + ": null")
  678. } else {
  679. alert("cond_b" + z + "_" + x + ": " + error.name)
  680. break
  681. }
  682. }
  683. // 子條件取值 : 條件右 ON / OFF / 輸入數值
  684. try {
  685. var cond_c_value = document.getElementById("cond_c" + z + "_" + x).value;
  686. // console.log("cond_c" + z + "_" + x + ": " + cond_c_value)
  687. set_Schedule += '"cond_c' + z + '_' + x + '": "' + cond_c_value + '", ' ;
  688. if (cond_c_value == '') {
  689. alert('條件欄位輸入有誤, 請再次確認')
  690. break
  691. }
  692. } catch (error) {
  693. if (error.name == 'TypeError') {
  694. // console.log("cond_c" + z + "_" + x + ": null")
  695. } else {
  696. alert("cond_c" + z + "_" + x + ": " + error.name)
  697. break
  698. }
  699. }
  700. }
  701. // 子 物件動作 取值
  702. for (let y = 1; y <= act_add_child_i; y++) {
  703. // 子物件動作取值 : 物件 do_obj1_1
  704. try {
  705. var do_obj_value = document.getElementById("do_obj" + z + "_" + y).value;
  706. if (do_obj_value == '') {
  707. alert('物件欄位輸入有誤, 請再次確認')
  708. break
  709. }
  710. // console.log("do_obj" + z + "_" + y + ": " + do_obj_value)
  711. set_Schedule += '"do_obj' + z + '_' + y + '": "' + do_obj_value + '", ' ;
  712. command_test += '{"tank_num": "' + cond_tank_value + '", "command": "' + do_obj_value + '", "value":"';
  713. } catch (error) {
  714. if (error.name == 'TypeError') {
  715. // console.log("do_obj" + z + "_" + y + ": null")
  716. } else {
  717. alert("do_obj" + z + "_" + y + ": " + error.name)
  718. break
  719. }
  720. }
  721. // 子物件動作取值 : 動作 do_act1_1
  722. try {
  723. var do_act_value = document.getElementById("do_act" + z + "_" + y).value;
  724. if (do_act_value == '') {
  725. alert('動作欄位輸入有誤, 請再次確認')
  726. break
  727. }
  728. // console.log("do_act" + z + "_" + y + ": " + do_act_value)
  729. set_Schedule += '"do_act' + z + '_' + y + '": "' + do_act_value + '", ' ;
  730. command_test += do_act_value + '" }';
  731. } catch (error) {
  732. if (error.name == 'TypeError') {
  733. // console.log("do_obj" + z + "_" + y + ": null")
  734. } else {
  735. alert("do_act" + z + "_" + y + ": " + error.name)
  736. break
  737. }
  738. }
  739. }
  740. }
  741. // 整理資料用
  742. set_Schedule += '"": ""}' ;
  743. // console.log('set_Schedule: ' + set_Schedule)
  744. $('#value_test').text('set_Schedule: ' + set_Schedule)
  745. $('#command_test').text('command_test: ' + command_test)
  746. }
  747. function AJAXtest(params) {
  748. test();
  749. var schedule_data = {
  750. "condition":new_condition_i,
  751. "cond_add_child":cond_add_child_i,
  752. "act_add_child":act_add_child_i,
  753. "set_Schedule":set_Schedule
  754. };
  755. $.get('/dry_block_set', schedule_data, function (res) {
  756. // console.log("res.condition: " + res.condition)
  757. // console.log("res.cond_add_child: " + res.cond_add_child)
  758. // console.log("res.act_add_child: " + res.act_add_child)
  759. console.log("res.response: " + res.response)
  760. }, 'json');
  761. }
  762. </script>
  763. <div id="coffee_footer">
  764. <!-- 匯入共同使用的 footer.html 內容 -->
  765. {% include 'footer.html' %}
  766. </div>
  767. </div>
  768. </body>
  769. </html>