Spaces:
Sleeping
Sleeping
init
Browse files- app/app_device_routes.py +86 -2
- app/static/js/app-device.js +326 -136
- app/templates/index.html +11 -0
app/app_device_routes.py
CHANGED
@@ -170,7 +170,7 @@ def register_device_routes(app, login_required, DEVICE_SERVER_URL):
|
|
170 |
}), 502 # Bad Gateway
|
171 |
|
172 |
except requests.exceptions.Timeout:
|
173 |
-
logger.error(f"μ₯μΉ μλ² μ°κ²° νμμμ ({
|
174 |
return jsonify({
|
175 |
"success": False,
|
176 |
"error": "μ₯μΉ μλ² μ°κ²° νμμμ. μλ² μλ΅μ΄ λ무 λ립λλ€."
|
@@ -375,4 +375,88 @@ def register_device_routes(app, login_required, DEVICE_SERVER_URL):
|
|
375 |
return jsonify({
|
376 |
"success": False,
|
377 |
"error": f"νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ: {str(e)}"
|
378 |
-
}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
}), 502 # Bad Gateway
|
171 |
|
172 |
except requests.exceptions.Timeout:
|
173 |
+
logger.error(f"μ₯μΉ μλ² μ°κ²° νμμμ ({get_device_url()})")
|
174 |
return jsonify({
|
175 |
"success": False,
|
176 |
"error": "μ₯μΉ μλ² μ°κ²° νμμμ. μλ² μλ΅μ΄ λ무 λ립λλ€."
|
|
|
375 |
return jsonify({
|
376 |
"success": False,
|
377 |
"error": f"νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ: {str(e)}"
|
378 |
+
}), 500
|
379 |
+
|
380 |
+
|
381 |
+
@app.route('/api/device/execute-custom', methods=['POST'])
|
382 |
+
@login_required
|
383 |
+
def execute_custom_program():
|
384 |
+
"""μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν API"""
|
385 |
+
logger.info("μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μμ²")
|
386 |
+
|
387 |
+
try:
|
388 |
+
# μμ² λ°μ΄ν° νμΈ
|
389 |
+
request_data = request.get_json()
|
390 |
+
if not request_data or 'command' not in request_data:
|
391 |
+
logger.error("λͺ
λ Ήμ΄κ° μ 곡λμ§ μμμ΅λλ€.")
|
392 |
+
return jsonify({
|
393 |
+
"success": False,
|
394 |
+
"error": "μ€νν λͺ
λ Ήμ΄λ₯Ό μ 곡ν΄μ£ΌμΈμ."
|
395 |
+
}), 400 # Bad Request
|
396 |
+
|
397 |
+
command = request_data['command'].strip()
|
398 |
+
if not command:
|
399 |
+
logger.error("λͺ
λ Ήμ΄κ° λΉμ΄ μμ΅λλ€.")
|
400 |
+
return jsonify({
|
401 |
+
"success": False,
|
402 |
+
"error": "μ€νν λͺ
λ Ήμ΄λ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
403 |
+
}), 400 # Bad Request
|
404 |
+
|
405 |
+
# νμ¬ μ₯μΉ μλ² URL κ°μ Έμ€κΈ°
|
406 |
+
current_device_url = get_device_url()
|
407 |
+
api_path = "/api/execute-custom" # LocalPCAgentμ ν΄λΉ API μλν¬μΈνΈκ° μμ΄μΌ ν¨
|
408 |
+
|
409 |
+
logger.info(f"μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μμ²: {current_device_url}{api_path}, λͺ
λ Ήμ΄: {command}")
|
410 |
+
response = requests.post(
|
411 |
+
f"{current_device_url}{api_path}",
|
412 |
+
json={"command": command},
|
413 |
+
timeout=10 # νλ‘κ·Έλ¨ μ€νμλ λ κΈ΄ μκ° λΆμ¬
|
414 |
+
)
|
415 |
+
|
416 |
+
logger.debug(f"μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μλ΅ μν μ½λ: {response.status_code}")
|
417 |
+
|
418 |
+
if response.status_code == 200:
|
419 |
+
try:
|
420 |
+
data = response.json()
|
421 |
+
success = data.get("success", False)
|
422 |
+
message = data.get("message", "")
|
423 |
+
logger.info(f"μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μλ΅: {success}, {message}")
|
424 |
+
return jsonify(data) # μλ² μλ΅ κ·Έλλ‘ λ°ν
|
425 |
+
except requests.exceptions.JSONDecodeError:
|
426 |
+
logger.error("μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μλ΅ JSON νμ± μ€ν¨")
|
427 |
+
return jsonify({
|
428 |
+
"success": False,
|
429 |
+
"error": "μλ²λ‘λΆν° μ ν¨νμ§ μμ JSON μλ΅"
|
430 |
+
}), 502
|
431 |
+
else:
|
432 |
+
error_message = f"μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μμ² μ€ν¨: {response.status_code}"
|
433 |
+
try:
|
434 |
+
error_message += f" - {response.json().get('error', response.text)}"
|
435 |
+
except Exception:
|
436 |
+
error_message += f" - {response.text}"
|
437 |
+
logger.warning(error_message)
|
438 |
+
return jsonify({
|
439 |
+
"success": False,
|
440 |
+
"error": error_message
|
441 |
+
}), 502
|
442 |
+
|
443 |
+
except requests.exceptions.Timeout:
|
444 |
+
logger.error("μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μμ² μκ° μ΄κ³Ό")
|
445 |
+
return jsonify({
|
446 |
+
"success": False,
|
447 |
+
"error": "νλ‘κ·Έλ¨ μ€ν μμ² μκ°μ΄ μ΄κ³Όλμμ΅λλ€."
|
448 |
+
}), 504
|
449 |
+
|
450 |
+
except requests.exceptions.ConnectionError:
|
451 |
+
logger.error("μ₯μΉ κ΄λ¦¬ μλ² μ°κ²° μ€ν¨")
|
452 |
+
return jsonify({
|
453 |
+
"success": False,
|
454 |
+
"error": "μ₯μΉ κ΄λ¦¬ μλ²μ μ°κ²°ν μ μμ΅λλ€. μλ²κ° μ€ν μ€μΈμ§ νμΈν΄μ£ΌμΈμ."
|
455 |
+
}), 503
|
456 |
+
|
457 |
+
except Exception as e:
|
458 |
+
logger.error(f"μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ: {e}", exc_info=True)
|
459 |
+
return jsonify({
|
460 |
+
"success": False,
|
461 |
+
"error": f"νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ: {str(e)}"
|
462 |
+
}), 500
|
app/static/js/app-device.js
CHANGED
@@ -9,72 +9,88 @@ const DeviceControl = {
|
|
9 |
isStatusChecked: false,
|
10 |
isLoadingPrograms: false,
|
11 |
programsList: [],
|
12 |
-
|
13 |
// DOM μμλ€
|
14 |
elements: {
|
15 |
// ν λ° μΉμ
|
16 |
deviceTab: null,
|
17 |
deviceSection: null,
|
18 |
-
|
19 |
// μ°κ²° κ΄λ ¨
|
20 |
deviceServerUrlInput: null,
|
21 |
connectDeviceServerBtn: null,
|
22 |
deviceConnectionStatus: null,
|
23 |
-
|
24 |
// κΈ°λ³Έ κΈ°λ₯
|
25 |
deviceBasicFunctions: null,
|
26 |
checkDeviceStatusBtn: null,
|
27 |
deviceStatusResult: null,
|
28 |
-
|
29 |
-
// νλ‘κ·Έλ¨ μ€ν
|
30 |
-
deviceProgramControl: null,
|
31 |
getProgramsBtn: null,
|
32 |
programsList: null,
|
33 |
programSelectDropdown: null,
|
34 |
executeProgramBtn: null,
|
35 |
-
executeResult: null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
},
|
37 |
-
|
38 |
// λͺ¨λ μ΄κΈ°ν
|
39 |
init: function() {
|
40 |
console.log('μ₯μΉ μ μ΄ λͺ¨λ μ΄κΈ°ν μ€...');
|
41 |
-
|
42 |
// DOM μμ μ°Έμ‘° κ°μ Έμ€κΈ°
|
43 |
this.initElements();
|
44 |
-
|
45 |
// μ΄λ²€νΈ 리μ€λ λ±λ‘
|
46 |
this.initEventListeners();
|
47 |
-
|
48 |
console.log('μ₯μΉ μ μ΄ λͺ¨λ μ΄κΈ°ν μλ£');
|
49 |
},
|
50 |
-
|
51 |
// DOM μμ μ°Έμ‘° μ΄κΈ°ν
|
52 |
initElements: function() {
|
53 |
// ν λ° μΉμ
|
54 |
this.elements.deviceTab = document.getElementById('deviceTab');
|
55 |
this.elements.deviceSection = document.getElementById('deviceSection');
|
56 |
-
|
57 |
// μ°κ²° κ΄λ ¨
|
58 |
this.elements.deviceServerUrlInput = document.getElementById('deviceServerUrlInput');
|
59 |
this.elements.connectDeviceServerBtn = document.getElementById('connectDeviceServerBtn');
|
60 |
this.elements.deviceConnectionStatus = document.getElementById('deviceConnectionStatus');
|
61 |
-
|
62 |
// κΈ°λ³Έ κΈ°λ₯
|
63 |
this.elements.deviceBasicFunctions = document.getElementById('deviceBasicFunctions');
|
64 |
this.elements.checkDeviceStatusBtn = document.getElementById('checkDeviceStatusBtn');
|
65 |
this.elements.deviceStatusResult = document.getElementById('deviceStatusResult');
|
66 |
-
|
67 |
-
// νλ‘κ·Έλ¨ μ€ν
|
68 |
this.elements.deviceProgramControl = document.getElementById('deviceProgramControl');
|
69 |
this.elements.getProgramsBtn = document.getElementById('getProgramsBtn');
|
70 |
this.elements.programsList = document.getElementById('programsList');
|
71 |
this.elements.programSelectDropdown = document.getElementById('programSelectDropdown');
|
72 |
this.elements.executeProgramBtn = document.getElementById('executeProgramBtn');
|
73 |
this.elements.executeResult = document.getElementById('executeResult');
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
console.log('μ₯μΉ μ μ΄ DOM μμ μ°Έμ‘° μ΄κΈ°ν μλ£');
|
76 |
},
|
77 |
-
|
78 |
// μ΄λ²€νΈ 리μ€λ λ±λ‘
|
79 |
initEventListeners: function() {
|
80 |
// ν μ ν
|
@@ -84,7 +100,7 @@ const DeviceControl = {
|
|
84 |
this.switchToDeviceTab();
|
85 |
});
|
86 |
}
|
87 |
-
|
88 |
// μλ² μ°κ²°
|
89 |
if (this.elements.connectDeviceServerBtn) {
|
90 |
this.elements.connectDeviceServerBtn.addEventListener('click', () => {
|
@@ -92,7 +108,7 @@ const DeviceControl = {
|
|
92 |
this.connectServer();
|
93 |
});
|
94 |
}
|
95 |
-
|
96 |
// μν° ν€λ‘ μ°κ²°
|
97 |
if (this.elements.deviceServerUrlInput) {
|
98 |
this.elements.deviceServerUrlInput.addEventListener('keydown', (event) => {
|
@@ -103,7 +119,7 @@ const DeviceControl = {
|
|
103 |
}
|
104 |
});
|
105 |
}
|
106 |
-
|
107 |
// μ₯μΉ μν νμΈ
|
108 |
if (this.elements.checkDeviceStatusBtn) {
|
109 |
this.elements.checkDeviceStatusBtn.addEventListener('click', () => {
|
@@ -111,7 +127,7 @@ const DeviceControl = {
|
|
111 |
this.checkDeviceStatus();
|
112 |
});
|
113 |
}
|
114 |
-
|
115 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν
|
116 |
if (this.elements.getProgramsBtn) {
|
117 |
this.elements.getProgramsBtn.addEventListener('click', () => {
|
@@ -119,7 +135,7 @@ const DeviceControl = {
|
|
119 |
this.loadProgramsList();
|
120 |
});
|
121 |
}
|
122 |
-
|
123 |
// νλ‘κ·Έλ¨ μ ν λ³κ²½
|
124 |
if (this.elements.programSelectDropdown) {
|
125 |
this.elements.programSelectDropdown.addEventListener('change', (event) => {
|
@@ -127,76 +143,102 @@ const DeviceControl = {
|
|
127 |
this.updateExecuteButton();
|
128 |
});
|
129 |
}
|
130 |
-
|
131 |
-
// νλ‘κ·Έλ¨ μ€ν
|
132 |
if (this.elements.executeProgramBtn) {
|
133 |
this.elements.executeProgramBtn.addEventListener('click', () => {
|
134 |
const programId = this.elements.programSelectDropdown.value;
|
135 |
-
console.log(
|
136 |
this.executeProgram(programId);
|
137 |
});
|
138 |
}
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
console.log('μ₯μΉ μ μ΄ μ΄λ²€νΈ 리μ€λ λ±λ‘ μλ£');
|
141 |
},
|
142 |
-
|
143 |
// μ₯μΉ μ μ΄ νμΌλ‘ μ ν
|
144 |
switchToDeviceTab: function() {
|
145 |
// λͺ¨λ νκ³Ό ν μ½ν
μΈ λΉνμ±ν
|
146 |
const tabs = document.querySelectorAll('.tab');
|
147 |
const tabContents = document.querySelectorAll('.tab-content');
|
148 |
-
|
149 |
tabs.forEach(tab => tab.classList.remove('active'));
|
150 |
tabContents.forEach(content => content.classList.remove('active'));
|
151 |
-
|
152 |
// μ₯μΉ μ μ΄ ν νμ±ν
|
153 |
this.elements.deviceTab.classList.add('active');
|
154 |
this.elements.deviceSection.classList.add('active');
|
155 |
-
|
156 |
console.log('μ₯μΉ μ μ΄ νμΌλ‘ μ ν μλ£');
|
157 |
},
|
158 |
-
|
159 |
// μλ² μ°κ²° ν¨μ
|
160 |
connectServer: async function() {
|
161 |
// URL κ°μ Έμ€κΈ° (μ
λ ₯λ κ²μ΄ μμΌλ©΄ λ°±μ
μΌλ‘ μ¬μ©)
|
162 |
const inputUrl = this.elements.deviceServerUrlInput.value.trim();
|
163 |
-
|
164 |
// μ°κ²° μλ μ€ UI μ
λ°μ΄νΈ
|
165 |
this.elements.connectDeviceServerBtn.disabled = true;
|
166 |
this.updateConnectionStatus('connecting', 'νκ²½λ³μμ μ μ₯λ μλ²λ‘ μ°κ²° μλ μ€...');
|
167 |
-
|
168 |
try {
|
169 |
console.log('νκ²½λ³μμ μ μ₯λ μ₯μΉ μλ²λ‘ μ°κ²° μλ');
|
170 |
-
|
171 |
// λ°±μλ API νΈμΆνμ¬ μλ² μν νμΈ
|
172 |
const response = await AppUtils.fetchWithTimeout('/api/device/status', {
|
173 |
method: 'GET'
|
174 |
}, 10000); // 10μ΄ νμμμ
|
175 |
-
|
176 |
const data = await response.json();
|
177 |
-
|
178 |
if (response.ok && data.success) {
|
179 |
// μ°κ²° μ±κ³΅
|
180 |
console.log('νκ²½λ³μ μ€μ μ₯μΉ μλ² μ°κ²° μ±κ³΅:', data);
|
181 |
this.isConnected = true;
|
182 |
this.updateConnectionStatus('connected', `μλ² μ°κ²° μ±κ³΅! μν: ${data.server_status || 'μ μ'}`);
|
183 |
-
|
184 |
// κΈ°λ₯ UI νμ±ν
|
185 |
-
this.elements.deviceBasicFunctions.classList.add('active');
|
186 |
-
this.elements.deviceProgramControl.classList.add('active');
|
187 |
-
|
|
|
|
|
|
|
188 |
// μ₯μΉ μν μλ 체ν¬
|
189 |
this.checkDeviceStatus();
|
190 |
-
|
191 |
// νλ‘κ·Έλ¨ λͺ©οΏ½οΏ½ μλ λ‘λ
|
192 |
this.loadProgramsList();
|
193 |
-
|
194 |
// μμ€ν
μλ¦Ό
|
195 |
AppUtils.addSystemNotification(`μ₯μΉ κ΄λ¦¬ μλ² μ°κ²° μ±κ³΅! (νκ²½λ³μ URL)`);
|
196 |
} else {
|
197 |
// νκ²½λ³μ URL μ°κ²° μ€ν¨, μ
λ ₯λ URLλ‘ μλ
|
198 |
console.warn('νκ²½λ³μ μ€μ μ₯μΉ μλ² μ°κ²° μ€ν¨, μ
λ ₯ URLλ‘ μ¬μλν©λλ€:', data);
|
199 |
-
|
200 |
// μ
λ ₯ URLμ΄ μλμ§ νμΈ
|
201 |
if (!inputUrl) {
|
202 |
console.error('μ
λ ₯λ URLμ΄ μμ΄ μ°κ²° μ€ν¨');
|
@@ -204,11 +246,11 @@ const DeviceControl = {
|
|
204 |
this.updateConnectionStatus('error', 'νκ²½λ³μ URL μ°κ²° μ€ν¨ λ° μ
λ ₯λ URLμ΄ μμ΅λλ€. URLμ μ
λ ₯ν΄μ£ΌμΈμ.');
|
205 |
return;
|
206 |
}
|
207 |
-
|
208 |
// μ
λ ₯ URLλ‘ μ¬μλ
|
209 |
this.updateConnectionStatus('connecting', `μ
λ ₯ URL(${inputUrl})λ‘ μ°κ²° μλ μ€...`);
|
210 |
console.log(`μ
λ ₯ν URLλ‘ μ₯μΉ μλ² μ°κ²° μλ: ${inputUrl}`);
|
211 |
-
|
212 |
// λ°±μλ API νΈμΆ - μ
λ ₯ URL μ¬μ©
|
213 |
const customUrlResponse = await AppUtils.fetchWithTimeout('/api/device/connect', {
|
214 |
method: 'POST',
|
@@ -217,25 +259,29 @@ const DeviceControl = {
|
|
217 |
},
|
218 |
body: JSON.stringify({ url: inputUrl })
|
219 |
}, 10000);
|
220 |
-
|
221 |
const customUrlData = await customUrlResponse.json();
|
222 |
-
|
223 |
if (customUrlResponse.ok && customUrlData.success) {
|
224 |
// μ
λ ₯ URL μ°κ²° μ±κ³΅
|
225 |
console.log('μ
λ ₯ URL μ₯μΉ μλ² μ°κ²° μ±κ³΅:', customUrlData);
|
226 |
this.isConnected = true;
|
227 |
this.updateConnectionStatus('connected', `μλ² μ°κ²° μ±κ³΅! μν: ${customUrlData.server_status || 'μ μ'}`);
|
228 |
-
|
229 |
// κΈ°λ₯ UI νμ±ν
|
230 |
-
this.elements.deviceBasicFunctions.classList.add('active');
|
231 |
-
this.elements.deviceProgramControl.classList.add('active');
|
232 |
-
|
|
|
|
|
|
|
|
|
233 |
// μ₯μΉ μν μλ 체ν¬
|
234 |
this.checkDeviceStatus();
|
235 |
-
|
236 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μλ λ‘λ
|
237 |
this.loadProgramsList();
|
238 |
-
|
239 |
// μμ€ν
μλ¦Ό
|
240 |
AppUtils.addSystemNotification(`μ₯μΉ κ΄λ¦¬ μλ² μ°κ²° μ±κ³΅! (${inputUrl})`);
|
241 |
} else {
|
@@ -249,16 +295,16 @@ const DeviceControl = {
|
|
249 |
// μμΈ λ°μ
|
250 |
console.error('μλ² μ°κ²° μ€ μ€λ₯ λ°μ:', error);
|
251 |
this.isConnected = false;
|
252 |
-
|
253 |
// νκ²½λ³μ URL μ°κ²° μ€ν¨, μ
λ ₯λ URLλ‘ μλ
|
254 |
if (inputUrl) {
|
255 |
console.warn('νκ²½λ³μ URL μ°κ²° μ μ€λ₯ λ°μ, μ
λ ₯ URLλ‘ μ¬μλν©λλ€');
|
256 |
-
|
257 |
try {
|
258 |
// μ
λ ₯ URLλ‘ μ¬μλ
|
259 |
this.updateConnectionStatus('connecting', `μ
λ ₯ URL(${inputUrl})λ‘ μ°κ²° μλ μ€...`);
|
260 |
console.log(`μ
λ ₯ν URLλ‘ μ₯μΉ μλ² μ°κ²° μλ: ${inputUrl}`);
|
261 |
-
|
262 |
// λ°±μλ API νΈμΆ - μ
λ ₯ URL μ¬μ©
|
263 |
const customUrlResponse = await AppUtils.fetchWithTimeout('/api/device/connect', {
|
264 |
method: 'POST',
|
@@ -267,25 +313,29 @@ const DeviceControl = {
|
|
267 |
},
|
268 |
body: JSON.stringify({ url: inputUrl })
|
269 |
}, 10000);
|
270 |
-
|
271 |
const customUrlData = await customUrlResponse.json();
|
272 |
-
|
273 |
if (customUrlResponse.ok && customUrlData.success) {
|
274 |
// μ
λ ₯ URL μ°κ²° μ±κ³΅
|
275 |
console.log('μ
λ ₯ URL μ₯μΉ μλ² μ°κ²° μ±κ³΅:', customUrlData);
|
276 |
this.isConnected = true;
|
277 |
this.updateConnectionStatus('connected', `μλ² μ°κ²° μ±κ³΅! μν: ${customUrlData.server_status || 'μ μ'}`);
|
278 |
-
|
279 |
// κΈ°λ₯ UI νμ±ν
|
280 |
-
this.elements.deviceBasicFunctions.classList.add('active');
|
281 |
-
this.elements.deviceProgramControl.classList.add('active');
|
282 |
-
|
|
|
|
|
|
|
|
|
283 |
// μ₯μΉ μν μλ 체ν¬
|
284 |
this.checkDeviceStatus();
|
285 |
-
|
286 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μλ λ‘λ
|
287 |
this.loadProgramsList();
|
288 |
-
|
289 |
// μμ€ν
μλ¦Ό
|
290 |
AppUtils.addSystemNotification(`μ₯μΉ κ΄λ¦¬ μλ² μ°κ²° μ±κ³΅! (${inputUrl})`);
|
291 |
return; // μ±κ³΅νλ©΄ μ¬κΈ°μ μ’
λ£
|
@@ -297,7 +347,7 @@ const DeviceControl = {
|
|
297 |
} catch (inputUrlError) {
|
298 |
// μ
λ ₯ URLλ‘ μ¬μλ μ€ μ€λ₯
|
299 |
console.error('μ
λ ₯ URLλ‘ μ¬μλ μ€ μ€λ₯ λ°μ:', inputUrlError);
|
300 |
-
|
301 |
if (inputUrlError.message.includes('μκ°μ΄ μ΄κ³Ό')) {
|
302 |
this.updateConnectionStatus('error', 'μλ² μ°κ²° μκ° μ΄κ³Ό. μλ²κ° μ€ν μ€μΈμ§ νμΈν΄μ£ΌμΈμ.');
|
303 |
} else {
|
@@ -317,23 +367,24 @@ const DeviceControl = {
|
|
317 |
this.elements.connectDeviceServerBtn.disabled = false;
|
318 |
}
|
319 |
},
|
320 |
-
|
321 |
// μ°κ²° μν μ
λ°μ΄νΈ
|
322 |
updateConnectionStatus: function(status, message) {
|
323 |
const statusElement = this.elements.deviceConnectionStatus;
|
324 |
-
|
|
|
325 |
// λͺ¨λ μν ν΄λμ€ μ κ±°
|
326 |
statusElement.classList.remove('connected', 'disconnected', 'error', 'connecting');
|
327 |
-
|
328 |
// μνμ λ°λΌ ν΄λμ€ μΆκ°
|
329 |
statusElement.classList.add(status);
|
330 |
-
|
331 |
// λ©μμ§ μ
λ°μ΄νΈ
|
332 |
statusElement.textContent = message;
|
333 |
-
|
334 |
console.log(`μ°κ²° μν μ
λ°μ΄νΈ: ${status} - ${message}`);
|
335 |
},
|
336 |
-
|
337 |
// μ₯μΉ μν νμΈ
|
338 |
checkDeviceStatus: async function() {
|
339 |
if (!this.isConnected) {
|
@@ -341,26 +392,27 @@ const DeviceControl = {
|
|
341 |
console.error('μ₯μΉ μν νμΈ μλ μ€ μ€λ₯: μλ² μ°κ²° μλ¨');
|
342 |
return;
|
343 |
}
|
344 |
-
|
345 |
// μν νμΈ μ€ UI μ
λ°μ΄νΈ
|
346 |
this.elements.checkDeviceStatusBtn.disabled = true;
|
347 |
this.elements.deviceStatusResult.value = 'μ₯μΉ μν νμΈ μ€...';
|
348 |
-
|
349 |
try {
|
350 |
console.log('μ₯μΉ μν νμΈ μμ² μ μ‘');
|
351 |
-
|
352 |
// λ°±μλ API νΈμΆ
|
353 |
const response = await AppUtils.fetchWithTimeout('/api/device/status', {
|
354 |
method: 'GET'
|
355 |
});
|
356 |
-
|
357 |
const data = await response.json();
|
358 |
-
|
359 |
if (response.ok && data.success) {
|
360 |
// μν νμΈ μ±κ³΅
|
361 |
console.log('μ₯μΉ μν νμΈ μ±κ³΅:', data);
|
362 |
this.isStatusChecked = true;
|
363 |
-
|
|
|
364 |
} else {
|
365 |
// μν νμΈ μ€ν¨
|
366 |
console.error('μ₯μΉ μν νμΈ μ€ν¨:', data);
|
@@ -375,7 +427,7 @@ const DeviceControl = {
|
|
375 |
this.elements.checkDeviceStatusBtn.disabled = false;
|
376 |
}
|
377 |
},
|
378 |
-
|
379 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν
|
380 |
loadProgramsList: async function() {
|
381 |
if (!this.isConnected) {
|
@@ -383,43 +435,46 @@ const DeviceControl = {
|
|
383 |
console.error('νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν μλ μ€ μ€λ₯: μλ² μ°κ²° μλ¨');
|
384 |
return;
|
385 |
}
|
386 |
-
|
387 |
// μ΄λ―Έ λ‘λ© μ€μ΄λ©΄ μ€λ³΅ μμ² λ°©μ§
|
388 |
if (this.isLoadingPrograms) {
|
389 |
console.log('μ΄λ―Έ νλ‘κ·Έλ¨ λͺ©λ‘ λ‘λ© μ€');
|
390 |
return;
|
391 |
}
|
392 |
-
|
393 |
// λ‘λ© μ€ UI μ
λ°μ΄νΈ
|
394 |
this.isLoadingPrograms = true;
|
395 |
-
this.elements.getProgramsBtn.disabled = true;
|
396 |
-
this.elements.programsList
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
|
|
|
|
|
|
402 |
try {
|
403 |
console.log('νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν μμ² μ μ‘');
|
404 |
-
|
405 |
// λ°±μλ API νΈμΆ
|
406 |
const response = await AppUtils.fetchWithTimeout('/api/device/programs', {
|
407 |
method: 'GET'
|
408 |
});
|
409 |
-
|
410 |
const data = await response.json();
|
411 |
-
|
412 |
if (response.ok && data.success) {
|
413 |
// λͺ©λ‘ μ‘°ν μ±κ³΅
|
414 |
console.log('νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν μ±κ³΅:', data);
|
415 |
this.programsList = data.programs || [];
|
416 |
-
|
417 |
// λͺ©λ‘ νμ
|
418 |
this.displayProgramsList();
|
419 |
-
|
420 |
// λλ‘λ€μ΄ μ
λ°μ΄νΈ
|
421 |
this.updateProgramsDropdown();
|
422 |
-
|
423 |
// μ€ν λ²νΌ μν μ
λ°μ΄νΈ
|
424 |
this.updateExecuteButton();
|
425 |
} else {
|
@@ -434,14 +489,15 @@ const DeviceControl = {
|
|
434 |
} finally {
|
435 |
// λ‘λ© μν λ° λ²νΌ μν 볡μ
|
436 |
this.isLoadingPrograms = false;
|
437 |
-
|
438 |
}
|
439 |
},
|
440 |
-
|
441 |
// νλ‘κ·Έλ¨ λͺ©λ‘ νμ
|
442 |
displayProgramsList: function() {
|
443 |
const programsListElement = this.elements.programsList;
|
444 |
-
|
|
|
445 |
if (!this.programsList || this.programsList.length === 0) {
|
446 |
programsListElement.innerHTML = `
|
447 |
<div class="no-programs-message">
|
@@ -450,7 +506,7 @@ const DeviceControl = {
|
|
450 |
`;
|
451 |
return;
|
452 |
}
|
453 |
-
|
454 |
// ν
μ΄λΈ ννλ‘ νλ‘κ·Έλ¨ λͺ©λ‘ νμ
|
455 |
let html = `
|
456 |
<table class="program-list">
|
@@ -463,7 +519,7 @@ const DeviceControl = {
|
|
463 |
</thead>
|
464 |
<tbody>
|
465 |
`;
|
466 |
-
|
467 |
// νλ‘κ·Έλ¨ νλͺ© μμ±
|
468 |
this.programsList.forEach(program => {
|
469 |
html += `
|
@@ -474,7 +530,7 @@ const DeviceControl = {
|
|
474 |
</tr>
|
475 |
`;
|
476 |
});
|
477 |
-
|
478 |
html += `
|
479 |
</tbody>
|
480 |
</table>
|
@@ -482,17 +538,18 @@ const DeviceControl = {
|
|
482 |
μ΄ ${this.programsList.length}κ° νλ‘κ·Έλ¨
|
483 |
</div>
|
484 |
`;
|
485 |
-
|
486 |
programsListElement.innerHTML = html;
|
487 |
},
|
488 |
-
|
489 |
// νλ‘κ·Έλ¨ λλ‘λ€μ΄ μ
λ°μ΄νΈ
|
490 |
updateProgramsDropdown: function() {
|
491 |
const dropdown = this.elements.programSelectDropdown;
|
492 |
-
|
|
|
493 |
// κΈ°μ‘΄ μ΅μ
μ κ±°
|
494 |
dropdown.innerHTML = '';
|
495 |
-
|
496 |
// κΈ°λ³Έ μ΅μ
μΆκ°
|
497 |
const defaultOption = document.createElement('option');
|
498 |
defaultOption.value = '';
|
@@ -500,52 +557,53 @@ const DeviceControl = {
|
|
500 |
? '-- μ€νν νλ‘κ·Έλ¨ μ ν --'
|
501 |
: '-- νλ‘κ·Έλ¨ μμ --';
|
502 |
dropdown.appendChild(defaultOption);
|
503 |
-
|
504 |
// νλ‘κ·Έλ¨ μ΅μ
μΆκ°
|
505 |
this.programsList.forEach(program => {
|
506 |
const option = document.createElement('option');
|
507 |
option.value = program.id || '';
|
508 |
option.textContent = program.name || 'μ μ μμ';
|
509 |
-
|
510 |
// μ€λͺ
μ΄ μμΌλ©΄ κ΄νΈλ‘ μΆκ°
|
511 |
if (program.description) {
|
512 |
option.textContent += ` (${program.description})`;
|
513 |
}
|
514 |
-
|
515 |
dropdown.appendChild(option);
|
516 |
});
|
517 |
},
|
518 |
-
|
519 |
// μ€ν λ²νΌ μν μ
λ°μ΄νΈ
|
520 |
updateExecuteButton: function() {
|
521 |
const dropdown = this.elements.programSelectDropdown;
|
522 |
const executeBtn = this.elements.executeProgramBtn;
|
523 |
-
|
|
|
524 |
// μ νλ νλ‘κ·Έλ¨μ΄ μμ λλ§ λ²νΌ νμ±ν
|
525 |
executeBtn.disabled = !dropdown.value;
|
526 |
},
|
527 |
-
|
528 |
-
// νλ‘κ·Έλ¨ μ€ν
|
529 |
executeProgram: async function(programId) {
|
530 |
if (!this.isConnected) {
|
531 |
this.showExecuteResult('error', 'μ€λ₯: λ¨Όμ μλ²μ μ°κ²°ν΄μΌ ν©λλ€.');
|
532 |
console.error('νλ‘κ·Έλ¨ μ€ν μλ μ€ μ€λ₯: μλ² μ°κ²° μλ¨');
|
533 |
return;
|
534 |
}
|
535 |
-
|
536 |
if (!programId) {
|
537 |
this.showExecuteResult('error', 'μ€λ₯: μ€νν νλ‘κ·Έλ¨μ μ νν΄μ£ΌμΈμ.');
|
538 |
console.error('νλ‘κ·Έλ¨ μ€ν μλ μ€ μ€λ₯: νλ‘κ·Έλ¨ ID μμ');
|
539 |
return;
|
540 |
}
|
541 |
-
|
542 |
// μ€ν μ€ UI μ
λ°μ΄νΈ
|
543 |
-
this.elements.executeProgramBtn.disabled = true;
|
544 |
this.showExecuteResult('loading', 'νλ‘κ·Έλ¨ μ€ν μ€...');
|
545 |
-
|
546 |
try {
|
547 |
console.log(`νλ‘κ·Έλ¨ μ€ν μμ² μ μ‘: ${programId}`);
|
548 |
-
|
549 |
// λ°±μλ API νΈμΆ
|
550 |
const response = await AppUtils.fetchWithTimeout(`/api/device/programs/${programId}/execute`, {
|
551 |
method: 'POST',
|
@@ -554,14 +612,14 @@ const DeviceControl = {
|
|
554 |
},
|
555 |
body: JSON.stringify({})
|
556 |
}, 15000); // 15μ΄ νμμμ (μ€νμ μκ°μ΄ λ 걸릴 μ μμ)
|
557 |
-
|
558 |
const data = await response.json();
|
559 |
-
|
560 |
if (response.ok && data.success) {
|
561 |
// μ€ν μ±κ³΅
|
562 |
console.log('νλ‘κ·Έλ¨ μ€ν μ±κ³΅:', data);
|
563 |
this.showExecuteResult('success', `μ€ν μ±κ³΅: ${data.message || 'νλ‘κ·Έλ¨μ΄ μ±κ³΅μ μΌλ‘ μ€νλμμ΅λλ€.'}`);
|
564 |
-
|
565 |
// μμ€ν
μλ¦Ό
|
566 |
AppUtils.addSystemNotification(`νλ‘κ·Έλ¨ μ€ν μ±κ³΅: ${this.getSelectedProgramName()}`);
|
567 |
} else {
|
@@ -572,7 +630,7 @@ const DeviceControl = {
|
|
572 |
} catch (error) {
|
573 |
// μμΈ λ°μ
|
574 |
console.error('νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ:', error);
|
575 |
-
|
576 |
if (error.message.includes('μκ°μ΄ μ΄κ³Ό')) {
|
577 |
this.showExecuteResult('error', 'νλ‘κ·Έλ¨ μ€ν μμ² μκ° μ΄κ³Ό. μλ² μλ΅μ΄ μμ΅λλ€.');
|
578 |
} else {
|
@@ -580,20 +638,24 @@ const DeviceControl = {
|
|
580 |
}
|
581 |
} finally {
|
582 |
// λ²νΌ λ€μ νμ±ν
|
583 |
-
this.elements.executeProgramBtn.disabled = false;
|
584 |
}
|
585 |
},
|
586 |
-
|
587 |
// μ νλ νλ‘κ·Έλ¨ μ΄λ¦ κ°μ Έμ€κΈ°
|
588 |
getSelectedProgramName: function() {
|
589 |
const dropdown = this.elements.programSelectDropdown;
|
|
|
590 |
const selectedOption = dropdown.options[dropdown.selectedIndex];
|
591 |
return selectedOption ? selectedOption.textContent : 'μ μ μλ νλ‘κ·Έλ¨';
|
592 |
},
|
593 |
-
|
594 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μ€λ₯ νμ
|
595 |
showProgramsError: function(errorMessage) {
|
596 |
-
this.elements.programsList
|
|
|
|
|
|
|
597 |
<div class="error-message">
|
598 |
<i class="fas fa-exclamation-circle"></i> ${errorMessage}
|
599 |
<button class="retry-button" id="retryLoadProgramsBtn">
|
@@ -601,24 +663,31 @@ const DeviceControl = {
|
|
601 |
</button>
|
602 |
</div>
|
603 |
`;
|
604 |
-
|
605 |
// μ¬μλ λ²νΌ μ΄λ²€νΈ 리μ€λ
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
610 |
},
|
611 |
-
|
612 |
-
// μ€ν κ²°κ³Ό νμ
|
613 |
showExecuteResult: function(status, message) {
|
614 |
const resultElement = this.elements.executeResult;
|
615 |
-
|
|
|
616 |
// λͺ¨λ μν ν΄λμ€ μ κ±°
|
617 |
resultElement.classList.remove('success', 'error', 'warning');
|
618 |
-
|
619 |
// λ΄μ© μ΄κΈ°ν
|
620 |
resultElement.innerHTML = '';
|
621 |
-
|
622 |
// μνμ λ°λΌ μ²λ¦¬
|
623 |
switch (status) {
|
624 |
case 'success':
|
@@ -639,15 +708,136 @@ const DeviceControl = {
|
|
639 |
default:
|
640 |
resultElement.textContent = message;
|
641 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
}
|
|
|
643 |
};
|
644 |
|
645 |
// νμ΄μ§ λ‘λ μλ£ μ λͺ¨λ μ΄κΈ°ν
|
646 |
document.addEventListener('DOMContentLoaded', function() {
|
647 |
console.log('μ₯μΉ μ μ΄ λͺ¨λ λ‘λλ¨');
|
648 |
-
|
649 |
// DOMμ΄ μμ ν λ‘λλ ν μ½κ°μ μ§μ°μ λκ³ μ΄κΈ°ν
|
|
|
650 |
setTimeout(() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
651 |
DeviceControl.init();
|
652 |
}, 100);
|
653 |
-
});
|
|
|
9 |
isStatusChecked: false,
|
10 |
isLoadingPrograms: false,
|
11 |
programsList: [],
|
12 |
+
|
13 |
// DOM μμλ€
|
14 |
elements: {
|
15 |
// ν λ° μΉμ
|
16 |
deviceTab: null,
|
17 |
deviceSection: null,
|
18 |
+
|
19 |
// μ°κ²° κ΄λ ¨
|
20 |
deviceServerUrlInput: null,
|
21 |
connectDeviceServerBtn: null,
|
22 |
deviceConnectionStatus: null,
|
23 |
+
|
24 |
// κΈ°λ³Έ κΈ°λ₯
|
25 |
deviceBasicFunctions: null,
|
26 |
checkDeviceStatusBtn: null,
|
27 |
deviceStatusResult: null,
|
28 |
+
|
29 |
+
// νλ‘κ·Έλ¨ μ€ν (미리 μ μλ)
|
30 |
+
deviceProgramControl: null, // μ΄ μμκ° μ μλμ΄ μλμ§ νμΈ νμ
|
31 |
getProgramsBtn: null,
|
32 |
programsList: null,
|
33 |
programSelectDropdown: null,
|
34 |
executeProgramBtn: null,
|
35 |
+
executeResult: null,
|
36 |
+
|
37 |
+
// ================== μΆκ° μμ 1/4 ==================
|
38 |
+
// μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν
|
39 |
+
deviceCustomControl: null,
|
40 |
+
customCommandInput: null,
|
41 |
+
executeCustomBtn: null,
|
42 |
+
customExecuteResult: null
|
43 |
+
// ================== μΆκ° λ 1/4 ====================
|
44 |
},
|
45 |
+
|
46 |
// λͺ¨λ μ΄κΈ°ν
|
47 |
init: function() {
|
48 |
console.log('μ₯μΉ μ μ΄ λͺ¨λ μ΄κΈ°ν μ€...');
|
49 |
+
|
50 |
// DOM μμ μ°Έμ‘° κ°μ Έμ€κΈ°
|
51 |
this.initElements();
|
52 |
+
|
53 |
// μ΄λ²€νΈ 리μ€λ λ±λ‘
|
54 |
this.initEventListeners();
|
55 |
+
|
56 |
console.log('μ₯μΉ μ μ΄ λͺ¨λ μ΄κΈ°ν μλ£');
|
57 |
},
|
58 |
+
|
59 |
// DOM μμ μ°Έμ‘° μ΄κΈ°ν
|
60 |
initElements: function() {
|
61 |
// ν λ° μΉμ
|
62 |
this.elements.deviceTab = document.getElementById('deviceTab');
|
63 |
this.elements.deviceSection = document.getElementById('deviceSection');
|
64 |
+
|
65 |
// μ°κ²° κ΄λ ¨
|
66 |
this.elements.deviceServerUrlInput = document.getElementById('deviceServerUrlInput');
|
67 |
this.elements.connectDeviceServerBtn = document.getElementById('connectDeviceServerBtn');
|
68 |
this.elements.deviceConnectionStatus = document.getElementById('deviceConnectionStatus');
|
69 |
+
|
70 |
// κΈ°λ³Έ κΈ°λ₯
|
71 |
this.elements.deviceBasicFunctions = document.getElementById('deviceBasicFunctions');
|
72 |
this.elements.checkDeviceStatusBtn = document.getElementById('checkDeviceStatusBtn');
|
73 |
this.elements.deviceStatusResult = document.getElementById('deviceStatusResult');
|
74 |
+
|
75 |
+
// νλ‘κ·Έλ¨ μ€ν (미리 μ μλ)
|
76 |
this.elements.deviceProgramControl = document.getElementById('deviceProgramControl');
|
77 |
this.elements.getProgramsBtn = document.getElementById('getProgramsBtn');
|
78 |
this.elements.programsList = document.getElementById('programsList');
|
79 |
this.elements.programSelectDropdown = document.getElementById('programSelectDropdown');
|
80 |
this.elements.executeProgramBtn = document.getElementById('executeProgramBtn');
|
81 |
this.elements.executeResult = document.getElementById('executeResult');
|
82 |
+
|
83 |
+
// ================== μΆκ° μμ 2/4 ==================
|
84 |
+
// μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν
|
85 |
+
this.elements.deviceCustomControl = document.getElementById('deviceCustomControl');
|
86 |
+
this.elements.customCommandInput = document.getElementById('customCommandInput');
|
87 |
+
this.elements.executeCustomBtn = document.getElementById('executeCustomBtn');
|
88 |
+
this.elements.customExecuteResult = document.getElementById('customExecuteResult');
|
89 |
+
// ================== μΆκ° λ 2/4 ====================
|
90 |
+
|
91 |
console.log('μ₯μΉ μ μ΄ DOM μμ μ°Έμ‘° μ΄κΈ°ν μλ£');
|
92 |
},
|
93 |
+
|
94 |
// μ΄λ²€νΈ 리μ€λ λ±λ‘
|
95 |
initEventListeners: function() {
|
96 |
// ν μ ν
|
|
|
100 |
this.switchToDeviceTab();
|
101 |
});
|
102 |
}
|
103 |
+
|
104 |
// μλ² μ°κ²°
|
105 |
if (this.elements.connectDeviceServerBtn) {
|
106 |
this.elements.connectDeviceServerBtn.addEventListener('click', () => {
|
|
|
108 |
this.connectServer();
|
109 |
});
|
110 |
}
|
111 |
+
|
112 |
// μν° ν€λ‘ μ°κ²°
|
113 |
if (this.elements.deviceServerUrlInput) {
|
114 |
this.elements.deviceServerUrlInput.addEventListener('keydown', (event) => {
|
|
|
119 |
}
|
120 |
});
|
121 |
}
|
122 |
+
|
123 |
// μ₯μΉ μν νμΈ
|
124 |
if (this.elements.checkDeviceStatusBtn) {
|
125 |
this.elements.checkDeviceStatusBtn.addEventListener('click', () => {
|
|
|
127 |
this.checkDeviceStatus();
|
128 |
});
|
129 |
}
|
130 |
+
|
131 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν
|
132 |
if (this.elements.getProgramsBtn) {
|
133 |
this.elements.getProgramsBtn.addEventListener('click', () => {
|
|
|
135 |
this.loadProgramsList();
|
136 |
});
|
137 |
}
|
138 |
+
|
139 |
// νλ‘κ·Έλ¨ μ ν λ³κ²½
|
140 |
if (this.elements.programSelectDropdown) {
|
141 |
this.elements.programSelectDropdown.addEventListener('change', (event) => {
|
|
|
143 |
this.updateExecuteButton();
|
144 |
});
|
145 |
}
|
146 |
+
|
147 |
+
// νλ‘κ·Έλ¨ μ€ν (미리 μ μλ)
|
148 |
if (this.elements.executeProgramBtn) {
|
149 |
this.elements.executeProgramBtn.addEventListener('click', () => {
|
150 |
const programId = this.elements.programSelectDropdown.value;
|
151 |
+
console.log(`미리 μ μλ νλ‘κ·Έλ¨ μ€ν λ²νΌ ν΄λ¦, μ νλ ID: ${programId}`);
|
152 |
this.executeProgram(programId);
|
153 |
});
|
154 |
}
|
155 |
+
|
156 |
+
// ================== μΆκ° μμ 3/4 ==================
|
157 |
+
// μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν λ²νΌ ν΄λ¦
|
158 |
+
if (this.elements.executeCustomBtn) {
|
159 |
+
this.elements.executeCustomBtn.addEventListener('click', () => {
|
160 |
+
const command = this.elements.customCommandInput.value;
|
161 |
+
console.log(`μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν λ²νΌ ν΄λ¦, λͺ
λ Ήμ΄: ${command}`);
|
162 |
+
this.executeCustomProgram(command);
|
163 |
+
});
|
164 |
+
}
|
165 |
+
|
166 |
+
// μν° ν€λ‘ μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν
|
167 |
+
if (this.elements.customCommandInput) {
|
168 |
+
this.elements.customCommandInput.addEventListener('keydown', (event) => {
|
169 |
+
if (event.key === 'Enter') {
|
170 |
+
console.log('μ¬μ©μ μ μ λͺ
λ Ήμ΄ μ
λ ₯ νλμμ μν° ν€ κ°μ§');
|
171 |
+
event.preventDefault(); // νΌ μ μΆ λ°©μ§ λ± κΈ°λ³Έ λμ λ§κΈ°
|
172 |
+
const command = this.elements.customCommandInput.value;
|
173 |
+
this.executeCustomProgram(command);
|
174 |
+
}
|
175 |
+
});
|
176 |
+
}
|
177 |
+
// ================== μΆκ° λ 3/4 ====================
|
178 |
+
|
179 |
console.log('μ₯μΉ μ μ΄ μ΄λ²€νΈ 리μ€λ λ±λ‘ μλ£');
|
180 |
},
|
181 |
+
|
182 |
// μ₯μΉ μ μ΄ νμΌλ‘ μ ν
|
183 |
switchToDeviceTab: function() {
|
184 |
// λͺ¨λ νκ³Ό ν μ½ν
μΈ λΉνμ±ν
|
185 |
const tabs = document.querySelectorAll('.tab');
|
186 |
const tabContents = document.querySelectorAll('.tab-content');
|
187 |
+
|
188 |
tabs.forEach(tab => tab.classList.remove('active'));
|
189 |
tabContents.forEach(content => content.classList.remove('active'));
|
190 |
+
|
191 |
// μ₯μΉ μ μ΄ ν νμ±ν
|
192 |
this.elements.deviceTab.classList.add('active');
|
193 |
this.elements.deviceSection.classList.add('active');
|
194 |
+
|
195 |
console.log('μ₯μΉ μ μ΄ νμΌλ‘ μ ν μλ£');
|
196 |
},
|
197 |
+
|
198 |
// μλ² μ°κ²° ν¨μ
|
199 |
connectServer: async function() {
|
200 |
// URL κ°μ Έμ€κΈ° (μ
λ ₯λ κ²μ΄ μμΌλ©΄ λ°±μ
μΌλ‘ μ¬μ©)
|
201 |
const inputUrl = this.elements.deviceServerUrlInput.value.trim();
|
202 |
+
|
203 |
// μ°κ²° μλ μ€ UI μ
λ°μ΄νΈ
|
204 |
this.elements.connectDeviceServerBtn.disabled = true;
|
205 |
this.updateConnectionStatus('connecting', 'νκ²½λ³μμ μ μ₯λ μλ²λ‘ μ°κ²° μλ μ€...');
|
206 |
+
|
207 |
try {
|
208 |
console.log('νκ²½λ³μμ μ μ₯λ μ₯μΉ μλ²λ‘ μ°κ²° μλ');
|
209 |
+
|
210 |
// λ°±μλ API νΈμΆνμ¬ μλ² μν νμΈ
|
211 |
const response = await AppUtils.fetchWithTimeout('/api/device/status', {
|
212 |
method: 'GET'
|
213 |
}, 10000); // 10μ΄ νμμμ
|
214 |
+
|
215 |
const data = await response.json();
|
216 |
+
|
217 |
if (response.ok && data.success) {
|
218 |
// μ°κ²° μ±κ³΅
|
219 |
console.log('νκ²½λ³μ μ€μ μ₯μΉ μλ² μ°κ²° μ±κ³΅:', data);
|
220 |
this.isConnected = true;
|
221 |
this.updateConnectionStatus('connected', `μλ² μ°κ²° μ±κ³΅! μν: ${data.server_status || 'μ μ'}`);
|
222 |
+
|
223 |
// κΈ°λ₯ UI νμ±ν
|
224 |
+
if(this.elements.deviceBasicFunctions) this.elements.deviceBasicFunctions.classList.add('active');
|
225 |
+
if(this.elements.deviceProgramControl) this.elements.deviceProgramControl.classList.add('active');
|
226 |
+
// ================== μΆκ° (connectServer μ±κ³΅ μ UI νμ±ν) ==================
|
227 |
+
if(this.elements.deviceCustomControl) this.elements.deviceCustomControl.classList.add('active');
|
228 |
+
// ================== μΆκ° λ =============================================
|
229 |
+
|
230 |
// μ₯μΉ μν μλ 체ν¬
|
231 |
this.checkDeviceStatus();
|
232 |
+
|
233 |
// νλ‘κ·Έλ¨ λͺ©οΏ½οΏ½ μλ λ‘λ
|
234 |
this.loadProgramsList();
|
235 |
+
|
236 |
// μμ€ν
μλ¦Ό
|
237 |
AppUtils.addSystemNotification(`μ₯μΉ κ΄λ¦¬ μλ² μ°κ²° μ±κ³΅! (νκ²½λ³μ URL)`);
|
238 |
} else {
|
239 |
// νκ²½λ³μ URL μ°κ²° μ€ν¨, μ
λ ₯λ URLλ‘ μλ
|
240 |
console.warn('νκ²½λ³μ μ€μ μ₯μΉ μλ² μ°κ²° μ€ν¨, μ
λ ₯ URLλ‘ μ¬μλν©λλ€:', data);
|
241 |
+
|
242 |
// μ
λ ₯ URLμ΄ μλμ§ νμΈ
|
243 |
if (!inputUrl) {
|
244 |
console.error('μ
λ ₯λ URLμ΄ μμ΄ μ°κ²° μ€ν¨');
|
|
|
246 |
this.updateConnectionStatus('error', 'νκ²½λ³μ URL μ°κ²° μ€ν¨ λ° μ
λ ₯λ URLμ΄ μμ΅λλ€. URLμ μ
λ ₯ν΄μ£ΌμΈμ.');
|
247 |
return;
|
248 |
}
|
249 |
+
|
250 |
// μ
λ ₯ URLλ‘ μ¬μλ
|
251 |
this.updateConnectionStatus('connecting', `μ
λ ₯ URL(${inputUrl})λ‘ μ°κ²° μλ μ€...`);
|
252 |
console.log(`μ
λ ₯ν URLλ‘ μ₯μΉ μλ² μ°κ²° μλ: ${inputUrl}`);
|
253 |
+
|
254 |
// λ°±μλ API νΈμΆ - μ
λ ₯ URL μ¬μ©
|
255 |
const customUrlResponse = await AppUtils.fetchWithTimeout('/api/device/connect', {
|
256 |
method: 'POST',
|
|
|
259 |
},
|
260 |
body: JSON.stringify({ url: inputUrl })
|
261 |
}, 10000);
|
262 |
+
|
263 |
const customUrlData = await customUrlResponse.json();
|
264 |
+
|
265 |
if (customUrlResponse.ok && customUrlData.success) {
|
266 |
// μ
λ ₯ URL μ°κ²° μ±κ³΅
|
267 |
console.log('μ
λ ₯ URL μ₯μΉ μλ² μ°κ²° μ±κ³΅:', customUrlData);
|
268 |
this.isConnected = true;
|
269 |
this.updateConnectionStatus('connected', `μλ² μ°κ²° μ±κ³΅! μν: ${customUrlData.server_status || 'μ μ'}`);
|
270 |
+
|
271 |
// κΈ°λ₯ UI νμ±ν
|
272 |
+
if(this.elements.deviceBasicFunctions) this.elements.deviceBasicFunctions.classList.add('active');
|
273 |
+
if(this.elements.deviceProgramControl) this.elements.deviceProgramControl.classList.add('active');
|
274 |
+
// ================== μΆκ° (connectServer μ±κ³΅ μ UI νμ±ν) ==================
|
275 |
+
if(this.elements.deviceCustomControl) this.elements.deviceCustomControl.classList.add('active');
|
276 |
+
// ================== μΆκ° λ =============================================
|
277 |
+
|
278 |
+
|
279 |
// μ₯μΉ μν μλ 체ν¬
|
280 |
this.checkDeviceStatus();
|
281 |
+
|
282 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μλ λ‘λ
|
283 |
this.loadProgramsList();
|
284 |
+
|
285 |
// μμ€ν
μλ¦Ό
|
286 |
AppUtils.addSystemNotification(`μ₯μΉ κ΄λ¦¬ μλ² μ°κ²° μ±κ³΅! (${inputUrl})`);
|
287 |
} else {
|
|
|
295 |
// μμΈ λ°μ
|
296 |
console.error('μλ² μ°κ²° μ€ μ€λ₯ λ°μ:', error);
|
297 |
this.isConnected = false;
|
298 |
+
|
299 |
// νκ²½λ³μ URL μ°κ²° μ€ν¨, μ
λ ₯λ URLλ‘ μλ
|
300 |
if (inputUrl) {
|
301 |
console.warn('νκ²½λ³μ URL μ°κ²° μ μ€λ₯ λ°μ, μ
λ ₯ URLλ‘ μ¬μλν©λλ€');
|
302 |
+
|
303 |
try {
|
304 |
// μ
λ ₯ URLλ‘ μ¬μλ
|
305 |
this.updateConnectionStatus('connecting', `μ
λ ₯ URL(${inputUrl})λ‘ μ°κ²° μλ μ€...`);
|
306 |
console.log(`μ
λ ₯ν URLλ‘ μ₯μΉ μλ² μ°κ²° μλ: ${inputUrl}`);
|
307 |
+
|
308 |
// λ°±μλ API νΈμΆ - μ
λ ₯ URL μ¬μ©
|
309 |
const customUrlResponse = await AppUtils.fetchWithTimeout('/api/device/connect', {
|
310 |
method: 'POST',
|
|
|
313 |
},
|
314 |
body: JSON.stringify({ url: inputUrl })
|
315 |
}, 10000);
|
316 |
+
|
317 |
const customUrlData = await customUrlResponse.json();
|
318 |
+
|
319 |
if (customUrlResponse.ok && customUrlData.success) {
|
320 |
// μ
λ ₯ URL μ°κ²° μ±κ³΅
|
321 |
console.log('μ
λ ₯ URL μ₯μΉ μλ² μ°κ²° μ±κ³΅:', customUrlData);
|
322 |
this.isConnected = true;
|
323 |
this.updateConnectionStatus('connected', `μλ² μ°κ²° μ±κ³΅! μν: ${customUrlData.server_status || 'μ μ'}`);
|
324 |
+
|
325 |
// κΈ°λ₯ UI νμ±ν
|
326 |
+
if(this.elements.deviceBasicFunctions) this.elements.deviceBasicFunctions.classList.add('active');
|
327 |
+
if(this.elements.deviceProgramControl) this.elements.deviceProgramControl.classList.add('active');
|
328 |
+
// ================== μΆκ° (connectServer μ±κ³΅ μ UI νμ±ν) ==================
|
329 |
+
if(this.elements.deviceCustomControl) this.elements.deviceCustomControl.classList.add('active');
|
330 |
+
// ================== μΆκ° λ =============================================
|
331 |
+
|
332 |
+
|
333 |
// μ₯μΉ μν μλ 체ν¬
|
334 |
this.checkDeviceStatus();
|
335 |
+
|
336 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μλ λ‘λ
|
337 |
this.loadProgramsList();
|
338 |
+
|
339 |
// μμ€ν
μλ¦Ό
|
340 |
AppUtils.addSystemNotification(`μ₯μΉ κ΄λ¦¬ μλ² μ°κ²° μ±κ³΅! (${inputUrl})`);
|
341 |
return; // μ±κ³΅νλ©΄ μ¬κΈ°μ μ’
λ£
|
|
|
347 |
} catch (inputUrlError) {
|
348 |
// μ
λ ₯ URLλ‘ μ¬μλ μ€ μ€λ₯
|
349 |
console.error('μ
λ ₯ URLλ‘ μ¬μλ μ€ μ€λ₯ λ°μ:', inputUrlError);
|
350 |
+
|
351 |
if (inputUrlError.message.includes('μκ°μ΄ μ΄κ³Ό')) {
|
352 |
this.updateConnectionStatus('error', 'μλ² μ°κ²° μκ° μ΄κ³Ό. μλ²κ° μ€ν μ€μΈμ§ νμΈν΄μ£ΌμΈμ.');
|
353 |
} else {
|
|
|
367 |
this.elements.connectDeviceServerBtn.disabled = false;
|
368 |
}
|
369 |
},
|
370 |
+
|
371 |
// μ°κ²° μν μ
λ°μ΄νΈ
|
372 |
updateConnectionStatus: function(status, message) {
|
373 |
const statusElement = this.elements.deviceConnectionStatus;
|
374 |
+
if (!statusElement) return; // μμ μμΌλ©΄ μ’
λ£
|
375 |
+
|
376 |
// λͺ¨λ μν ν΄λμ€ μ κ±°
|
377 |
statusElement.classList.remove('connected', 'disconnected', 'error', 'connecting');
|
378 |
+
|
379 |
// μνμ λ°λΌ ν΄λμ€ μΆκ°
|
380 |
statusElement.classList.add(status);
|
381 |
+
|
382 |
// λ©μμ§ μ
λ°μ΄νΈ
|
383 |
statusElement.textContent = message;
|
384 |
+
|
385 |
console.log(`μ°κ²° μν μ
λ°μ΄νΈ: ${status} - ${message}`);
|
386 |
},
|
387 |
+
|
388 |
// μ₯μΉ μν νμΈ
|
389 |
checkDeviceStatus: async function() {
|
390 |
if (!this.isConnected) {
|
|
|
392 |
console.error('μ₯μΉ μν νμΈ μλ μ€ μ€λ₯: μλ² μ°κ²° μλ¨');
|
393 |
return;
|
394 |
}
|
395 |
+
|
396 |
// μν νμΈ μ€ UI μ
λ°μ΄νΈ
|
397 |
this.elements.checkDeviceStatusBtn.disabled = true;
|
398 |
this.elements.deviceStatusResult.value = 'μ₯μΉ μν νμΈ μ€...';
|
399 |
+
|
400 |
try {
|
401 |
console.log('μ₯μΉ μν νμΈ μμ² μ μ‘');
|
402 |
+
|
403 |
// λ°±μλ API νΈμΆ
|
404 |
const response = await AppUtils.fetchWithTimeout('/api/device/status', {
|
405 |
method: 'GET'
|
406 |
});
|
407 |
+
|
408 |
const data = await response.json();
|
409 |
+
|
410 |
if (response.ok && data.success) {
|
411 |
// μν νμΈ μ±κ³΅
|
412 |
console.log('μ₯μΉ μν νμΈ μ±κ³΅:', data);
|
413 |
this.isStatusChecked = true;
|
414 |
+
// JSON λ°μ΄ν°λ₯Ό 보기 μ’κ² ν¬λ§·ν
νμ¬ νμ
|
415 |
+
this.elements.deviceStatusResult.value = JSON.stringify(data.data || data, null, 2); // data.data μ°μ νμΈ
|
416 |
} else {
|
417 |
// μν νμΈ μ€ν¨
|
418 |
console.error('μ₯μΉ μν νμΈ μ€ν¨:', data);
|
|
|
427 |
this.elements.checkDeviceStatusBtn.disabled = false;
|
428 |
}
|
429 |
},
|
430 |
+
|
431 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν
|
432 |
loadProgramsList: async function() {
|
433 |
if (!this.isConnected) {
|
|
|
435 |
console.error('νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν μλ μ€ μ€λ₯: μλ² μ°κ²° μλ¨');
|
436 |
return;
|
437 |
}
|
438 |
+
|
439 |
// μ΄λ―Έ λ‘λ© μ€μ΄λ©΄ μ€λ³΅ μμ² λ°©μ§
|
440 |
if (this.isLoadingPrograms) {
|
441 |
console.log('μ΄λ―Έ νλ‘κ·Έλ¨ λͺ©λ‘ λ‘λ© μ€');
|
442 |
return;
|
443 |
}
|
444 |
+
|
445 |
// λ‘λ© μ€ UI μ
λ°μ΄νΈ
|
446 |
this.isLoadingPrograms = true;
|
447 |
+
if(this.elements.getProgramsBtn) this.elements.getProgramsBtn.disabled = true; // λ²νΌ μ‘΄μ¬ μ¬λΆ νμΈ
|
448 |
+
if(this.elements.programsList) { // λͺ©λ‘ μμ μ‘΄μ¬ μ¬λΆ νμΈ
|
449 |
+
this.elements.programsList.innerHTML = `
|
450 |
+
<div class="loading-message">
|
451 |
+
${AppUtils.createLoadingSpinner()} νλ‘κ·Έλ¨ λͺ©λ‘ λ‘λ μ€...
|
452 |
+
</div>
|
453 |
+
`;
|
454 |
+
}
|
455 |
+
|
456 |
+
|
457 |
try {
|
458 |
console.log('νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν μμ² μ μ‘');
|
459 |
+
|
460 |
// λ°±μλ API νΈμΆ
|
461 |
const response = await AppUtils.fetchWithTimeout('/api/device/programs', {
|
462 |
method: 'GET'
|
463 |
});
|
464 |
+
|
465 |
const data = await response.json();
|
466 |
+
|
467 |
if (response.ok && data.success) {
|
468 |
// λͺ©λ‘ μ‘°ν μ±κ³΅
|
469 |
console.log('νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν μ±κ³΅:', data);
|
470 |
this.programsList = data.programs || [];
|
471 |
+
|
472 |
// λͺ©λ‘ νμ
|
473 |
this.displayProgramsList();
|
474 |
+
|
475 |
// λλ‘λ€μ΄ μ
λ°μ΄νΈ
|
476 |
this.updateProgramsDropdown();
|
477 |
+
|
478 |
// μ€ν λ²νΌ μν μ
λ°μ΄νΈ
|
479 |
this.updateExecuteButton();
|
480 |
} else {
|
|
|
489 |
} finally {
|
490 |
// λ‘λ© μν λ° λ²νΌ μν 볡μ
|
491 |
this.isLoadingPrograms = false;
|
492 |
+
if(this.elements.getProgramsBtn) this.elements.getProgramsBtn.disabled = false; // λ²νΌ μ‘΄μ¬ μ¬λΆ νμΈ
|
493 |
}
|
494 |
},
|
495 |
+
|
496 |
// νλ‘κ·Έλ¨ λͺ©λ‘ νμ
|
497 |
displayProgramsList: function() {
|
498 |
const programsListElement = this.elements.programsList;
|
499 |
+
if (!programsListElement) return; // μμ μμΌλ©΄ μ’
λ£
|
500 |
+
|
501 |
if (!this.programsList || this.programsList.length === 0) {
|
502 |
programsListElement.innerHTML = `
|
503 |
<div class="no-programs-message">
|
|
|
506 |
`;
|
507 |
return;
|
508 |
}
|
509 |
+
|
510 |
// ν
μ΄λΈ ννλ‘ νλ‘κ·Έλ¨ λͺ©λ‘ νμ
|
511 |
let html = `
|
512 |
<table class="program-list">
|
|
|
519 |
</thead>
|
520 |
<tbody>
|
521 |
`;
|
522 |
+
|
523 |
// νλ‘κ·Έλ¨ νλͺ© μμ±
|
524 |
this.programsList.forEach(program => {
|
525 |
html += `
|
|
|
530 |
</tr>
|
531 |
`;
|
532 |
});
|
533 |
+
|
534 |
html += `
|
535 |
</tbody>
|
536 |
</table>
|
|
|
538 |
μ΄ ${this.programsList.length}κ° νλ‘κ·Έλ¨
|
539 |
</div>
|
540 |
`;
|
541 |
+
|
542 |
programsListElement.innerHTML = html;
|
543 |
},
|
544 |
+
|
545 |
// νλ‘κ·Έλ¨ λλ‘λ€μ΄ μ
λ°μ΄νΈ
|
546 |
updateProgramsDropdown: function() {
|
547 |
const dropdown = this.elements.programSelectDropdown;
|
548 |
+
if (!dropdown) return; // μμ μμΌλ©΄ μ’
λ£
|
549 |
+
|
550 |
// κΈ°μ‘΄ μ΅μ
μ κ±°
|
551 |
dropdown.innerHTML = '';
|
552 |
+
|
553 |
// κΈ°λ³Έ μ΅μ
μΆκ°
|
554 |
const defaultOption = document.createElement('option');
|
555 |
defaultOption.value = '';
|
|
|
557 |
? '-- μ€νν νλ‘κ·Έλ¨ μ ν --'
|
558 |
: '-- νλ‘κ·Έλ¨ μμ --';
|
559 |
dropdown.appendChild(defaultOption);
|
560 |
+
|
561 |
// νλ‘κ·Έλ¨ μ΅μ
μΆκ°
|
562 |
this.programsList.forEach(program => {
|
563 |
const option = document.createElement('option');
|
564 |
option.value = program.id || '';
|
565 |
option.textContent = program.name || 'μ μ μμ';
|
566 |
+
|
567 |
// μ€λͺ
μ΄ μμΌλ©΄ κ΄νΈλ‘ μΆκ°
|
568 |
if (program.description) {
|
569 |
option.textContent += ` (${program.description})`;
|
570 |
}
|
571 |
+
|
572 |
dropdown.appendChild(option);
|
573 |
});
|
574 |
},
|
575 |
+
|
576 |
// μ€ν λ²νΌ μν μ
λ°μ΄νΈ
|
577 |
updateExecuteButton: function() {
|
578 |
const dropdown = this.elements.programSelectDropdown;
|
579 |
const executeBtn = this.elements.executeProgramBtn;
|
580 |
+
if (!dropdown || !executeBtn) return; // μμ μμΌλ©΄ μ’
λ£
|
581 |
+
|
582 |
// μ νλ νλ‘κ·Έλ¨μ΄ μμ λλ§ λ²νΌ νμ±ν
|
583 |
executeBtn.disabled = !dropdown.value;
|
584 |
},
|
585 |
+
|
586 |
+
// νλ‘κ·Έλ¨ μ€ν (미리 μ μλ)
|
587 |
executeProgram: async function(programId) {
|
588 |
if (!this.isConnected) {
|
589 |
this.showExecuteResult('error', 'μ€λ₯: λ¨Όμ μλ²μ μ°κ²°ν΄μΌ ν©λλ€.');
|
590 |
console.error('νλ‘κ·Έλ¨ μ€ν μλ μ€ μ€λ₯: μλ² μ°κ²° μλ¨');
|
591 |
return;
|
592 |
}
|
593 |
+
|
594 |
if (!programId) {
|
595 |
this.showExecuteResult('error', 'μ€λ₯: μ€νν νλ‘κ·Έλ¨μ μ νν΄μ£ΌμΈμ.');
|
596 |
console.error('νλ‘κ·Έλ¨ μ€ν μλ μ€ μ€λ₯: νλ‘κ·Έλ¨ ID μμ');
|
597 |
return;
|
598 |
}
|
599 |
+
|
600 |
// μ€ν μ€ UI μ
λ°μ΄νΈ
|
601 |
+
if(this.elements.executeProgramBtn) this.elements.executeProgramBtn.disabled = true;
|
602 |
this.showExecuteResult('loading', 'νλ‘κ·Έλ¨ μ€ν μ€...');
|
603 |
+
|
604 |
try {
|
605 |
console.log(`νλ‘κ·Έλ¨ μ€ν μμ² μ μ‘: ${programId}`);
|
606 |
+
|
607 |
// λ°±μλ API νΈμΆ
|
608 |
const response = await AppUtils.fetchWithTimeout(`/api/device/programs/${programId}/execute`, {
|
609 |
method: 'POST',
|
|
|
612 |
},
|
613 |
body: JSON.stringify({})
|
614 |
}, 15000); // 15μ΄ νμμμ (μ€νμ μκ°μ΄ λ 걸릴 μ μμ)
|
615 |
+
|
616 |
const data = await response.json();
|
617 |
+
|
618 |
if (response.ok && data.success) {
|
619 |
// μ€ν μ±κ³΅
|
620 |
console.log('νλ‘κ·Έλ¨ μ€ν μ±κ³΅:', data);
|
621 |
this.showExecuteResult('success', `μ€ν μ±κ³΅: ${data.message || 'νλ‘κ·Έλ¨μ΄ μ±κ³΅μ μΌλ‘ μ€νλμμ΅λλ€.'}`);
|
622 |
+
|
623 |
// μμ€ν
μλ¦Ό
|
624 |
AppUtils.addSystemNotification(`νλ‘κ·Έλ¨ μ€ν μ±κ³΅: ${this.getSelectedProgramName()}`);
|
625 |
} else {
|
|
|
630 |
} catch (error) {
|
631 |
// μμΈ λ°μ
|
632 |
console.error('νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ:', error);
|
633 |
+
|
634 |
if (error.message.includes('μκ°μ΄ μ΄κ³Ό')) {
|
635 |
this.showExecuteResult('error', 'νλ‘κ·Έλ¨ μ€ν μμ² μκ° μ΄κ³Ό. μλ² μλ΅μ΄ μμ΅λλ€.');
|
636 |
} else {
|
|
|
638 |
}
|
639 |
} finally {
|
640 |
// λ²νΌ λ€μ νμ±ν
|
641 |
+
if(this.elements.executeProgramBtn) this.elements.executeProgramBtn.disabled = false;
|
642 |
}
|
643 |
},
|
644 |
+
|
645 |
// μ νλ νλ‘κ·Έλ¨ μ΄λ¦ κ°μ Έμ€κΈ°
|
646 |
getSelectedProgramName: function() {
|
647 |
const dropdown = this.elements.programSelectDropdown;
|
648 |
+
if (!dropdown) return 'μ μ μλ νλ‘κ·Έλ¨';
|
649 |
const selectedOption = dropdown.options[dropdown.selectedIndex];
|
650 |
return selectedOption ? selectedOption.textContent : 'μ μ μλ νλ‘κ·Έλ¨';
|
651 |
},
|
652 |
+
|
653 |
// νλ‘κ·Έλ¨ λͺ©λ‘ μ€λ₯ νμ
|
654 |
showProgramsError: function(errorMessage) {
|
655 |
+
const programsListElement = this.elements.programsList;
|
656 |
+
if (!programsListElement) return; // μμ μμΌλ©΄ μ’
λ£
|
657 |
+
|
658 |
+
programsListElement.innerHTML = `
|
659 |
<div class="error-message">
|
660 |
<i class="fas fa-exclamation-circle"></i> ${errorMessage}
|
661 |
<button class="retry-button" id="retryLoadProgramsBtn">
|
|
|
663 |
</button>
|
664 |
</div>
|
665 |
`;
|
666 |
+
|
667 |
// μ¬μλ λ²νΌ μ΄λ²€νΈ 리μ€λ
|
668 |
+
// μ΄μ μ μΆκ°λ 리μ€λκ° μλ€λ©΄ μ κ±°νκ³ λ€μ μΆκ°νλ κ²μ΄ μμ ν μ μμ
|
669 |
+
const retryBtn = document.getElementById('retryLoadProgramsBtn');
|
670 |
+
if (retryBtn) {
|
671 |
+
retryBtn.replaceWith(retryBtn.cloneNode(true)); // 리μ€λ μ κ±° νΈλ¦
|
672 |
+
document.getElementById('retryLoadProgramsBtn').addEventListener('click', () => {
|
673 |
+
console.log('νλ‘κ·Έλ¨ λͺ©λ‘ μ¬μλ λ²νΌ ν΄λ¦');
|
674 |
+
this.loadProgramsList();
|
675 |
+
});
|
676 |
+
}
|
677 |
+
|
678 |
},
|
679 |
+
|
680 |
+
// μ€ν κ²°κ³Ό νμ (미리 μ μλ νλ‘κ·Έλ¨ μ©)
|
681 |
showExecuteResult: function(status, message) {
|
682 |
const resultElement = this.elements.executeResult;
|
683 |
+
if (!resultElement) return; // μμ μμΌλ©΄ μ’
λ£
|
684 |
+
|
685 |
// λͺ¨λ μν ν΄λμ€ μ κ±°
|
686 |
resultElement.classList.remove('success', 'error', 'warning');
|
687 |
+
|
688 |
// λ΄μ© μ΄κΈ°ν
|
689 |
resultElement.innerHTML = '';
|
690 |
+
|
691 |
// μνμ λ°λΌ μ²λ¦¬
|
692 |
switch (status) {
|
693 |
case 'success':
|
|
|
708 |
default:
|
709 |
resultElement.textContent = message;
|
710 |
}
|
711 |
+
},
|
712 |
+
|
713 |
+
// ================== μΆκ° μμ 4/4 ==================
|
714 |
+
// μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν
|
715 |
+
executeCustomProgram: async function(command) {
|
716 |
+
if (!this.isConnected) {
|
717 |
+
this.showCustomExecuteResult('error', 'μ€λ₯: λ¨Όμ μλ²μ μ°κ²°ν΄μΌ ν©λλ€.');
|
718 |
+
console.error('μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μλ μ€ μ€λ₯: μλ² μ°κ²° μλ¨');
|
719 |
+
return;
|
720 |
+
}
|
721 |
+
|
722 |
+
if (!command || command.trim() === '') {
|
723 |
+
this.showCustomExecuteResult('error', 'μ€λ₯: μ€νν λͺ
λ Ήμ΄λ₯Ό μ
λ ₯ν΄μ£ΌμΈμ.');
|
724 |
+
console.error('μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μλ μ€ μ€λ₯: λͺ
λ Ήμ΄ μμ');
|
725 |
+
return;
|
726 |
+
}
|
727 |
+
|
728 |
+
// μ€ν μ€ UI μ
λ°μ΄νΈ
|
729 |
+
if(this.elements.executeCustomBtn) this.elements.executeCustomBtn.disabled = true;
|
730 |
+
this.showCustomExecuteResult('loading', 'λͺ
λ Ήμ΄ μ€ν μ€...');
|
731 |
+
|
732 |
+
try {
|
733 |
+
console.log(`μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μμ² μ μ‘: ${command}`);
|
734 |
+
|
735 |
+
// λ°±μλ API νΈμΆ
|
736 |
+
const response = await AppUtils.fetchWithTimeout('/api/device/execute-custom', {
|
737 |
+
method: 'POST',
|
738 |
+
headers: {
|
739 |
+
'Content-Type': 'application/json'
|
740 |
+
},
|
741 |
+
body: JSON.stringify({ command: command })
|
742 |
+
}, 15000); // 15μ΄ νμμμ
|
743 |
+
|
744 |
+
const data = await response.json();
|
745 |
+
|
746 |
+
if (response.ok && data.success) {
|
747 |
+
// μ€ν μ±κ³΅
|
748 |
+
console.log('μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μ±κ³΅:', data);
|
749 |
+
|
750 |
+
// κ²°κ³Ό νμ
|
751 |
+
let successMessage = `λͺ
λ Ήμ΄ μ€ν μ±κ³΅: ${data.message || ''}`;
|
752 |
+
|
753 |
+
// μΆλ ₯ λ΄μ©μ΄ μμΌλ©΄ μΆκ° (HTML μμ μ²λ¦¬ ν¬ν¨)
|
754 |
+
if (data.output && data.output.trim()) {
|
755 |
+
successMessage += `<div class="command-output"><pre>${AppUtils.escapeHtml(data.output)}</pre></div>`;
|
756 |
+
}
|
757 |
+
|
758 |
+
this.showCustomExecuteResult('success', successMessage);
|
759 |
+
|
760 |
+
// μμ€ν
μλ¦Ό
|
761 |
+
AppUtils.addSystemNotification(`μ¬μ©μ μ μ λͺ
λ Ήμ΄ μ€ν μ±κ³΅: ${command}`);
|
762 |
+
} else {
|
763 |
+
// μ€ν μ€ν¨
|
764 |
+
console.error('μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μ€ν¨:', data);
|
765 |
+
|
766 |
+
let errorMessage = `μ€ν μ€ν¨: ${data.error || 'μ μ μλ μ€λ₯'}`;
|
767 |
+
|
768 |
+
// μ€λ₯ μΆλ ₯μ΄ μμΌλ©΄ μΆκ° (HTML μμ μ²λ¦¬ ν¬ν¨)
|
769 |
+
if (data.error_output && data.error_output.trim()) {
|
770 |
+
errorMessage += `<div class="command-error"><pre>${AppUtils.escapeHtml(data.error_output)}</pre></div>`;
|
771 |
+
}
|
772 |
+
|
773 |
+
this.showCustomExecuteResult('error', errorMessage);
|
774 |
+
}
|
775 |
+
} catch (error) {
|
776 |
+
// μμΈ λ°μ
|
777 |
+
console.error('μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ:', error);
|
778 |
+
|
779 |
+
if (error.message.includes('μκ°μ΄ μ΄κ³Ό')) {
|
780 |
+
this.showCustomExecuteResult('error', 'λͺ
λ Ήμ΄ μ€ν μμ² μκ° μ΄κ³Ό. μλ² μλ΅μ΄ μμ΅λλ€.');
|
781 |
+
} else {
|
782 |
+
this.showCustomExecuteResult('error', `λͺ
λ Ήμ΄ μ€ν μ€ μ€λ₯ λ°μ: ${error.message}`);
|
783 |
+
}
|
784 |
+
} finally {
|
785 |
+
// λ²νΌ λ€μ νμ±ν
|
786 |
+
if(this.elements.executeCustomBtn) this.elements.executeCustomBtn.disabled = false;
|
787 |
+
}
|
788 |
+
},
|
789 |
+
|
790 |
+
// μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν κ²°κ³Ό νμ
|
791 |
+
showCustomExecuteResult: function(status, message) {
|
792 |
+
const resultElement = this.elements.customExecuteResult;
|
793 |
+
if (!resultElement) return; // μμ μμΌλ©΄ μ’
λ£
|
794 |
+
|
795 |
+
// λͺ¨λ μν ν΄λμ€ μ κ±°
|
796 |
+
resultElement.classList.remove('success', 'error', 'warning');
|
797 |
+
|
798 |
+
// λ΄μ© μ΄κΈ°ν
|
799 |
+
resultElement.innerHTML = '';
|
800 |
+
|
801 |
+
// μνμ λ°λΌ μ²λ¦¬
|
802 |
+
switch (status) {
|
803 |
+
case 'success':
|
804 |
+
resultElement.classList.add('success');
|
805 |
+
// HTML λ©μμ§ μ½μ
μ μ£Όμ (innerHTML μ¬μ©)
|
806 |
+
resultElement.innerHTML = `<i class="fas fa-check-circle"></i> ${message}`;
|
807 |
+
break;
|
808 |
+
case 'error':
|
809 |
+
resultElement.classList.add('error');
|
810 |
+
resultElement.innerHTML = `<i class="fas fa-exclamation-circle"></i> ${message}`;
|
811 |
+
break;
|
812 |
+
case 'warning':
|
813 |
+
resultElement.classList.add('warning');
|
814 |
+
resultElement.innerHTML = `<i class="fas fa-exclamation-triangle"></i> ${message}`;
|
815 |
+
break;
|
816 |
+
case 'loading':
|
817 |
+
// λ‘λ© μ€νΌλ ν¨μκ° AppUtilsμ μλ€κ³ κ°μ
|
818 |
+
resultElement.innerHTML = `${AppUtils.createLoadingSpinner()} ${message}`;
|
819 |
+
break;
|
820 |
+
default:
|
821 |
+
resultElement.textContent = message; // κΈ°λ³Έμ ν
μ€νΈλ§ νμ
|
822 |
+
}
|
823 |
}
|
824 |
+
// ================== μΆκ° λ 4/4 ====================
|
825 |
};
|
826 |
|
827 |
// νμ΄μ§ λ‘λ μλ£ μ λͺ¨λ μ΄κΈ°ν
|
828 |
document.addEventListener('DOMContentLoaded', function() {
|
829 |
console.log('μ₯μΉ μ μ΄ λͺ¨λ λ‘λλ¨');
|
830 |
+
|
831 |
// DOMμ΄ μμ ν λ‘λλ ν μ½κ°μ μ§μ°μ λκ³ μ΄κΈ°ν
|
832 |
+
// DOM μμκ° νμ€ν λ‘λλ νμ μ΄κΈ°ννκΈ° μν¨
|
833 |
setTimeout(() => {
|
834 |
+
// AppUtilsκ° μ μλμλμ§ νμΈ (μμ‘΄μ±)
|
835 |
+
if (typeof AppUtils === 'undefined') {
|
836 |
+
console.error('AppUtilsκ° μ μλμ§ μμ DeviceControl μ΄κΈ°ν μ€ν¨.');
|
837 |
+
// νμνλ€λ©΄ μ¬μ©μμκ² μλ¦Ό νμ
|
838 |
+
alert('νμ΄μ§ μ΄κΈ°ν μ€λ₯: νμ μ νΈλ¦¬ν°(AppUtils)λ₯Ό λ‘λν μ μμ΅λλ€.');
|
839 |
+
return;
|
840 |
+
}
|
841 |
DeviceControl.init();
|
842 |
}, 100);
|
843 |
+
});
|
app/templates/index.html
CHANGED
@@ -121,6 +121,7 @@
|
|
121 |
</div>
|
122 |
</div>
|
123 |
</section>
|
|
|
124 |
<!-- μ₯μΉ μ μ΄ ν -->
|
125 |
<section id="deviceSection" class="tab-content">
|
126 |
<div class="device-connection">
|
@@ -156,6 +157,16 @@
|
|
156 |
<button id="executeProgramBtn" class="execute-btn" disabled>μ νν νλ‘κ·Έλ¨ μ€ν</button>
|
157 |
<div id="executeResult" class="execute-result"></div>
|
158 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
</section>
|
160 |
</main>
|
161 |
|
|
|
121 |
</div>
|
122 |
</div>
|
123 |
</section>
|
124 |
+
|
125 |
<!-- μ₯μΉ μ μ΄ ν -->
|
126 |
<section id="deviceSection" class="tab-content">
|
127 |
<div class="device-connection">
|
|
|
157 |
<button id="executeProgramBtn" class="execute-btn" disabled>μ νν νλ‘κ·Έλ¨ μ€ν</button>
|
158 |
<div id="executeResult" class="execute-result"></div>
|
159 |
</div>
|
160 |
+
|
161 |
+
<!-- μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν μΉμ
μΆκ° -->
|
162 |
+
<div id="deviceCustomControl" class="program-control">
|
163 |
+
<h3>4. μ¬μ©μ μ μ νλ‘κ·Έλ¨ μ€ν</h3>
|
164 |
+
<div class="custom-command-container">
|
165 |
+
<input type="text" id="customCommandInput" placeholder="μ€νν λͺ
λ Ήμ΄ λλ νλ‘κ·Έλ¨ κ²½λ‘ μ
λ ₯">
|
166 |
+
<button id="executeCustomBtn">μ€ν</button>
|
167 |
+
</div>
|
168 |
+
<div id="customExecuteResult" class="execute-result"></div>
|
169 |
+
</div>
|
170 |
</section>
|
171 |
</main>
|
172 |
|