-
diff --git a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts
index 17dd5b9..11e1037 100644
--- a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts
+++ b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.ts
@@ -22,7 +22,14 @@ 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, StringParam, stringParamsDefinition } from 'src/app/shared/helpers/recipe';
+import {
+ getMaterialType,
+ getCategories,
+ isNonMaterial,
+ StringParam,
+ stringParamsDefinition,
+ conditionTests,
+} from 'src/app/shared/helpers/recipe';
@Component({
selector: 'app-recipe-list',
@@ -58,12 +65,12 @@ export class RecipeListComponent implements OnInit {
showStringParamSelector: boolean = false;
currentSelectStringParam: number | null = null;
- stringParamForm = this._formBuilder.group({
- stringParamData: this._formBuilder.array<{
- pkey: string;
- pvalue: any;
- }[]>([]),
- }, { updateOn: 'blur' });
+ stringParamForm = this._formBuilder.group(
+ {
+ stringParamData: this._formBuilder.array([]),
+ },
+ { updateOn: 'blur' }
+ );
constructor(
private _recipeService: RecipeService,
@@ -87,39 +94,43 @@ export class RecipeListComponent implements OnInit {
.pipe(first())
.subscribe(({ result }) => {
this._recipeListOriginalArray = result;
- result.forEach((recipeDetailMat: RecipeDetailMat) => {
-
+ result.forEach((recipeDetailMat: RecipeDetailMat, index: number) => {
// StringParam
- if(recipeDetailMat.StringParam != "" || recipeDetailMat.StringParam != null) {
+ 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() },
- ]
- }))
-
+ 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));
+ this.stringParamData.push(
+ this._formBuilder.array(stringParamListTransform)
+ );
+
+ this.stringParams[index] = stringParamList;
// console.log("string param", this.stringParamData.at(6));
}
-
this.recipeListData.push(
this._formBuilder.group({
StringParam: [
{
value: recipeDetailMat.StringParam,
disabled: !this.isEditable(),
- }
+ },
],
isUse: [
{ value: recipeDetailMat.isUse, disabled: !this.isEditable() },
@@ -139,7 +150,7 @@ export class RecipeListComponent implements OnInit {
],
stirTime: [
{
- value: recipeDetailMat.stirTime,
+ value: recipeDetailMat.stirTime / 10,
disabled: !this.isEditable(),
},
],
@@ -185,7 +196,7 @@ export class RecipeListComponent implements OnInit {
this.isMatLoaded = true;
});
- console.log("string param form",this.stringParamForm);
+ console.log('string param form', this.stringParamForm);
this.recipeListForm.valueChanges.subscribe((value) => {
// console.log(value.recipeListData);
@@ -233,7 +244,7 @@ export class RecipeListComponent implements OnInit {
}
get stringParamControlAtIdx() {
- return (this.stringParamData.at(this.currentSelectStringParam!) as FormArray);
+ return this.stringParamData.at(this.currentSelectStringParam!) as FormArray;
}
isEditable() {
@@ -257,20 +268,21 @@ export class RecipeListComponent implements OnInit {
console.log('set mat ', material, 'to slot', i);
}
- getTypeForRecipeListAtIndex(i: any){
+ getTypeForRecipeListAtIndex(i: any) {
let target = this.recipeListData.at(i);
-
// search from full detail
- for(const category of Object.keys(this.categoriedMaterial)){
- let finder = this.categoriedMaterial[category].find(mat => mat.id == target.value.materialPathId);
+ for (const category of Object.keys(this.categoriedMaterial)) {
+ let finder = this.categoriedMaterial[category].find(
+ (mat) => mat.id == target.value.materialPathId
+ );
if (finder != undefined) {
// console.log('found ', finder.name, ' in ', category);
return {
- "category": category,
- "name": finder.name,
- "id": finder.id
+ category: category,
+ name: finder.name,
+ id: finder.id,
};
}
}
@@ -278,16 +290,16 @@ export class RecipeListComponent implements OnInit {
// console.log("did not find in full detail");
return {
- "category": "others",
- "name": target.value.name,
- "id": target.value.materialPathId
+ category: 'others',
+ name: target.value.name,
+ id: target.value.materialPathId,
};
}
// TODO: Filter from full detail by type
ListCategory = () => {
let catMap: { [key: string]: any[] } = {
- 'others': []
+ others: [],
};
// create category map
@@ -295,21 +307,19 @@ export class RecipeListComponent implements OnInit {
catMap[category] = [];
});
- console.log("generated category", catMap);
+ console.log('generated category', catMap);
this.fullMaterialList!.forEach((mat) => {
let category = getMaterialType(mat.materialId);
- if(Array.isArray(catMap[category])){
+ if (Array.isArray(catMap[category])) {
catMap[category].push({
id: mat.materialId,
name: mat.name,
});
}
-
});
-
return catMap;
};
@@ -317,11 +327,12 @@ export class RecipeListComponent implements OnInit {
// exposed from mat_type.ts
isEquipment = (materialId: number) => isNonMaterial(materialId);
- isNotExistbyCatagories = (materialId : number) => getMaterialType(materialId) == 'others';
+ isNotExistbyCatagories = (materialId: number) =>
+ getMaterialType(materialId) == 'others';
isStringParamExist = (i: number) => {
let rawStringParam = this.recipeListData.at(i).get('StringParam')?.value;
- if(rawStringParam){
+ if (rawStringParam) {
return true;
} else {
return false;
@@ -331,25 +342,19 @@ export class RecipeListComponent implements OnInit {
getStringParamOfIndex = (i: number | null) => {
let idx = i || -1;
- if(idx == -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)
+ let params = this.stringParams[idx];
return params;
-
};
getStringParam = (i: number, key: string) => {
-
// get param at index
- let param = this.stringParams[i].find(param => {
- if(param.pkey == key){
+ let param = this.stringParams[i].find((param) => {
+ if (param.pkey == key) {
return param;
} else {
return undefined;
@@ -357,23 +362,50 @@ export class RecipeListComponent implements OnInit {
});
return param;
- }
+ };
- setStringParam = (i: number, key: string,event: any) => {
- console.log("check on string param", this.stringParams);
+ setStringParam = (i: number, key: string, event: any) => {
+ console.log('check on string param', this.stringParams, i, key, event);
- let value = event.target.value;
+ // let value = event.target.value;
- if(value != ""){
+ let stringVal = event.target.value;
+
+ if (event != undefined) {
// get param at index
- this.stringParams[i].find(param => {
- if(param.pkey == key){
- param.pvalue = value;
- }
- })
- }
+ // this.stringParams[i].find((param) => {
+ // if (param.pkey == key) {
+ // param.pvalue = event;
+ // }
+ // });
- }
+ event = stringVal == undefined ? event: stringVal;
+
+ this.stringParams[i].find((param) => param.pkey == key)!.pvalue = event.toString();
+
+ console.log("finder", this.stringParams[i].find((param) => param.pkey == key));
+
+ // update string param form
+ // console.log(this.stringParamData.controls[i].get(key));
+
+
+ let targetControl = ((this.stringParamData.controls[i]) as FormArray).controls;
+ let pindex = 0;
+
+ targetControl.forEach((control: any, index: number) => {
+ if (control.get('pkey')!.value == key) {
+ pindex = index;
+ }
+ });
+
+ // set value
+ targetControl[pindex].get('pvalue')!.setValue(event);
+
+ console.log("set value", targetControl[pindex].get('pvalue')!.value);
+
+ // console.log('set string param', this.stringParams, i, key, event);
+ }
+ };
openStringParamEditor(i: any) {
console.log('open param list for ', i);
@@ -381,5 +413,12 @@ export class RecipeListComponent implements OnInit {
this.currentSelectStringParam = i;
}
- alterStringParamDisplayName = (name: string) => stringParamsDefinition[name];
+ alterStringParamDisplayName = (name: string) =>{
+ // console.log("alterStringParamDisplayName", name, stringParamsDefinition[name]);
+
+ return stringParamsDefinition[name] || name;
+ };
+
+ displayByCond = (index: number, key: string, condition: string) =>
+ conditionTests[condition](this.recipeListData.value[index][key]);
}
diff --git a/client/src/app/shared/helpers/recipe.ts b/client/src/app/shared/helpers/recipe.ts
index 318ec7b..64c8a21 100644
--- a/client/src/app/shared/helpers/recipe.ts
+++ b/client/src/app/shared/helpers/recipe.ts
@@ -89,3 +89,7 @@ export class StringParam {
export var stringParamsDefinition: { [key: string]: string } = {
'esp-v2-press-value': 'Current 100 x mA ( 10 - 24 )'
}
+
+export var conditionTests: { [key: string]: (arg: any) => boolean } = {
+ 'not-zero': (arg: any) => arg != 0
+}