From e5eee656d592497d4187b59ac87219854b2e149c Mon Sep 17 00:00:00 2001 From: Kenta420 Date: Thu, 19 Oct 2023 15:45:24 +0700 Subject: [PATCH] update env --- .../recipe-details.component.html | 13 +- .../recipe-details.component.ts | 150 ++++++++++-------- .../recipe-list/recipe-list.component.html | 6 +- .../recipe-list/recipe-list.component.ts | 55 ++++++- client/src/environments/environment.ts | 2 +- 5 files changed, 143 insertions(+), 83 deletions(-) diff --git a/client/src/app/features/recipes/recipe-details/recipe-details.component.html b/client/src/app/features/recipes/recipe-details/recipe-details.component.html index 4544b22..44f5ff6 100644 --- a/client/src/app/features/recipes/recipe-details/recipe-details.component.html +++ b/client/src/app/features/recipes/recipe-details/recipe-details.component.html @@ -6,21 +6,18 @@
- {{ originalRecipeDetail.recipe.name }} + {{ recipeMetaData!.name }}
|
- {{ originalRecipeDetail.recipe.productCode }} + {{ recipeMetaData!.productCode }}

Last Modify

- {{ - originalRecipeDetail.recipe.lastModified - | date : "dd/MM/yyyy HH:mm:ss" - }} + {{ recipeMetaData!.lastModified | date : "dd/MM/yyyy HH:mm:ss" }}

