-
Notifications
You must be signed in to change notification settings - Fork 69
Allow pre-selecting vehicle, version, and board via URL parameters #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -302,17 +302,32 @@ var rebuildConfig = { | |||||||||||||
| versionId: null, | ||||||||||||||
| boardId: null, | ||||||||||||||
| selectedFeatures: [], | ||||||||||||||
| isRebuildMode: false | ||||||||||||||
| isRebuildMode: false, | ||||||||||||||
| fromUrlParams: false | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| async function init() { | ||||||||||||||
| if (typeof rebuildFromBuildId !== 'undefined') { | ||||||||||||||
| await initRebuild(rebuildFromBuildId); | ||||||||||||||
| } else { | ||||||||||||||
| initFromUrlParams(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| fetchVehicles(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function initFromUrlParams() { | ||||||||||||||
| const params = new URLSearchParams(window.location.search); | ||||||||||||||
| const hasParams = params.has('vehicle') || params.has('board') || params.has('version'); | ||||||||||||||
|
|
||||||||||||||
| 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'); | ||||||||||||||
|
Comment on lines
+323
to
+325
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let us call it |
||||||||||||||
|
|
||||||||||||||
| // Set flag to indicate URL parameters were provided | ||||||||||||||
| rebuildConfig.fromUrlParams = hasParams; | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be avoided? This won't be needed if we have a common error handling as described in the other comment. |
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| async function initRebuild(buildId) { | ||||||||||||||
| try { | ||||||||||||||
| const buildResponse = await fetch(`/api/v1/builds/${buildId}`); | ||||||||||||||
|
|
@@ -361,6 +376,7 @@ function clearRebuildConfig() { | |||||||||||||
| rebuildConfig.boardId = null; | ||||||||||||||
| rebuildConfig.selectedFeatures = []; | ||||||||||||||
| rebuildConfig.isRebuildMode = false; | ||||||||||||||
| rebuildConfig.fromUrlParams = false; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // enables or disables the elements with ids passed as an array | ||||||||||||||
|
|
@@ -400,10 +416,17 @@ 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 if (rebuildConfig.fromUrlParams) { | ||||||||||||||
| console.warn(`URL parameter vehicle '${rebuildConfig.vehicleId}' not found. Defaulting to first available vehicle.`); | ||||||||||||||
| rebuildConfig.vehicleId = null; | ||||||||||||||
| } else { | ||||||||||||||
| rebuildConfig.vehicleId = null; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+419
to
+429
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have one common error message for both cases? That way we can also avoid multiple if-else cases. Maybe something like, "Vehicle XXX is no longer listed for building. Redirecting to new build page...". |
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -442,10 +465,17 @@ 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 if (rebuildConfig.fromUrlParams) { | ||||||||||||||
| console.warn(`URL parameter version '${rebuildConfig.versionId}' not found for vehicle '${new_vehicle_id}'. Defaulting to first available version.`); | ||||||||||||||
| rebuildConfig.versionId = null; | ||||||||||||||
| } else { | ||||||||||||||
| rebuildConfig.versionId = null; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+468
to
+478
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other comment for vehicles. |
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -498,10 +528,17 @@ 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 if (rebuildConfig.fromUrlParams) { | ||||||||||||||
| console.warn(`URL parameter board '${rebuildConfig.boardId}' not found for version '${version_id}'. Defaulting to first available board.`); | ||||||||||||||
| rebuildConfig.boardId = null; | ||||||||||||||
| } else { | ||||||||||||||
| rebuildConfig.boardId = null; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+531
to
+541
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other comment for vehicles. |
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename
initRebuildtoinitPreSelectand do both in same function (and get rid ofinitFromUrlParamsaltogether). We first check ifrebuild_fromparam is there, if not we check vehicle_id, board_id and version_id are present, and set those properties.The only difference would be that we would not be setting selected_features[], in second case.