From ce7d5954270a1ff5a34369378f99fa97eeb36582 Mon Sep 17 00:00:00 2001 From: "pakintada@gmail.com" Date: Fri, 1 Mar 2024 14:33:48 +0700 Subject: [PATCH] fix(diff_commit_merge): delayed commit data load condition --- .../src/app/core/layout/layout.component.html | 2 +- .../src/app/core/layout/layout.component.ts | 9 +- .../src/app/core/services/recipe.service.ts | 4 +- .../app/features/merge/merge.component.html | 19 +- .../src/app/features/merge/merge.component.ts | 168 +++++++++++------- .../recipe-list/recipe-list.component.html | 10 +- .../recipe-list/recipe-list.component.ts | 84 ++++++--- .../recipe-topping.component.ts | 113 +++++++++--- 8 files changed, 278 insertions(+), 131 deletions(-) diff --git a/client/src/app/core/layout/layout.component.html b/client/src/app/core/layout/layout.component.html index 31e3fc2..8bf8344 100644 --- a/client/src/app/core/layout/layout.component.html +++ b/client/src/app/core/layout/layout.component.html @@ -41,7 +41,7 @@ - @@ -202,6 +205,11 @@ [index]=" getToppingSlotNumber(getTypeForRecipeListAtIndex(i)['id']) " + [diffContext]=" + buildToppingContext( + getToppingSlotNumber(getTypeForRecipeListAtIndex(i)['id']) + ) + " (toppingSetChange)="onToppingSetChange($event, i)" > diff --git a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts index 383723d..0ab62b5 100644 --- a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts +++ b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts @@ -50,6 +50,7 @@ export class RecipeListComponent implements OnInit, OnChanges { @Input() diffChangeContext: { changeContext: any; skipZeroes: boolean; + toppingData: any; } | undefined = undefined; @Output() recipeListFormChange = new EventEmitter(); @@ -299,6 +300,7 @@ export class RecipeListComponent implements OnInit, OnChanges { this.stringParams[index] = stringParamList; } + // console.log("string param debug", this.stringParamData); // --------------- mapping missing data --------------- @@ -491,6 +493,8 @@ export class RecipeListComponent implements OnInit, OnChanges { let currStringParam = new StringParam(recipeDetailMat.StringParam); let stringParamList = currStringParam.extract().as_list(); + console.log('string param list',stringParamList); + let stringParamListTransform: any[] = []; for (let param of stringParamList) { // boolean transform @@ -508,6 +512,8 @@ export class RecipeListComponent implements OnInit, OnChanges { this.stringParams[index] = stringParamList; } + console.log("string param debug change", this.stringParamData); + // --------------- mapping missing data --------------- // map name @@ -593,38 +599,42 @@ export class RecipeListComponent implements OnInit, OnChanges { ] }) ); + + // map material + // fullMaterialList + this.setNameToRecipeList(); }); // resub listener - this.recipeListForm.valueChanges.subscribe((value) => { - // console.log(value.recipeListData); - // console.log("original recipe detail",this._recipeListOriginalArray); - if ( - !isEqual( - sortBy(value, 'materialID'), - sortBy(this._recipeListOriginalArray, 'materialID') - ) - ) { - let emitted_res: any[] = []; + // this.recipeListForm.valueChanges.subscribe((value) => { + // // console.log(value.recipeListData); + // // console.log("original recipe detail",this._recipeListOriginalArray); + // if ( + // !isEqual( + // sortBy(value, 'materialID'), + // sortBy(this._recipeListOriginalArray, 'materialID') + // ) + // ) { + // let emitted_res: any[] = []; - // force type change. temporary solution - forEach(value.recipeListData!, (recipeDetailMat: any) => { - recipeDetailMat.materialPathId = parseInt( - recipeDetailMat.materialPathId! - ); + // // force type change. temporary solution + // forEach(value.recipeListData!, (recipeDetailMat: any) => { + // recipeDetailMat.materialPathId = parseInt( + // recipeDetailMat.materialPathId! + // ); - // revert stirTime - recipeDetailMat.stirTime = recipeDetailMat.stirTime!; + // // revert stirTime + // recipeDetailMat.stirTime = recipeDetailMat.stirTime!; - emitted_res.push(recipeDetailMat); - }); + // emitted_res.push(recipeDetailMat); + // }); - this.recipeListFormChange.emit([this.toppingList, emitted_res] as unknown[]); - } else { - this.recipeListFormChange.emit([]); - } - }); + // this.recipeListFormChange.emit([this.toppingList, emitted_res] as unknown[]); + // } else { + // this.recipeListFormChange.emit([]); + // } + // }); this.stringParamForm.valueChanges.subscribe((value) => { // value.stringParamData: Array @@ -672,6 +682,7 @@ export class RecipeListComponent implements OnInit, OnChanges { } }); + } } } @@ -1044,4 +1055,29 @@ export class RecipeListComponent implements OnInit, OnChanges { return true; } + // reinit + buildToppingContext(index: number){ + + if(this.diffChangeContext != undefined && this.diffChangeContext.toppingData != undefined){ + // console.log('building context of topping',index, this.diffChangeContext.toppingData[index]) + return { + enableEditInDiffMode: false, + preFetchedData: [this.diffChangeContext.toppingData[index]] + }; + } + + + return undefined; + } + + // name mapping + setNameToRecipeList(){ + this.recipeListData.value.forEach((recipe: any, index: number) => { + // get name from full material list + let mat_name = this.fullMaterialList!.find( + (mat) => mat.materialId.toString() == recipe.materialPathId.toString() + )!.name; + this.recipeListData.at(index).get('name')?.setValue(mat_name); + }); + } } diff --git a/client/src/app/features/recipes/recipe-details/recipe-topping/recipe-topping.component.ts b/client/src/app/features/recipes/recipe-details/recipe-topping/recipe-topping.component.ts index 32545ff..5cbb873 100644 --- a/client/src/app/features/recipes/recipe-details/recipe-topping/recipe-topping.component.ts +++ b/client/src/app/features/recipes/recipe-details/recipe-topping/recipe-topping.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; import { CommonModule } from '@angular/common'; import { NgSelectModule } from '@ng-select/ng-select'; import { @@ -22,9 +22,13 @@ import { ActivatedRoute } from '@angular/router'; imports: [CommonModule, NgSelectModule, FormsModule, ReactiveFormsModule], templateUrl: './recipe-topping.component.html', }) -export class RecipeToppingComponent implements OnInit { +export class RecipeToppingComponent implements OnInit, OnChanges { @Input() productCode: string = ''; @Input() index: number | undefined = undefined; + @Input() diffContext: { + enableEditInDiffMode: boolean; + preFetchedData: any; + } | undefined = undefined; @Output() toppingSetChange = new EventEmitter(); allToppings: Topping | undefined = undefined; @@ -70,39 +74,62 @@ export class RecipeToppingComponent implements OnInit { async ngOnInit(): Promise { // get topping of this recipe - // initialize toppinglist form + // is read mode? + if(this.diffContext != undefined){ + let toppingData = this.diffContext.preFetchedData! as Array; + let readonly = this.diffContext.enableEditInDiffMode; + // suppose the topping data is array - ( - await this._toppingService.getToppingsOfRecipe( - await this._recipeService.getCurrentCountry(), - this._recipeService.getCurrentFile(), - this.productCode - ) - ).subscribe((data) => { - this._toppingSetOriginalArray = data; - console.log('ToppingSet', data, this.index, data.length >= this.index!, data[0]); + // reset form + this.toppingList.clear(); + + // initialize toppinglist form + toppingData.forEach((topping, index) => { + this.listGroupId.push(topping.ListGroupID); + + this.toppingList.push( + this._formBuilder.group({ + isUse: {value: topping.isUse, disabled: readonly}, + groupID: {value: topping.groupID, disabled: readonly}, + defaultIDSelect: {value: topping.defaultIDSelect, disabled: readonly}, + ListGroupID: {value: topping.ListGroupID, disabled: readonly}, + }) + ); + }); + } else { + // initialize toppinglist form + ( + await this._toppingService.getToppingsOfRecipe( + await this._recipeService.getCurrentCountry(), + this._recipeService.getCurrentFile(), + this.productCode + ) + ).subscribe((data) => { + this._toppingSetOriginalArray = data; + console.log('ToppingSet', data, this.index, data.length >= this.index!, data[0]); - if(data[this.index!] != undefined && data[this.index!] != null){ + if(data[this.index!] != undefined && data[this.index!] != null){ - this.listGroupId.push(data[this.index!].ListGroupID); + this.listGroupId.push(data[this.index!].ListGroupID); - // check length of toppingList if in range with given index - if (data.length >= this.index!) { - this.toppingList.push( - this._formBuilder.group({ - isUse: data[this.index!].isUse, - groupID: data[this.index!].groupID, - defaultIDSelect: data[this.index!].defaultIDSelect, - ListGroupID: data[this.index!].ListGroupID, - }) - ); + // check length of toppingList if in range with given index + if (data.length >= this.index!) { + this.toppingList.push( + this._formBuilder.group({ + isUse: data[this.index!].isUse, + groupID: data[this.index!].groupID, + defaultIDSelect: data[this.index!].defaultIDSelect, + ListGroupID: data[this.index!].ListGroupID, + }) + ); + } + + console.log('SubscribeToppingSet', this.toppingList, "list group id=", this.listGroupId); } - console.log('SubscribeToppingSet', this.toppingList, "list group id=", this.listGroupId); - } - - }); + }); + } // get all topping ( @@ -136,6 +163,32 @@ export class RecipeToppingComponent implements OnInit { this.toppingForm.valueChanges.subscribe((value) => {this.triggerValueChange();}); } + // apply on read mode + ngOnChanges(changes: SimpleChanges): void { + console.log('changes on topping', changes); + + if(changes['preFetchedData']){ + let toppingSet = changes['preFetchedData'].currentValue as Array; + + this.toppingList.clear(); + + // initialize toppinglist form + toppingSet.forEach((topping, index) => { + this.listGroupId.push(topping.ListGroupID); + + this.toppingList.push( + this._formBuilder.group({ + isUse: {value: topping.isUse, disabled: true}, + groupID: {value: topping.groupID, disabled: true}, + defaultIDSelect: {value: topping.defaultIDSelect, disabled: true}, + ListGroupID: {value: topping.ListGroupID, disabled: true}, + }) + ); + }); + } + } + + compareFunc = (a: any, b: any) => a.toString() === b.toString(); mapToppingListToMember = (mm: string[]) => @@ -307,4 +360,8 @@ export class RecipeToppingComponent implements OnInit { ListGroupID: value.ListGroupID, }; }; + + + // read only mode + isReadonly = () => this.diffContext != undefined && this.diffContext.enableEditInDiffMode; }