Browse Source

save 로직 변경

v2
원형 1 year ago
parent
commit
8300644267
  1. 57
      src/main/resources/static/index.html

57
src/main/resources/static/index.html

@ -2055,42 +2055,45 @@
} }
function saveToConfig() { function saveToConfig() {
fetch('http://localhost:8080/setting/device',{ const deviceData = collectData();
method: 'POST', const protocolData = collectConfigData();
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(collectData())
}).then(res => {
if(!res.ok) {
alert('전송 실패')
}
}).catch(()=>{
alert('device 설정 전송 중 통신 오류 발생');
});
const isConfigValid = isValidRegisterConfig(collectConfigData());
if (!isConfigValid) { if (!isValidRegisterConfig(protocolData)) {
// 유효성 검사에 실패하면 경고 메시지를 띄우고 함수 실행을 중단합니다.
alert("현재 Register 설정이 유효하지 않습니다. 저장할 수 없습니다. 콘솔을 확인하세요."); alert("현재 Register 설정이 유효하지 않습니다. 저장할 수 없습니다. 콘솔을 확인하세요.");
return; // 여기서 저장을 중단하고 다음 코드를 실행하지 않습니다. return;
} }
fetch('http://localhost:8080/setting/protocol', {
// 두 개의 fetch를 병렬 실행
const deviceReq = fetch('http://localhost:8080/setting/device', {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json'}, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(collectConfigData()) body: JSON.stringify(deviceData)
}).then(res => { });
if (!res.ok) {
alert('Register 설정 전송 실패: ' + res.statusText); 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 => { .catch(err => {
console.error('Register 설정 전송 중 오류 발생:', error); // 네트워크 오류 로깅 console.error('전송 중 오류 발생:', err);
alert('Register 설정 전송 중 통신 오류 발생'); alert('save failure');
}) });
} }
document.querySelectorAll('.save-file').forEach(btn=>btn.addEventListener('click', () => {saveToConfig()})) document.querySelectorAll('.save-file').forEach(btn=>btn.addEventListener('click', () => {saveToConfig()}))

Loading…
Cancel
Save