|
-
-
-
+
|
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 47e0dfa..8295062 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,5 +1,5 @@
import { NgFor, NgIf } from '@angular/common';
-import { Component, Input, OnInit } from '@angular/core';
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import {
FormArray,
FormBuilder,
@@ -7,6 +7,7 @@ import {
FormGroup,
ReactiveFormsModule,
} from '@angular/forms';
+import { isEqual, sortBy } from 'lodash';
import { first } from 'rxjs';
import {
RecipeDetail,
@@ -15,20 +16,6 @@ import {
import { RecipeService } from 'src/app/core/services/recipe.service';
import { Action, ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
-export 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',
@@ -36,14 +23,8 @@ export interface RecipeListDataFormGroup {
imports: [NgIf, NgFor, ReactiveFormsModule],
})
export class RecipeListComponent implements OnInit {
- @Input({ required: true }) parentForm!: FormGroup;
- @Input({ required: true }) actionRecord!: ActionRecord<
- RecipeDetail | RecipeDetailMat
- >;
-
- @Input({ required: true }) recipeDetailOriginal!: any;
-
@Input({ required: true }) productCode!: string;
+ @Output() recipeListFormChange = new EventEmitter();
isMatLoaded: boolean = false;
@@ -52,20 +33,27 @@ export class RecipeListComponent implements OnInit {
private _formBuilder: FormBuilder
) {}
+ recipeListForm = this._formBuilder.group(
+ {
+ recipeListData: this._formBuilder.array([]),
+ },
+ { updateOn: 'blur' }
+ );
+
+ private _recipeListOriginalArray!: RecipeDetailMat[];
+
ngOnInit(): void {
this._recipeService
.getRecipeDetailMat(this.productCode)
.pipe(first())
.subscribe(({ result }) => {
- if (this.recipeDetailOriginal)
- this.recipeDetailOriginal.recipeListData = result;
- else this.recipeDetailOriginal = { recipeListData: result };
+ this._recipeListOriginalArray = result;
result.forEach((recipeDetailMat: RecipeDetailMat) => {
this.recipeListData.push(
this._formBuilder.group({
+ isUse: recipeDetailMat.isUse,
materialID: recipeDetailMat.materialID,
- name: recipeDetailMat.name,
- enable: recipeDetailMat.isUse,
+ name: [{ value: recipeDetailMat.name, disabled: true }],
mixOrder: recipeDetailMat.mixOrder,
stirTime: recipeDetailMat.stirTime,
powderGram: recipeDetailMat.powderGram,
@@ -79,43 +67,24 @@ export class RecipeListComponent implements OnInit {
});
this.isMatLoaded = true;
});
+
+ this.recipeListForm.valueChanges.subscribe((value) => {
+ console.log(value.recipeListData);
+ console.log(this._recipeListOriginalArray);
+ if (
+ !isEqual(
+ sortBy(value, 'materialID'),
+ sortBy(this._recipeListOriginalArray, 'materialID')
+ )
+ ) {
+ this.recipeListFormChange.emit(true);
+ } else {
+ this.recipeListFormChange.emit(false);
+ }
+ });
}
get recipeListData(): FormArray {
- return this.parentForm.get('recipeListData') as FormArray;
- }
-
- addRecipeData(): void {
- const newRecipeDetailMat: RecipeDetailMat = {
- materialID: 0,
- name: '',
- mixOrder: 0,
- feedParameter: 0,
- feedPattern: 0,
- isUse: false,
- materialPathId: 0,
- powderGram: 0,
- powderTime: 0,
- stirTime: 0,
- syrupGram: 0,
- syrupTime: 0,
- waterCold: 0,
- waterYield: 0,
- };
- this.recipeListData.push(this._formBuilder.group(newRecipeDetailMat));
- this.actionRecord.addAction(
- new Action('add', newRecipeDetailMat, 'recipeListData')
- );
- }
-
- deleteRecipeData(index: number): void {
- const recipeDetailMat: RecipeDetailMat =
- this.recipeListData.at(index).value;
-
- this.recipeListData.removeAt(index);
-
- this.actionRecord.addAction(
- new Action('delete', recipeDetailMat, 'recipeListData')
- );
+ return this.recipeListForm.get('recipeListData') as FormArray;
}
}
diff --git a/client/src/app/features/recipes/recipes.component.html b/client/src/app/features/recipes/recipes.component.html
index 2b47002..0fba628 100644
--- a/client/src/app/features/recipes/recipes.component.html
+++ b/client/src/app/features/recipes/recipes.component.html
@@ -1,5 +1,5 @@
diff --git a/client/src/app/features/recipes/recipes.component.ts b/client/src/app/features/recipes/recipes.component.ts
index 50a187c..04153c5 100644
--- a/client/src/app/features/recipes/recipes.component.ts
+++ b/client/src/app/features/recipes/recipes.component.ts
@@ -313,13 +313,15 @@ export class RecipesComponent implements OnInit, OnDestroy {
openJsonTab() {
window.open(
- environment.api + `/recipes/${this._recipeService.getCurrentFile()}/json`,
+ environment.api +
+ `/recipes/${this._recipeService.getCurrentCountry()}/${this._recipeService.getCurrentFile()}/json`,
'_blank'
);
}
scrollToTop() {
- this.tableCtx!.nativeElement.scroll;
+ const table = this.tableCtx!.nativeElement;
+ table.scrollTo({ top: 0, behavior: 'smooth' });
}
ngOnDestroy(): void {
diff --git a/server/contracts/recipe.go b/server/contracts/recipe.go
index c2daaff..07cb8f3 100644
--- a/server/contracts/recipe.go
+++ b/server/contracts/recipe.go
@@ -55,12 +55,12 @@ type RecipeDetailResponse struct {
}
type RecipeDetailMat struct {
+ IsUse bool `json:"isUse"`
MaterialID uint64 `json:"materialID"`
Name string `json:"name"`
MixOrder int `json:"mixOrder"`
FeedParameter int `json:"feedParameter"`
FeedPattern int `json:"feedPattern"`
- IsUse bool `json:"isUse"`
MaterialPathId int `json:"materialPathId"`
PowderGram int `json:"powderGram"`
PowderTime int `json:"powderTime"`
diff --git a/server/data/data.go b/server/data/data.go
index e9204b4..5f80add 100644
--- a/server/data/data.go
+++ b/server/data/data.go
@@ -33,7 +33,7 @@ type Data struct {
func NewData() *Data {
countries := []helpers.CountryName{{
- CountryID: "thai",
+ CountryID: "tha",
CountryName: "Thailand",
}, {
CountryID: "mys",
@@ -46,8 +46,8 @@ func NewData() *Data {
allRecipeFiles := helpers.ScanRecipeFiles(countries)
- defaultFile := "coffeethai02_580.json"
- defaultCountry := "thai"
+ defaultFile := "coffeethai02_600.json"
+ defaultCountry := "tha"
defaultRecipe, err := helpers.ReadRecipeFile(defaultCountry, defaultFile)
if err != nil {
diff --git a/server/helpers/filereader.go b/server/helpers/filereader.go
index 35cc138..60c2d3c 100644
--- a/server/helpers/filereader.go
+++ b/server/helpers/filereader.go
@@ -32,10 +32,6 @@ func ReadFile(filePath string) (string, error) {
func ReadRecipeFile(countryID, filePath string) (*models.Recipe, error) {
- if countryID == "thai" {
- countryID = ""
- }
-
file, err := os.Open(path.Join("cofffeemachineConfig", countryID, filePath))
if err != nil {
@@ -69,12 +65,7 @@ func ScanRecipeFiles(countries []CountryName) map[string][]RecipePath {
recipeFiles := map[string][]RecipePath{}
for _, country := range countries {
- var files []string
- if country.CountryID == "thai" {
- files = ListFile("cofffeemachineConfig/coffeethai02_*.json")
- } else {
- files = ListFile("cofffeemachineConfig/" + country.CountryID + "/coffeethai02_*.json")
- }
+ files := ListFile("cofffeemachineConfig/" + country.CountryID + "/coffeethai02_*.json")
sort.Slice(files, func(i, j int) bool {
file1, err := os.Stat(files[i])
diff --git a/server/services/recipe/recipe.go b/server/services/recipe/recipe.go
index ba12f3a..51bab85 100644
--- a/server/services/recipe/recipe.go
+++ b/server/services/recipe/recipe.go
@@ -73,12 +73,12 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
for _, mat := range matsCode {
if v.MaterialPathId == int(mat.MaterialID) {
result.Result = append(result.Result, contracts.RecipeDetailMat{
+ IsUse: v.IsUse,
MaterialID: mat.MaterialID,
Name: mat.PackageDescription,
MixOrder: v.MixOrder,
FeedParameter: v.FeedParameter,
FeedPattern: v.FeedPattern,
- IsUse: v.IsUse,
MaterialPathId: v.MaterialPathId,
PowderGram: v.PowderGram,
PowderTime: v.PowderTime,
|