diff --git a/web/static/js/add_build.js b/web/static/js/add_build.js index b65241d..31fb715 100644 --- a/web/static/js/add_build.js +++ b/web/static/js/add_build.js @@ -308,11 +308,20 @@ var rebuildConfig = { async function init() { if (typeof rebuildFromBuildId !== 'undefined') { await initRebuild(rebuildFromBuildId); + } else { + initFromUrlParams(); } fetchVehicles(); } +function initFromUrlParams() { + const params = new URLSearchParams(window.location.search); + if (params.has('vehicle')) rebuildConfig.vehicleId = params.get('vehicle'); + if (params.has('board')) rebuildConfig.boardId = params.get('board'); + if (params.has('version')) rebuildConfig.versionId = params.get('version'); +} + async function initRebuild(buildId) { try { const buildResponse = await fetch(`/api/v1/builds/${buildId}`); @@ -400,10 +409,14 @@ function fetchVehicles() { if (rebuildConfig.vehicleId) { const vehicleExists = all_vehicles.some(v => v.id === rebuildConfig.vehicleId); if (!vehicleExists) { - console.warn(`Rebuild vehicle '${rebuildConfig.vehicleId}' not found in available vehicles`); - alert(`Warning: The vehicle from the original build is no longer available.\n\nRedirecting to new build page...`); - window.location.href = '/add_build'; - return; + if (rebuildConfig.isRebuildMode) { + console.warn(`Rebuild vehicle '${rebuildConfig.vehicleId}' not found in available vehicles`); + alert(`Warning: The vehicle from the original build is no longer available.\n\nRedirecting to new build page...`); + window.location.href = '/add_build'; + return; + } else { + rebuildConfig.vehicleId = null; + } } } @@ -442,10 +455,14 @@ function onVehicleChange(new_vehicle_id) { if (rebuildConfig.versionId) { const versionExists = all_versions.some(v => v.id === rebuildConfig.versionId); if (!versionExists) { - console.warn(`Rebuild version '${rebuildConfig.versionId}' not found for vehicle '${new_vehicle_id}'`); - alert(`Warning: The version from the original build is no longer available.\n\nRedirecting to new build page...`); - window.location.href = '/add_build'; - return; + if (rebuildConfig.isRebuildMode) { + console.warn(`Rebuild version '${rebuildConfig.versionId}' not found for vehicle '${new_vehicle_id}'`); + alert(`Warning: The version from the original build is no longer available.\n\nRedirecting to new build page...`); + window.location.href = '/add_build'; + return; + } else { + rebuildConfig.versionId = null; + } } } @@ -498,10 +515,14 @@ function onVersionChange(new_version) { if (rebuildConfig.boardId) { const boardExists = boards.some(b => b.id === rebuildConfig.boardId); if (!boardExists) { - console.warn(`Rebuild board '${rebuildConfig.boardId}' not found for version '${version_id}'`); - alert(`Warning: The board from the original build is no longer available.\n\nRedirecting to new build page...`); - window.location.href = '/add_build'; - return; + if (rebuildConfig.isRebuildMode) { + console.warn(`Rebuild board '${rebuildConfig.boardId}' not found for version '${version_id}'`); + alert(`Warning: The board from the original build is no longer available.\n\nRedirecting to new build page...`); + window.location.href = '/add_build'; + return; + } else { + rebuildConfig.boardId = null; + } } }