From e5ca3ea1f08fa919ae97a868195014a1949647c9 Mon Sep 17 00:00:00 2001 From: gudae01 Date: Mon, 21 Jul 2025 15:25:52 +0900 Subject: [PATCH] =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/index.html | 100 ++++++++++++++++++--------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 69f57f6..811799d 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -55,7 +55,6 @@
-
Parity:
@@ -495,8 +494,8 @@ - + @@ -575,8 +574,8 @@ - + @@ -613,7 +612,7 @@ - + @@ -734,6 +733,7 @@ const opcUaAddBtn = document.getElementById('opcua_add_btn'); const opcUaFieldList = document.getElementById('opcua-field-list'); const opcUaRowTemplate = document.getElementById('opcua-row-template'); + const canRowTemplate = document.getElementById('can-row-template'); const canFieldList = document.getElementById('can-field-list'); // 페이지 로드 시 자동으로 JSON 파일들 로드 @@ -790,12 +790,6 @@ } }; - reader.onerror = () => { - alert(`An error occurred while reading the file. (${DeviceFileType})`); - console.error(`FileReader error for ${DeviceFileType}:`, reader.error); - uploadDeviceFileInput.value = ''; - }; - reader.readAsText(selectedDeviceFile); }); }); @@ -854,11 +848,6 @@ uploadFileInput.value = ''; } }; - - reader.onerror = () => { - alert(`An error occurred while reading the file. (${fileType})`); - uploadFileInput.value = ''; - }; reader.readAsText(selectedFile); }); }); @@ -934,6 +923,32 @@ } } + /*---can 테이블에 행 추가 로직---*/ + document.getElementById('can-field-list').addEventListener('click', function (e) { + let tr = e.target.closest('tr'); + if (!tr) return; + + Array.from(this.children).forEach(row => row.classList.remove('selected-row')); + tr.classList.add('selected-row'); + selectedRow = tr; + + document.getElementById('can_field_input').value = tr.querySelector('.can-field-display').textContent; + document.getElementById('can_id_input').value = tr.querySelector('.can-id-display').textContent; + document.getElementById('can_odt_input').value = tr.querySelector('.can-odt-display').textContent; + document.getElementById('can_dv_input').value = tr.querySelector('.can-dv-display').textContent; + document.getElementById('can_shift_input').value = tr.querySelector('.can-shift-display').textContent; + document.getElementById('can_expr_input').value = tr.querySelector('.can-expr-display').textContent; + document.getElementById('can_mask_input').value = tr.querySelector('.can-mask-display').textContent; + }); + // 처음에 행이 없으면 빈 행을 하나 추가 + if (canFieldList.children.length === 0) { + const canRowTemplate = document.getElementById('can-row-template'); + if (canRowTemplate) { + const newRow = canRowTemplate.content.cloneNode(true); + opcUaList.appendChild(newRow); + } + } + modbusAddBtn.addEventListener('click', () => { const field = document.getElementById('modbus_field_input').value; const addr = document.getElementById('modbus_addr_input').value; @@ -1042,14 +1057,14 @@ } // 입력 필드 초기화 - document.getElementById('modbus_field_input').value = ''; - document.getElementById('modbus_addr_input').value = ''; - document.getElementById('modbus_idt_input').value = ''; - document.getElementById('modbus_odt_input').value = ''; - document.getElementById('modbus_dv_input').value = ''; - document.getElementById('modbus_shift_input').value = ''; - document.getElementById('modbus_expr_input').value = ''; - document.getElementById('modbus_mask_input').value = ''; + document.getElementById('opcua_field_input').value = ''; + document.getElementById('opcua_addr_input').value = ''; + document.getElementById('opcua_ns_input').value = ''; + document.getElementById('opcua_odt_input').value = ''; + document.getElementById('opcua_dv_input').value = ''; + document.getElementById('opcua_shift_input').value = ''; + document.getElementById('opcua_expr_input').value = ''; + document.getElementById('opcua_mask_input').value = ''; }); @@ -1093,15 +1108,32 @@ const expr = document.getElementById('can_expr_input').value; const mask = document.getElementById('can_mask_input').value; const canRowTemplate = document.getElementById('can-row-template'); - const newRow = canRowTemplate.content.cloneNode(true); - newRow.querySelector('.can-field-display').textContent = field; - newRow.querySelector('.can-id-display').textContent = id; - newRow.querySelector('.can-odt-display').textContent = odt; - newRow.querySelector('.can-dv-display').textContent = dv; - newRow.querySelector('.can-shift-display').textContent = shift; - newRow.querySelector('.can-expr-display').textContent = expr; - newRow.querySelector('.can-mask-display').textContent = mask; - canFieldList.appendChild(newRow); + const firstRow = canFieldList.querySelector('tr'); + + // 첫 행이 비어있다면 그 자리에 값을 넣기 + if (firstRow && firstRow.querySelector('.can-field-display').textContent.trim() === '') { + firstRow.querySelector('.can-field-display').textContent = field; + firstRow.querySelector('.can-id-display').textContent = id; + firstRow.querySelector('.can-odt-display').textContent = odt; + firstRow.querySelector('.can-dv-display').textContent = dv; + firstRow.querySelector('.can-shift-display').textContent = shift; + firstRow.querySelector('.can-expr-display').textContent = expr; + firstRow.querySelector('.can-mask-display').textContent = mask; + } else { + // 새로운 행을 추가 + const newRow = canRowTemplate.content.cloneNode(true); + newRow.querySelector('.can-field-display').textContent = field; + newRow.querySelector('.can-id-display').textContent = id; + newRow.querySelector('.can-odt-display').textContent = odt; + newRow.querySelector('.can-dv-display').textContent = dv; + newRow.querySelector('.can-shift-display').textContent = shift; + newRow.querySelector('.can-expr-display').textContent = expr; + newRow.querySelector('.can-mask-display').textContent = mask; + + canFieldList.appendChild(newRow); + } + + // 입력 필드 초기화 document.getElementById('can_field_input').value = ''; document.getElementById('can_id_input').value = ''; document.getElementById('can_odt_input').value = ''; @@ -1424,7 +1456,7 @@ console.warn(`Protocol load failed: HTTP ${protocolResponse.status}`); } } catch (error) { - console.error('Protocol load failed:', error.message); + console.error('./Protocol load failed:', error.message); } } /*-----------------------------------------------------*/