
--- client/views/pages/teacher/RoadMap.vue
+++ client/views/pages/teacher/RoadMap.vue
... | ... | @@ -1205,6 +1205,16 @@ |
1205 | 1205 |
|
1206 | 1206 |
if (item.prblm_id && item.prblm_id.length > 0) { |
1207 | 1207 |
item.prblm_id.forEach(prblm => { |
1208 |
+ if (seqIndex === 2) { |
|
1209 |
+ this.learningId1 = item.learning_id; |
|
1210 |
+ } |
|
1211 |
+ if (seqIndex === 3) { |
|
1212 |
+ this.learningId2 = item.learning_id; |
|
1213 |
+ } |
|
1214 |
+ if (seqIndex === 6) { |
|
1215 |
+ this.learningId3 = item.learning_id; |
|
1216 |
+ } |
|
1217 |
+ |
|
1208 | 1218 |
this.RoadMap[seqIndex].push({ |
1209 | 1219 |
learningId: item.learning_id, |
1210 | 1220 |
prblmId: prblm.prblm_id, |
... | ... | @@ -1245,14 +1255,6 @@ |
1245 | 1255 |
const originalSeq = this.OrginRoadMap[position] || []; |
1246 | 1256 |
const insertList = []; |
1247 | 1257 |
const insertExistList = []; |
1248 |
- const updateList = []; |
|
1249 |
- const deleteList = []; |
|
1250 |
- |
|
1251 |
- // 원본 데이터의 wdCntId와 wdBookId를 매핑하여 쉽게 조회할 수 있도록 객체화 |
|
1252 |
- const originalMap = {}; |
|
1253 |
- originalSeq.forEach(item => { |
|
1254 |
- originalMap[item.wdCntId] = item.wdBookId; |
|
1255 |
- }); |
|
1256 | 1258 |
|
1257 | 1259 |
// currentSeq와 originalSeq 비교 |
1258 | 1260 |
const isEqual = currentSeq.length === originalSeq.length && currentSeq.every((currentItem, index) => { |
... | ... | @@ -1265,19 +1267,6 @@ |
1265 | 1267 |
console.log(`Position ${position}: currentSeq and originalSeq are identical. No action taken.`); |
1266 | 1268 |
continue; // 다음 위치로 넘어감 |
1267 | 1269 |
} |
1268 |
- // 삭제할 데이터 찾기 |
|
1269 |
- originalSeq.forEach(originalItem => { |
|
1270 |
- const { wdCntId, wdBookId } = originalItem; |
|
1271 |
- const currentItemExists = currentSeq.some(item => item.wdCntId === wdCntId); |
|
1272 |
- |
|
1273 |
- // 현재 시퀀스에 존재하지 않는 경우 삭제 리스트에 추가 |
|
1274 |
- if (!currentItemExists) { |
|
1275 |
- deleteList.push({ |
|
1276 |
- wordContentId: wdCntId, |
|
1277 |
- wordBookId: wdBookId, |
|
1278 |
- }); |
|
1279 |
- } |
|
1280 |
- }); |
|
1281 | 1270 |
|
1282 | 1271 |
currentSeq.forEach(currentItem => { |
1283 | 1272 |
const { wdBookId, wdCntId } = currentItem; |
... | ... | @@ -1285,31 +1274,15 @@ |
1285 | 1274 |
if (!this.isFirst) { |
1286 | 1275 |
insertList.push({ wordBookId: wdBookId }); |
1287 | 1276 |
} else { |
1288 |
- // 현재 아이템의 wdCntId가 원본에 존재하는지 확인 |
|
1289 |
- if (originalMap[wdCntId] !== undefined) { |
|
1290 |
- // 원본에 존재하는 경우 |
|
1291 |
- const originalWdBookId = originalMap[wdCntId]; |
|
1292 |
- |
|
1293 |
- if (originalWdBookId !== wdBookId) { |
|
1294 |
- // wdBookId가 변경된 경우 업데이트 리스트에 추가 |
|
1295 |
- updateList.push({ |
|
1296 |
- wordContentId: wdCntId, |
|
1297 |
- wordBookId: originalWdBookId, // 기존 wdBookId |
|
1298 |
- NewWordBookId: wdBookId, // 새로운 wdBookId |
|
1299 |
- }); |
|
1300 |
- } |
|
1301 |
- } else { |
|
1302 |
- // 원본에 존재하지 않는 경우 |
|
1303 |
- let cntId = null; |
|
1304 |
- if (position === 1) { |
|
1305 |
- cntId = this.wordContentId1; |
|
1306 |
- } else if (position === 5) { |
|
1307 |
- cntId = this.wordContentId2; |
|
1308 |
- } else if (position === 9) { |
|
1309 |
- cntId = this.wordContentId3; |
|
1310 |
- } |
|
1311 |
- insertExistList.push({ wordBookId: wdBookId, wordContentId: cntId }); |
|
1277 |
+ let cntId = null; |
|
1278 |
+ if (position === 1) { |
|
1279 |
+ cntId = this.wordContentId1; |
|
1280 |
+ } else if (position === 5) { |
|
1281 |
+ cntId = this.wordContentId2; |
|
1282 |
+ } else if (position === 9) { |
|
1283 |
+ cntId = this.wordContentId3; |
|
1312 | 1284 |
} |
1285 |
+ insertExistList.push({ wordBookId: wdBookId, wordContentId: cntId }); |
|
1313 | 1286 |
} |
1314 | 1287 |
}); |
1315 | 1288 |
|
... | ... | @@ -1329,23 +1302,9 @@ |
1329 | 1302 |
}); |
1330 | 1303 |
} |
1331 | 1304 |
|
1332 |
- // 필요 시에만 추가 요청 보내기 |
|
1333 |
- const promises = []; |
|
1334 | 1305 |
if (insertExistList.length > 0) { |
1335 |
- promises.push(this.sendInsertExistRequest(insertExistList)); |
|
1306 |
+ await this.sendInsertExistRequest(insertExistList); |
|
1336 | 1307 |
} |
1337 |
- if (updateList.length > 0) { |
|
1338 |
- promises.push(this.sendUpdateRequest(updateList)); |
|
1339 |
- } |
|
1340 |
- if (deleteList.length > 0) { |
|
1341 |
- promises.push(this.sendDeleteRequest(deleteList)); |
|
1342 |
- } |
|
1343 |
- |
|
1344 |
- // 모든 요청을 병렬로 실행 |
|
1345 |
- if (promises.length > 0) { |
|
1346 |
- await Promise.all(promises); |
|
1347 |
- } |
|
1348 |
- |
|
1349 | 1308 |
} |
1350 | 1309 |
}, |
1351 | 1310 |
|
... | ... | @@ -1371,25 +1330,6 @@ |
1371 | 1330 |
} |
1372 | 1331 |
}, |
1373 | 1332 |
|
1374 |
- // 데이터 업데이트 요청 보내기 |
|
1375 |
- async sendUpdateRequest(updateList) { |
|
1376 |
- try { |
|
1377 |
- const response = await axios.post("/wordContent/updateContent.json", updateList); |
|
1378 |
- console.log("Update response:", response.data); |
|
1379 |
- } catch (error) { |
|
1380 |
- console.error("Error updating data:", error); |
|
1381 |
- } |
|
1382 |
- }, |
|
1383 |
- |
|
1384 |
- // 데이터 삭제 요청 보내기 |
|
1385 |
- async sendDeleteRequest(deleteList) { |
|
1386 |
- try { |
|
1387 |
- const response = await axios.post("/wordContent/deleteContent.json", deleteList); |
|
1388 |
- console.log("Delete response:", response.data); |
|
1389 |
- } catch (error) { |
|
1390 |
- console.error("Error deleting data:", error); |
|
1391 |
- } |
|
1392 |
- }, |
|
1393 | 1333 |
|
1394 | 1334 |
// 로드맵 데이터 사용 |
1395 | 1335 |
async postRoadMaps() { |
... | ... | @@ -1418,8 +1358,6 @@ |
1418 | 1358 |
} else { |
1419 | 1359 |
this.insertRoadData(); |
1420 | 1360 |
} |
1421 |
- |
|
1422 |
- |
|
1423 | 1361 |
}, |
1424 | 1362 |
|
1425 | 1363 |
// 로드맵 등록하기 |
... | ... | @@ -1510,6 +1448,7 @@ |
1510 | 1448 |
.then(response => { |
1511 | 1449 |
console.log(`Update successful:`, response.data); |
1512 | 1450 |
if (response.data > 0) { |
1451 |
+ this.postPrblmBookExist(); |
|
1513 | 1452 |
} |
1514 | 1453 |
}) |
1515 | 1454 |
.catch(error => { |
... | ... | @@ -1564,6 +1503,76 @@ |
1564 | 1503 |
console.error("Error during registering problems:", error); |
1565 | 1504 |
}); |
1566 | 1505 |
}, |
1506 |
+ |
|
1507 |
+ // 로드맵 문제 수정 |
|
1508 |
+ postPrblmBookExist() { |
|
1509 |
+ const changedProblemList = []; |
|
1510 |
+ const validPositions = [2, 3, 6]; // prblm_id가 있는 인덱스들 |
|
1511 |
+ |
|
1512 |
+ validPositions.forEach(position => { |
|
1513 |
+ const currentSeq = this.RoadMap[position] || []; |
|
1514 |
+ const originalSeq = this.OrginRoadMap[position] || []; |
|
1515 |
+ |
|
1516 |
+ console.log('currentSeq:', currentSeq); |
|
1517 |
+ console.log('originalSeq:', originalSeq); |
|
1518 |
+ // 크기가 다를 경우, 모든 currentSeq 항목을 변경된 것으로 처리 |
|
1519 |
+ if (currentSeq.length !== originalSeq.length) { |
|
1520 |
+ currentSeq.forEach(currentItem => { |
|
1521 |
+ let learningId = null; |
|
1522 |
+ if (position === 2) { |
|
1523 |
+ learningId = this.learningId1; |
|
1524 |
+ } else if (position === 3) { |
|
1525 |
+ learningId = this.learningId2; |
|
1526 |
+ } else if (position === 6) { |
|
1527 |
+ learningId = this.learningId3; |
|
1528 |
+ } |
|
1529 |
+ |
|
1530 |
+ changedProblemList.push({ |
|
1531 |
+ learningId: learningId, |
|
1532 |
+ prblmId: currentItem.prblmId, |
|
1533 |
+ }); |
|
1534 |
+ }); |
|
1535 |
+ |
|
1536 |
+ } else { |
|
1537 |
+ // 크기가 같은 경우, 기존 비교 로직을 그대로 적용 |
|
1538 |
+ currentSeq.forEach(currentItem => { |
|
1539 |
+ const originalItem = originalSeq.find(item => item.prblmId === currentItem.prblmId); |
|
1540 |
+ |
|
1541 |
+ if (!originalItem || JSON.stringify(originalItem) !== JSON.stringify(currentItem)) { |
|
1542 |
+ let learningId = null; |
|
1543 |
+ if (position === 2) { |
|
1544 |
+ learningId = this.learningId1; |
|
1545 |
+ } else if (position === 3) { |
|
1546 |
+ learningId = this.learningId2; |
|
1547 |
+ } else if (position === 6) { |
|
1548 |
+ learningId = this.learningId3; |
|
1549 |
+ } |
|
1550 |
+ |
|
1551 |
+ changedProblemList.push({ |
|
1552 |
+ learningId: learningId, |
|
1553 |
+ prblmId: currentItem.prblmId, |
|
1554 |
+ }); |
|
1555 |
+ } |
|
1556 |
+ }); |
|
1557 |
+ } |
|
1558 |
+ }); |
|
1559 |
+ |
|
1560 |
+ |
|
1561 |
+ // 변경된 문제가 있다면, 서버에 업데이트 요청 |
|
1562 |
+ if (changedProblemList.length > 0) { |
|
1563 |
+ axios.post("/problemBook/registerExist.json", changedProblemList) |
|
1564 |
+ .then(response => { |
|
1565 |
+ console.log("Problems updated successfully:", response.data); |
|
1566 |
+ this.fetchRoadmapData(); |
|
1567 |
+ alert("학습 로드맵 문제 수정이 완료되었습니다!"); |
|
1568 |
+ }) |
|
1569 |
+ .catch(error => { |
|
1570 |
+ console.error("Error during updating problems:", error); |
|
1571 |
+ }); |
|
1572 |
+ } else { |
|
1573 |
+ console.log("No changes detected in prblm_id."); |
|
1574 |
+ } |
|
1575 |
+ }, |
|
1567 | 1576 |
}, |
1568 | 1577 |
watch: { |
1569 | 1578 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?