From 79b1fc2f2424f61881f622f1ebbea4cb03467392 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 8 Oct 2020 15:28:34 +0200 Subject: [PATCH] fix update recipe --- .../wwwroot/src/@types/recipe-current.d.ts | 1 + .../wwwroot/src/services/recipeService.ts | 12 +++++++++--- Thermo.Active/wwwroot/src/store/recipe.store.ts | 14 +++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Thermo.Active/wwwroot/src/@types/recipe-current.d.ts b/Thermo.Active/wwwroot/src/@types/recipe-current.d.ts index b1e2c4a8..977e995d 100644 --- a/Thermo.Active/wwwroot/src/@types/recipe-current.d.ts +++ b/Thermo.Active/wwwroot/src/@types/recipe-current.d.ts @@ -21,6 +21,7 @@ declare module Recipe { valueAct: number, numDec: number, id: number, + checkpointHMI: number; enumVal: { [id: string]: { text: string, anim: string } } } diff --git a/Thermo.Active/wwwroot/src/services/recipeService.ts b/Thermo.Active/wwwroot/src/services/recipeService.ts index 134739ca..073ff127 100644 --- a/Thermo.Active/wwwroot/src/services/recipeService.ts +++ b/Thermo.Active/wwwroot/src/services/recipeService.ts @@ -27,18 +27,23 @@ export class RecipeService extends baseRestService { async Update(model: { [id: string]: Recipe.IValue }) { let payload = {} + let needsUpdate = false; for (const key in model) { - if (model.hasOwnProperty(key)) { + if (model.hasOwnProperty(key) && model[key].setpointHMI != model[key].checkpointHMI) { if (typeof model[key]?.setpointHMI === "boolean") payload[key] = model[key]?.setpointHMI ? 1 : 0; else payload[key] = model[key]?.setpointHMI; + + // resetto il checkpoint + model[key].checkpointHMI = model[key].setpointHMI; + needsUpdate = true; } } - let result = await this.Put((await this.BASE_URL()) + "update", payload, true); - return result; + if (!needsUpdate) return; + await this.Put((await this.BASE_URL()) + "update", payload, true); } async UpdateChanges(newmodel: { [id: string]: Recipe.IValue }, oldmodel: { [id: string]: Recipe.IValue }) { @@ -60,6 +65,7 @@ export class RecipeService extends baseRestService { async Confirm(section: string) { let result = await this.Put((await this.BASE_URL()) + "confirm?section=" + section, null, true); + recipeActions.resetCheckPoint(store); return result; } diff --git a/Thermo.Active/wwwroot/src/store/recipe.store.ts b/Thermo.Active/wwwroot/src/store/recipe.store.ts index 8f1c5c36..e6e30e6a 100644 --- a/Thermo.Active/wwwroot/src/store/recipe.store.ts +++ b/Thermo.Active/wwwroot/src/store/recipe.store.ts @@ -13,6 +13,7 @@ export interface RecipeActions { setChanged(context, value); setCurrent(context, model: Recipe.IRecipe, avoidSetpointHMI: boolean); setOverview(context, model: Overview.IOverview); + resetCheckPoint(context); } export interface RecipeGetters { @@ -72,6 +73,8 @@ export const recipeStore = { if (model.avoidSetpoint) m.setpointHMI = v.setpointHMI; Object.assign(v, m); + if (!model.avoidSetpoint) + v.checkpointHMI = v.setpointHMI; } else { (state._map as Map).set(m.id, m) @@ -81,7 +84,13 @@ export const recipeStore = { } } }, - + ResetCheckpoint(state) { + for (const key in state.current) + if (state.current.hasOwnProperty(key)) { + let m = state.current[key] as Recipe.IValue; + m.checkpointHMI = m.setpointHMI; + } + }, SetOverview(state, model: Overview.IOverview) { for (const key in model) { if (model.hasOwnProperty(key)) { @@ -106,6 +115,9 @@ export const recipeStore = { reset(context) { context.commit("Reset") }, + resetCheckPoint(context) { + context.commit("ResetCheckpoint"); + }, async setCurrent(context, model: Recipe.IRecipe, avoidSetpointHMI: boolean = false) { context.commit("SetCurrent", { avoidSetpoint: avoidSetpointHMI, recipe: model });