fix country params
This commit is contained in:
parent
4ece2cf30c
commit
09d71ac61e
13 changed files with 299 additions and 242 deletions
|
|
@ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http';
|
|||
import { Injectable } from '@angular/core';
|
||||
import { MaterialCode, MaterialSetting } from '../models/recipe.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, count } from 'rxjs';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
|
||||
import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage';
|
||||
|
|
@ -44,11 +44,13 @@ export class MaterialService {
|
|||
"name": string,
|
||||
"type": string
|
||||
}[] | 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();
|
||||
|
||||
// finalize fetch from what?
|
||||
|
|
@ -102,6 +104,8 @@ export class MaterialService {
|
|||
|
||||
console.log('Material.service::fullname: ', fullname);
|
||||
|
||||
await AsyncStorage.setItem('currentRecipeCountry', fullname);
|
||||
|
||||
// localStorage.setItem('currentRecipeCountry', fullname);
|
||||
return fullname;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,12 +96,16 @@ export class RecipeService {
|
|||
}
|
||||
|
||||
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>(
|
||||
environment.api + '/recipes/' + productCode,
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: await this.getCurrentCountry(this.department!),
|
||||
country: asyncCountry,
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
|
|
@ -112,12 +116,15 @@ export class RecipeService {
|
|||
async getRecipeDetailMat(
|
||||
productCode: string
|
||||
): Promise<Observable<{ result: RecipeDetailMat[]; }>> {
|
||||
|
||||
let asyncCountry = await this.getCurrentCountry(this.department!);
|
||||
|
||||
return this._httpClient.get<{ result: RecipeDetailMat[] }>(
|
||||
environment.api + '/recipes/' + productCode + '/mat',
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: await this.getCurrentCountry(this.department!),
|
||||
country: asyncCountry,
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
|
|
@ -251,6 +258,7 @@ export class RecipeService {
|
|||
}
|
||||
|
||||
getSubMenus(country: string, filename: string, productCode: string) {
|
||||
console.log('getSubMenus', country, filename, productCode);
|
||||
return this._httpClient.get<Recipe01[]>(
|
||||
environment.api +
|
||||
'/recipes/' +
|
||||
|
|
|
|||
|
|
@ -1,16 +1,22 @@
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, count } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Topping, ToppingSet } from '../models/recipe.model';
|
||||
import { RecipeService } from './recipe.service';
|
||||
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
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>(
|
||||
`${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[]>(
|
||||
`${environment.api}/recipes/${country}/${filename}/${productCode}/toppings`,
|
||||
{
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toppingSet" class="carousel-item w-full">
|
||||
<!-- <div id="toppingSet" class="carousel-item w-full">
|
||||
<div
|
||||
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)"
|
||||
></app-recipe-toppingset>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- try pop up modal -->
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
|||
import { ToppingService } from 'src/app/core/services/topping.service';
|
||||
|
||||
import { copy, transformToTSV } from 'src/app/shared/helpers/copy';
|
||||
import { RecipeToppingsetComponent } from "./recipe-toppingset/recipe-toppingset.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipe-details',
|
||||
|
|
@ -41,7 +40,6 @@ import { RecipeToppingsetComponent } from "./recipe-toppingset/recipe-toppingset
|
|||
ConfirmModal,
|
||||
DatePipe,
|
||||
RecipeListComponent,
|
||||
RecipeToppingsetComponent,
|
||||
FormsModule
|
||||
]
|
||||
})
|
||||
|
|
@ -109,7 +107,7 @@ export class RecipeDetailsComponent implements OnInit {
|
|||
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);
|
||||
this.submenus = data;
|
||||
});
|
||||
|
|
@ -117,7 +115,7 @@ export class RecipeDetailsComponent implements OnInit {
|
|||
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;
|
||||
// console.log('Toppings', data);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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 {
|
||||
FormArray,
|
||||
FormBuilder,
|
||||
|
|
@ -291,6 +291,7 @@ export class RecipeListComponent implements OnInit {
|
|||
// TODO: embed this to recipelist
|
||||
this._materialService.getMaterialCodes()).subscribe((materials) => {
|
||||
this.materialList = materials;
|
||||
console.log("[MatService] get materials", materials.length);
|
||||
});
|
||||
|
||||
(await this._materialService.getFullMaterialDetail()).subscribe((materials) => {
|
||||
|
|
@ -384,6 +385,17 @@ export class RecipeListComponent implements OnInit {
|
|||
|
||||
this.fullMaterialList!.forEach((mat) => {
|
||||
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])) {
|
||||
catMap[category].push({
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|||
import { RecipeService } from 'src/app/core/services/recipe.service';
|
||||
import { ToppingService } from 'src/app/core/services/topping.service';
|
||||
import { Topping, ToppingGroup, ToppingSet } from 'src/app/core/models/recipe.model';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipe-topping',
|
||||
|
|
@ -27,17 +28,19 @@ export class RecipeToppingComponent implements OnInit {
|
|||
id: string;
|
||||
members: { id: string; name: string }[];
|
||||
}[] = [];
|
||||
department = this._route.snapshot.paramMap.get('department');
|
||||
|
||||
constructor(
|
||||
private _recipeService: RecipeService,
|
||||
private _toppingService: ToppingService
|
||||
private _toppingService: ToppingService,
|
||||
private _route: ActivatedRoute
|
||||
) {}
|
||||
async ngOnInit(): Promise<void> {
|
||||
this._toppingService
|
||||
(await this._toppingService
|
||||
.getToppings(
|
||||
await this._recipeService.getCurrentCountry(),
|
||||
this.department!,
|
||||
this._recipeService.getCurrentFile()
|
||||
)
|
||||
))
|
||||
.subscribe((data) => {
|
||||
this.allToppings = data;
|
||||
// console.log('allToppings', data);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<table class="table" [formGroup]="toppingForm">
|
||||
<!-- <table class="table" [formGroup]="toppingForm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Slot (Material Id)</th>
|
||||
|
|
@ -48,4 +48,4 @@
|
|||
<!-- ListGroupID -->
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</table> -->
|
||||
|
|
|
|||
|
|
@ -1,220 +1,220 @@
|
|||
import { NgFor } from '@angular/common';
|
||||
import { Component, Input, Output, OnInit, EventEmitter } from '@angular/core';
|
||||
import {
|
||||
FormArray,
|
||||
FormBuilder,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
} from '@angular/forms';
|
||||
import { forEach, isEqual } from 'lodash';
|
||||
import {
|
||||
Topping,
|
||||
ToppingGroup,
|
||||
ToppingList,
|
||||
ToppingSet,
|
||||
} from 'src/app/core/models/recipe.model';
|
||||
import { RecipeService } from 'src/app/core/services/recipe.service';
|
||||
import { ToppingService } from 'src/app/core/services/topping.service';
|
||||
import { NgSelectModule } from '@ng-select/ng-select';
|
||||
import { CommonModule } from '@angular/common';
|
||||
// import { NgFor } from '@angular/common';
|
||||
// import { Component, Input, Output, OnInit, EventEmitter } from '@angular/core';
|
||||
// import {
|
||||
// FormArray,
|
||||
// FormBuilder,
|
||||
// FormsModule,
|
||||
// ReactiveFormsModule,
|
||||
// } from '@angular/forms';
|
||||
// import { forEach, isEqual } from 'lodash';
|
||||
// import {
|
||||
// Topping,
|
||||
// ToppingGroup,
|
||||
// ToppingList,
|
||||
// ToppingSet,
|
||||
// } from 'src/app/core/models/recipe.model';
|
||||
// import { RecipeService } from 'src/app/core/services/recipe.service';
|
||||
// import { ToppingService } from 'src/app/core/services/topping.service';
|
||||
// import { NgSelectModule } from '@ng-select/ng-select';
|
||||
// import { CommonModule } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipe-toppingset',
|
||||
templateUrl: './recipe-toppingset.component.html',
|
||||
standalone: true,
|
||||
imports: [
|
||||
NgFor,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
CommonModule,
|
||||
NgSelectModule,
|
||||
],
|
||||
})
|
||||
export class RecipeToppingsetComponent implements OnInit {
|
||||
@Input() productCode!: string;
|
||||
@Output() toppingSetChange = new EventEmitter<unknown[]>();
|
||||
// @Component({
|
||||
// selector: 'app-recipe-toppingset',
|
||||
// templateUrl: './recipe-toppingset.component.html',
|
||||
// standalone: true,
|
||||
// imports: [
|
||||
// NgFor,
|
||||
// FormsModule,
|
||||
// ReactiveFormsModule,
|
||||
// CommonModule,
|
||||
// NgSelectModule,
|
||||
// ],
|
||||
// })
|
||||
// export class RecipeToppingsetComponent implements OnInit {
|
||||
// @Input() productCode!: string;
|
||||
// @Output() toppingSetChange = new EventEmitter<unknown[]>();
|
||||
|
||||
allToppings: Topping | undefined = undefined;
|
||||
// allToppings: Topping | undefined = undefined;
|
||||
|
||||
allToppingsDefinitions:
|
||||
| { groupId: string; name: string; members: string; default: string }[]
|
||||
| null = [{ groupId: '0', name: 'none', members: '0', default: '0' }];
|
||||
// allToppingsDefinitions:
|
||||
// | { groupId: string; name: string; members: string; default: string }[]
|
||||
// | null = [{ groupId: '0', name: 'none', members: '0', default: '0' }];
|
||||
|
||||
allToppingMembersByGroup: {
|
||||
id: string;
|
||||
members: { id: string; name: string }[];
|
||||
}[] = [];
|
||||
// allToppingMembersByGroup: {
|
||||
// id: string;
|
||||
// members: { id: string; name: string }[];
|
||||
// }[] = [];
|
||||
|
||||
private _toppingSetOriginalArray!: ToppingSet[];
|
||||
// private _toppingSetOriginalArray!: ToppingSet[];
|
||||
|
||||
constructor(
|
||||
private _recipeService: RecipeService,
|
||||
private _toppingService: ToppingService,
|
||||
private _formBuilder: FormBuilder
|
||||
) {}
|
||||
// constructor(
|
||||
// private _recipeService: RecipeService,
|
||||
// private _toppingService: ToppingService,
|
||||
// private _formBuilder: FormBuilder
|
||||
// ) {}
|
||||
|
||||
toppingForm = this._formBuilder.group(
|
||||
{
|
||||
toppingList: this._formBuilder.array([]),
|
||||
},
|
||||
{ updateOn: 'blur' }
|
||||
);
|
||||
// toppingForm = this._formBuilder.group(
|
||||
// {
|
||||
// toppingList: this._formBuilder.array([]),
|
||||
// },
|
||||
// { updateOn: 'blur' }
|
||||
// );
|
||||
|
||||
get toppingList(): FormArray {
|
||||
return this.toppingForm.get('toppingList') as FormArray;
|
||||
}
|
||||
// get toppingList(): FormArray {
|
||||
// return this.toppingForm.get('toppingList') as FormArray;
|
||||
// }
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this._toppingService
|
||||
.getToppingsOfRecipe(
|
||||
await this._recipeService.getCurrentCountry(),
|
||||
this._recipeService.getCurrentFile(),
|
||||
this.productCode
|
||||
)
|
||||
.subscribe((data) => {
|
||||
// this.toppingForm.patchValue({toppingList: data});
|
||||
this._toppingSetOriginalArray = data;
|
||||
// async ngOnInit(): Promise<void> {
|
||||
// this._toppingService
|
||||
// .getToppingsOfRecipe(
|
||||
// await this._recipeService.getCurrentCountry(),
|
||||
// this._recipeService.getCurrentFile(),
|
||||
// this.productCode
|
||||
// )
|
||||
// .subscribe((data) => {
|
||||
// // this.toppingForm.patchValue({toppingList: data});
|
||||
// this._toppingSetOriginalArray = data;
|
||||
|
||||
data.forEach((toppingSet: ToppingSet) => {
|
||||
this.toppingList.push(
|
||||
this._formBuilder.group({
|
||||
isUse: toppingSet.isUse,
|
||||
groupID: toppingSet.groupID,
|
||||
defaultIDSelect: toppingSet.defaultIDSelect,
|
||||
ListGroupID: toppingSet.ListGroupID,
|
||||
})
|
||||
);
|
||||
});
|
||||
// data.forEach((toppingSet: ToppingSet) => {
|
||||
// this.toppingList.push(
|
||||
// this._formBuilder.group({
|
||||
// isUse: toppingSet.isUse,
|
||||
// groupID: toppingSet.groupID,
|
||||
// defaultIDSelect: toppingSet.defaultIDSelect,
|
||||
// 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
|
||||
this._toppingService
|
||||
.getToppings(
|
||||
await this._recipeService.getCurrentCountry(),
|
||||
this._recipeService.getCurrentFile()
|
||||
)
|
||||
.subscribe((data) => {
|
||||
this.allToppings = data;
|
||||
// console.log('allToppings', data);
|
||||
// // fetch all toppings : group and list
|
||||
// this._toppingService
|
||||
// .getToppings(
|
||||
// await this._recipeService.getCurrentCountry(),
|
||||
// this._recipeService.getCurrentFile()
|
||||
// )
|
||||
// .subscribe((data) => {
|
||||
// this.allToppings = data;
|
||||
// // console.log('allToppings', data);
|
||||
|
||||
data.ToppingGroup.forEach((group: ToppingGroup) => {
|
||||
if (this.allToppingsDefinitions != null) {
|
||||
// this.allToppingsDefinitions = {};
|
||||
this.allToppingsDefinitions.push({
|
||||
groupId: group.groupID,
|
||||
name: group.name,
|
||||
members: group.idInGroup,
|
||||
default: group.idDefault,
|
||||
});
|
||||
// data.ToppingGroup.forEach((group: ToppingGroup) => {
|
||||
// if (this.allToppingsDefinitions != null) {
|
||||
// // this.allToppingsDefinitions = {};
|
||||
// this.allToppingsDefinitions.push({
|
||||
// groupId: group.groupID,
|
||||
// name: group.name,
|
||||
// members: group.idInGroup,
|
||||
// default: group.idDefault,
|
||||
// });
|
||||
|
||||
this.allToppingMembersByGroup.push({
|
||||
id: group.groupID,
|
||||
members: this.mapToppingListToMember(group.idInGroup.split(',')),
|
||||
});
|
||||
}
|
||||
});
|
||||
// this.allToppingMembersByGroup.push({
|
||||
// id: group.groupID,
|
||||
// members: this.mapToppingListToMember(group.idInGroup.split(',')),
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
// console.log(this.allToppingsDefinitions);
|
||||
// console.log('allToppingMembersByGroup', this.allToppingMembersByGroup);
|
||||
});
|
||||
// // console.log(this.allToppingsDefinitions);
|
||||
// // console.log('allToppingMembersByGroup', this.allToppingMembersByGroup);
|
||||
// });
|
||||
|
||||
this.toppingForm.valueChanges.subscribe((value) => {
|
||||
//validator
|
||||
for (let i = 0; i < value.toppingList!.length; i++) {
|
||||
let toppingSet = value.toppingList![i] as any;
|
||||
// this.toppingForm.valueChanges.subscribe((value) => {
|
||||
// //validator
|
||||
// for (let i = 0; i < value.toppingList!.length; i++) {
|
||||
// let toppingSet = value.toppingList![i] as any;
|
||||
|
||||
// handle null case
|
||||
if (toppingSet.defaultIDSelect == null) {
|
||||
toppingSet.defaultIDSelect = 0;
|
||||
}
|
||||
// // handle null case
|
||||
// if (toppingSet.defaultIDSelect == null) {
|
||||
// toppingSet.defaultIDSelect = 0;
|
||||
// }
|
||||
|
||||
// handle null case
|
||||
if (toppingSet.groupID == null) {
|
||||
toppingSet.groupID = '0';
|
||||
}
|
||||
// // handle null case
|
||||
// if (toppingSet.groupID == null) {
|
||||
// toppingSet.groupID = '0';
|
||||
// }
|
||||
|
||||
// handle null case
|
||||
if (!Array.isArray(toppingSet.ListGroupID)) {
|
||||
toppingSet.ListGroupID = [parseInt(toppingSet.groupID), 0, 0, 0];
|
||||
}
|
||||
}
|
||||
let isDiff = !isEqual(this._toppingSetOriginalArray, value.toppingList!);
|
||||
// // handle null case
|
||||
// if (!Array.isArray(toppingSet.ListGroupID)) {
|
||||
// toppingSet.ListGroupID = [parseInt(toppingSet.groupID), 0, 0, 0];
|
||||
// }
|
||||
// }
|
||||
// let isDiff = !isEqual(this._toppingSetOriginalArray, value.toppingList!);
|
||||
|
||||
if (isDiff) {
|
||||
let newToppingSetList: any[] = [];
|
||||
// if (isDiff) {
|
||||
// let newToppingSetList: any[] = [];
|
||||
|
||||
forEach(value.toppingList!, (toppingSet: any) => {
|
||||
// transform value
|
||||
toppingSet.defaultIDSelect = parseInt(toppingSet.defaultIDSelect);
|
||||
// forEach(value.toppingList!, (toppingSet: any) => {
|
||||
// // transform value
|
||||
// toppingSet.defaultIDSelect = parseInt(toppingSet.defaultIDSelect);
|
||||
|
||||
newToppingSetList.push(toppingSet);
|
||||
});
|
||||
// newToppingSetList.push(toppingSet);
|
||||
// });
|
||||
|
||||
// console.log('newToppingList', newToppingSetList);
|
||||
this.toppingSetChange.emit(newToppingSetList as unknown[]);
|
||||
} else {
|
||||
// console.log('newToppingListNoChange', value.toppingList);
|
||||
this.toppingSetChange.emit([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
// // console.log('newToppingList', newToppingSetList);
|
||||
// this.toppingSetChange.emit(newToppingSetList as unknown[]);
|
||||
// } else {
|
||||
// // console.log('newToppingListNoChange', value.toppingList);
|
||||
// this.toppingSetChange.emit([]);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// match group id to its name
|
||||
getGroupName(groupID: string) {
|
||||
// check if array
|
||||
if (Array.isArray(this.allToppings!.ToppingGroup)) {
|
||||
return (this.allToppings!.ToppingGroup as ToppingGroup[]).find(
|
||||
(group) => group.groupID == groupID
|
||||
)?.name;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
// // match group id to its name
|
||||
// getGroupName(groupID: string) {
|
||||
// // check if array
|
||||
// if (Array.isArray(this.allToppings!.ToppingGroup)) {
|
||||
// return (this.allToppings!.ToppingGroup as ToppingGroup[]).find(
|
||||
// (group) => group.groupID == groupID
|
||||
// )?.name;
|
||||
// } else {
|
||||
// return undefined;
|
||||
// }
|
||||
// }
|
||||
|
||||
openToppingList(i: any) {
|
||||
console.log('select', i);
|
||||
}
|
||||
// openToppingList(i: any) {
|
||||
// console.log('select', i);
|
||||
// }
|
||||
|
||||
currentGroupId(i: any) {
|
||||
console.log('currentGroupId', i);
|
||||
return (this.toppingForm.value.toppingList![i] as any).groupID as string;
|
||||
}
|
||||
// currentGroupId(i: any) {
|
||||
// console.log('currentGroupId', i);
|
||||
// return (this.toppingForm.value.toppingList![i] as any).groupID as string;
|
||||
// }
|
||||
|
||||
getMembersByGroupId(groupID: string) {
|
||||
return this.allToppingMembersByGroup.find((x) => x.id == groupID)?.members;
|
||||
}
|
||||
// getMembersByGroupId(groupID: string) {
|
||||
// return this.allToppingMembersByGroup.find((x) => x.id == groupID)?.members;
|
||||
// }
|
||||
|
||||
getGroupIdByIndex(i: number) {
|
||||
// console.log("getGroupId",this.toppingList.value![i])
|
||||
return (this.toppingList.value![i] as any).groupID as string;
|
||||
}
|
||||
// getGroupIdByIndex(i: number) {
|
||||
// // console.log("getGroupId",this.toppingList.value![i])
|
||||
// return (this.toppingList.value![i] as any).groupID as string;
|
||||
// }
|
||||
|
||||
mapToppingListToMember = (mm: string[]) =>
|
||||
mm.map((m) => {
|
||||
// find actual topping from toppingList
|
||||
let actualTopping = this.allToppings!.ToppingList.find((t) => t.id == m);
|
||||
// mapToppingListToMember = (mm: string[]) =>
|
||||
// mm.map((m) => {
|
||||
// // find actual topping from toppingList
|
||||
// let actualTopping = this.allToppings!.ToppingList.find((t) => t.id == m);
|
||||
|
||||
return {
|
||||
id: actualTopping!.id,
|
||||
name: actualTopping?.name == null ? m : actualTopping!.name,
|
||||
};
|
||||
});
|
||||
// return {
|
||||
// id: actualTopping!.id,
|
||||
// name: actualTopping?.name == null ? m : actualTopping!.name,
|
||||
// };
|
||||
// });
|
||||
|
||||
getDefaultOfGroup(groupID: any) {
|
||||
this.toppingList.controls.forEach((control) => {
|
||||
if ((control.value as any).groupID == groupID) {
|
||||
let newDefault = this.allToppingsDefinitions!.find(
|
||||
(x) => x.groupId == groupID
|
||||
)!.default;
|
||||
// set new defaultid
|
||||
control.get('defaultIDSelect')?.setValue(newDefault);
|
||||
}
|
||||
});
|
||||
}
|
||||
// getDefaultOfGroup(groupID: any) {
|
||||
// this.toppingList.controls.forEach((control) => {
|
||||
// if ((control.value as any).groupID == groupID) {
|
||||
// let newDefault = this.allToppingsDefinitions!.find(
|
||||
// (x) => x.groupId == groupID
|
||||
// )!.default;
|
||||
// // set new defaultid
|
||||
// control.get('defaultIDSelect')?.setValue(newDefault);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
compareFunc = (a: any, b: any) => a.toString() === b.toString();
|
||||
}
|
||||
// compareFunc = (a: any, b: any) => a.toString() === b.toString();
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -241,8 +241,8 @@ export class RecipesComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||
this.materialList = materials;
|
||||
});
|
||||
|
||||
this._toppingService
|
||||
.getToppings(this.department, this._recipeService.getCurrentFile())
|
||||
(await this._toppingService
|
||||
.getToppings(this.department, this._recipeService.getCurrentFile()))
|
||||
.subscribe((tp) => {
|
||||
this.toppings = {
|
||||
toppingGroup: tp.ToppingGroup,
|
||||
|
|
|
|||
|
|
@ -184,6 +184,8 @@ func NewData(taoLogger *logger.TaoLogger) *Data {
|
|||
|
||||
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 == "" {
|
||||
return d.currentRecipe["tha"]
|
||||
}
|
||||
|
|
@ -194,7 +196,7 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
|
||||
if recipe, ok := d.recipeMap[filename]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
return recipe.Recipe[countryID]
|
||||
}
|
||||
|
||||
|
|
@ -204,13 +206,13 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
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.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
|
|
@ -248,21 +250,41 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
|
||||
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 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 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
fmt.Println("No result in current recipe", countryID)
|
||||
} 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 {
|
||||
if v.ProductCode == productCode {
|
||||
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getSuccess", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
|
||||
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]
|
||||
}
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
|
||||
for _, v := range countries {
|
||||
if v.CountryName == countryID {
|
||||
d.CurrentCountryID[countryID] = v.CountryID
|
||||
// d.CurrentCountryID[countryID] = v.CountryID
|
||||
countryID = v.CountryID
|
||||
break
|
||||
}
|
||||
|
|
@ -286,7 +308,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
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 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
|
|
@ -373,15 +395,15 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
|
||||
if !strings.Contains(filename, "tmp") {
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
copy(result, d.currentRecipe[countryID].MaterialSetting)
|
||||
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
|
||||
// copy(result, d.currentRecipe[countryID].MaterialSetting)
|
||||
// d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
|
||||
return d.currentRecipe[countryID].MaterialSetting
|
||||
}
|
||||
|
||||
if recipe, ok := d.recipeMap[filename]; ok {
|
||||
copy(result, recipe.Recipe[countryID].MaterialSetting)
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
return d.currentRecipe[countryID].MaterialSetting
|
||||
}
|
||||
}
|
||||
|
|
@ -390,19 +412,19 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
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.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
|
|
@ -443,12 +465,12 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
|
|||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -510,12 +532,12 @@ func (d *Data) GetToppings(countryID, filename string) models.Topping {
|
|||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -533,7 +555,7 @@ func (d *Data) GetToppingsOfRecipe(countryID, filename string, productCode strin
|
|||
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -549,7 +571,7 @@ func (d *Data) GetSubmenusOfRecipe(countryID, filename, productCode string) ([]m
|
|||
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
|
|||
countryID, err := mr.data.GetCountryIDByName(country)
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
|
|||
|
||||
matIDuint, err := strconv.ParseUint(matID, 10, 64)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
|
|||
}
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue