fix country params

This commit is contained in:
pakintada@gmail.com 2024-01-19 14:59:21 +07:00
parent 4ece2cf30c
commit 09d71ac61e
13 changed files with 299 additions and 242 deletions

View file

@ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { MaterialCode, MaterialSetting } from '../models/recipe.model'; import { MaterialCode, MaterialSetting } from '../models/recipe.model';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs'; import { Observable, count } from 'rxjs';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe'; import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage'; import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage';
@ -44,11 +44,13 @@ export class MaterialService {
"name": string, "name": string,
"type": string "type": string
}[] | null>>{ }[] | null>>{
console.log("getFullMaterialDetail", country, filename, country || this.getCurrentCountry(this.department!)); console.log("getFullMaterialDetail", country, "where filename = ",filename, "department.short = ", this.department!);
let asyncCountry = await AsyncStorage.getItem<string>('currentRecipeCountry'); let currentCountryWithoutDepartment = await this.getCurrentCountry();
let asyncCountry = await this.getCurrentCountry(this.department!);
country = country || asyncCountry; console.log("[FullMatFetchService] get current country = ", currentCountryWithoutDepartment, " do switch tuple = ", getCountryMapSwitcher(currentCountryWithoutDepartment));
country = getCountryMapSwitcher(currentCountryWithoutDepartment);
filename = filename || this.getCurrentFile(); filename = filename || this.getCurrentFile();
// finalize fetch from what? // finalize fetch from what?
@ -102,6 +104,8 @@ export class MaterialService {
console.log('Material.service::fullname: ', fullname); console.log('Material.service::fullname: ', fullname);
await AsyncStorage.setItem('currentRecipeCountry', fullname);
// localStorage.setItem('currentRecipeCountry', fullname); // localStorage.setItem('currentRecipeCountry', fullname);
return fullname; return fullname;
} }

View file

