feat: add location_slots to job_reservations for full slot persistence and update version to 0.9.1
Fix: modems do not show as "missing" any more, cleans up the dashboard.
This commit is contained in:
@@ -2015,6 +2015,13 @@ async function plannerSave() {
|
||||
const method = isEdit ? 'PUT' : 'POST';
|
||||
|
||||
const plannerDeviceType = document.querySelector('input[name="planner_device_type"]:checked')?.value || 'seismograph';
|
||||
// Save full slot list including empties so they survive round-trips
|
||||
const allSlots = plannerState.slots.map(s => ({
|
||||
unit_id: s.unit_id || null,
|
||||
location_name: s.location_name || null,
|
||||
power_type: s.power_type || null,
|
||||
notes: s.notes || null
|
||||
}));
|
||||
const payload = {
|
||||
name, start_date: start, end_date: end,
|
||||
project_id: projectId || null,
|
||||
@@ -2022,7 +2029,8 @@ async function plannerSave() {
|
||||
device_type: plannerDeviceType,
|
||||
color, notes: notes || null,
|
||||
estimated_units: estUnits,
|
||||
quantity_needed: totalSlots
|
||||
quantity_needed: totalSlots,
|
||||
location_slots: allSlots
|
||||
};
|
||||
|
||||
const resp = await fetch(url, {
|
||||
@@ -2118,9 +2126,24 @@ async function openPlanner(reservationId) {
|
||||
plannerSetColor(res.color || '#3B82F6', true);
|
||||
const dtRadio = document.querySelector(`input[name="planner_device_type"][value="${res.device_type || 'seismograph'}"]`);
|
||||
if (dtRadio) dtRadio.checked = true;
|
||||
// Pre-fill slots from existing assigned units
|
||||
for (const u of (res.assigned_units || [])) {
|
||||
plannerState.slots.push({ unit_id: u.id, power_type: u.power_type || null, notes: u.notes || null, location_name: u.location_name || null });
|
||||
// Restore full slot list — use location_slots if available, else fall back to assigned_units only
|
||||
const assignedById = {};
|
||||
for (const u of (res.assigned_units || [])) assignedById[u.id] = u;
|
||||
if (res.location_slots && res.location_slots.length > 0) {
|
||||
for (const s of res.location_slots) {
|
||||
const filled = s.unit_id ? (assignedById[s.unit_id] || {}) : {};
|
||||
plannerState.slots.push({
|
||||
unit_id: s.unit_id || null,
|
||||
power_type: s.power_type || filled.power_type || null,
|
||||
notes: s.notes || filled.notes || null,
|
||||
location_name: s.location_name || filled.location_name || null
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Legacy: no location_slots stored, just load filled ones
|
||||
for (const u of (res.assigned_units || [])) {
|
||||
plannerState.slots.push({ unit_id: u.id, power_type: u.power_type || null, notes: u.notes || null, location_name: u.location_name || null });
|
||||
}
|
||||
}
|
||||
|
||||
const titleEl = document.getElementById('planner-form-title');
|
||||
|
||||
Reference in New Issue
Block a user