add string param support
This commit is contained in:
parent
98341d2d80
commit
636a700a79
8 changed files with 294 additions and 35 deletions
|
|
@ -129,7 +129,7 @@ export interface ToppingList {
|
|||
id: string;
|
||||
isUse: string;
|
||||
isShow: string;
|
||||
stringParam: string;
|
||||
StringParam: string;
|
||||
name: string;
|
||||
nonCashPrice: string;
|
||||
otherName: string;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,11 @@
|
|||
<td class="m-2 px-4 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||
<div class="flex items-center">
|
||||
<p>Volume= </p>
|
||||
<input type="text" class="input w-16" formControlName="powderGram" />
|
||||
<input
|
||||
type="text"
|
||||
class="input w-16"
|
||||
formControlName="powderGram"
|
||||
/>
|
||||
<p> gram</p>
|
||||
</div>
|
||||
</td>
|
||||
|
|
@ -56,36 +60,64 @@
|
|||
<td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||
<input type="text" class="input" formControlName="name" />
|
||||
</td>
|
||||
<td class="m-2 px-4 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||
<div class="flex items-center">
|
||||
<td class="m-2 px-4 py-4 space-y-2 font-medium text-gray-900 whitespace-nowrap">
|
||||
<div class="flex items-center space-x-4">
|
||||
<div
|
||||
class="flex items-center rounded-md p-2"
|
||||
*ngIf="isStringParamExist(i)"
|
||||
|
||||
<p>StringParam=</p>
|
||||
<input type="text" class="input w-16" formControlName="StringParam" />
|
||||
>
|
||||
<div class="flex items-center bg-orange-400 rounded-md p-2" *ngFor="let param of getStringParamOfIndex(i)">
|
||||
<p> </p>
|
||||
<input
|
||||
type="text"
|
||||
class="input w-16"
|
||||
placeholder="{{param.pvalue}}"
|
||||
(click)="openStringParamEditor(i)"
|
||||
/>
|
||||
<p *ngIf="param.pkey == 'esp-v2-press-value'"> mA</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Volume= </p>
|
||||
<input type="text" class="input w-16" formControlName="powderGram" />
|
||||
<div class="flex items-center bg-violet-400 rounded-md p-2">
|
||||
<p>Volume= </p>
|
||||
<input
|
||||
type="text"
|
||||
class="input w-16"
|
||||
formControlName="powderGram"
|
||||
/>
|
||||
<p> gram</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center" *ngIf="getTypeForRecipeListAtIndex(i)['id'] == 1002">
|
||||
<div
|
||||
class="flex items-center"
|
||||
*ngIf="getTypeForRecipeListAtIndex(i)['id'] == 1002"
|
||||
>
|
||||
<p>Hot= </p>
|
||||
<input type="text" class="input w-16" formControlName="waterYield" />
|
||||
<input
|
||||
type="text"
|
||||
class="input w-16"
|
||||
formControlName="waterYield"
|
||||
/>
|
||||
<p> ml </p>
|
||||
<p>Grinder= </p><input type="text" class="input w-16" formControlName="stirTime" /><p> sec</p>
|
||||
<p>Grinder= </p>
|
||||
<input type="text" class="input w-16" formControlName="stirTime" />
|
||||
<p> sec</p>
|
||||
</div>
|
||||
</td>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- others -->
|
||||
<div *ngIf="(isNotExistbyCatagories(getTypeForRecipeListAtIndex(i)['id']) || isEquipment(getTypeForRecipeListAtIndex(i)['id']))">
|
||||
<div
|
||||
*ngIf="
|
||||
isNotExistbyCatagories(getTypeForRecipeListAtIndex(i)['id']) ||
|
||||
isEquipment(getTypeForRecipeListAtIndex(i)['id'])
|
||||
"
|
||||
>
|
||||
<td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||
<input type="text" class="input" formControlName="name" />
|
||||
</td>
|
||||
</div>
|
||||
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -124,3 +156,33 @@
|
|||
</div>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<!-- show string param modal -->
|
||||
|
||||
<input
|
||||
type="checkbox"
|
||||
id="string_param_selector"
|
||||
class="modal-toggle"
|
||||
#checkBox="ngModel"
|
||||
[(ngModel)]="showStringParamSelector"
|
||||
/>
|
||||
<label for="string_param_selector" class="modal">
|
||||
<div class="modal-box max-h-[400px] overflow-scroll" [formGroup]="stringParamForm">
|
||||
<div formArrayName="stringParamData" *ngFor="let paramAtIdx of stringParamData.controls; let isdx = index">
|
||||
<div *ngIf="isdx == currentSelectStringParam" formGroupName="{{ isdx }}">
|
||||
<!-- show input -->
|
||||
<p class="flex top-0 right-0 justify-end font-bold text-xs m-2">isdx={{isdx}}</p>
|
||||
<div *ngFor="let param of stringParamControlAtIdx.controls; let idx = index">
|
||||
<!-- <p>idx={{idx}}</p> -->
|
||||
<div formGroupName="{{ idx }}" class="flex items-center p-2 space-x-4">
|
||||
<!-- <input type="text" class="input input-disabled" formControlName="pkey" [disabled]="true"/> -->
|
||||
<p>{{alterStringParamDisplayName(param.value.pkey)}}</p>
|
||||
<input type="text" class="input bg-slate-400" formControlName="pvalue" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</label>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import { UserService } from 'src/app/core/services/user.service';
|
|||
import { Action, ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { NgSelectModule } from '@ng-select/ng-select';
|
||||
import { getMaterialType, getCategories, isNonMaterial } from 'src/app/shared/helpers/mat_type';
|
||||
import { getMaterialType, getCategories, isNonMaterial, StringParam, stringParamsDefinition } from 'src/app/shared/helpers/recipe';
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipe-list',
|
||||
|
|
@ -47,6 +47,24 @@ export class RecipeListComponent implements OnInit {
|
|||
|
||||
categoriedMaterial: { [key: string]: { id: number; name: string }[] } = {};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// string params
|
||||
stringParams: {
|
||||
[key: number]: {
|
||||
pkey: string;
|
||||
pvalue: any;
|
||||
}[];
|
||||
} = {};
|
||||
showStringParamSelector: boolean = false;
|
||||
currentSelectStringParam: number | null = null;
|
||||
|
||||
stringParamForm = this._formBuilder.group({
|
||||
stringParamData: this._formBuilder.array<{
|
||||
pkey: string;
|
||||
pvalue: any;
|
||||
}[]>([]),
|
||||
}, { updateOn: 'blur' });
|
||||
|
||||
constructor(
|
||||
private _recipeService: RecipeService,
|
||||
private _materialService: MaterialService,
|
||||
|
|
@ -70,6 +88,31 @@ export class RecipeListComponent implements OnInit {
|
|||
.subscribe(({ result }) => {
|
||||
this._recipeListOriginalArray = result;
|
||||
result.forEach((recipeDetailMat: RecipeDetailMat) => {
|
||||
|
||||
// StringParam
|
||||
if(recipeDetailMat.StringParam != "" || recipeDetailMat.StringParam != null) {
|
||||
let currStringParam = new StringParam(recipeDetailMat.StringParam);
|
||||
let stringParamList = currStringParam.extract().as_list();
|
||||
|
||||
let stringParamListTransform = [];
|
||||
for(let param of stringParamList) {
|
||||
stringParamListTransform.push(this._formBuilder.group({
|
||||
pkey: [
|
||||
{ value: param.pkey, disabled: !this.isEditable() },
|
||||
],
|
||||
pvalue: [
|
||||
{ value: param.pvalue, disabled: !this.isEditable() },
|
||||
]
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
this.stringParamData.push(this._formBuilder.array(stringParamListTransform));
|
||||
|
||||
// console.log("string param", this.stringParamData.at(6));
|
||||
}
|
||||
|
||||
|
||||
this.recipeListData.push(
|
||||
this._formBuilder.group({
|
||||
StringParam: [
|
||||
|
|
@ -142,6 +185,8 @@ export class RecipeListComponent implements OnInit {
|
|||
this.isMatLoaded = true;
|
||||
});
|
||||
|
||||
console.log("string param form",this.stringParamForm);
|
||||
|
||||
this.recipeListForm.valueChanges.subscribe((value) => {
|
||||
// console.log(value.recipeListData);
|
||||
// console.log("original recipe detail",this._recipeListOriginalArray);
|
||||
|
|
@ -167,7 +212,7 @@ export class RecipeListComponent implements OnInit {
|
|||
}
|
||||
});
|
||||
|
||||
// TODO: make this
|
||||
// TODO: embed this to recipelist
|
||||
this._materialService.getMaterialCodes().subscribe((materials) => {
|
||||
this.materialList = materials;
|
||||
});
|
||||
|
|
@ -183,6 +228,14 @@ export class RecipeListComponent implements OnInit {
|
|||
return this.recipeListForm.get('recipeListData') as FormArray;
|
||||
}
|
||||
|
||||
get stringParamData(): FormArray {
|
||||
return this.stringParamForm.get('stringParamData') as FormArray;
|
||||
}
|
||||
|
||||
get stringParamControlAtIdx() {
|
||||
return (this.stringParamData.at(this.currentSelectStringParam!) as FormArray);
|
||||
}
|
||||
|
||||
isEditable() {
|
||||
return this._userService
|
||||
.getCurrentUser()!
|
||||
|
|
@ -265,4 +318,68 @@ export class RecipeListComponent implements OnInit {
|
|||
// exposed from mat_type.ts
|
||||
isEquipment = (materialId: number) => isNonMaterial(materialId);
|
||||
isNotExistbyCatagories = (materialId : number) => getMaterialType(materialId) == 'others';
|
||||
|
||||
isStringParamExist = (i: number) => {
|
||||
let rawStringParam = this.recipeListData.at(i).get('StringParam')?.value;
|
||||
if(rawStringParam){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
getStringParamOfIndex = (i: number | null) => {
|
||||
let idx = i || -1;
|
||||
|
||||
if(idx == -1){
|
||||
return [];
|
||||
}
|
||||
|
||||
let rawStringParam = new StringParam(this.recipeListData.at(idx).get('StringParam')?.value);
|
||||
let params = rawStringParam.extract().as_list();
|
||||
|
||||
this.stringParams[idx] = params;
|
||||
// console.log("string param", this.stringParams)
|
||||
|
||||
return params;
|
||||
|
||||
};
|
||||
|
||||
getStringParam = (i: number, key: string) => {
|
||||
|
||||
// get param at index
|
||||
let param = this.stringParams[i].find(param => {
|
||||
if(param.pkey == key){
|
||||
return param;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
setStringParam = (i: number, key: string,event: any) => {
|
||||
console.log("check on string param", this.stringParams);
|
||||
|
||||
let value = event.target.value;
|
||||
|
||||
if(value != ""){
|
||||
// get param at index
|
||||
this.stringParams[i].find(param => {
|
||||
if(param.pkey == key){
|
||||
param.pvalue = value;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
openStringParamEditor(i: any) {
|
||||
console.log('open param list for ', i);
|
||||
this.showStringParamSelector = true;
|
||||
this.currentSelectStringParam = i;
|
||||
}
|
||||
|
||||
alterStringParamDisplayName = (name: string) => stringParamsDefinition[name];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,52 @@ export function isNonMaterial(materialId: number) {
|
|||
return (
|
||||
rangeMaterialMapping['cup'](materialId) ||
|
||||
rangeMaterialMapping['lid'](materialId) ||
|
||||
rangeMaterialMapping['straw'](materialId) || rangeMaterialMapping['whipper'](materialId)
|
||||
rangeMaterialMapping['straw'](materialId) ||
|
||||
rangeMaterialMapping['whipper'](materialId) ||
|
||||
rangeMaterialMapping['ice'](materialId)
|
||||
);
|
||||
}
|
||||
|
||||
// StringParam
|
||||
|
||||
export class StringParam {
|
||||
StringParam: string;
|
||||
extractedParams: { [key: string]: any } = {};
|
||||
|
||||
|
||||
constructor(StringParam: string) {
|
||||
this.StringParam = StringParam;
|
||||
}
|
||||
|
||||
extract(){
|
||||
|
||||
// split by ,
|
||||
const params = this.StringParam.split(',');
|
||||
|
||||
for (const param of params) {
|
||||
const [key, value] = param.split('=');
|
||||
if(key != ''){
|
||||
this.extractedParams[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
as_list(){
|
||||
let res: {pkey: string; pvalue:any}[] = [];
|
||||
// iter through param
|
||||
for(let p of Object.keys(this.extractedParams)){
|
||||
res.push({
|
||||
"pkey": p,
|
||||
"pvalue": this.extractedParams[p]
|
||||
})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
export var stringParamsDefinition: { [key: string]: string } = {
|
||||
'esp-v2-press-value': 'Current 100 x mA ( 10 - 24 )'
|
||||
}
|
||||
|
|
@ -55,6 +55,7 @@ type RecipeDetailResponse struct {
|
|||
}
|
||||
|
||||
type RecipeDetailMat struct {
|
||||
StringParam string `json:"StringParam"`
|
||||
IsUse bool `json:"isUse"`
|
||||
MaterialID uint64 `json:"materialID"`
|
||||
Name string `json:"name"`
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"recipe-manager/helpers"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/services/logger"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -49,6 +50,34 @@ func NewData(taoLogger *logger.TaoLogger) *Data {
|
|||
|
||||
defaultFile := "coffeethai02_600.json"
|
||||
defaultCountry := "tha"
|
||||
|
||||
// read latest version
|
||||
// set latest to default version
|
||||
latest_version, err := strconv.Atoi(strings.Split(strings.Split(defaultFile, "_")[1], ".")[0])
|
||||
|
||||
if err != nil {
|
||||
taoLogger.Log.Debug("Error when retrieved current version", zap.Error(err))
|
||||
}
|
||||
|
||||
for _, v := range allRecipeFiles[defaultCountry] {
|
||||
|
||||
// extract filename as version
|
||||
current_version_iter, err := strconv.Atoi(strings.Split(strings.Split(v.Name, "_")[1], ".")[0])
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if current_version_iter > latest_version {
|
||||
// taoLogger.Log.Debug("current_version_iter", zap.Any("current_version_iter", current_version_iter))
|
||||
// set latest
|
||||
latest_version = current_version_iter
|
||||
defaultFile = v.Name
|
||||
}
|
||||
}
|
||||
|
||||
taoLogger.Log.Debug("defaultFile", zap.Any("defaultFile", defaultFile), zap.Any("latest_version", latest_version))
|
||||
|
||||
defaultRecipe, err := helpers.ReadRecipeFile(defaultCountry, defaultFile)
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -172,6 +201,8 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
}
|
||||
}
|
||||
|
||||
d.taoLogger.Log.Debug("GetRecipe01ByProductCode", zap.Any("productCode", productCode), zap.Any("version", recipe.MachineSetting.ConfigNumber))
|
||||
|
||||
d.currentRecipe = recipe
|
||||
|
||||
// save to map
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ type Recipe01 struct {
|
|||
OnTOP bool `json:"OnTOP"`
|
||||
LastChange string `json:"LastChange"`
|
||||
MenuStatus int `json:"MenuStatus"`
|
||||
RemainingCups json.Number `json:"RemainingCups"`
|
||||
StringParam string `json:"StringParam"`
|
||||
TextForWarningBeforePay []string `json:"TextForWarningBeforePay"`
|
||||
CashPrice int `json:"cashPrice"`
|
||||
|
|
@ -104,18 +103,19 @@ func (r *Recipe01) FromMap(m map[string]interface{}) Recipe01 {
|
|||
}
|
||||
|
||||
type MatRecipe struct {
|
||||
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"`
|
||||
StirTime int `json:"stirTime"`
|
||||
SyrupGram int `json:"syrupGram"`
|
||||
SyrupTime int `json:"syrupTime"`
|
||||
WaterCold int `json:"waterCold"`
|
||||
WaterYield int `json:"waterYield"`
|
||||
StringParam string `json:"StringParam"`
|
||||
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"`
|
||||
StirTime int `json:"stirTime"`
|
||||
SyrupGram int `json:"syrupGram"`
|
||||
SyrupTime int `json:"syrupTime"`
|
||||
WaterCold int `json:"waterCold"`
|
||||
WaterYield int `json:"waterYield"`
|
||||
}
|
||||
|
||||
type ToppingSet struct {
|
||||
|
|
@ -152,7 +152,7 @@ type ToppingList struct {
|
|||
ID int `json:"id"`
|
||||
IsUse bool `json:"isUse"`
|
||||
IsShow bool `json:"isShow"`
|
||||
StringParam string `json:"stringParam"`
|
||||
StringParam string `json:"StringParam"`
|
||||
Name string `json:"name"`
|
||||
NonCashPrice int `json:"nonCashPrice"`
|
||||
OtherName string `json:"otherName"`
|
||||
|
|
|
|||
|
|
@ -117,12 +117,13 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
break
|
||||
} else if mat.MaterialName != "" {
|
||||
mat_name = mat.MaterialName
|
||||
fmt.Println("SetMat", mat_name)
|
||||
// fmt.Println("SetMat", mat_name)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
result.Result = append(result.Result, contracts.RecipeDetailMat{
|
||||
StringParam: v.StringParam,
|
||||
IsUse: v.IsUse,
|
||||
MaterialID: mat.ID,
|
||||
Name: mat_name,
|
||||
|
|
@ -147,6 +148,7 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
if len(result.Result) < 30 {
|
||||
for i := len(result.Result); i < 30; i++ {
|
||||
result.Result = append(result.Result, contracts.RecipeDetailMat{
|
||||
StringParam: "",
|
||||
IsUse: false,
|
||||
MaterialID: 0,
|
||||
Name: "",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue