Sửa lỗi quyền chia sẻ và hiển thị lên map ở các liên kết chéo

This commit is contained in:
2026-06-10 10:59:34 +07:00
parent 02cd68f23c
commit 6378bcae5d
8 changed files with 135 additions and 63 deletions
+49 -2
View File
@@ -1099,6 +1099,12 @@ async function openScene(sceneId, privacy, shareToken, force = false, initialPit
const scene = await sceneRes.json();
const hotspots = await hotspotsRes.json();
// [FIX] Lưu tourId đang hoạt động sau khi đã nạp dữ liệu scene thành công
const currentTourId = scene.tourId?._id || scene.tourId || scene._id;
if (!localStorage.getItem('activeTourId') || force) {
localStorage.setItem('activeTourId', currentTourId);
}
if (!sceneRes.ok) throw new Error(scene.message || 'Failed to fetch scene details');
// [FIX CRITICAL] Kiểm tra bảo mật Client-side:
@@ -1158,6 +1164,7 @@ async function openScene(sceneId, privacy, shareToken, force = false, initialPit
localStorage.removeItem('activeSceneId');
localStorage.removeItem('activeScenePrivacy');
localStorage.removeItem('activeSceneToken');
localStorage.removeItem('activeTourId');
// Kiểm tra nếu đang truy cập qua link trực tiếp (URL có sceneId) mà gặp lỗi (do xóa token hoặc token không hợp lệ)
const urlParams = new URLSearchParams(window.location.search);
@@ -1231,6 +1238,29 @@ window.handleHotspotCreation = async function(pitch, yaw, existingHotspot = null
}
});
// [Task 3.1] Lắng nghe thay đổi để nhận diện liên kết chéo
select.onchange = () => {
const selectedId = select.value;
const targetScene = scenes.find(s => s._id === selectedId);
const activeTourId = localStorage.getItem('activeTourId');
const targetTourId = targetScene?.tourId?._id || targetScene?.tourId;
let crossLinkNotice = document.getElementById('hs-crosslink-notice');
if (!crossLinkNotice) {
crossLinkNotice = document.createElement('div');
crossLinkNotice.id = 'hs-crosslink-notice';
crossLinkNotice.style = 'font-size: 11px; margin-top: 5px; color: #ffc107; display: none;';
select.parentNode.appendChild(crossLinkNotice);
}
if (targetTourId && activeTourId && targetTourId !== activeTourId) {
crossLinkNotice.innerText = "️ Cảnh này thuộc Tour khác. Liên kết sẽ được tạo dưới dạng liên kết chéo.";
crossLinkNotice.style.display = 'block';
} else {
crossLinkNotice.style.display = 'none';
}
};
// QUAN TRỌNG: Chỉ điền dữ liệu hotspot cũ SAU KHI dropdown đã được nạp đầy đủ options
if (existingHotspot) {
document.getElementById('hs-title').value = existingHotspot.title || '';
@@ -1277,6 +1307,10 @@ window.handleHotspotCreation = async function(pitch, yaw, existingHotspot = null
sceneData.append('lng', lng);
sceneData.append('privacy', 'public');
// [FIX] Kế thừa tourId từ cảnh cha khi tạo cảnh mới qua hotspot upload
const activeTourId = localStorage.getItem('activeTourId');
if (activeTourId) sceneData.append('tourId', activeTourId);
uploadWithProgress(`${API_BASE_URL}/scenes`, 'POST', sceneData, token, 'hs', async (sceneRes) => {
await saveHotspotToDB(pitch, yaw, formData.get('title'), formData.get('description'), sceneRes.scene._id, existingHotspot?._id);
closeHotspotModal();
@@ -2029,6 +2063,10 @@ window.openEditMetadataModal = function(scene, isChildArg = null) {
sharedUsersData = scene.sharedWith || [];
sharedEmailsData = scene.sharedEmails || [];
// [FIX] Cập nhật activeTourId ngay khi chỉnh sửa để đồng bộ luồng tạo tour
const currentTourId = scene.tourId?._id || scene.tourId || scene._id;
localStorage.setItem('activeTourId', currentTourId);
document.getElementById('edit-modal-scene-id').value = scene._id;
document.getElementById('edit-modal-title').value = scene.name || scene.title || '';
document.getElementById('edit-modal-description').value = scene.description || '';
@@ -2047,12 +2085,21 @@ window.openEditMetadataModal = function(scene, isChildArg = null) {
privacySelect.disabled = true;
childInfo.style.display = 'block';
if (modalTitle) modalTitle.innerText = "Chi tiết Cảnh con (Kế thừa)";
childInfo.innerHTML = `️ Cảnh này thuộc một tour. Quyền riêng tư được quản lý bởi Cảnh gốc.`;
// [Task 3.2] Nhận diện và hiển thị nhãn liên kết chéo
const activeTourId = localStorage.getItem('activeTourId');
const sceneTourId = scene.tourId?._id || scene.tourId;
let crossLabel = activeTourId && sceneTourId && activeTourId !== sceneTourId.toString()
? `<br><span style="color: #ffc107; font-weight: bold;">⚠️ Liên kết Tour khác:</span> Quyền riêng tư được quản lý bởi Tour gốc của cảnh này.`
: `️ Cảnh này thuộc một tour. Quyền riêng tư được quản lý bởi Cảnh gốc.`;
childInfo.innerHTML = crossLabel;
} else {
privacySelect.value = scene.privacy;
privacySelect.disabled = false;
childInfo.style.display = 'none';
childInfo.style.display = 'block';
if (modalTitle) modalTitle.innerText = "Sửa 3D Scene (Cảnh gốc)";
// [Task 3.2] Cảnh báo Privacy cho Cảnh gốc
childInfo.innerHTML = `<i style="color: #888;">️ Thay đổi sẽ áp dụng cho toàn bộ tour này. Các cảnh liên kết chéo từ tour khác sẽ KHÔNG bị ảnh hưởng.</i>`;
}
handleEditPrivacyChange(); // Cập nhật hiển thị nút bánh răng