change material selection
This commit is contained in:
parent
f9d833e3b7
commit
3698e6e3c0
7 changed files with 49 additions and 28 deletions
|
|
@ -36,6 +36,9 @@ export class MaterialService {
|
|||
}[] | null>{
|
||||
console.log("getFullMaterialDetail", country, filename);
|
||||
|
||||
country = country || this.getCurrentCountry();
|
||||
filename = filename || this.getCurrentFile();
|
||||
|
||||
return this._httpClient.get<{
|
||||
"materialId": number,
|
||||
"name": string,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { ConfirmModal } from 'src/app/shared/modal/confirm/confirm-modal.compone
|
|||
import { animate, style, transition, trigger } from '@angular/animations';
|
||||
import { RecipeListComponent } from './recipe-list/recipe-list.component';
|
||||
import {
|
||||
Recipe01,
|
||||
RecipeDetail,
|
||||
RecipeDetailMat,
|
||||
Topping,
|
||||
|
|
|
|||
|
|
@ -76,16 +76,17 @@
|
|||
<p class="font-bold text-lg m-2">Materials</p>
|
||||
</div>
|
||||
<div
|
||||
*ngFor="let material of materialList"
|
||||
*ngFor="let material of fullMaterialList"
|
||||
class="flex flex-row m-2 overflow-y-scroll"
|
||||
>
|
||||
<button
|
||||
class="btn bg-primary btn-md border-2 text-base text-gray-700"
|
||||
(click)="selectMaterial(currentSelectRecipeList!, material)"
|
||||
(click)="selectMaterial(currentSelectRecipeList!, material.materialId)"
|
||||
>
|
||||
{{ material.materialID }}
|
||||
{{ material.materialId }}
|
||||
</button>
|
||||
<h3 class="m-3">{{ material.PackageDescription }}</h3>
|
||||
<h3 class="m-3">{{ material.name }}</h3>
|
||||
<p class="m-3">{{ material.type }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ export class RecipeListComponent implements OnInit {
|
|||
@Output() recipeListFormChange = new EventEmitter<unknown[]>();
|
||||
|
||||
materialList: MaterialCode[] = [];
|
||||
|
||||
fullMaterialList: { materialId: number; name: string; type: string; }[] | null = [];
|
||||
showMaterialSelector: boolean = false;
|
||||
|
||||
currentSelectRecipeList: number | null = null;
|
||||
|
|
@ -109,8 +111,13 @@ export class RecipeListComponent implements OnInit {
|
|||
|
||||
});
|
||||
|
||||
// TODO: make this
|
||||
this._materialService.getMaterialCodes().subscribe((materials) => {
|
||||
this.materialList = materials;
|
||||
});
|
||||
|
||||
this._materialService.getFullMaterialDetail().subscribe((materials) => {
|
||||
this.fullMaterialList = materials;
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -128,11 +135,11 @@ export class RecipeListComponent implements OnInit {
|
|||
this.currentSelectRecipeList = i;
|
||||
}
|
||||
|
||||
selectMaterial(i: number, material: MaterialCode){
|
||||
selectMaterial(i: number, material: number){
|
||||
|
||||
this.showMaterialSelector = false;
|
||||
|
||||
this.recipeListData.at(i).get('materialPathId')?.setValue(material.materialID);
|
||||
console.log("set mat ", material.materialID, "to slot", i);
|
||||
this.recipeListData.at(i).get('materialPathId')?.setValue(material);
|
||||
console.log("set mat ", material, "to slot", i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,15 +22,15 @@
|
|||
[clearable]="false"
|
||||
[compareWith]="this.compareFunc"
|
||||
formControlName="groupID"
|
||||
(close)="getDefaultOfGroup(getGroupIdByIndex(i))"
|
||||
>
|
||||
<ng-option
|
||||
*ngFor="let item of allToppingsDefinitions"
|
||||
[value]="item.groupId.toString()"
|
||||
>{{ item.name }} ({{ item.groupId }})</ng-option
|
||||
>
|
||||
<div>{{ item.name }} ({{ item.groupId }})</div>
|
||||
</ng-option>
|
||||
</ng-select>
|
||||
|
||||
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<ng-select
|
||||
|
|
|
|||
|
|
@ -34,14 +34,16 @@ export class RecipeToppingsetComponent implements OnInit {
|
|||
@Input() productCode!: string;
|
||||
@Output() toppingSetChange = new EventEmitter<unknown[]>();
|
||||
|
||||
toppingSetList: ToppingSet[] = [];
|
||||
allToppings: Topping | undefined = undefined;
|
||||
|
||||
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[];
|
||||
|
||||
|
|
@ -70,16 +72,10 @@ export class RecipeToppingsetComponent implements OnInit {
|
|||
this.productCode
|
||||
)
|
||||
.subscribe((data) => {
|
||||
console.log('getToppingset', data);
|
||||
this.toppingSetList = data;
|
||||
// this.toppingForm.patchValue({toppingList: data});
|
||||
this._toppingSetOriginalArray = data;
|
||||
|
||||
data.forEach((toppingSet: ToppingSet) => {
|
||||
// console.log("getToppingset",toppingSet);
|
||||
|
||||
// toppingSet.ListGroupID = toppingSet.ListGroupID.map((id) => id.toString());
|
||||
|
||||
this.toppingList.push(
|
||||
this._formBuilder.group({
|
||||
isUse: toppingSet.isUse,
|
||||
|
|
@ -90,7 +86,7 @@ export class RecipeToppingsetComponent implements OnInit {
|
|||
);
|
||||
});
|
||||
|
||||
console.log('controls', this.toppingList.controls);
|
||||
// console.log('controls', this.toppingList.controls);
|
||||
|
||||
// this.toppingSetChange.emit(this.toppingSetList);
|
||||
});
|
||||
|
|
@ -112,12 +108,12 @@ export class RecipeToppingsetComponent implements OnInit {
|
|||
groupId: group.groupID,
|
||||
name: group.name,
|
||||
members: group.idInGroup,
|
||||
default: group.idDefault
|
||||
default: group.idDefault,
|
||||
});
|
||||
|
||||
this.allToppingMembersByGroup.push({
|
||||
id: group.groupID,
|
||||
members: this.mapToppingListToMember(group.idInGroup.split(','))
|
||||
members: this.mapToppingListToMember(group.idInGroup.split(',')),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -158,14 +154,13 @@ export class RecipeToppingsetComponent implements OnInit {
|
|||
newToppingSetList.push(toppingSet);
|
||||
});
|
||||
|
||||
console.log('newToppingList', newToppingSetList);
|
||||
// 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
|
||||
|
|
@ -190,13 +185,12 @@ export class RecipeToppingsetComponent implements OnInit {
|
|||
}
|
||||
|
||||
getMembersByGroupId(groupID: string) {
|
||||
return this.allToppingMembersByGroup
|
||||
.find((x) => x.id == groupID)
|
||||
?.members;
|
||||
return this.allToppingMembersByGroup.find((x) => x.id == groupID)?.members;
|
||||
}
|
||||
|
||||
getGroupIdByIndex(i: number) {
|
||||
return (this.toppingForm.value.toppingList![i] as any).groupID as string;
|
||||
// console.log("getGroupId",this.toppingList.value![i])
|
||||
return (this.toppingList.value![i] as any).groupID as string;
|
||||
}
|
||||
|
||||
mapToppingListToMember = (mm: string[]) =>
|
||||
|
|
@ -210,6 +204,17 @@ export class RecipeToppingsetComponent implements OnInit {
|
|||
};
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,9 +112,13 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
if v.MaterialPathId == int(mat.ID) {
|
||||
mat_name := ""
|
||||
for _, m := range matsCode {
|
||||
if m.MaterialID == mat.ID {
|
||||
if m.MaterialID == mat.ID && mat.MaterialName == "" {
|
||||
mat_name = m.PackageDescription
|
||||
break
|
||||
} else if mat.MaterialName != "" {
|
||||
mat_name = mat.MaterialName
|
||||
fmt.Println("SetMat", mat_name)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue