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>{
|
}[] | null>{
|
||||||
console.log("getFullMaterialDetail", country, filename);
|
console.log("getFullMaterialDetail", country, filename);
|
||||||
|
|
||||||
|
country = country || this.getCurrentCountry();
|
||||||
|
filename = filename || this.getCurrentFile();
|
||||||
|
|
||||||
return this._httpClient.get<{
|
return this._httpClient.get<{
|
||||||
"materialId": number,
|
"materialId": number,
|
||||||
"name": string,
|
"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 { animate, style, transition, trigger } from '@angular/animations';
|
||||||
import { RecipeListComponent } from './recipe-list/recipe-list.component';
|
import { RecipeListComponent } from './recipe-list/recipe-list.component';
|
||||||
import {
|
import {
|
||||||
|
Recipe01,
|
||||||
RecipeDetail,
|
RecipeDetail,
|
||||||
RecipeDetailMat,
|
RecipeDetailMat,
|
||||||
Topping,
|
Topping,
|
||||||
|
|
|
||||||
|
|
@ -76,16 +76,17 @@
|
||||||
<p class="font-bold text-lg m-2">Materials</p>
|
<p class="font-bold text-lg m-2">Materials</p>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
*ngFor="let material of materialList"
|
*ngFor="let material of fullMaterialList"
|
||||||
class="flex flex-row m-2 overflow-y-scroll"
|
class="flex flex-row m-2 overflow-y-scroll"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="btn bg-primary btn-md border-2 text-base text-gray-700"
|
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>
|
</button>
|
||||||
<h3 class="m-3">{{ material.PackageDescription }}</h3>
|
<h3 class="m-3">{{ material.name }}</h3>
|
||||||
|
<p class="m-3">{{ material.type }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ export class RecipeListComponent implements OnInit {
|
||||||
@Output() recipeListFormChange = new EventEmitter<unknown[]>();
|
@Output() recipeListFormChange = new EventEmitter<unknown[]>();
|
||||||
|
|
||||||
materialList: MaterialCode[] = [];
|
materialList: MaterialCode[] = [];
|
||||||
|
|
||||||
|
fullMaterialList: { materialId: number; name: string; type: string; }[] | null = [];
|
||||||
showMaterialSelector: boolean = false;
|
showMaterialSelector: boolean = false;
|
||||||
|
|
||||||
currentSelectRecipeList: number | null = null;
|
currentSelectRecipeList: number | null = null;
|
||||||
|
|
@ -109,8 +111,13 @@ export class RecipeListComponent implements OnInit {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: make this
|
||||||
this._materialService.getMaterialCodes().subscribe((materials) => {
|
this._materialService.getMaterialCodes().subscribe((materials) => {
|
||||||
this.materialList = materials;
|
this.materialList = materials;
|
||||||
|
});
|
||||||
|
|
||||||
|
this._materialService.getFullMaterialDetail().subscribe((materials) => {
|
||||||
|
this.fullMaterialList = materials;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,11 +135,11 @@ export class RecipeListComponent implements OnInit {
|
||||||
this.currentSelectRecipeList = i;
|
this.currentSelectRecipeList = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectMaterial(i: number, material: MaterialCode){
|
selectMaterial(i: number, material: number){
|
||||||
|
|
||||||
this.showMaterialSelector = false;
|
this.showMaterialSelector = false;
|
||||||
|
|
||||||
this.recipeListData.at(i).get('materialPathId')?.setValue(material.materialID);
|
this.recipeListData.at(i).get('materialPathId')?.setValue(material);
|
||||||
console.log("set mat ", material.materialID, "to slot", i);
|
console.log("set mat ", material, "to slot", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,15 @@
|
||||||
[clearable]="false"
|
[clearable]="false"
|
||||||
[compareWith]="this.compareFunc"
|
[compareWith]="this.compareFunc"
|
||||||
formControlName="groupID"
|
formControlName="groupID"
|
||||||
|
(close)="getDefaultOfGroup(getGroupIdByIndex(i))"
|
||||||
>
|
>
|
||||||
<ng-option
|
<ng-option
|
||||||
*ngFor="let item of allToppingsDefinitions"
|
*ngFor="let item of allToppingsDefinitions"
|
||||||
[value]="item.groupId.toString()"
|
[value]="item.groupId.toString()"
|
||||||
>{{ item.name }} ({{ item.groupId }})</ng-option
|
|
||||||
>
|
>
|
||||||
|
<div>{{ item.name }} ({{ item.groupId }})</div>
|
||||||
|
</ng-option>
|
||||||
</ng-select>
|
</ng-select>
|
||||||
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
<ng-select
|
<ng-select
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,16 @@ export class RecipeToppingsetComponent implements OnInit {
|
||||||
@Input() productCode!: string;
|
@Input() productCode!: string;
|
||||||
@Output() toppingSetChange = new EventEmitter<unknown[]>();
|
@Output() toppingSetChange = new EventEmitter<unknown[]>();
|
||||||
|
|
||||||
toppingSetList: ToppingSet[] = [];
|
|
||||||
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: { id: string; members: {id:string, name:string}[] }[] = [];
|
allToppingMembersByGroup: {
|
||||||
|
id: string;
|
||||||
|
members: { id: string; name: string }[];
|
||||||
|
}[] = [];
|
||||||
|
|
||||||
private _toppingSetOriginalArray!: ToppingSet[];
|
private _toppingSetOriginalArray!: ToppingSet[];
|
||||||
|
|
||||||
|
|
@ -70,16 +72,10 @@ export class RecipeToppingsetComponent implements OnInit {
|
||||||
this.productCode
|
this.productCode
|
||||||
)
|
)
|
||||||
.subscribe((data) => {
|
.subscribe((data) => {
|
||||||
console.log('getToppingset', data);
|
|
||||||
this.toppingSetList = 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) => {
|
||||||
// console.log("getToppingset",toppingSet);
|
|
||||||
|
|
||||||
// toppingSet.ListGroupID = toppingSet.ListGroupID.map((id) => id.toString());
|
|
||||||
|
|
||||||
this.toppingList.push(
|
this.toppingList.push(
|
||||||
this._formBuilder.group({
|
this._formBuilder.group({
|
||||||
isUse: toppingSet.isUse,
|
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);
|
// this.toppingSetChange.emit(this.toppingSetList);
|
||||||
});
|
});
|
||||||
|
|
@ -112,12 +108,12 @@ export class RecipeToppingsetComponent implements OnInit {
|
||||||
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(',')),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -158,14 +154,13 @@ export class RecipeToppingsetComponent implements OnInit {
|
||||||
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
|
||||||
|
|
@ -190,13 +185,12 @@ export class RecipeToppingsetComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
getMembersByGroupId(groupID: string) {
|
getMembersByGroupId(groupID: string) {
|
||||||
return this.allToppingMembersByGroup
|
return this.allToppingMembersByGroup.find((x) => x.id == groupID)?.members;
|
||||||
.find((x) => x.id == groupID)
|
|
||||||
?.members;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getGroupIdByIndex(i: number) {
|
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[]) =>
|
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();
|
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) {
|
if v.MaterialPathId == int(mat.ID) {
|
||||||
mat_name := ""
|
mat_name := ""
|
||||||
for _, m := range matsCode {
|
for _, m := range matsCode {
|
||||||
if m.MaterialID == mat.ID {
|
if m.MaterialID == mat.ID && mat.MaterialName == "" {
|
||||||
mat_name = m.PackageDescription
|
mat_name = m.PackageDescription
|
||||||
break
|
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