@ -96,12 +96,16 @@ export class RecipeService {
} }
async getRecipeDetail(productCode: string): Promise<Observable<RecipeDetail>> { async getRecipeDetail(productCode: string): Promise<Observable<RecipeDetail>> {
let asyncCountry = await this.getCurrentCountry(this.department!);
console.log('get detail by asyncCountry', asyncCountry);
return this._httpClient.get<RecipeDetail>( return this._httpClient.get<RecipeDetail>(
environment.api + '/recipes/' + productCode, environment.api + '/recipes/' + productCode,
{ {
params: { params: {
filename: this.getCurrentFile(), filename: this.getCurrentFile(),
country: await this.getCurrentCountry(this.department!), country: asyncCountry,
}, },
withCredentials: true, withCredentials: true,
responseType: 'json', responseType: 'json',
@ -112,12 +116,15 @@ export class RecipeService {
async getRecipeDetailMat( async getRecipeDetailMat(
productCode: string productCode: string
): Promise<Observable<{ result: RecipeDetailMat[]; }>> { ): Promise<Observable<{ result: RecipeDetailMat[]; }>> {
let asyncCountry = await this.getCurrentCountry(this.department!);
return this._httpClient.get<{ result: RecipeDetailMat[] }>( return this._httpClient.get<{ result: RecipeDetailMat[] }>(
environment.api + '/recipes/' + productCode + '/mat', environment.api + '/recipes/' + productCode + '/mat',
{ {
params: { params: {
filename: this.getCurrentFile(), filename: this.getCurrentFile(),
country: await this.getCurrentCountry(this.department!), country: asyncCountry,
}, },
withCredentials: true, withCredentials: true,
responseType: 'json', responseType: 'json',
@ -251,6 +258,7 @@ export class RecipeService {
} }
getSubMenus(country: string, filename: string, productCode: string) { getSubMenus(country: string, filename: string, productCode: string) {
console.log('getSubMenus', country, filename, productCode);
return this._httpClient.get<Recipe01[]>( return this._httpClient.get<Recipe01[]>(
environment.api + environment.api +
'/recipes/' + '/recipes/' +

View file

@ -1,16 +1,22 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable, count } from 'rxjs';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { Topping, ToppingSet } from '../models/recipe.model'; import { Topping, ToppingSet } from '../models/recipe.model';
import { RecipeService } from './recipe.service';
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ToppingService { export class ToppingService {
constructor(private _httpClient: HttpClient) {} constructor(private _httpClient: HttpClient, private _recipeService: RecipeService) {}
getToppings(country: string, filename: string): Observable<Topping> { async getToppings(country: string, filename: string): Promise<Observable<Topping>> {
console.log("getToppings", country);
let asyncCountry = await this._recipeService.getCurrentCountry();
country = getCountryMapSwitcher(asyncCountry);
console.log("getToppingsPreFetch", country, asyncCountry);
return this._httpClient.get<Topping>( return this._httpClient.get<Topping>(
`${environment.api}/recipes/${country}/${filename}/toppings`, `${environment.api}/recipes/${country}/${filename}/toppings`,
{ {
@ -23,7 +29,11 @@ export class ToppingService {
); );
} }
getToppingsOfRecipe(country: string, filename: string, productCode: string): Observable<ToppingSet[]> { async getToppingsOfRecipe(country: string, filename: string, productCode: string): Promise<Observable<ToppingSet[]>> {
console.log("getToppingsOfRecipe", country);
let asyncCountry = await this._recipeService.getCurrentCountry();
country = country || asyncCountry;
console.log("getToppingsOfRecipePreFetch", country, asyncCountry);
return this._httpClient.get<ToppingSet[]>( return this._httpClient.get<ToppingSet[]>(
`${environment.api}/recipes/${country}/${filename}/${productCode}/toppings`, `${environment.api}/recipes/${country}/${filename}/${productCode}/toppings`,
{ {

View file

@ -130,7 +130,7 @@
</div> </div>
</div> </div>
<div id="toppingSet" class="carousel-item w-full"> <!-- <div id="toppingSet" class="carousel-item w-full">
<div <div
class="overflow-auto h-[75vh] mb-4 rounded bg-white border border-gray-200 shadow max-w-screen-xl" class="overflow-auto h-[75vh] mb-4 rounded bg-white border border-gray-200 shadow max-w-screen-xl"
> >
@ -139,7 +139,7 @@
(toppingSetChange)="onToppingListChange($event)" (toppingSetChange)="onToppingListChange($event)"
></app-recipe-toppingset> ></app-recipe-toppingset>
</div> </div>
</div> </div> -->
</div> </div>
<!-- try pop up modal --> <!-- try pop up modal -->

View file

@ -20,7 +20,6 @@ import { UserPermissions } from 'src/app/core/auth/userPermissions';
import { ToppingService } from 'src/app/core/services/topping.service'; import { ToppingService } from 'src/app/core/services/topping.service';
import { copy, transformToTSV } from 'src/app/shared/helpers/copy'; import { copy, transformToTSV } from 'src/app/shared/helpers/copy';
import { RecipeToppingsetComponent } from "./recipe-toppingset/recipe-toppingset.component";
@Component({ @Component({
selector: 'app-recipe-details', selector: 'app-recipe-details',
@ -41,7 +40,6 @@ import { RecipeToppingsetComponent } from "./recipe-toppingset/recipe-toppingset
ConfirmModal, ConfirmModal,
DatePipe, DatePipe,
RecipeListComponent, RecipeListComponent,
RecipeToppingsetComponent,
FormsModule FormsModule
] ]
}) })
@ -109,7 +107,7 @@ export class RecipeDetailsComponent implements OnInit {
this.recipeOriginalDetail = { ...this.recipeDetailForm.getRawValue() }; this.recipeOriginalDetail = { ...this.recipeDetailForm.getRawValue() };
}); });
this._recipeService.getSubMenus(await this._recipeService.getCurrentCountry(this.department), this._recipeService.getCurrentFile(), this.productCode).subscribe((data) => { this._recipeService.getSubMenus(await this._recipeService.getCurrentCountry(), this._recipeService.getCurrentFile(), this.productCode).subscribe((data) => {
console.log('Submenus', data); console.log('Submenus', data);
this.submenus = data; this.submenus = data;
}); });
@ -117,7 +115,7 @@ export class RecipeDetailsComponent implements OnInit {
this.recipeDetailForm.valueChanges.subscribe(this.onRecipeDetailFormChange); this.recipeDetailForm.valueChanges.subscribe(this.onRecipeDetailFormChange);
this._toppingService.getToppingsOfRecipe(this.department, this._recipeService.getCurrentFile(), this.productCode).subscribe((data) => { (await this._toppingService.getToppingsOfRecipe(this.department, this._recipeService.getCurrentFile(), this.productCode)).subscribe((data) => {
this.toppingSet = data; this.toppingSet = data;
// console.log('Toppings', data); // console.log('Toppings', data);
}) })

View file

@ -1,5 +1,5 @@
import { NgFor, NgIf } from '@angular/common'; import { NgFor, NgIf } from '@angular/common';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Component, EventEmitter, Input, OnInit, Output, ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR } from '@angular/core';
import { import {
FormArray, FormArray,
FormBuilder, FormBuilder,
@ -291,6 +291,7 @@ export class RecipeListComponent implements OnInit {
// TODO: embed this to recipelist // TODO: embed this to recipelist
this._materialService.getMaterialCodes()).subscribe((materials) => { this._materialService.getMaterialCodes()).subscribe((materials) => {
this.materialList = materials; this.materialList = materials;
console.log("[MatService] get materials", materials.length);
}); });
(await this._materialService.getFullMaterialDetail()).subscribe((materials) => { (await this._materialService.getFullMaterialDetail()).subscribe((materials) => {
@ -384,6 +385,17 @@ export class RecipeListComponent implements OnInit {
this.fullMaterialList!.forEach((mat) => { this.fullMaterialList!.forEach((mat) => {
let category = getMaterialType(mat.materialId); let category = getMaterialType(mat.materialId);
// try again
if(category == 'others'){
// find min
// console.log(Math.floor(mat.materialId / 1000) );
let interCode = Math.floor(mat.materialId / 10000) * 10000;
let originalCode = mat.materialId - (interCode);
console.log("from",mat.materialId,"interCode", interCode, "originalCode", originalCode);
category = getMaterialType(originalCode);
console.log("get original category of inter", category);
}
if (Array.isArray(catMap[category])) { if (Array.isArray(catMap[category])) {
catMap[category].push({ catMap[category].push({

View file

@ -5,6 +5,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RecipeService } from 'src/app/core/services/recipe.service'; import { RecipeService } from 'src/app/core/services/recipe.service';
import { ToppingService } from 'src/app/core/services/topping.service'; import { ToppingService } from 'src/app/core/services/topping.service';
import { Topping, ToppingGroup, ToppingSet } from 'src/app/core/models/recipe.model'; import { Topping, ToppingGroup, ToppingSet } from 'src/app/core/models/recipe.model';
import { ActivatedRoute } from '@angular/router';
@Component({ @Component({
selector: 'app-recipe-topping', selector: 'app-recipe-topping',
@ -27,17 +28,19 @@ export class RecipeToppingComponent implements OnInit {
id: string; id: string;
members: { id: string; name: string }[]; members: { id: string; name: string }[];
}[] = []; }[] = [];
department = this._route.snapshot.paramMap.get('department');
constructor( constructor(
private _recipeService: RecipeService, private _recipeService: RecipeService,
private _toppingService: ToppingService private _toppingService: ToppingService,
private _route: ActivatedRoute
) {} ) {}
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this._toppingService (await this._toppingService
.getToppings( .getToppings(
await this._recipeService.getCurrentCountry(), this.department!,
this._recipeService.getCurrentFile() this._recipeService.getCurrentFile()
) ))
.subscribe((data) => { .subscribe((data) => {
this.allToppings = data; this.allToppings = data;
// console.log('allToppings', data); // console.log('allToppings', data);

View file

@ -1,4 +1,4 @@
<table class="table" [formGroup]="toppingForm"> <!-- <table class="table" [formGroup]="toppingForm">
<thead> <thead>
<tr> <tr>
<th>Slot (Material Id)</th> <th>Slot (Material Id)</th>
@ -48,4 +48,4 @@
<!-- ListGroupID --> <!-- ListGroupID -->
</tr> </tr>
</tbody> </tbody>
</table> </table> -->

View file

@ -1,220 +1,220 @@
import { NgFor } from '@angular/common'; // import { NgFor } from '@angular/common';
import { Component, Input, Output, OnInit, EventEmitter } from '@angular/core'; // import { Component, Input, Output, OnInit, EventEmitter } from '@angular/core';
import { // import {
FormArray, // FormArray,
FormBuilder, // FormBuilder,
FormsModule, // FormsModule,
ReactiveFormsModule, // ReactiveFormsModule,
} from '@angular/forms'; // } from '@angular/forms';
import { forEach, isEqual } from 'lodash'; // import { forEach, isEqual } from 'lodash';
import { // import {
Topping, // Topping,
ToppingGroup, // ToppingGroup,
ToppingList, // ToppingList,
ToppingSet, // ToppingSet,
} from 'src/app/core/models/recipe.model'; // } from 'src/app/core/models/recipe.model';
import { RecipeService } from 'src/app/core/services/recipe.service'; // import { RecipeService } from 'src/app/core/services/recipe.service';
import { ToppingService } from 'src/app/core/services/topping.service'; // import { ToppingService } from 'src/app/core/services/topping.service';
import { NgSelectModule } from '@ng-select/ng-select'; // import { NgSelectModule } from '@ng-select/ng-select';
import { CommonModule } from '@angular/common'; // import { CommonModule } from '@angular/common';
@Component({ // @Component({
selector: 'app-recipe-toppingset', // selector: 'app-recipe-toppingset',
templateUrl: './recipe-toppingset.component.html', // templateUrl: './recipe-toppingset.component.html',
standalone: true, // standalone: true,
imports: [ // imports: [
NgFor, // NgFor,
FormsModule, // FormsModule,
ReactiveFormsModule, // ReactiveFormsModule,
CommonModule, // CommonModule,
NgSelectModule, // NgSelectModule,
], // ],
}) // })
export class RecipeToppingsetComponent implements OnInit { // export class RecipeToppingsetComponent implements OnInit {
@Input() productCode!: string; // @Input() productCode!: string;
@Output() toppingSetChange = new EventEmitter<unknown[]>(); // @Output() toppingSetChange = new EventEmitter<unknown[]>();
allToppings: Topping | undefined = undefined; // allToppings: Topping | undefined = undefined;
allToppingsDefinitions: // allToppingsDefinitions:
| { groupId: string; name: string; members: string; default: string }[] // | { groupId: string; name: string; members: string; default: string }[]
| null = [{ groupId: '0', name: 'none', members: '0', default: '0' }]; // | null = [{ groupId: '0', name: 'none', members: '0', default: '0' }];
allToppingMembersByGroup: { // allToppingMembersByGroup: {
id: string; // id: string;
members: { id: string; name: string }[]; // members: { id: string; name: string }[];
}[] = []; // }[] = [];
private _toppingSetOriginalArray!: ToppingSet[]; // private _toppingSetOriginalArray!: ToppingSet[];
constructor( // constructor(
private _recipeService: RecipeService, // private _recipeService: RecipeService,
private _toppingService: ToppingService, // private _toppingService: ToppingService,
private _formBuilder: FormBuilder // private _formBuilder: FormBuilder
) {} // ) {}
toppingForm = this._formBuilder.group( // toppingForm = this._formBuilder.group(
{ // {
toppingList: this._formBuilder.array([]), // toppingList: this._formBuilder.array([]),
}, // },
{ updateOn: 'blur' } // { updateOn: 'blur' }
); // );
get toppingList(): FormArray { // get toppingList(): FormArray {
return this.toppingForm.get('toppingList') as FormArray; // return this.toppingForm.get('toppingList') as FormArray;
} // }
async ngOnInit(): Promise<void> { // async ngOnInit(): Promise<void> {
this._toppingService // this._toppingService
.getToppingsOfRecipe( // .getToppingsOfRecipe(
await this._recipeService.getCurrentCountry(), // await this._recipeService.getCurrentCountry(),
this._recipeService.getCurrentFile(), // this._recipeService.getCurrentFile(),
this.productCode // this.productCode
) // )
.subscribe((data) => { // .subscribe((data) => {
// this.toppingForm.patchValue({toppingList: data}); // // this.toppingForm.patchValue({toppingList: data});
this._toppingSetOriginalArray = data; // this._toppingSetOriginalArray = data;
data.forEach((toppingSet: ToppingSet) => { // data.forEach((toppingSet: ToppingSet) => {
this.toppingList.push( // this.toppingList.push(
this._formBuilder.group({ // this._formBuilder.group({
isUse: toppingSet.isUse, // isUse: toppingSet.isUse,
groupID: toppingSet.groupID, // groupID: toppingSet.groupID,
defaultIDSelect: toppingSet.defaultIDSelect, // defaultIDSelect: toppingSet.defaultIDSelect,
ListGroupID: toppingSet.ListGroupID, // ListGroupID: toppingSet.ListGroupID,
}) // })
); // );
}); // });
// console.log('controls', this.toppingList.controls); // // console.log('controls', this.toppingList.controls);
// this.toppingSetChange.emit(this.toppingSetList); // // this.toppingSetChange.emit(this.toppingSetList);
}); // });
// fetch all toppings : group and list // // fetch all toppings : group and list
this._toppingService // this._toppingService
.getToppings( // .getToppings(
await this._recipeService.getCurrentCountry(), // await this._recipeService.getCurrentCountry(),
this._recipeService.getCurrentFile() // this._recipeService.getCurrentFile()
) // )
.subscribe((data) => { // .subscribe((data) => {
this.allToppings = data; // this.allToppings = data;
// console.log('allToppings', data); // // console.log('allToppings', data);
data.ToppingGroup.forEach((group: ToppingGroup) => { // data.ToppingGroup.forEach((group: ToppingGroup) => {
if (this.allToppingsDefinitions != null) { // if (this.allToppingsDefinitions != null) {
// this.allToppingsDefinitions = {}; // // this.allToppingsDefinitions = {};
this.allToppingsDefinitions.push({ // this.allToppingsDefinitions.push({
groupId: group.groupID, // groupId: group.groupID,
name: group.name, // name: group.name,
members: group.idInGroup, // members: group.idInGroup,
default: group.idDefault, // default: group.idDefault,
}); // });
this.allToppingMembersByGroup.push({ // this.allToppingMembersByGroup.push({
id: group.groupID, // id: group.groupID,
members: this.mapToppingListToMember(group.idInGroup.split(',')), // members: this.mapToppingListToMember(group.idInGroup.split(',')),
}); // });
} // }
}); // });
// console.log(this.allToppingsDefinitions); // // console.log(this.allToppingsDefinitions);
// console.log('allToppingMembersByGroup', this.allToppingMembersByGroup); // // console.log('allToppingMembersByGroup', this.allToppingMembersByGroup);
}); // });
this.toppingForm.valueChanges.subscribe((value) => { // this.toppingForm.valueChanges.subscribe((value) => {
//validator // //validator
for (let i = 0; i < value.toppingList!.length; i++) { // for (let i = 0; i < value.toppingList!.length; i++) {
let toppingSet = value.toppingList![i] as any; // let toppingSet = value.toppingList![i] as any;
// handle null case // // handle null case
if (toppingSet.defaultIDSelect == null) { // if (toppingSet.defaultIDSelect == null) {
toppingSet.defaultIDSelect = 0; // toppingSet.defaultIDSelect = 0;
} // }
// handle null case // // handle null case
if (toppingSet.groupID == null) { // if (toppingSet.groupID == null) {
toppingSet.groupID = '0'; // toppingSet.groupID = '0';
} // }
// handle null case // // handle null case
if (!Array.isArray(toppingSet.ListGroupID)) { // if (!Array.isArray(toppingSet.ListGroupID)) {
toppingSet.ListGroupID = [parseInt(toppingSet.groupID), 0, 0, 0]; // toppingSet.ListGroupID = [parseInt(toppingSet.groupID), 0, 0, 0];
} // }
} // }
let isDiff = !isEqual(this._toppingSetOriginalArray, value.toppingList!); // let isDiff = !isEqual(this._toppingSetOriginalArray, value.toppingList!);
if (isDiff) { // if (isDiff) {
let newToppingSetList: any[] = []; // let newToppingSetList: any[] = [];
forEach(value.toppingList!, (toppingSet: any) => { // forEach(value.toppingList!, (toppingSet: any) => {
// transform value // // transform value
toppingSet.defaultIDSelect = parseInt(toppingSet.defaultIDSelect); // toppingSet.defaultIDSelect = parseInt(toppingSet.defaultIDSelect);
newToppingSetList.push(toppingSet); // newToppingSetList.push(toppingSet);
}); // });
// console.log('newToppingList', newToppingSetList); // // console.log('newToppingList', newToppingSetList);
this.toppingSetChange.emit(newToppingSetList as unknown[]); // this.toppingSetChange.emit(newToppingSetList as unknown[]);
} else { // } else {
// console.log('newToppingListNoChange', value.toppingList); // // console.log('newToppingListNoChange', value.toppingList);
this.toppingSetChange.emit([]); // this.toppingSetChange.emit([]);
} // }
}); // });
} // }
// match group id to its name // // match group id to its name
getGroupName(groupID: string) { // getGroupName(groupID: string) {
// check if array // // check if array
if (Array.isArray(this.allToppings!.ToppingGroup)) { // if (Array.isArray(this.allToppings!.ToppingGroup)) {
return (this.allToppings!.ToppingGroup as ToppingGroup[]).find( // return (this.allToppings!.ToppingGroup as ToppingGroup[]).find(
(group) => group.groupID == groupID // (group) => group.groupID == groupID
)?.name; // )?.name;
} else { // } else {
return undefined; // return undefined;
} // }
} // }
openToppingList(i: any) { // openToppingList(i: any) {
console.log('select', i); // console.log('select', i);
} // }
currentGroupId(i: any) { // currentGroupId(i: any) {
console.log('currentGroupId', i); // console.log('currentGroupId', i);
return (this.toppingForm.value.toppingList![i] as any).groupID as string; // return (this.toppingForm.value.toppingList![i] as any).groupID as string;
} // }
getMembersByGroupId(groupID: string) { // getMembersByGroupId(groupID: string) {
return this.allToppingMembersByGroup.find((x) => x.id == groupID)?.members; // return this.allToppingMembersByGroup.find((x) => x.id == groupID)?.members;
} // }
getGroupIdByIndex(i: number) { // getGroupIdByIndex(i: number) {
// console.log("getGroupId",this.toppingList.value![i]) // // console.log("getGroupId",this.toppingList.value![i])
return (this.toppingList.value![i] as any).groupID as string; // return (this.toppingList.value![i] as any).groupID as string;
} // }
mapToppingListToMember = (mm: string[]) => // mapToppingListToMember = (mm: string[]) =>
mm.map((m) => { // mm.map((m) => {
// find actual topping from toppingList // // find actual topping from toppingList
let actualTopping = this.allToppings!.ToppingList.find((t) => t.id == m); // let actualTopping = this.allToppings!.ToppingList.find((t) => t.id == m);
return { // return {
id: actualTopping!.id, // id: actualTopping!.id,
name: actualTopping?.name == null ? m : actualTopping!.name, // name: actualTopping?.name == null ? m : actualTopping!.name,
}; // };
}); // });
getDefaultOfGroup(groupID: any) { // getDefaultOfGroup(groupID: any) {
this.toppingList.controls.forEach((control) => { // this.toppingList.controls.forEach((control) => {
if ((control.value as any).groupID == groupID) { // if ((control.value as any).groupID == groupID) {
let newDefault = this.allToppingsDefinitions!.find( // let newDefault = this.allToppingsDefinitions!.find(
(x) => x.groupId == groupID // (x) => x.groupId == groupID
)!.default; // )!.default;
// set new defaultid // // set new defaultid
control.get('defaultIDSelect')?.setValue(newDefault); // control.get('defaultIDSelect')?.setValue(newDefault);
} // }
}); // });
} // }
compareFunc = (a: any, b: any) => a.toString() === b.toString(); // compareFunc = (a: any, b: any) => a.toString() === b.toString();
} // }

View file

@ -241,8 +241,8 @@ export class RecipesComponent implements OnInit, OnDestroy, AfterViewInit {
this.materialList = materials; this.materialList = materials;
}); });
this._toppingService (await this._toppingService
.getToppings(this.department, this._recipeService.getCurrentFile()) .getToppings(this.department, this._recipeService.getCurrentFile()))
.subscribe((tp) => { .subscribe((tp) => {
this.toppings = { this.toppings = {
toppingGroup: tp.ToppingGroup, toppingGroup: tp.ToppingGroup,

View file

@ -184,6 +184,8 @@ func NewData(taoLogger *logger.TaoLogger) *Data {
func (d *Data) GetRecipe(countryID, filename string) *models.Recipe { func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
d.taoLogger.Log.Debug("invoke GetRecipe", zap.String("countryID", countryID), zap.String("filename", filename))
if countryID == "" { if countryID == "" {
return d.currentRecipe["tha"] return d.currentRecipe["tha"]
} }
@ -194,7 +196,7 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
if recipe, ok := d.recipeMap[filename]; ok { if recipe, ok := d.recipeMap[filename]; ok {
d.CurrentFile[countryID] = filename d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID // d.CurrentCountryID[countryID] = countryID
return recipe.Recipe[countryID] return recipe.Recipe[countryID]
} }
@ -204,13 +206,13 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
filename = d.CurrentFile[countryID] filename = d.CurrentFile[countryID]
} }
d.CurrentFile[countryID] = filename // d.CurrentFile[countryID] = filename
d.taoLogger.Log.Debug("GetRecipe", zap.String("filename", filename), zap.String("countryID", countryID)) d.taoLogger.Log.Debug("GetRecipe", zap.String("filename", filename), zap.String("countryID", countryID))
d.CurrentCountryID[countryID] = countryID // d.CurrentCountryID[countryID] = countryID
recipe, err := helpers.ReadRecipeFile(countryID, filename) recipe, err := helpers.ReadRecipeFile(countryID, filename)
if err != nil { if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err)) d.taoLogger.Log.Error("GetRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
return d.currentRecipe[countryID] return d.currentRecipe[countryID]
} }
@ -248,21 +250,41 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string) (models.Recipe01, error) { func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string) (models.Recipe01, error) {
// try convert
if len(countryID) != 3 {
for k, v := range d.CurrentCountryID {
fmt.Println("GetRecipe01ByProductCode.Iterate", k, v, v == countryID)
if v == countryID {
countryID = k
break
}
}
}
fmt.Println("GetRecipe01ByProductCode", filename, countryID, productCode)
if !strings.Contains(filename, "tmp") { if !strings.Contains(filename, "tmp") {
if filename == "" || filename == d.CurrentFile[countryID] { if filename == "" || filename == d.CurrentFile[countryID] {
fmt.Println("GetRecipe01ByProductCode.ReadCurrent", filename, d.CurrentFile) // , d.CurrentFile, countryID, "result by country id", len(d.currentRecipe[countryID].Recipe01)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::filename", filename)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::countryID", countryID)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::CurrentFile", d.CurrentFile)
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::CurrentCountryID", d.CurrentCountryID)
for _, v := range d.currentRecipe[countryID].Recipe01 { for _, v := range d.currentRecipe[countryID].Recipe01 {
if v.ProductCode == productCode { if v.ProductCode == productCode {
return v, nil return v, nil
} }
} }
fmt.Println("No result in current recipe", countryID)
} else if recipe, ok := d.recipeMap[filename]; ok { } else if recipe, ok := d.recipeMap[filename]; ok {
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile) fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile, recipe.Recipe[countryID], "countryID=", countryID)
for _, v := range recipe.Recipe[countryID].Recipe01 { for _, v := range recipe.Recipe[countryID].Recipe01 {
if v.ProductCode == productCode { if v.ProductCode == productCode {
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getSuccess", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
return v, nil return v, nil
} }
} }
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getFail", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
} }
} }
@ -272,12 +294,12 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
filename = d.CurrentFile[countryID] filename = d.CurrentFile[countryID]
} }
d.CurrentFile[countryID] = filename // d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID // d.CurrentCountryID[countryID] = countryID
for _, v := range countries { for _, v := range countries {
if v.CountryName == countryID { if v.CountryName == countryID {
d.CurrentCountryID[countryID] = v.CountryID // d.CurrentCountryID[countryID] = v.CountryID
countryID = v.CountryID countryID = v.CountryID
break break
} }
@ -286,7 +308,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
recipe, err := helpers.ReadRecipeFile(countryID, filename) recipe, err := helpers.ReadRecipeFile(countryID, filename)
if err != nil { if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err)) d.taoLogger.Log.Error("GetRecipe01ByProductCode: Error when read recipe file, Return default recipe", zap.Error(err))
for _, v := range d.currentRecipe[countryID].Recipe01 { for _, v := range d.currentRecipe[countryID].Recipe01 {
if v.ProductCode == productCode { if v.ProductCode == productCode {
return v, nil return v, nil
@ -373,15 +395,15 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
if !strings.Contains(filename, "tmp") { if !strings.Contains(filename, "tmp") {
if filename == "" || filename == d.CurrentFile[countryID] { if filename == "" || filename == d.CurrentFile[countryID] {
copy(result, d.currentRecipe[countryID].MaterialSetting) // copy(result, d.currentRecipe[countryID].MaterialSetting)
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result)) // d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
return d.currentRecipe[countryID].MaterialSetting return d.currentRecipe[countryID].MaterialSetting
} }
if recipe, ok := d.recipeMap[filename]; ok { if recipe, ok := d.recipeMap[filename]; ok {
copy(result, recipe.Recipe[countryID].MaterialSetting) copy(result, recipe.Recipe[countryID].MaterialSetting)
d.CurrentFile[countryID] = filename d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID // d.CurrentCountryID[countryID] = countryID
return d.currentRecipe[countryID].MaterialSetting return d.currentRecipe[countryID].MaterialSetting
} }
} }
@ -390,19 +412,19 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
filename = d.CurrentFile[countryID] filename = d.CurrentFile[countryID]
} }
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("filename", filename), zap.Any("countryID", countryID)) // d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("filename", filename), zap.Any("countryID", countryID))
d.CurrentFile[countryID] = filename // d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID // d.CurrentCountryID[countryID] = countryID
recipe, err := helpers.ReadRecipeFile(countryID, filename) recipe, err := helpers.ReadRecipeFile(countryID, filename)
if err != nil { if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err)) d.taoLogger.Log.Error("GetMaterialSetting: Error when read recipe file, Return default recipe", zap.Error(err))
copy(result, d.currentRecipe[countryID].MaterialSetting) copy(result, d.currentRecipe[countryID].MaterialSetting)
return d.currentRecipe[countryID].MaterialSetting return d.currentRecipe[countryID].MaterialSetting
} }
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting)) // d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting))
d.currentRecipe[countryID] = recipe d.currentRecipe[countryID] = recipe
@ -443,12 +465,12 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
filename = d.CurrentFile[countryID] filename = d.CurrentFile[countryID]
} }
d.CurrentFile[countryID] = filename // d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID // d.CurrentCountryID[countryID] = countryID
recipe, err := helpers.ReadRecipeFile(countryID, filename) recipe, err := helpers.ReadRecipeFile(countryID, filename)
if err != nil { if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err)) d.taoLogger.Log.Error("GetMaterialCode: Error when read recipe file, Return default recipe", zap.Error(err))
return d.currentRecipe[countryID].MaterialCode return d.currentRecipe[countryID].MaterialCode
} }
@ -510,12 +532,12 @@ func (d *Data) GetToppings(countryID, filename string) models.Topping {
filename = d.CurrentFile[countryID] filename = d.CurrentFile[countryID]
} }
d.CurrentFile[countryID] = filename // d.CurrentFile[countryID] = filename
d.CurrentCountryID[countryID] = countryID // d.CurrentCountryID[countryID] = countryID
recipe, err := helpers.ReadRecipeFile(countryID, filename) recipe, err := helpers.ReadRecipeFile(countryID, filename)
if err != nil { if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err)) d.taoLogger.Log.Error("GetToppings: Error when read recipe file, Return default recipe", zap.Error(err))
return d.currentRecipe[countryID].Topping return d.currentRecipe[countryID].Topping
} }
@ -533,7 +555,7 @@ func (d *Data) GetToppingsOfRecipe(countryID, filename string, productCode strin
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode) recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
if err != nil { if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err)) d.taoLogger.Log.Error("GetToppingOfRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
return []models.ToppingSet{}, err return []models.ToppingSet{}, err
} }
@ -549,7 +571,7 @@ func (d *Data) GetSubmenusOfRecipe(countryID, filename, productCode string) ([]m
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode) recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
if err != nil { if err != nil {
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err)) d.taoLogger.Log.Error("GetSubmenusOfRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
return []models.Recipe01{}, err return []models.Recipe01{}, err
} }

View file

@ -131,7 +131,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
countryID, err := mr.data.GetCountryIDByName(country) countryID, err := mr.data.GetCountryIDByName(country)
if err != nil { if err != nil {
mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err)) // mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
http.Error(w, "Country not found", http.StatusNotFound) http.Error(w, "Country not found", http.StatusNotFound)
return return
} }
@ -142,7 +142,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
matIDuint, err := strconv.ParseUint(matID, 10, 64) matIDuint, err := strconv.ParseUint(matID, 10, 64)
if err != nil { if err != nil {
mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err)) // mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
http.Error(w, "Invalid material id", http.StatusBadRequest) http.Error(w, "Invalid material id", http.StatusBadRequest)
return return
} }
@ -157,7 +157,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
} }
if err := json.NewEncoder(w).Encode(matSetting); err != nil { if err := json.NewEncoder(w).Encode(matSetting); err != nil {
mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err)) // mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
http.Error(w, "Internal Error", http.StatusInternalServerError) http.Error(w, "Internal Error", http.StatusInternalServerError)
return return
} }

View file

@ -67,7 +67,7 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
return contracts.RecipeDetailMatListResponse{}, fmt.Errorf("country name: %s not found", request.Country) return contracts.RecipeDetailMatListResponse{}, fmt.Errorf("country name: %s not found", request.Country)
} }
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("request", request)) rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("request", request))
recipe, err := rs.db.GetRecipe01ByProductCode(request.Filename, request.Country, request.ProductCode) recipe, err := rs.db.GetRecipe01ByProductCode(request.Filename, request.Country, request.ProductCode)