From e9a3e8e42bf966fba38649783ac0ebc8531aeb0a Mon Sep 17 00:00:00 2001 From: Adriano Date: Sun, 22 Feb 2026 19:07:55 +0100 Subject: [PATCH] fix: rewrite subtask editing to reuse add form instead of inline table row Edit button now opens the same "Nuova Misurazione" form pre-filled with existing data, showing "Modifica Misurazione" title and "Aggiorna Misurazione" button. Also adds marker_number to SubtaskUpdate schema so edits persist. Co-Authored-By: Claude Opus 4.6 --- client/templates/maker/task_editor.html | 206 ++++-------------------- server/schemas/task.py | 1 + 2 files changed, 32 insertions(+), 175 deletions(-) diff --git a/client/templates/maker/task_editor.html b/client/templates/maker/task_editor.html index 3ea02bf..6897f15 100644 --- a/client/templates/maker/task_editor.html +++ b/client/templates/maker/task_editor.html @@ -542,58 +542,35 @@ - @@ -772,8 +633,8 @@
-

- {{ _('Nuova Misurazione') }} +

@@ -789,7 +650,7 @@
@@ -871,11 +732,11 @@
- -
@@ -1105,11 +966,7 @@ function taskEditor() { newTask: { title: '', directive: '', description: '' }, // ---- Subtask CRUD state ---- - editingSubtask: null, - editSubtaskData: { - marker_number: 1, description: '', measurement_type: '', - nominal: null, utl: null, uwl: null, lwl: null, ltl: null, unit: 'mm' - }, + editingSubtaskId: null, addingSubtaskForTask: null, newSubtask: { marker_number: 1, description: '', measurement_type: '', @@ -1211,7 +1068,7 @@ function taskEditor() { } // Reset inline editors when collapsing if (this.expandedTask !== taskId) { - this.editingSubtask = null; + this.editingSubtaskId = null; this.addingSubtaskForTask = null; } }, @@ -1476,7 +1333,7 @@ function taskEditor() { }, openAddSubtask(task) { - this.editingSubtask = null; + this.editingSubtaskId = null; this.addingSubtaskForTask = task.id; this.resetNewSubtask(task.id); }, @@ -1530,9 +1387,10 @@ function taskEditor() { }, startEditSubtask(subtask, taskId) { - this.addingSubtaskForTask = null; - this.editingSubtask = subtask.id; - this.editSubtaskData = { + // Open the same form used for adding, but pre-filled with existing data + this.editingSubtaskId = subtask.id; + this.addingSubtaskForTask = taskId; + this.newSubtask = { marker_number: subtask.marker_number, description: subtask.description || '', measurement_type: subtask.measurement_type || '', @@ -1545,29 +1403,27 @@ function taskEditor() { }; }, - cancelEditSubtask() { - this.editingSubtask = null; - this.editSubtaskData = { - marker_number: 1, description: '', measurement_type: '', - nominal: null, utl: null, uwl: null, lwl: null, ltl: null, unit: 'mm' - }; + cancelSubtaskForm(taskId) { + this.editingSubtaskId = null; + this.addingSubtaskForTask = null; + this.resetNewSubtask(taskId); }, async updateSubtask(subtaskId, taskId) { - if (!this.editSubtaskData.description.trim()) return; + if (!this.newSubtask.description.trim()) return; this.saving = true; this.errorMessage = ''; const payload = { - marker_number: this.editSubtaskData.marker_number || 1, - description: this.editSubtaskData.description.trim(), - measurement_type: this.editSubtaskData.measurement_type || null, - nominal: this.editSubtaskData.nominal, - utl: this.editSubtaskData.utl, - uwl: this.editSubtaskData.uwl, - lwl: this.editSubtaskData.lwl, - ltl: this.editSubtaskData.ltl, - unit: this.editSubtaskData.unit || 'mm' + marker_number: this.newSubtask.marker_number || 1, + description: this.newSubtask.description.trim(), + measurement_type: this.newSubtask.measurement_type || null, + nominal: this.newSubtask.nominal, + utl: this.newSubtask.utl, + uwl: this.newSubtask.uwl, + lwl: this.newSubtask.lwl, + ltl: this.newSubtask.ltl, + unit: this.newSubtask.unit || 'mm' }; try { @@ -1593,7 +1449,7 @@ function taskEditor() { task.subtasks[idx] = { ...task.subtasks[idx], ...data }; } } - this.cancelEditSubtask(); + this.cancelSubtaskForm(taskId); this.successMessage = {{ _("Misurazione aggiornata")|tojson }}; } } catch (err) { diff --git a/server/schemas/task.py b/server/schemas/task.py index 79a419b..9119a14 100644 --- a/server/schemas/task.py +++ b/server/schemas/task.py @@ -20,6 +20,7 @@ class SubtaskCreate(BaseModel): class SubtaskUpdate(BaseModel): """Schema for updating a subtask.""" + marker_number: Optional[int] = Field(None, ge=1) description: Optional[str] = Field(None, min_length=1, max_length=500) measurement_type: Optional[str] = Field(None, max_length=100) nominal: Optional[float] = None