add concat unedit key when send

This commit is contained in:
pakintada@gmail.com 2024-01-22 09:23:16 +07:00
parent cfd5c723c0
commit 17c4b116b0

View file

@ -174,7 +174,6 @@ export class RecipeDetailsComponent implements OnInit {
username = this._userService.getCurrentUser()!.name;
// diff with rawValue, then send
let to_send = {
@ -218,11 +217,12 @@ export class RecipeDetailsComponent implements OnInit {
isShow: (this.rawRecipe as any).isShow,
disable: (this.rawRecipe as any).disable,
recipes: [...(this.repl.length <= 0 ? [] : this.repl)],
SubMenu: [...((this.rawRecipe! as any).SubMenu!)],
ToppingSet: [...((this.rawRecipe as any).ToppingSet)],
SubMenu: [...(this.rawRecipe! as any).SubMenu!],
ToppingSet: [...(this.rawRecipe as any).ToppingSet],
};
// TODO: update value in targeted recipe
this.concatNoEditKeyToMap(this.rawRecipe, to_send);
console.log('to_send', to_send);
this._recipeService.editChanges(
await this._recipeService.getCurrentCountry(this.department),
@ -232,7 +232,11 @@ export class RecipeDetailsComponent implements OnInit {
}
);
console.log('Sending changes');
void this._router.navigate(['/' + this.department + '/recipes']);
void this._router
.navigate(['/' + this.department + '/recipes'])
.then(() => {
window.location.reload();
});
},
};
@ -277,14 +281,27 @@ export class RecipeDetailsComponent implements OnInit {
this.tpl = repl[0] as never[];
// check length of toppinglist
console.log("tpl length", this.tpl.length, "original length", (this.rawRecipe! as any).ToppingSet.length);
for(let ti = 0; ti < this.tpl.length; ti++){
console.log(
'tpl length',
this.tpl.length,
'original length',
(this.rawRecipe! as any).ToppingSet.length
);
for (let ti = 0; ti < this.tpl.length; ti++) {
// check at the same index
if(!isEqual(this.tpl[ti][0], (this.rawRecipe as any).ToppingSet[ti])){
console.log('topping list changed', ti, this.tpl[ti][0], (this.rawRecipe as any).ToppingSet[ti]);
if (!isEqual(this.tpl[ti][0], (this.rawRecipe as any).ToppingSet[ti])) {
console.log(
'topping list changed',
ti,
this.tpl[ti][0],
(this.rawRecipe as any).ToppingSet[ti]
);
// update raw recipe
(this.rawRecipe as any).ToppingSet[ti] = this.tpl[ti][0];
console.log('after update topping', (this.rawRecipe as any).ToppingSet[ti]);
console.log(
'after update topping',
(this.rawRecipe as any).ToppingSet[ti]
);
}
}
@ -327,5 +344,12 @@ export class RecipeDetailsComponent implements OnInit {
console.log('Selected submenu', productCode);
}
// concat remaining unused keys
concatNoEditKeyToMap(source: any, target: any) {
for (const key of Object.keys(source)) {
if (!Object.keys(target).includes(key)) {
target[key] = source[key];
}
}
}
}