From 830064426721d21cf92b5642f5c62edf8813ea06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=ED=98=95?= <147372294+blissyou@users.noreply.github.com> Date: Mon, 30 Jun 2025 15:01:58 +0900 Subject: [PATCH] =?UTF-8?q?save=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/index.html | 57 +++++++++++++++------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 8a31eff..84443c1 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -2055,42 +2055,45 @@ } function saveToConfig() { - fetch('http://localhost:8080/setting/device',{ - method: 'POST', - headers: {'Content-Type': 'application/json'}, - body: JSON.stringify(collectData()) - }).then(res => { - if(!res.ok) { - alert('전송 실패') - } - }).catch(()=>{ - alert('device 설정 전송 중 통신 오류 발생'); - }); - - const isConfigValid = isValidRegisterConfig(collectConfigData()); + const deviceData = collectData(); + const protocolData = collectConfigData(); - if (!isConfigValid) { - // 유효성 검사에 실패하면 경고 메시지를 띄우고 함수 실행을 중단합니다. + if (!isValidRegisterConfig(protocolData)) { alert("현재 Register 설정이 유효하지 않습니다. 저장할 수 없습니다. 콘솔을 확인하세요."); - return; // 여기서 저장을 중단하고 다음 코드를 실행하지 않습니다. + return; } - fetch('http://localhost:8080/setting/protocol', { + + // 두 개의 fetch를 병렬 실행 + const deviceReq = fetch('http://localhost:8080/setting/device', { method: 'POST', - headers: {'Content-Type': 'application/json'}, - body: JSON.stringify(collectConfigData()) - }).then(res => { - if (!res.ok) { - alert('Register 설정 전송 실패: ' + res.statusText); + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(deviceData) + }); + + const protocolReq = fetch('http://localhost:8080/setting/protocol', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(protocolData) + }); + + // 모든 요청이 성공하면 성공 알림 + Promise.all([deviceReq, protocolReq]) + .then(([res1, res2]) => { + if (res1.ok && res2.ok) { + alert('saved successfully'); + } else { + alert('save failure'); + console.error('device 응답:', res1.status, 'protocol 응답:', res2.status); } }) - .catch(error => { - console.error('Register 설정 전송 중 오류 발생:', error); // 네트워크 오류 로깅 - alert('Register 설정 전송 중 통신 오류 발생'); - }) - + .catch(err => { + console.error('전송 중 오류 발생:', err); + alert('save failure'); + }); } + document.querySelectorAll('.save-file').forEach(btn=>btn.addEventListener('click', () => {saveToConfig()}))