block_view.html 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  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://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  12. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  13. <!--可用來建立使用者小圖示-->
  14. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  15. <script language="JavaScript">
  16. $(function(){
  17. // 網頁 title
  18. $("#coffee_title_pc").text("檢視積木條件");
  19. $("#coffee_title_phone").text("檢視積木條件");
  20. // 使用者權限判斷
  21. // $('.select-input').prop('disabled', false);
  22. });
  23. var Z;
  24. var X;
  25. var Y;
  26. var TT = {}; // 將總條件句/附加條件句/物件動作句存入 字典, 後續傳給 dry_block_format 再組合
  27. </script>
  28. <style>
  29. /* .boardpic_position {
  30. position: absolute;
  31. top: 80px;
  32. left: 25px;
  33. } */
  34. .r5_position {
  35. position: absolute;
  36. top: 160px;
  37. left: 310px;
  38. width: 40px;
  39. height: 150px;
  40. border-style: solid;
  41. border-color: aqua;
  42. }
  43. .div_relay_css {
  44. position: absolute;
  45. border-style: solid;
  46. border-color: aqua;
  47. text-align: center;
  48. font-size: 12px;
  49. }
  50. /* header */
  51. /* 文字輸入框 */
  52. .input-text {
  53. height: 25px;
  54. width: 40px;
  55. text-align: center;
  56. margin-left: 2px;
  57. margin-right: 5px;
  58. }
  59. /* 致動器狀態表格置中 */
  60. .label_ActuatorStatus {
  61. margin: auto;
  62. }
  63. /* 致動器 ON 樣式 */
  64. .input-button-on {
  65. color: #008CBA;
  66. border: 2px rgb(182, 181, 181) solid;
  67. background-color: whitesmoke;
  68. padding: 1px 3px;
  69. width: 45px;
  70. }
  71. /* 致動器 OFF 樣式 */
  72. .input-button-off {
  73. color: #707070;
  74. border: 2px rgb(192, 192, 192) solid;
  75. background-color: whitesmoke;
  76. padding: 1px 3px;
  77. width: 45px;
  78. }
  79. /* 輸入按鈕 */
  80. .input-button {
  81. font-size: 14px;
  82. color: #008CBA;
  83. border: 2px rgb(182, 181, 181) solid;
  84. background-color: whitesmoke;
  85. padding: 1px 3px;
  86. }
  87. /* 大表格樣式 */
  88. .table-all {
  89. font-size:18px;
  90. border:2px #cccccc solid;
  91. margin-left: 10px;
  92. margin-right: 10px;
  93. width: 98%;
  94. }
  95. /* footer */
  96. .footer{
  97. height: 40px;
  98. box-sizing: border-box;
  99. /* 設定footer絕對位置在底部 */
  100. position: absolute;
  101. bottom: 0px;
  102. width: 100%;
  103. background-color: #eee;
  104. text-align: center;
  105. }
  106. html, body {
  107. height: 100%;
  108. /* margin: 0; */
  109. position: relative;
  110. }
  111. #wrapper {
  112. /* 設定高度最小為100%, 如果內容區塊很多, 可以長大 */
  113. min-height: 100%;
  114. /* 位置設為relative, 作為footer區塊位置的參考 */
  115. position: relative;
  116. }
  117. </style>
  118. </head>
  119. <body style="font-size: 18px;">
  120. <div id="wrapper" style="height: auto;">
  121. <div id="coffee_header">
  122. <!-- 匯入共同使用的 header.html 內容 -->
  123. {% include 'header.html' %}
  124. </div>
  125. <table style="width: 700px;">
  126. <!-- <table style="position: absolute; top: 75px; left: 25px; width: max-content;"> -->
  127. <!-- 選擇燒錄桶槽 -->
  128. <tr>
  129. <td>
  130. <script>
  131. // 貨櫃-桶槽對應
  132. const containerTOtank = {
  133. 'CleanContainer':[{'CCI1':'清洗貨櫃內'},
  134. {'CCO1':'清洗貨櫃外'},
  135. {'C1':'清洗槽 1'}, {'C2':'清洗槽 2'}, {'C3':'清洗槽 3'}, {'C4':'清洗槽 4'},
  136. {'R1':'中水桶 1'},
  137. {'S1':'色選機 1'}, {'S2':'色選機 2'},
  138. {'SO1':'色選機出料 1'}, {'SO2':'色選機出料 2'},
  139. {'P1':'脫皮機 1'}, {'P2':'脫皮機 2'},
  140. {'PO1':'脫皮機出料 1'}, {'PO2':'脫皮機出料 2'}
  141. ],
  142. 'FermentContainer':[{'FCI1':'發酵貨櫃內'},
  143. {'FCO1':'發酵貨櫃外'},
  144. {'FI1':'發酵槽入料 1'}, {'FI2':'發酵槽入料 2'},
  145. {'F1':'發酵槽 1'}, {'F2':'發酵槽 2'}, {'F3':'發酵槽 3'}, {'F4':'發酵槽 4'}, {'F5':'發酵槽 5'}, {'F6':'發酵槽 6'},
  146. {'F7':'發酵槽 7'}, {'F8':'發酵槽 8'}, {'F9':'發酵槽 9'}, {'F10':'發酵槽 10'}, {'F11':'發酵槽 11'}, {'F12':'發酵槽 12'},
  147. {'FO1':'發酵槽出料 1'}, {'FO2':'發酵槽出料 2'}
  148. ],
  149. 'DryContainer':[{'DCI1':'乾燥貨櫃內'},
  150. {'DCO1':'乾燥貨櫃外'},
  151. {'DI1':'乾燥槽入料 1'}, {'DI2':'乾燥槽入料 2'},
  152. {'D1':'乾燥槽 1'}, {'D2':'乾燥槽 2'}, {'D3':'乾燥槽 3'}, {'D4':'乾燥槽 4'}, {'D5':'乾燥槽 5'}, {'D6':'乾燥槽 6'},
  153. {'D7':'乾燥槽 7'}, {'D8':'乾燥槽 8'}, {'D9':'乾燥槽 9'}, {'D10':'乾燥槽 10'}, {'D11':'乾燥槽 11'}, {'D12':'乾燥槽 12'},
  154. {'DO1':'乾燥槽出料 1'}, {'DO2':'乾燥槽出料 2'}
  155. ]
  156. }
  157. </script>
  158. <u>使用者名稱 : </u>
  159. <select id="prog_username">
  160. <option value="user" selected>user</option>
  161. <option value=""></option>
  162. {% for username in username_data %}
  163. <option value="{{username[0]}}">{{username[0]}}</option>
  164. {% endfor %}
  165. </select>
  166. <u>欲燒錄之桶槽 : </u>
  167. <select id="prog_container" onchange="renew_tank()" class="select-input">
  168. <option value="DryContainer" selected>乾燥槽</option>
  169. <option value=""></option>
  170. <option value="CleanContainer">清洗槽</option>
  171. <option value="FermentContainer">發酵槽</option>
  172. <option value="DryContainer">乾燥槽</option>
  173. </select>
  174. <select id="prog_tank" onchange="" class="select-input">
  175. <option value="D2" selected>乾燥槽 2</option>
  176. <option value=""></option>
  177. </select>
  178. <input type="button" value="查詢" onclick="select_cond()">
  179. <br>
  180. <!-- <input type="button" value="前往指定燒錄桶槽" onclick="GoToBoardLoaderPage()"> -->
  181. <script>
  182. function select_cond() {
  183. var target_prog_username = $("#prog_username").val();
  184. var target_prog_tank = $("#prog_tank").val();
  185. console.log("target_prog_username: " + target_prog_username);
  186. console.log("target_prog_tank: " + target_prog_tank);
  187. var SelectCondData = {"username":target_prog_username,
  188. "tank":target_prog_tank}
  189. $.ajax({
  190. type:"GET",
  191. url:"/select_cond",
  192. data:SelectCondData,
  193. dataType:"JSON",
  194. async:false,
  195. success:function (res){
  196. cond_cond = res['cond']
  197. // 取得總條件數、子條件數、子物件數最大值
  198. const COND_NUMS = cond_cond.length; // 總條件數
  199. var COND_ADD_NUMS_LIST = [];
  200. var COND_COM_NUMS_LIST = [];
  201. for (let Z = 0; Z < cond_cond.length; Z++) {
  202. COND_ADD_NUMS_LIST.push(cond_cond[Z].cond_add.length)
  203. COND_COM_NUMS_LIST.push(cond_cond[Z].cond_com.length)
  204. }
  205. // console.log("COND_ADD_NUMS_LIST: " + COND_ADD_NUMS_LIST);
  206. // console.log("COND_COM_NUMS_LIST: " + COND_COM_NUMS_LIST);
  207. const COND_ADD_NUMS = Math.max(...COND_ADD_NUMS_LIST)+1; // 子條件數
  208. const COND_COM_NUMS = Math.max(...COND_COM_NUMS_LIST); // 子物件數
  209. // console.log("COND_ADD_NUMS: " + COND_ADD_NUMS);
  210. // console.log("COND_COM_NUMS: " + COND_COM_NUMS);
  211. // 清空 DBvalue
  212. document.getElementById("DBvalue").innerHTML = '';
  213. // 生成積木
  214. DBvalue_btn(COND_NUMS, COND_ADD_NUMS, COND_COM_NUMS);
  215. for (let c_n = 0; c_n < cond_cond.length; c_n++) {
  216. // console.log("cond_cond[" + c_n + "]: " + cond_cond[c_n] + "_" + typeof(cond_cond[c_n]))
  217. if (typeof(cond_cond[c_n]) === 'object') {
  218. // main
  219. // console.log("cond_main: " + cond_cond[c_n].cond_main);
  220. var target_main = cond_cond[c_n].cond_main.split(' ');
  221. if (target_main[0] === 'else' && target_main[1] === 'if') {
  222. target_main[0] = target_main[0] + " " + target_main[1];
  223. target_main[1] = target_main[2];
  224. target_main[2] = target_main[3];
  225. target_main[3] = target_main[4];
  226. }
  227. $("#cond_z" + (c_n+1) + "_1").val(target_main[0]);
  228. $("#cond_a" + (c_n+1) + "_1").val(target_main[1]);
  229. $("#cond_b" + (c_n+1) + "_1").val(target_main[2]);
  230. $("#cond_c" + (c_n+1) + "_1").val(target_main[3]);
  231. // add
  232. // console.log("cond_add: " + cond_cond[c_n].cond_add + "_" + typeof(cond_cond[c_n].cond_add));
  233. if (typeof(cond_cond[c_n].cond_add) === 'object') {
  234. for (let add_n = 0; add_n < cond_cond[c_n].cond_add.length; add_n++) {
  235. // console.log("cond_cond[" + c_n + "].cond_add[" + add_n + "]: " + cond_cond[c_n].cond_add[add_n])
  236. var target_add = cond_cond[c_n].cond_add[add_n].split(' ');
  237. $("#cond_d" + (c_n+1) + "_" + (add_n+2) + "").val(target_add[0]);
  238. $("#cond_a" + (c_n+1) + "_" + (add_n+2) + "").val(target_add[1]);
  239. $("#cond_b" + (c_n+1) + "_" + (add_n+2) + "").val(target_add[2]);
  240. $("#cond_c" + (c_n+1) + "_" + (add_n+2) + "").val(target_add[3]);
  241. }
  242. }
  243. // com
  244. // console.log("cond_com: " + cond_cond[c_n].cond_com + "_" + typeof(cond_cond[c_n].cond_com));
  245. if (typeof(cond_cond[c_n].cond_com) === 'object') {
  246. for (let obj_n = 0; obj_n < cond_cond[c_n].cond_com.length; obj_n++) {
  247. // console.log("cond_cond[" + c_n + "].cond_com[" + obj_n + "]: " + cond_cond[c_n].cond_com[obj_n]) // R1_vacuum on
  248. var target_obj = cond_cond[c_n].cond_com[obj_n].split(' ');
  249. // console.log("target_obj: " + target_obj); // R1_vacuum,on
  250. // console.log(pin_data_relay_option.includes(target_obj[0]))
  251. // 物件動作包含此積木程式的物件
  252. $("#do_obj" + (c_n+1) + "_" + (obj_n+1) + "").val(target_obj[0]);
  253. // console.log('renew((' + (c_n+1) + ') + "_" + (' + (obj_n+1) + '))')
  254. eval('renew((c_n+1) + "_" + (obj_n+1))');
  255. $("#do_act" + (c_n+1) + "_" + (obj_n+1) + "").val(target_obj[1]);
  256. // console.log("target_obj[0]: " + target_obj[0]);
  257. if (target_obj[0] === 'sleep') {
  258. showSleepValue((c_n+1) + "_" + (obj_n+1), target_obj[1]);
  259. } else if (target_obj[0].includes("Motor")) {
  260. showMotorValue((c_n+1) + "_" + (obj_n+1), target_obj[1]);
  261. }
  262. }
  263. }
  264. }
  265. }
  266. new_condition_i = COND_NUMS; // 總條件數
  267. cond_add_child_i = COND_ADD_NUMS; // 子條件數
  268. act_add_child_i = COND_COM_NUMS; // 子物件數
  269. // document.getElementById("DBvalue").innerText = COND_NUMS + "_" + COND_ADD_NUMS + "_" + COND_COM_NUMS;
  270. },
  271. error: function (thrownError){
  272. alert("cond 取值失敗\n" + thrownError.statusText);
  273. document.getElementById("DBvalue").innerText = "(請確認是否有此桶槽/貨櫃之條件積木)";
  274. }
  275. })
  276. }
  277. </script>
  278. </td>
  279. </tr>
  280. <!-- coffee1.0 板子圖片 -->
  281. <!-- 燒錄制動器 / 感測器 -->
  282. <!-- 感測器取值頻率 -->
  283. <!-- 制動器感測器項目取值 -->
  284. <!-- 積木程式 -->
  285. <tr>
  286. <td>
  287. <span style="background-color:burlywood">積木條件</span><br>
  288. <div id="DBvalue">
  289. <!-- 積木條件 -->
  290. 積木在這裡
  291. </div>
  292. <script>
  293. // 指令燒錄桶槽時, 跳出桶槽選項
  294. var Value = '';
  295. function renew_tank() {
  296. var prog_container_value = $("#prog_container").val();
  297. // console.log("prog_container_value: " + prog_container_value);
  298. Value = '';
  299. try {
  300. for (let i = 0; i < containerTOtank[prog_container_value].length; i++) {
  301. Value += '<option value="' + Object.keys(containerTOtank[prog_container_value][i]) + '">' + Object.values(containerTOtank[prog_container_value][i]) + '</option>';
  302. }
  303. } catch (error) {
  304. if (error.name === 'TypeError') {
  305. Value = '';
  306. }
  307. }
  308. var sectorSelect = document.getElementById("prog_tank");
  309. if (sectorSelect != null) {
  310. sectorSelect.innerHTML = Value;
  311. }
  312. }
  313. function DBvalue_btn(z_notempty_NUM, a_notempty_NUM, o_notempty_NUM) {
  314. var html = '<div id="box">';
  315. for (let condadd_parent_num = 1; condadd_parent_num <= z_notempty_NUM; condadd_parent_num++) {
  316. html += '' +
  317. '<div id="newcondition_' + condadd_parent_num + '" class="newcondition_css">' +
  318. '<div id="condition' + condadd_parent_num + '">' +
  319. '<div id="condition' + condadd_parent_num + '_' + '1' + '">' +
  320. '條件 ' +
  321. '<select id="cond_z' + condadd_parent_num + '_' + '1' + '">' +
  322. '<option value="if">if</option>' +
  323. '<option value="else if">else if</option>' +
  324. '<option value="else">else</option>' +
  325. '</select> ' +
  326. '<input type="text" id="cond_a' + condadd_parent_num + '_' + '1' + '">' +
  327. // pin_data_sensor_option +
  328. // '<option value="tankstatus">tankstatus</option>' +
  329. // '</textarea> ' +
  330. '<select id="cond_b' + condadd_parent_num + '_' + '1' + '">' +
  331. '<option value=""></option>' +
  332. '<option value=">">&gt;</option>' +
  333. '<option value=">=">&gt;=</option>' +
  334. '<option value="==">==</option>' +
  335. '<option value="<=">&lt;=</option>' +
  336. '<option value="<">&lt;</option>' +
  337. '</select> ' +
  338. '<input list="cond_list_c' + condadd_parent_num + '_' + '1' + '" id="cond_c' + condadd_parent_num + '_' + '1' + '">' +
  339. '<datalist id="cond_list_c' + condadd_parent_num + '_' + '1' + '">' +
  340. '<option value="on">ON</option>' +
  341. '<option value="off">OFF</option>' +
  342. '<option value="">(或請自行輸入數值)</option>' +
  343. '<option value="Waiting">空桶等待</option>' +
  344. '<option value="InputtingBean">入豆中</option>' +
  345. '<option value="InputtingBean_Pause">入豆暫停</option>' +
  346. '<option value="InputtingBean_Finish">入豆完成</option>' +
  347. '<option value="InputtingWater">夾層入水</option>' +
  348. '<option value="Drying">乾燥中</option>' +
  349. '<option value="Drying_Finish">乾燥完成</option>' +
  350. '<option value="OutputtingBean">可出豆</option>' +
  351. '<option value="OutputtingBean_Finish">出豆完成</option>' +
  352. '</datalist> ' +
  353. '<input type="button" class="input-cond-add" id="cond_add' + condadd_parent_num + '_' + '1' + '" value="條件++" onclick="cond_add(cond_add' + condadd_parent_num + '_' + '1' + ')"><br>' +
  354. '</div>';
  355. for (let cond_add_child_i = 2; cond_add_child_i <= a_notempty_NUM; cond_add_child_i++) {
  356. // if (cond_d_data[condadd_parent_num][cond_add_child_i] == '') {
  357. // // alert("cond_d_data[" + condadd_parent_num + "][" + cond_add_child_i + " ] + 為空值")
  358. // continue
  359. // }
  360. html +=
  361. '<div id="condition' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  362. '<select id="cond_d' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  363. '<option value=""></option>' +
  364. '<option value="&&">&&</option>' +
  365. '<option value="||">||</option>' +
  366. '</select> ' +
  367. '<input type="text" id="cond_a' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  368. // pin_data_sensor_option +
  369. // '<option value="tankstatus">tankstatus</option>' +
  370. // '</select> ' +
  371. '<select id="cond_b' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  372. '<option value=""></option>' +
  373. '<option value=">">&gt;</option>' +
  374. '<option value=">=">&gt;=</option>' +
  375. '<option value="==">==</option>' +
  376. '<option value="<=">&lt;=</option>' +
  377. '<option value="<">&lt;</option>' +
  378. '</select> ' +
  379. '<input list="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '" id="cond_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  380. '<datalist id="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  381. '<option value="on">ON</option>' +
  382. '<option value="off">OFF</option>' +
  383. '<option value="">(或請自行輸入數值)</option>' +
  384. '<option value="Waiting">空桶等待</option>' +
  385. '<option value="InputtingBean">入豆中</option>' +
  386. '<option value="InputtingBean_Pause">入豆暫停</option>' +
  387. '<option value="InputtingBean_Finish">入豆完成</option>' +
  388. '<option value="InputtingWater">夾層入水</option>' +
  389. '<option value="Drying">乾燥中</option>' +
  390. '<option value="Drying_Finish">乾燥完成</option>' +
  391. '<option value="OutputtingBean">可出豆</option>' +
  392. '<option value="OutputtingBean_Finish">出豆完成</option>' +
  393. '</datalist> ' +
  394. '<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 + '\');">';
  395. if (cond_add_child_i == 2) {
  396. html +=
  397. '<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>';
  398. } else {
  399. html +=
  400. '<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 + ');" style="display: none;"><br>';
  401. }
  402. html += '</div>';
  403. }
  404. html += '</div>';
  405. // 新增的物件動作
  406. html += '<div id="action' + condadd_parent_num + '">';
  407. for (let cond_add_child_i = 1; cond_add_child_i <= o_notempty_NUM; cond_add_child_i++) {
  408. // if (cond_obj_data[condadd_parent_num][cond_add_child_i] == '') {
  409. // // alert("cond_d_data[" + condadd_parent_num + "][" + cond_add_child_i + " ] + 為空值")
  410. // continue
  411. // }
  412. html +=
  413. '<div id="action' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  414. '物件 ' +
  415. '<input type="text" id="do_obj' + condadd_parent_num + '_' + cond_add_child_i + '" onChange="renew(\''+ condadd_parent_num + '_' + cond_add_child_i + '\', this.selectedIndex);">' +
  416. // pin_data_relay_option +
  417. // '</select>' +
  418. // '<select id="do_act' + new_condition_i + '_1">' +
  419. // '<option value="">請由左方選取物件' +
  420. // '</select> ' +
  421. ' 動作 ' +
  422. '<div id="do_action' + condadd_parent_num + '_' + cond_add_child_i + '" style="display: inline-block;">' +
  423. '</div>' +
  424. '<input type="button" class="input-act-delete" id="act_del' + condadd_parent_num + '_' + cond_add_child_i + '" value="物件動作--" onclick="act_del(\'' + condadd_parent_num + '_' + cond_add_child_i + '\');">';
  425. if (cond_add_child_i == 1) {
  426. html +=
  427. '<input type="button" class="input-act-add" id="act_add' + condadd_parent_num + '_' + cond_add_child_i + '" value="物件動作++" onclick="act_add(act_add' + condadd_parent_num + '_' + cond_add_child_i + ');"><br>';
  428. } else {
  429. html +=
  430. '<input type="button" class="input-act-add" id="act_add' + condadd_parent_num + '_' + cond_add_child_i + '" value="物件動作++" onclick="act_add(act_add' + condadd_parent_num + '_' + cond_add_child_i + ');" style="display: none;"><br>';
  431. }
  432. html += '</div>';
  433. }
  434. html += '</div>';
  435. // 新增的 條件物件動作++ 條件物件動作-- 按鈕
  436. html += '<input type="button" class="input-delete" id="del' + condadd_parent_num + '" value="條件物件動作--" onclick="Delete(' + condadd_parent_num + ');"><br>' +
  437. '<input type="button" class="input-add" id="add' + condadd_parent_num + '" value="條件物件動作++" onclick="Add(add' + condadd_parent_num + ');">' +
  438. '</div><br>' ;
  439. }
  440. html += '</div>' ;
  441. var divbox = document.getElementById('DBvalue');
  442. divbox.insertAdjacentHTML('beforeend', html);
  443. }
  444. </script>
  445. </td>
  446. </tr>
  447. <tr>
  448. <td>
  449. <br>
  450. <hr>
  451. <br>
  452. </td>
  453. </tr>
  454. <!-- 積木取值 -->
  455. <tr>
  456. <td style="background-color: red; height: 77px; vertical-align: middle; text-align: center;">
  457. <input type="button" id="test" value="(單元測試保留) 顯示積木條件" onclick="getValue();"><br>
  458. <input type="button" id="test" value="(單元測試保留) 積木條件 json 格式 + MQTT + toDB" onclick="MQTTgetValue();"><br>
  459. </td>
  460. </tr>
  461. <!-- 積木取值 文字輸出 -->
  462. <tr>
  463. <td colspan="2">
  464. *** 以下內容測試用, 之後會刪除<br>
  465. Value : <span id="show_Value"></span><br><br>
  466. <!-- MySQL : <span id="show_MySQLcommand"></span><br><br> -->
  467. MQTT : <span id="show_MQTTcommand"></span>
  468. </td>
  469. </tr>
  470. <!-- 燒錄 -->
  471. <tr>
  472. <td style="background-color: red; height: 77px; vertical-align: middle; text-align: center;">
  473. <input type="button" value="(單元測試保留) 更新 main.c 檔案" onclick="prog_creat_hex();"><br>
  474. <input type="button" value="(單元測試保留) 更新 SDIO.hex 檔案 + MQTT 其內容 + 備份 SDIO.hex toGit" onclick="programmer();">
  475. </td>
  476. </tr>
  477. <tr>
  478. <td style="background-color: red; height: 50px; vertical-align: middle; text-align: center;">
  479. <input type="button" value="進行 OTA 燒錄" onclick="prog_OTA();">
  480. </td>
  481. </tr>
  482. <script>
  483. function prog_creat_hex() {
  484. MQTTgetValue();
  485. $.ajax({
  486. type:"GET",
  487. url:"/creat_hex",
  488. data:TT,
  489. dataType:"text",
  490. async:false,
  491. success:function (res) {
  492. $("#creat_hex_Value").text(res);
  493. },
  494. error: function (thrownError) {
  495. alert(thrownError.statusText);
  496. $("#creat_hex_Value").text(thrownError.statusText);
  497. }
  498. })
  499. }
  500. function programmer(params) {
  501. var confirm_programmer = confirm("即將燒錄 Coffee1.0, 確定請按下 [確認] :");
  502. if (!confirm_programmer) {
  503. alert("已取消燒錄");
  504. } else {
  505. var prog_tank_data = $('#prog_tank').find(':selected').val();
  506. var prog_data = {'tank':prog_tank_data,
  507. 'USERNAME': USERNAME}
  508. $("#programmer_Value").text("控制板燒錄中 ...");
  509. $.get('/board_programmer', prog_data, function (res) {
  510. $("#programmer_Value").text(res);
  511. alert(res);
  512. }, 'text');
  513. }
  514. }
  515. function prog_OTA() {
  516. prog_creat_hex();
  517. programmer();
  518. }
  519. </script>
  520. <!-- 燒錄結果顯示 -->
  521. <tr>
  522. <td colspan="2">
  523. creat_hex 結果:<span id="creat_hex_Value"></span><br>
  524. <br>
  525. 燒錄結果:<span id="programmer_Value"></span>
  526. </td>
  527. </tr>
  528. </table>
  529. <!-- Relay、感測器選值時, 左側圖片顯示對應項目 -->
  530. <script>
  531. // 當右方的下拉式選單選擇時, 更新左方圖片上的文字 - relay
  532. function select_relay(id) {
  533. var select_relay_text = $("#select_relay_" + id).find(':selected').text()
  534. // console.log("select_relay_text: " + select_relay_text)
  535. if (select_relay_text == '') {
  536. $("#relay" + id).text('');
  537. document.getElementById("relay" + id).style.backgroundColor = 'transparent';
  538. } else {
  539. $("#relay" + id).text(select_relay_text);
  540. document.getElementById("relay" + id).style.backgroundColor = 'lightblue';
  541. document.getElementById("relay" + id).style.color = 'black';
  542. document.getElementById("relay" + id).style.fontWeight = '600';
  543. }
  544. }
  545. var sensorlist = ['', '分壓類比', 'PWM', 'PWM', '類比', '類比', '分壓類比', '類比', '485', '數位',
  546. 'PWM', '數位', '數位', '分壓類比', '數位', 'I2C', 'UART', 'UART', 'UART', '數位']
  547. // selectSensor
  548. function selectSensor(PinNum) {
  549. var Pin_sensor = $("#selectSensor_" + PinNum).find(':selected').text();
  550. // console.log("Pin_sensor: " + Pin_sensor)
  551. if (Pin_sensor == '') {
  552. $("#sensor_" + PinNum).text('');
  553. document.getElementById("sensor_" + PinNum).style.backgroundColor = 'transparent';
  554. } else {
  555. $("#sensor_" + PinNum).text(Pin_sensor);
  556. // alert("sensorlist[PinNum]]\n" + sensorlist[PinNum.substring(1)])
  557. if (sensorlist[PinNum.substring(1)] == '類比') {
  558. document.getElementById("sensor_" + PinNum).style.backgroundColor = 'lightgreen';
  559. } else if (sensorlist[PinNum.substring(1)] == 'PWM') {
  560. document.getElementById("sensor_" + PinNum).style.backgroundColor = 'lightcyan';
  561. } else if (sensorlist[PinNum.substring(1)] == '數位') {
  562. document.getElementById("sensor_" + PinNum).style.backgroundColor = 'lightgoldenrodyellow';
  563. } else if (sensorlist[PinNum.substring(1)] == 'UART') {
  564. document.getElementById("sensor_" + PinNum).style.backgroundColor = 'linen';
  565. } else if (sensorlist[PinNum.substring(1)] == '分壓類比') {
  566. document.getElementById("sensor_" + PinNum).style.backgroundColor = 'lavender';
  567. } else if (sensorlist[PinNum.substring(1)] == 'I2C' || sensorlist[PinNum.substring(1)] == '485') {
  568. document.getElementById("sensor_" + PinNum).style.backgroundColor = 'lightpink';
  569. }
  570. document.getElementById("sensor_" + PinNum).style.color = 'black';
  571. document.getElementById("sensor_" + PinNum).style.fontWeight = '600';
  572. }
  573. }
  574. </script>
  575. <!-- -->
  576. <script>
  577. var relay_data = ''; // 積木程式 制動器選項
  578. var sensor_data = ''; // 積木程式 感測器選項
  579. var obj_data = ''; // 積木程式 物件選項:桶槽狀態 暫停秒數
  580. const list_R = ['R1','R2','R3','R4','R5','R6','R7','R8','R9','R10','R11','R12','R13','R14','R15','R16','R17','R18','R19','R20']
  581. var list_relay_item = []; // R1~R20 對應的 relay 取值
  582. const list_M = ['M1','M2','M3','M4','M5','M6','M7','M8','M9','M10','M11','M12','M13','M14','M15','M16','M17','M18','M19']
  583. var list_sensor_item = []; // M1~M19 對應的 sensor 取值
  584. const list_M_Hz = ['M1_Hz','M2_Hz','M3_Hz','M4_Hz','M5_Hz','M6_Hz','M7_Hz','M8_Hz','M9_Hz','M10_Hz',
  585. 'M11_Hz','M12_Hz','M13_Hz','M14_Hz','M15_Hz','M16_Hz','M17_Hz','M18_Hz','M19_Hz'];
  586. var list_sensorHz_item = [] // M1~M19 對應的取值頻率
  587. function ItemGetValueToDB() {
  588. var ethernet_text = $("#select_ethernet_1").find(':selected').val();
  589. var wifi_text = $("#select_wifi_1").find(':selected').val();
  590. var zigbee_text = $("#select_zigbee_1").find(':selected').val();
  591. var tank_text = $('#prog_tank').find(':selected').val();
  592. console.log("ethernet_text: " + ethernet_text);
  593. console.log("wifi_text: " + wifi_text);
  594. console.log("zigbee_text: " + zigbee_text);
  595. console.log("tank_text: " + tank_text);
  596. list_relay_item = [];
  597. for (let i = 1; i < 21; i++) {
  598. var relay_text = $("#select_relay_" + i).find(':selected').val();
  599. if (relay_text != '') {
  600. list_relay_item.push(relay_text);
  601. } else {
  602. list_relay_item.push('');
  603. }
  604. }
  605. console.log("list_relay_item: " + list_relay_item);
  606. list_sensor_item = [];
  607. for (let i = 1; i < 20; i++) {
  608. var sensor_text = $("#selectSensor_M" + i).find(':selected').val();
  609. if (sensor_text != '') {
  610. list_sensor_item.push(sensor_text);
  611. } else {
  612. list_sensor_item.push('');
  613. }
  614. }
  615. console.log("list_sensor_item: " + list_sensor_item);
  616. list_sensorHz_item = [];
  617. // list_M_Hz = ['M1_Hz','M2_Hz','M3_Hz','M4_Hz','M5_Hz','M6_Hz','M7_Hz','M8_Hz','M9_Hz','M10_Hz',
  618. // 'M11_Hz','M12_Hz','M13_Hz','M14_Hz','M15_Hz','M16_Hz','M17_Hz','M18_Hz','M19_Hz'];
  619. // var list_sensorHz_item
  620. for (let i = 1; i < 20; i++) {
  621. var sensor_text = $("#M" + i + "_Hz").val();
  622. if (sensor_text !== undefined) {
  623. console.log("sensor_text: ", sensor_text);
  624. list_sensorHz_item.push(sensor_text);
  625. } else {
  626. list_sensorHz_item.push('');
  627. }
  628. }
  629. var SQL_insert = 'INSERT INTO `coffee1_0_pin` (' +
  630. '`datetime`, `tid`, `ethernet`, `wifi`, `zigbee`, `' +
  631. list_R.join("`, `") +
  632. '`, `' +
  633. list_M.join("`, `") +
  634. '`, `' +
  635. list_M_Hz.join("`, `") +
  636. '`) VALUES (' +
  637. 'current_timestamp(), "' + Tank_ID + '", "' + ethernet_text + '", "' + wifi_text + '", "' + zigbee_text + '", "' +
  638. list_relay_item.join('", "') +
  639. '", "' +
  640. list_sensor_item.join('", "') +
  641. '", "' +
  642. list_sensorHz_item.join('", "') +
  643. '")';
  644. var sql_data = { "sql":SQL_insert };
  645. console.log("sql_data: ", sql_data)
  646. $.get('/sql_get', sql_data, function (res) {
  647. if (res['response'] == '') {
  648. alert("OK");
  649. } else {
  650. alert(res['response']);
  651. }
  652. location.reload();
  653. }, 'json');
  654. // ItemGetValue();
  655. // location.reload();
  656. }
  657. function ItemGetValue() {
  658. list_relay_item = [];
  659. // ethernet、wifi、zigbee 取值測試
  660. // var select_ethernet_text = $("#select_ethernet_1").find(':selected').text()
  661. // var select_wifi_text = $("#select_wifi_1").find(':selected').text()
  662. // var select_zigbee_text = $("#select_zigbee_1").find(':selected').text()
  663. // console.log("select_ethernet_text: " + select_ethernet_text)
  664. // console.log("select_wifi_text: " + select_wifi_text)
  665. // console.log("select_zigbee_text: " + select_zigbee_text)
  666. // 制動器感測器 下拉式選單 不可更改
  667. $('.select-input').prop('disabled', true);
  668. // relay 取值
  669. relay_dict = {};
  670. for (let i = 1; i < 21; i++) {
  671. var relay_text = $("#select_relay_" + i).find(':selected').val();
  672. if (relay_text != '') {
  673. relay_dict["R" + i] = "R" + i + "_" + relay_text;
  674. // console.log("R" + i + " : " + relay_text);
  675. list_relay_item.push(relay_text);
  676. } else {
  677. // relay_dict["R" + i] = "";
  678. // console.log("R" + i + " : ");
  679. list_relay_item.push('');
  680. }
  681. }
  682. // console.log("list_relay_item: " + list_relay_item);
  683. // relay_data = '<optgroup label="制動器狀態">';
  684. relay_data = '<option value=""></option>';
  685. for (let r in relay_dict) {
  686. // console.log(r + " : " + relay_dict[r]);
  687. relay_data += '<option value="' + relay_dict[r] + '">' + relay_dict[r] + '</option>';
  688. }
  689. relay_data += '<option value="sleep">sleep</option>' +
  690. '<option value="tankstatus">tankstatus</option>';
  691. // relay_data += '</optgroup>'
  692. // console.log("relay_data: " + relay_data)
  693. // sensor 取值 dict
  694. sensor_dict = {};
  695. for (let i = 1; i < 20; i++) {
  696. var sensor_text = $("#selectSensor_M" + i).find(':selected').text();
  697. if (sensor_text != '') {
  698. sensor_dict["M" + i] = "M" + i + "_" + sensor_text;
  699. // console.log("selectSensor_M" + i);
  700. // console.log("M" + i + "_" + sensor_text);
  701. } else {
  702. // sensor_dict["M" + i] = "";
  703. // console.log("selectSensor_M" + i);
  704. // console.log("");
  705. }
  706. }
  707. sensor_data = '';
  708. // sensor_data = '<optgroup label="感測器數值">';
  709. for (let s in sensor_dict) {
  710. // console.log(s + " : " + sensor_dict[s])
  711. sensor_data += '<option value="' + sensor_dict[s] + '">' + sensor_dict[s] + '</option>';
  712. }
  713. sensor_data += '<option value="tankstatus">tankstatus</option>';
  714. // sensor_data += '</optgroup>';
  715. // console.log("sensor_data: " + sensor_data)
  716. console.log("relay_data: " + relay_data);
  717. console.log("sensor_data: " + sensor_data);
  718. var relay_select_data = document.getElementById("");
  719. // // 賦值條件 a
  720. // var sectorSelect = document.getElementById("cond_a1_1");
  721. // sectorSelect.innerHTML = '<option value="">制動器 / 感測器</option>' + relay_data + sensor_data;
  722. // obj_data = '<option value="' + 'sleep' + '">' + 'sleep' + '</option>' +
  723. // '<option value="' + 'tankstatus' + '">' + 'tankstatus' + '</option>';
  724. // // 賦值物件 a
  725. // var sectorSelect = document.getElementById("do_obj1_1");
  726. // sectorSelect.innerHTML = '<option value="">制動器 / 暫停秒數 / 桶槽狀態</option>' + relay_data + obj_data;
  727. // ===== 下方傳值未測試 ====================================================
  728. // var loader_data = {
  729. // "ethernet_list":select_ethernet_text,
  730. // "wifi_list":select_wifi_text,
  731. // "zigbee_list":select_zigbee_text,
  732. // "relay_list":String(relay_list),
  733. // "pwm_list":String(pwm_list),
  734. // "digital_list":String(digital_list),
  735. // "uart_list":String(uart_list),
  736. // "i2c_list":String(i2c_list),
  737. // "s485_list":String(s485_list),
  738. // "ppa_list":String(ppa_list)
  739. // };
  740. // $.ajax({
  741. // type:"GET",
  742. // url:"/loader",
  743. // dataType:"JSON",
  744. // data:loader_data,
  745. // success:function (res) {
  746. // alert("ItemGetValue loader: " + res.response)
  747. // },
  748. // error: function (thrownError) {
  749. // alert(thrownError)
  750. // }
  751. // })
  752. }
  753. relay_obj2act = {'vacuum':['on', 'off'],
  754. 'solenoidvalve':['on', 'off'],
  755. 'diskvalve':['on', 'off'],
  756. 'warninglight':['on', 'off'],
  757. 'camera':['on', 'off'],
  758. 'heater':['on', 'off'],
  759. 'pump':['on', 'off'],
  760. 'sleep':'',
  761. 'tankstatus':['Waiting', 'InputtingBean', 'InputtingBean_Pause', 'InputtingBean_Finish',
  762. 'Drying', 'OutputtingBean', 'InputtingWater']
  763. }
  764. dry_object = new Array();
  765. dry_object['tankstatus'] = ["Waiting", "InputtingBean", "InputtingBean_Pause", "InputtingBean_Finish",
  766. "InputtingWater", "Drying", "Drying_Finish", "OutputtingBean", "OutputtingBean_Finish"]; // 暫停秒數
  767. // DRY_CONTAINER_STATUS 讓 do_act / dry_object 判斷用
  768. const DRY_CONTAINER_STATUS = {
  769. 'Waiting':'空桶等待',
  770. 'InputtingBean':'入豆中',
  771. 'InputtingBean_Pause':'入豆暫停',
  772. 'InputtingBean_Finish':'入豆完成',
  773. 'InputtingWater':'夾層入水',
  774. 'Drying':'乾燥中',
  775. 'Drying_Finish':'乾燥完成',
  776. 'OutputtingBean':'可出豆',
  777. 'OutputtingBean_Finish':'出豆完成'
  778. }
  779. function renew(obj_num, index) {
  780. // console.log("renew!!!" + obj_num + "_____" + index);
  781. var index_name = $('#do_obj' + obj_num).val();
  782. // console.log("index_name: " + index_name);
  783. var Value = '';
  784. if (index_name === 'sleep') {
  785. Value = ' 暫停秒數 : ' +
  786. ' <input type="range" style="cursor: pointer;" id="do_act' + obj_num + '" min="5" max="60" step="5" value="10" oninput="showSleepValue(\'' + obj_num + '\', this.value)" onchange="showSleepValue(\'' + obj_num + '\', this.value)">' +
  787. ' <span id="sleepValue_text' + obj_num + '">10s</span>';
  788. } else if (index_name === 'tankstatus') {
  789. Value = '<select id="do_act' + obj_num + '">';
  790. for(var i=0; i<dry_object['tankstatus'].length; i++){
  791. Value += '<option value=' + dry_object['tankstatus'][i] + '>' + DRY_CONTAINER_STATUS[dry_object['tankstatus'][i]] + '</option>';
  792. }
  793. Value += '</select>';
  794. } else if (index_name.includes('Motor')) {
  795. Value = ' 指定轉速 : ' +
  796. ' <input type="range" style="cursor: pointer;" id="do_act' + obj_num + '" min="-50" max="50" step="5" value="20" oninput="showMotorValue(\'' + obj_num + '\', this.value)" onchange="showMotorValue(\'' + obj_num + '\', this.value)">' +
  797. ' <span id="motorValue_text' + obj_num + '">20rpm</span>';
  798. } else if (index_name === '' || index_name == undefined) {
  799. } else {
  800. Value = '<select id="do_act' + obj_num + '">' +
  801. '<option value="on">on</option>' +
  802. '<option value="off">off</option>' +
  803. '</select>';
  804. }
  805. // try {
  806. // Value = '<select id="do_act' + obj_num + '">';
  807. // for(var i=0; i<dry_object[index].length; i++){
  808. // Value += '<option value=' + dry_object[index][i] + '>' + dry_object[index][i] + '</option>';
  809. // }
  810. // Value += '</select>';
  811. // } catch (e) {
  812. // if (e.name == 'TypeError' && index == '5') {
  813. // Value = ' 轉速 : ' +
  814. // ' <input type="range" style="cursor: pointer;" id="do_act' + obj_num + '" min="-50" max="50" step="5" value="0" oninput="showMotorValue(\'' + obj_num + '\', this.value)" onchange="showMotorValue(\'' + obj_num + '\', this.value)">' +
  815. // ' <span id="motorValue_text' + obj_num + '">0</span>';
  816. // } else if (e.name == 'TypeError' && index == '11') {
  817. // Value = ' 目標溫度 : ' +
  818. // ' <input type="range" style="cursor: pointer;" id="do_act' + obj_num + '" min="20.0" max="50.0" step="0.5" value="28.0" oninput="showTempValue(\'' + obj_num + '\', this.value)" onchange="showTempValue(\'' + obj_num + '\', this.value)">' +
  819. // ' <span id="tempValue_text' + obj_num + '">28.0</span>';
  820. // } else if (e.name == 'TypeError' && index == '18') {
  821. // Value = ' 暫停秒數 : ' +
  822. // ' <input type="range" style="cursor: pointer;" id="do_act' + obj_num + '" min="5" max="60" step="5" value="10" oninput="showSleepValue(\'' + obj_num + '\', this.value)" onchange="showSleepValue(\'' + obj_num + '\', this.value)">' +
  823. // ' <span id="sleepValue_text' + obj_num + '">10s</span>';
  824. // }
  825. // }
  826. var sectorSelect = document.getElementById("do_action" + obj_num);
  827. if (sectorSelect != null) {
  828. sectorSelect.innerHTML = Value;
  829. }
  830. }
  831. function showSleepValue(obj_num, value) {
  832. document.getElementById("sleepValue_text" + obj_num).innerText = value + 's';
  833. }
  834. function showMotorValue(obj_num, value) {
  835. document.getElementById("motorValue_text" + obj_num).innerText = value + 'rpm';
  836. }
  837. function showSensorHzValue(obj_num, value) {
  838. document.getElementById(obj_num + "_HzText").innerText = value + 'Hz';
  839. }
  840. </script>
  841. <script>
  842. var cond_main = ''; // 主條件
  843. var cond_add_list = []; // 附加條件 List
  844. var cond_add_data = ''; // 欲加入附加條件的資料
  845. var cond_com_list = []; // 動作 List
  846. var cond_com_data = ''; // 欲加入動作的資料
  847. var cond_item = []; // 主條件+附加條件+動作 List
  848. function showValue() {
  849. cond_item = [];
  850. var command_test = '';
  851. Z = 0;
  852. TT = {}; // 將總條件句/附加條件句/物件動作句存入 字典, 後續傳給 dry_block_format 再組合
  853. var SQL_insert_total = ''; // MySQL 指令 全部條件輸出
  854. TT['mainLength'] = 0 // 總條件數
  855. TT['addLength'] = 0 // 子條件數
  856. TT['comLength'] = 0 // 子物件數
  857. // 條件物件動作 取值
  858. // for (let z = 1; z <= 2; z++) {
  859. for (let z = 1; z <= new_condition_i; z++) {
  860. var set_key = []; // List 加入變數名稱, INSERT DB 用
  861. var set_value = []; // List 加入值, INSERT DB 用
  862. // 初始清空
  863. cond_main = '';
  864. // if-while 取值
  865. try {
  866. var cond_z_value = document.getElementById("cond_z" + z + "_1").value;
  867. if (cond_z_value == '') {
  868. // alert('if/while 欄位未輸入')
  869. } else {
  870. Z = Z + 1;
  871. // if (Z > 4) {
  872. // alert("[Z > 4] 總條件數不得超過 3 項")
  873. // break
  874. // }
  875. // set_key.push('cond_z' + z + '_1');
  876. set_key.push('cond_z' + Z + '_1');
  877. set_value.push(cond_z_value);
  878. console.log("cond_z_value: " + cond_z_value);
  879. cond_main += cond_z_value + ' ';
  880. console.log("cond_main: " + cond_main);
  881. }
  882. } catch (error) {
  883. if (error.name == 'TypeError') {
  884. } else {
  885. alert("cond_z" + z + "_1: " + error.name)
  886. }
  887. }
  888. X = 1;
  889. cond_add_list = []; // 附加條件 List 清空
  890. for (let x = 1; x <= cond_add_child_i; x++) {
  891. // for (let x = 1; x <= cond_add_child_i; x++) {
  892. cond_add_data = ''; // 附加條件資料 清空
  893. if (x == 1) {
  894. // 主條件
  895. try {
  896. var cond_a_value = document.getElementById("cond_a" + z + "_" + x).value;
  897. if (cond_a_value == '') {
  898. // alert('主條件 感測器 欄位未輸入')
  899. } else {
  900. // set_key.push('cond_a' + z + '_' + X);
  901. set_key.push('cond_a' + Z + '_' + X);
  902. set_value.push(cond_a_value);
  903. console.log("cond_a_value: " + cond_a_value);
  904. cond_main += cond_a_value + ' ';
  905. }
  906. } catch (error) {
  907. if (error.name == 'TypeError') {
  908. } else {
  909. alert("cond_a" + z + "_" + x + ": " + error.name)
  910. }
  911. }
  912. // 子條件取值 : 條件中 > = <
  913. try {
  914. var cond_b_value = document.getElementById("cond_b" + z + "_" + x).value;
  915. if (cond_b_value == '') {
  916. // alert('主條件 比較運算子 欄位未輸入')
  917. } else {
  918. // set_key.push('cond_b' + z + '_' + X);
  919. set_key.push('cond_b' + Z + '_' + X);
  920. set_value.push(cond_b_value);
  921. console.log("cond_b_value: " + cond_b_value);
  922. // if (cond_b_value == 'MoreThan') { cond_main += '> '; }
  923. // else if (cond_b_value == 'MoreThanEqualTo') { cond_main += '>= '; }
  924. // else if (cond_b_value == 'Equal') { cond_main += '== '; }
  925. // else if (cond_b_value == 'LessThanEqualTo') { cond_main += '<= '; }
  926. // else if (cond_b_value == 'LessThan') { cond_main += '< '; }
  927. cond_main += cond_b_value + ' ';
  928. }
  929. } catch (error) {
  930. if (error.name == 'TypeError') {
  931. } else {
  932. alert("cond_b" + z + "_" + x + ": " + error.name)
  933. }
  934. }
  935. // 子條件取值 : 條件右 ON / OFF / 輸入數值
  936. try {
  937. var cond_c_value = document.getElementById("cond_c" + z + "_" + x).value;
  938. if (cond_c_value == '') {
  939. // alert('主條件 數值 欄位未輸入')
  940. } else {
  941. // console.log("Ctest: " + typeof(cond_c_value))
  942. set_key.push('cond_c' + Z + '_' + X);
  943. set_value.push(cond_c_value);
  944. console.log("cond_c_value: " + cond_c_value);
  945. if (relay_obj2act['tankstatus'].includes(cond_c_value)) {
  946. cond_main += "'" + cond_c_value + "'";
  947. } else {
  948. cond_main += cond_c_value;
  949. }
  950. // set_key.push('cond_c' + z + '_' + X);
  951. }
  952. } catch (error) {
  953. if (error.name == 'TypeError') {
  954. } else {
  955. alert("cond_c" + z + "_" + x + ": " + error.name)
  956. }
  957. }
  958. } else {
  959. // 附加條件 x > 1
  960. // 子條件取值 : 條件連接 and or
  961. try {
  962. var cond_d_value = document.getElementById("cond_d" + z + "_" + x).value;
  963. if (cond_d_value == '') {
  964. // alert('附加條件 and/or 欄位未輸入')
  965. } else {
  966. X = X + 1;
  967. // if (X > 13) {
  968. // alert("[X > 13] 子條件數不得超過 13 項")
  969. // break
  970. // }
  971. // set_key.push('cond_d' + z + '_' + X);
  972. set_key.push('cond_d' + Z + '_' + X);
  973. set_value.push(cond_d_value);
  974. cond_add_data += cond_d_value + ' ';
  975. }
  976. } catch (error) {
  977. if (error.name == 'TypeError') {
  978. } else {
  979. alert("cond_d" + z + "_" + x + ": " + error.name)
  980. }
  981. }
  982. // 感測器取值 :
  983. try {
  984. var cond_a_value = document.getElementById("cond_a" + z + "_" + x).value;
  985. if (cond_a_value == '') {
  986. // alert('附加條件 感測器 欄位未輸入')
  987. } else {
  988. // set_key.push('cond_a' + z + '_' + X);
  989. set_key.push('cond_a' + Z + '_' + X);
  990. set_value.push(cond_a_value);
  991. cond_add_data += cond_a_value + ' ';
  992. }
  993. } catch (error) {
  994. if (error.name == 'TypeError') {
  995. } else {
  996. alert("cond_a" + z + "_" + x + ": " + error.name)
  997. }
  998. }
  999. // 子條件取值 : 條件中 > = <
  1000. try {
  1001. var cond_b_value = document.getElementById("cond_b" + z + "_" + x).value;
  1002. if (cond_b_value == '') {
  1003. // alert('附加條件 比較運算子 欄位未輸入')
  1004. } else {
  1005. // set_key.push('cond_b' + z + '_' + X);
  1006. set_key.push('cond_b' + Z + '_' + X);
  1007. set_value.push(cond_b_value);
  1008. // if (cond_b_value == 'MoreThan') { cond_main += '> '; }
  1009. // else if (cond_b_value == 'MoreThanEqualTo') { cond_main += '>= '; }
  1010. // else if (cond_b_value == 'Equal') { cond_main += '== '; }
  1011. // else if (cond_b_value == 'LessThanEqualTo') { cond_main += '<= '; }
  1012. // else if (cond_b_value == 'LessThan') { cond_main += '< '; }
  1013. cond_add_data += cond_b_value;
  1014. }
  1015. } catch (error) {
  1016. if (error.name == 'TypeError') {
  1017. } else {
  1018. alert("cond_b" + z + "_" + x + ": " + error.name)
  1019. }
  1020. }
  1021. // 子條件取值 : 條件右 ON / OFF / 輸入數值
  1022. try {
  1023. var cond_c_value = document.getElementById("cond_c" + z + "_" + x).value;
  1024. if (cond_c_value == '') {
  1025. // alert('附加條件 數值 欄位未輸入')
  1026. } else {
  1027. // console.log("Ctest: " + cond_c_value)
  1028. set_key.push('cond_c' + Z + '_' + X);
  1029. set_value.push(cond_c_value);
  1030. if (relay_obj2act['tankstatus'].includes(cond_c_value)) {
  1031. cond_add_data += " '" + cond_c_value + "'";
  1032. } else {
  1033. cond_add_data += " " + cond_c_value;
  1034. }
  1035. // set_key.push('cond_c' + z + '_' + X);
  1036. }
  1037. } catch (error) {
  1038. if (error.name == 'TypeError') {
  1039. } else {
  1040. alert("cond_c" + z + "_" + x + ": " + error.name)
  1041. }
  1042. }
  1043. if (cond_add_data != '') {
  1044. console.log("cond_add_list: " + cond_add_list)
  1045. console.log("cond_add_data: " + cond_add_data)
  1046. cond_add_list.push(cond_add_data)
  1047. }
  1048. }
  1049. }
  1050. // 子 物件動作 取值
  1051. Y = 0;
  1052. cond_com_list = [];
  1053. for (let y = 1; y <= act_add_child_i; y++) {
  1054. cond_com_data = '';
  1055. // 子物件動作取值 : 物件 do_obj1_1
  1056. try {
  1057. var do_obj_value = document.getElementById("do_obj" + z + "_" + y).value;
  1058. // console.log("do_obj" + z + "_" + y + " : " + do_obj_value)
  1059. if (do_obj_value == '') {
  1060. // alert('物件 欄位未輸入')
  1061. } else {
  1062. Y = Y + 1;
  1063. // if (Y > 20) {
  1064. // alert("[Y > 20] 子物件數不得超過 20 項")
  1065. // break
  1066. // }
  1067. set_key.push('do_obj' + Z + '_' + Y);
  1068. set_value.push(do_obj_value);
  1069. cond_com_data += do_obj_value + ' ';
  1070. }
  1071. } catch (error) {
  1072. if (error.name == 'TypeError') {
  1073. } else {
  1074. alert("do_obj" + z + "_" + y + ": " + error.name)
  1075. }
  1076. }
  1077. // 子物件動作取值 : 動作 do_act1_1
  1078. try {
  1079. var do_act_value = document.getElementById("do_act" + z + "_" + y).value;
  1080. // console.log("do_act" + z + "_" + y + " : " + do_act_value)
  1081. if (do_act_value == '') {
  1082. // alert('動作 欄位未輸入')
  1083. } else {
  1084. set_key.push('do_act' + Z + '_' + Y);
  1085. // if (DRY_CONTAINER_STATUS[do_act_value] != undefined ) {
  1086. // console.log("=== != undefined ===")
  1087. // console.log(DRY_CONTAINER_STATUS[do_act_value])
  1088. // set_value.push(DRY_CONTAINER_STATUS[do_act_value]);
  1089. // cond_com_data += DRY_CONTAINER_STATUS[do_act_value];
  1090. // cond_com_list.push(cond_com_data);
  1091. // } else {
  1092. set_value.push(do_act_value);
  1093. cond_com_data += do_act_value;
  1094. cond_com_list.push(cond_com_data);
  1095. // }
  1096. }
  1097. } catch (error) {
  1098. if (error.name == 'TypeError') {
  1099. } else {
  1100. alert("do_act" + z + "_" + y + ": " + error.name)
  1101. }
  1102. }
  1103. }
  1104. // ===== 0324 測試 OK 勿刪 ===================================================
  1105. var A = 1;
  1106. var B = 1;
  1107. console.log("cond_add_list: " + cond_add_list);
  1108. console.log("cond_com_list: " + cond_com_list);
  1109. if (cond_main != '') {
  1110. TT['cond_main' + Z] = cond_main;
  1111. for (let a = 0; a < cond_add_list.length; a++) {
  1112. TT['cond_add'+ Z + '_' + A] = cond_add_list[a];
  1113. A = A + 1;
  1114. }
  1115. for (let b = 0; b < cond_com_list.length; b++) {
  1116. TT['cond_com'+ Z + '_' + B] = cond_com_list[b];
  1117. B = B + 1;
  1118. }
  1119. cond_item.push(
  1120. '{"cond_main":"' + cond_main + '", ' +
  1121. '"cond_add":["' + cond_add_list.join('", "') + '"], ' +
  1122. '"cond_com":["' + cond_com_list.join('", "') + '"]}'
  1123. )
  1124. }
  1125. console.log("cond_add_list.length: " + cond_add_list.length + "__" + typeof(cond_add_list.length))
  1126. console.log("TT['addLength']: " + TT['addLength'] + "__" + typeof(TT['addLength']))
  1127. if (cond_add_list.length > TT['addLength']) {
  1128. TT['addLength'] = cond_add_list.length
  1129. }
  1130. if (cond_com_list.length > TT['comLength']) {
  1131. TT['comLength'] = cond_com_list.length
  1132. }
  1133. }
  1134. // ========================================================
  1135. TT['mainLength'] = Z
  1136. console.log("***TT['mainLength']: " + TT['mainLength']);
  1137. console.log("***TT['addLength']: " + TT['addLength']);
  1138. console.log("***TT['comLength']: " + TT['comLength']);
  1139. TT['tank_num'] = $('#prog_tank').find(':selected').val();
  1140. // ========================================================
  1141. document.getElementById('show_Value').innerText = '"cond": [' + cond_item + ']';
  1142. }
  1143. function getValue(){
  1144. var confirm_getValue = confirm("請確認積木條件無誤後, 再按下 [確認] :");
  1145. if (!confirm_getValue) {
  1146. alert("已取消積木取值測試");
  1147. } else {
  1148. showValue();
  1149. }
  1150. }
  1151. function MQTTgetValue() {
  1152. var confirm_getValue = confirm("請確認積木條件無誤後, 再按下 [確認] :");
  1153. if (!confirm_getValue) {
  1154. alert("已取消積木取值測試");
  1155. } else {
  1156. showValue();
  1157. var msg_data;
  1158. $.get('/dry_block_format', TT, function (res) {
  1159. // alert("MQTT OK")
  1160. document.getElementById('show_MQTTcommand').innerText = JSON.stringify(res.response);
  1161. msg_data = JSON.stringify(res.response);
  1162. // 存值
  1163. var prog_tank_data = $('#prog_tank').find(':selected').val();
  1164. var SQL_insert = 'INSERT INTO `block_cond_dry_t` (' +
  1165. '`datetime`, `UserName`, `tank_num`, `cond`) VALUES (' +
  1166. 'current_timestamp(), \'' + USERNAME + '\', \'' + prog_tank_data.toLowerCase() + '\', \''
  1167. + String(msg_data).replaceAll("'", "") + '\');';
  1168. console.log("SQL_insert: " + SQL_insert);
  1169. sql_data = { "sql" : SQL_insert };
  1170. // $.get('/sql_get', sql_data, function (res) {
  1171. // // alert("OK")
  1172. // }, 'json');
  1173. }, 'json');
  1174. }
  1175. }
  1176. </script>
  1177. <!-- 條件物件 ++ -- -->
  1178. <script>
  1179. function act_add(evt) {
  1180. evt.style.display = "none";
  1181. var actadd_parent_num = String(evt.id).split('_')[1].slice(3, )
  1182. // console.log("actadd_parent_num: " + actadd_parent_num)
  1183. act_add_child_i++;
  1184. var html = '';
  1185. html +=
  1186. '<div id="action' + actadd_parent_num + '_' + act_add_child_i + '">' +
  1187. '物件 ' +
  1188. '<input type="text" id="do_obj' + actadd_parent_num + '_' + act_add_child_i + '" onChange="renew(\'' + actadd_parent_num + '_' + act_add_child_i + '\', this.selectedIndex);">' +
  1189. // pin_data_relay_option +
  1190. // '</select> ' +
  1191. '動作 ' +
  1192. '<div id="do_action' + actadd_parent_num + '_' + act_add_child_i + '" style="display: inline-block;">' +
  1193. '</div>' +
  1194. // '<select id="do_act' + actadd_parent_num + '_' + act_add_child_i + '">' +
  1195. // '<option value="">請由左方選取物件</option>' +
  1196. // '</select> ' +
  1197. '<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 + '\');">' +
  1198. '<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>' +
  1199. '</div>';
  1200. var divbox = document.getElementById('action' + actadd_parent_num);
  1201. divbox.insertAdjacentHTML('beforeend', html);
  1202. }
  1203. function act_del(evt) {
  1204. var del_action = document.getElementById('action' + evt);
  1205. del_action.innerHTML = ""
  1206. var parentObj = del_action.parentNode; // 取得欲刪除 div 的父類別
  1207. parentObj.removeChild(del_action) // 刪除 div
  1208. var del_act_parent_num = String(evt).split('_')[0]
  1209. var del_act_child_num = String(evt).split('_')[1]
  1210. // console.log('del_act_parent_num: ' + del_act_parent_num)
  1211. // console.log('del_act_child_num: ' + del_act_child_num)
  1212. var button_return_id = document.getElementById('act_add' + del_act_parent_num + '_' + String(parseInt(del_act_child_num)-1));
  1213. // console.log("test: " + 'cond_add' + del_act_parent_num + '_' + String(parseInt(del_act_child_num)-1))
  1214. // console.log("button_return_id: " + button_return_id) // null
  1215. if (button_return_id == null) {
  1216. var button_return_id = document.getElementById('act_add' + del_act_parent_num + '_1');
  1217. }
  1218. button_return_id.style.display = "inline";
  1219. }
  1220. // --------------------------------------------------------------------------------------------------
  1221. function cond_add(evt) { // cond_add1_1 下一個是 cond_add1(條件)_2(子條件)
  1222. evt.style.display = "none"; // 不顯示原按鈕
  1223. var condadd_parent_num = String(evt.id).split('_')[1].slice(3, ) // 把第一個條件的編號記下
  1224. // console.log("condadd_parent_num: " + condadd_parent_num)
  1225. cond_add_child_i++
  1226. var html = '';
  1227. html +=
  1228. '<div id="condition' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  1229. '<select id="cond_d' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  1230. '<option value=""></option>' +
  1231. '<option value="&&">&&</option>' +
  1232. '<option value="||">||</option>' +
  1233. '</select> ' +
  1234. '<input type="text" id="cond_a' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  1235. // pin_data_sensor_option +
  1236. // '<option value="tankstatus">tankstatus</option>' +
  1237. // '</select> ' +
  1238. '<select id="cond_b' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  1239. '<option value=""></option>' +
  1240. '<option value=">">&gt;</option>' +
  1241. '<option value=">=">&gt;=</option>' +
  1242. '<option value="==">==</option>' +
  1243. '<option value="<=">&lt;=</option>' +
  1244. '<option value="<">&lt;</option>' +
  1245. '</select> ' +
  1246. '<input list="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '" id="cond_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  1247. '<datalist id="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  1248. '<option value="on">ON</option>' +
  1249. '<option value="off">OFF</option>' +
  1250. '<option value="">(或請自行輸入數值)</option>' +
  1251. '<option value="Waiting">空桶等待</option>' +
  1252. '<option value="InputtingBean">入豆中</option>' +
  1253. '<option value="InputtingBean_Pause">入豆暫停</option>' +
  1254. '<option value="InputtingBean_Finish">入豆完成</option>' +
  1255. '<option value="InputtingWater">夾層入水</option>' +
  1256. '<option value="Drying">乾燥中</option>' +
  1257. '<option value="Drying_Finish">乾燥完成</option>' +
  1258. '<option value="OutputtingBean">可出豆</option>' +
  1259. '<option value="OutputtingBean_Finish">出豆完成</option>' +
  1260. '</datalist> ' +
  1261. '<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 + '\');">' +
  1262. '<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>' +
  1263. '</div>';
  1264. var divbox = document.getElementById('condition' + condadd_parent_num);
  1265. divbox.insertAdjacentHTML('beforeend', html);
  1266. }
  1267. function cond_del(evt) {
  1268. // console.log('evt: ' + evt)
  1269. var del_cond_child = document.getElementById('condition' + evt);
  1270. // console.log("del_cond_child: " + del_cond_child)
  1271. del_cond_child.innerHTML = ""
  1272. var parentObj = del_cond_child.parentNode; // 取得欲刪除 div 的父類別
  1273. parentObj.removeChild(del_cond_child) // 刪除 div
  1274. // 上一個按鈕要顯示出來
  1275. var del_cond_parent_num = String(evt).split('_')[0]
  1276. var del_cond_child_num = String(evt).split('_')[1]
  1277. console.log('del_cond_parent_num: ' + del_cond_parent_num)
  1278. console.log('del_cond_child_num: ' + del_cond_child_num)
  1279. var button_return_id = document.getElementById('cond_add' + del_cond_parent_num + '_' + String(parseInt(del_cond_child_num)-1));
  1280. console.log("test: " + 'cond_add' + del_cond_parent_num + '_' + String(parseInt(del_cond_child_num)-1))
  1281. console.log("button_return_id: " + button_return_id) // null
  1282. if (button_return_id == null) {
  1283. var button_return_id = document.getElementById('cond_add' + del_cond_parent_num + '_1');
  1284. }
  1285. try {
  1286. button_return_id.style.display = "inline";
  1287. } catch (error) {
  1288. if (error.name !== 'TypeError') {
  1289. alert("cond_add" + del_cond_parent_num + "_" + String(parseInt(del_cond_child_num)-1) + " 子條件刪除錯誤\n" +
  1290. error.name + "\n" +
  1291. error.message);
  1292. }
  1293. }
  1294. }
  1295. // -------------------------------------------------------------------------------------------------------------
  1296. function Add(evt) { // 網頁初始按鈕 onclick="Add(add1);
  1297. evt.style.display = "none"; // 元素不顯示。將 add1 的 input-button 不顯示
  1298. new_condition_i++; // 設定編號用
  1299. // var div = document.createElement('div'); // 輸出 <div></div>。此時並不會顯示,
  1300. // 需透過 appendChild()、insertBefore() 或 replaceChild() 等方法將新元素加入至指定的位置之後才會顯示。
  1301. // var cond_number = String(evt).slice(3, ) // 目前的 condition 條件物件動作 數 (最外層)
  1302. // var cond_a = 'cond_a' + cond_number + '_' + new_condition_i; // [條件] 左方 : 制動器感測器
  1303. // var cond_b = 'cond_b' + cond_number + '_' + new_condition_i; // [條件] 中間 : > / = / <
  1304. // var cond_c = 'cond_c' + cond_number + '_' + new_condition_i; // [條件] 右方 : ON / OFF / 數值
  1305. // var cond_d = 'cond_d' + cond_number + '_' + new_condition_i; // 條件] 最左方條件連接 : and / or
  1306. // div.id = 'newcondition_' + new_condition_i; // 設定 div 的 id
  1307. // div.style.marginTop = "10px"; // 新增的 div 設定 marginTop 屬性值
  1308. var html = ''
  1309. // 新增的條件
  1310. html +=
  1311. '<div id="newcondition_' + new_condition_i + '" class="newcondition_css">' +
  1312. '<div id="condition' + new_condition_i + '">' +
  1313. '<div id="condition' + new_condition_i + '_1">' +
  1314. '條件 ' +
  1315. '<select id="cond_z' + new_condition_i + '_1">' +
  1316. '<option value="if">if</option>' +
  1317. '<option value="else if">else if</option>' +
  1318. '<option value="else">else</option>' +
  1319. '</select> ' +
  1320. '<input type="text" id="cond_a' + new_condition_i + '_1">' +
  1321. // pin_data_sensor_option +
  1322. // '<option value="tankstatus">tankstatus</option>' +
  1323. // '</select> ' +
  1324. '<select id="cond_b' + new_condition_i + '_1">' +
  1325. '<option value=""></option>' +
  1326. '<option value=">">&gt;</option>' +
  1327. '<option value=">=">&gt;=</option>' +
  1328. '<option value="==">==</option>' +
  1329. '<option value="<=">&lt;=</option>' +
  1330. '<option value="<">&lt;</option>' +
  1331. '</select> ' +
  1332. '<input list="cond_list_c' + new_condition_i + '_1" id="cond_c' + new_condition_i + '_1">' +
  1333. '<datalist id="cond_list_c' + new_condition_i + '_1">' +
  1334. '<option value="on">ON</option>' +
  1335. '<option value="off">OFF</option>' +
  1336. '<option value="">(或請自行輸入數值)</option>' +
  1337. '<option value="Waiting">空桶等待</option>' +
  1338. '<option value="InputtingBean">入豆中</option>' +
  1339. '<option value="InputtingBean_Pause">入豆暫停</option>' +
  1340. '<option value="InputtingBean_Finish">入豆完成</option>' +
  1341. '<option value="InputtingWater">夾層入水</option>' +
  1342. '<option value="Drying">乾燥中</option>' +
  1343. '<option value="Drying_Finish">乾燥完成</option>' +
  1344. '<option value="OutputtingBean">可出豆</option>' +
  1345. '<option value="OutputtingBean_Finish">出豆完成</option>' +
  1346. '</datalist> ' +
  1347. '<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>' +
  1348. '</div></div>';
  1349. // 新增的物件動作
  1350. html +=
  1351. '<div id="action' + new_condition_i + '">' +
  1352. '<div id="action' + new_condition_i + '_1">' +
  1353. '物件 ' +
  1354. '<input type="text" id="do_obj' + new_condition_i + '_1" onChange="renew(\''+ new_condition_i + '_1\', this.selectedIndex);">' +
  1355. // pin_data_relay_option +
  1356. // '</select>' +
  1357. '動作 ' +
  1358. '<div id="do_action' + new_condition_i + '_1" style="display: inline-block;">' +
  1359. '</div>' +
  1360. '<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>' +
  1361. '</div>' +
  1362. '</div>' +
  1363. // 新增的 條件物件動作++ 條件物件動作-- 按鈕
  1364. '<input type="button" class="input-delete" id="del' + new_condition_i + '" value="條件物件動作--" onclick="Delete(' + new_condition_i + ');"><br>' +
  1365. '<input type="button" class="input-add" id="add' + new_condition_i + '" value="條件物件動作++" onclick="Add(add' + new_condition_i + ');">' +
  1366. '</div>' ;
  1367. var divbox = document.getElementById('box');
  1368. divbox.insertAdjacentHTML('beforeend', html);
  1369. };
  1370. function Delete(evt) {
  1371. var del_condition = document.getElementById('newcondition_' + evt);
  1372. del_condition.innerHTML = ""
  1373. var parentObj = del_condition.parentNode; // 取得欲刪除 div 的父類別
  1374. parentObj.removeChild(del_condition) // 刪除 div
  1375. // 上一個按鈕要顯示出來
  1376. var button_return_id = document.getElementById('add' + String(parseInt(evt)-1));
  1377. if (button_return_id == null) {
  1378. var button_return_id = document.getElementById('add1');
  1379. }
  1380. // console.log('button_return_id: ' + button_return_id)
  1381. button_return_id.style.display = "block"; // 元素顯示。顯示前一個 input-button
  1382. };
  1383. // --------------------------------------------------------------------------------------
  1384. </script>
  1385. <div id="coffee_footer">
  1386. <!-- 匯入共同使用的 footer.html 內容 -->
  1387. {% include 'footer.html' %}
  1388. <br>
  1389. <br>
  1390. </div>
  1391. </div>
  1392. </body>
  1393. </html>