Add step type support for work order profiles and steps, update database schema, APIs, and UI components to handle configurable step types.

This commit is contained in:
2026-05-17 19:21:11 -04:00
parent 309f19520b
commit 6307babbfa
8 changed files with 481 additions and 89 deletions
+17 -8
View File
@@ -178,14 +178,17 @@ func (h *ProfileHandler) CreateStep(w http.ResponseWriter, r *http.Request) {
respondError(w, http.StatusBadRequest, "title required")
return
}
if body.StepType == "" {
body.StepType = "work_step"
}
var maxOrder int
h.db.QueryRow(`SELECT ISNULL(MAX(step_order),0) FROM wo_profile_steps WHERE profile_id=@p1`, profileID).Scan(&maxOrder)
var sid int
err = h.db.QueryRow(`
INSERT INTO wo_profile_steps (profile_id, step_order, title, description, required)
OUTPUT INSERTED.id VALUES (@p1, @p2, @p3, @p4, @p5)`,
profileID, maxOrder+1, body.Title, body.Description, body.Required,
INSERT INTO wo_profile_steps (profile_id, step_order, title, description, required, step_type, type_config)
OUTPUT INSERTED.id VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7)`,
profileID, maxOrder+1, body.Title, body.Description, body.Required, body.StepType, body.TypeConfig,
).Scan(&sid)
if err != nil {
respondError(w, http.StatusInternalServerError, err.Error())
@@ -207,8 +210,11 @@ func (h *ProfileHandler) UpdateStep(w http.ResponseWriter, r *http.Request) {
respondError(w, http.StatusBadRequest, "title required")
return
}
h.db.Exec(`UPDATE wo_profile_steps SET title=@p1, description=@p2, required=@p3, step_order=@p4 WHERE id=@p5`,
body.Title, body.Description, body.Required, body.StepOrder, sid)
if body.StepType == "" {
body.StepType = "work_step"
}
h.db.Exec(`UPDATE wo_profile_steps SET title=@p1, description=@p2, required=@p3, step_order=@p4, step_type=@p5, type_config=@p6 WHERE id=@p7`,
body.Title, body.Description, body.Required, body.StepOrder, body.StepType, body.TypeConfig, sid)
var step model.ProfileStep
h.db.Get(&step, `SELECT * FROM wo_profile_steps WHERE id=@p1`, sid)
respond(w, http.StatusOK, step)
@@ -262,10 +268,13 @@ func (h *ProfileHandler) Apply(w http.ResponseWriter, r *http.Request) {
h.db.QueryRow(`SELECT ISNULL(MAX(step_order),0) FROM wo_steps WHERE wo_id=@p1`, woID).Scan(&maxOrder)
for _, s := range steps {
if s.StepType == "" {
s.StepType = "work_step"
}
h.db.Exec(`
INSERT INTO wo_steps (wo_id, step_order, title, description, required)
VALUES (@p1, @p2, @p3, @p4, @p5)`,
woID, maxOrder+s.StepOrder, s.Title, s.Description, s.Required)
INSERT INTO wo_steps (wo_id, step_order, title, description, required, step_type, type_config)
VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7)`,
woID, maxOrder+s.StepOrder, s.Title, s.Description, s.Required, s.StepType, s.TypeConfig)
}
// Fill instructions if blank; update priority only on draft WOs