@@ -112,9 +109,7 @@
- +
= + new BehaviorSubject(null); + + matForRecipeList = this.originalRecipeDetail.pipe( + map((x) => x?.recipe.recipes) + ); isLoaded: boolean = false; isMatLoaded: boolean = false; @@ -78,7 +83,7 @@ export class RecipeDetailsComponent implements OnInit { isShow: recipe.isShow, disable: recipe.disable, }); - this.originalRecipeDetail = { + this.originalRecipeDetail.next({ recipe: { lastModified: recipe.LastChange, productCode: recipe.productCode, @@ -92,71 +97,81 @@ export class RecipeDetailsComponent implements OnInit { disable: recipe.disable, }, recipes: recipe.recipes, - }; + }); this.recipeMetaData = recipeMetaData; this.isLoaded = true; - - const ids = this.originalRecipeDetail.recipes?.map( - (recipe) => recipe.materialPathId - ); - - this._materialService.getMaterialCodes(ids).subscribe((data) => { - this.originalRecipeDetail.recipe.recipes = recipe.recipes - .map((item) => { - for (let i = 0; i < data.length; i++) { - if (item.materialPathId === 0) { - return { - id: 0, - name: '', - enable: item.isUse, - mixOrder: item.MixOrder, - stirTime: item.stirTime, - powderGram: item.powderGram, - powderTime: item.powderTime, - syrupGram: item.syrupGram, - syrupTime: item.syrupTime, - waterCold: item.waterCold, - waterHot: item.waterYield, - }; - } - - if (item.materialPathId === data[i].materialID) { - return { - id: data[i].materialID, - name: data[i].PackageDescription, - enable: item.isUse, - mixOrder: item.MixOrder, - stirTime: item.stirTime, - powderGram: item.powderGram, - powderTime: item.powderTime, - syrupGram: item.syrupGram, - syrupTime: item.syrupTime, - waterCold: item.waterCold, - waterHot: item.waterYield, - }; - } - } - - return { - id: item.materialPathId, - name: '', - enable: item.isUse, - mixOrder: item.MixOrder, - stirTime: item.stirTime, - powderGram: item.powderGram, - powderTime: item.powderTime, - syrupGram: item.syrupGram, - syrupTime: item.syrupTime, - waterCold: item.waterCold, - waterHot: item.waterYield, - }; - }) - .sort((a, b) => { - return a.id === 0 ? 1 : a.id > b.id ? 1 : -1; - }); - this.isMatLoaded = true; - }); }); + + this.originalRecipeDetail.subscribe((originalRecipeDetail) => { + if (originalRecipeDetail == null) return; + + const ids = originalRecipeDetail.recipes?.map( + (recipe) => recipe.materialPathId + ); + + this._materialService.getMaterialCodes(ids).subscribe((data) => { + this.originalRecipeDetail.next({ + ...originalRecipeDetail, + recipe: { + ...originalRecipeDetail.recipe, + recipes: originalRecipeDetail + .recipes!.map((item) => { + for (let i = 0; i < data.length; i++) { + if (item.materialPathId === 0) { + return { + id: 0, + name: '', + enable: item.isUse, + mixOrder: item.MixOrder, + stirTime: item.stirTime, + powderGram: item.powderGram, + powderTime: item.powderTime, + syrupGram: item.syrupGram, + syrupTime: item.syrupTime, + waterCold: item.waterCold, + waterHot: item.waterYield, + }; + } + + if (item.materialPathId === data[i].materialID) { + return { + id: data[i].materialID, + name: data[i].PackageDescription, + enable: item.isUse, + mixOrder: item.MixOrder, + stirTime: item.stirTime, + powderGram: item.powderGram, + powderTime: item.powderTime, + syrupGram: item.syrupGram, + syrupTime: item.syrupTime, + waterCold: item.waterCold, + waterHot: item.waterYield, + }; + } + } + + return { + id: item.materialPathId, + name: '', + enable: item.isUse, + mixOrder: item.MixOrder, + stirTime: item.stirTime, + powderGram: item.powderGram, + powderTime: item.powderTime, + syrupGram: item.syrupGram, + syrupTime: item.syrupTime, + waterCold: item.waterCold, + waterHot: item.waterYield, + }; + }) + .sort((a, b) => { + return a.id === 0 ? 1 : a.id > b.id ? 1 : -1; + }), + }, + }); + this.isMatLoaded = true; + }); + }); } showConfirmSaveModal: EventEmitter = new EventEmitter(); @@ -197,6 +212,9 @@ export class RecipeDetailsComponent implements OnInit { } get isValueChanged() { - return !isEqual(this.recipeDetail.value, this.originalRecipeDetail?.recipe); + return !isEqual( + this.recipeDetail.value, + this.originalRecipeDetail.getValue()?.recipe + ); } } diff --git a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html index 846d667..0e162fc 100644 --- a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html +++ b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html @@ -16,16 +16,16 @@ -
+
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 63bb346..baa5a5d 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 @@ -1,18 +1,65 @@ import { NgFor, NgIf } from '@angular/common'; import { Component, Input, OnInit } from '@angular/core'; +import { + FormArray, + FormControl, + FormGroup, + ReactiveFormsModule, +} from '@angular/forms'; import { BehaviorSubject, Observable, map } from 'rxjs'; import { MaterialData } from 'src/app/shared/types/recipe'; +interface RecipeListDataFormGroup { + id: FormControl; + name: FormControl; + enable: FormControl; + mixOrder: FormControl; + stirTime: FormControl; + powderGram: FormControl; + powderTime: FormControl; + syrupGram: FormControl; + syrupTime: FormControl; + waterCold: FormControl; + waterHot: FormControl; +} + @Component({ selector: 'app-recipe-list', templateUrl: './recipe-list.component.html', standalone: true, - imports: [NgIf, NgFor], + imports: [NgIf, NgFor, ReactiveFormsModule], }) export class RecipeListComponent implements OnInit { - @Input({ required: true }) recipeListData: MaterialData[] | undefined; + @Input({ required: true }) recipeListData: Observable< + MaterialData[] | undefined + > = new Observable(undefined); - $isLoaded: Observable = new BehaviorSubject(false); + $isLoaded: Observable = this.recipeListData.pipe(map((x) => !!x)); - ngOnInit(): void {} + recipeListDataForm = new FormArray>([]); + + ngOnInit(): void { + this.recipeListData.subscribe((x) => { + if (x) { + for (let recipe of x) { + const x = new FormControl(0); + this.recipeListDataForm.push( + new FormGroup({ + id: new FormControl(recipe.id), + name: new FormControl(recipe.name), + enable: new FormControl(recipe.enable), + mixOrder: new FormControl(recipe.mixOrder), + stirTime: new FormControl(recipe.stirTime), + powderGram: new FormControl(recipe.powderGram), + powderTime: new FormControl(recipe.powderTime), + syrupGram: new FormControl(recipe.syrupGram), + syrupTime: new FormControl(recipe.syrupTime), + waterCold: new FormControl(recipe.waterCold), + waterHot: new FormControl(recipe.waterHot), + }) + ); + } + } + }); + } } diff --git a/client/src/environments/environment.ts b/client/src/environments/environment.ts index 33630d7..16ac628 100644 --- a/client/src/environments/environment.ts +++ b/client/src/environments/environment.ts @@ -1,4 +1,4 @@ export const environment = { production: true, - api: 'https://recipe.taobin.io:8090/api/', + api: 'https://recipe.taobin.io:8090/api', };