From e6f5d152f05a7608b79eaf2c1d059489a06a07a6 Mon Sep 17 00:00:00 2001 From: "pakintada@gmail.com" Date: Wed, 24 Jan 2024 16:25:49 +0700 Subject: [PATCH] add display materials WIP --- .gitmodules | 2 +- client/src/app/app-routing.module.ts | 21 +- .../src/app/core/layout/layout.component.ts | 5 + .../material-settings.component.html | 25 ++ .../material-settings.component.ts | 84 +++++++ .../recipe-list/recipe-list.component.html | 3 + .../recipe-list/recipe-list.component.ts | 21 +- .../recipe-toppingset.component.html | 51 ---- .../recipe-toppingset.component.ts | 220 ------------------ 9 files changed, 151 insertions(+), 281 deletions(-) create mode 100644 client/src/app/features/material-settings/material-settings.component.html create mode 100644 client/src/app/features/material-settings/material-settings.component.ts delete mode 100644 client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.html delete mode 100644 client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.ts diff --git a/.gitmodules b/.gitmodules index d2fa3b1..26c0cbe 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,5 +4,5 @@ branch = master [submodule "server/taobin_project"] path = server/taobin_project - url = ssh://ikong@192.168.10.159:/1TBHDD/ikong/taobin_project + url = ssh://ikong@192.168.10.159/1TBHDD/ikong/taobin_project branch = masterpiece diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index 3d30235..e6879bd 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -131,13 +131,20 @@ const routes: Routes = [ permissionsGuard(UserPermissions.THAI_PERMISSION), ], }, - // { - // path: 'log', - // loadComponent: () => - // import('./features/changelog/changelog.component').then( - // (m) => m.ChangelogComponent - // ), - // }, + { + path: 'log', + loadComponent: () => + import('./features/changelog/changelog.component').then( + (m) => m.ChangelogComponent + ), + }, + { + path: 'materials', + loadComponent: () => + import('./features/material-settings/material-settings.component').then( + (m) => m.MaterialSettingsComponent + ), + } ], }, { diff --git a/client/src/app/core/layout/layout.component.ts b/client/src/app/core/layout/layout.component.ts index d6281c5..bfa31d3 100644 --- a/client/src/app/core/layout/layout.component.ts +++ b/client/src/app/core/layout/layout.component.ts @@ -39,6 +39,11 @@ export class LayoutComponent implements OnInit, OnDestroy { icon_url: 'assets/icons/logs.svg', link: '/' + this.current_department + '/log', }, + { + name: 'Materials', + icon_url: '', + link: '/' + this.current_department + '/materials', + } ]; date = new Date(); clockSubscription: Subscription | null = null; diff --git a/client/src/app/features/material-settings/material-settings.component.html b/client/src/app/features/material-settings/material-settings.component.html new file mode 100644 index 0000000..317a7b3 --- /dev/null +++ b/client/src/app/features/material-settings/material-settings.component.html @@ -0,0 +1,25 @@ +
+ +
+
+ {{ cat }} + +
+
+
+ +
+
+
+ + + + +
+
+ +
+ + diff --git a/client/src/app/features/material-settings/material-settings.component.ts b/client/src/app/features/material-settings/material-settings.component.ts new file mode 100644 index 0000000..1459de9 --- /dev/null +++ b/client/src/app/features/material-settings/material-settings.component.ts @@ -0,0 +1,84 @@ +import { CommonModule, NgIf } from '@angular/common'; +import { Component, OnInit } from '@angular/core'; +import { MaterialService } from 'src/app/core/services/material.service'; +import { getCategories, getMaterialType } from 'src/app/shared/helpers/recipe'; + +@Component({ + selector: 'app-material-settings', + templateUrl: './material-settings.component.html', + standalone: true, + imports: [ + NgIf, + CommonModule + ] +}) +export class MaterialSettingsComponent implements OnInit { + // material settings + allMaterials: + | { + materialId: number; + name: string; + nameEN: string; + type: string; + }[] + | null = []; + + allMaterialsGroupedByTypes: { [key: string]: any[] } = {}; + + constructor(private _materialService: MaterialService) {} + + async ngOnInit(): Promise { + // do fetch material settings + (await this._materialService.getFullMaterialDetail()).subscribe((data) => { + this.allMaterials = data; + this.allMaterialsGroupedByTypes = this.ListCategory(); + }); + } + + +// ------------------ Functions --------------------- + + // filter material by type + ListCategory = () => { + let catMap: { [key: string]: any[] } = { + others: [], + }; + + // create category map + getCategories().forEach((category) => { + catMap[category] = []; + }); + + console.log('generated category', catMap); + + this.allMaterials!.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({ + id: mat.materialId, + name: mat.name, + nameEN: mat.nameEN, + }); + } + }); + + return catMap; + }; + + // list all categories + getCategories = () => { + return getCategories(); + } +} diff --git a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html index e0eb28b..78f9689 100644 --- a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html +++ b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html @@ -29,6 +29,9 @@ (click)="openMaterialList(i)" /> + + + 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 42a093e..a9f5e2e 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 @@ -34,6 +34,7 @@ import { } from 'src/app/shared/helpers/recipe'; import { RecipeToppingComponent } from '../recipe-topping/recipe-topping.component'; +import Lang from 'src/app/shared/helpers/lang'; @Component({ selector: 'app-recipe-list', @@ -49,7 +50,7 @@ export class RecipeListComponent implements OnInit { materialList: MaterialCode[] = []; fullMaterialList: - | { materialId: number; name: string; type: string }[] + | { materialId: number; name: string; nameEN: string;type: string }[] | null = []; showMaterialSelector: boolean = false; @@ -57,7 +58,7 @@ export class RecipeListComponent implements OnInit { isMatLoaded: boolean = false; - categoriedMaterial: { [key: string]: { id: number; name: string }[] } = {}; + categoriedMaterial: { [key: string]: { id: number; name: string; nameEN: string }[] } = {}; // ------------------------------------------------------------------------ // string params @@ -405,6 +406,7 @@ export class RecipeListComponent implements OnInit { catMap[category].push({ id: mat.materialId, name: mat.name, + nameEN: mat.nameEN, }); } }); @@ -571,4 +573,19 @@ export class RecipeListComponent implements OnInit { // trigger emitter this.recipeListFormChange.emit([this.toppingList, this.recipeListData.value]); } + + + + // language handler + async displayLang(material: any){ + let currLang = await Lang.getCurrentLanguage(); + + if(currLang == 'th'){ + return material.name; + } else { + return material.nameEN; + } + } + + } diff --git a/client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.html b/client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.html deleted file mode 100644 index 215a0f7..0000000 --- a/client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - --> diff --git a/client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.ts b/client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.ts deleted file mode 100644 index 26a3757..0000000 --- a/client/src/app/features/recipes/recipe-details/recipe-toppingset/recipe-toppingset.component.ts +++ /dev/null @@ -1,220 +0,0 @@ -// 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(); - -// 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 }[]; -// }[] = []; - -// private _toppingSetOriginalArray!: ToppingSet[]; - -// constructor( -// private _recipeService: RecipeService, -// private _toppingService: ToppingService, -// private _formBuilder: FormBuilder -// ) {} - -// toppingForm = this._formBuilder.group( -// { -// toppingList: this._formBuilder.array([]), -// }, -// { updateOn: 'blur' } -// ); - -// get toppingList(): FormArray { -// return this.toppingForm.get('toppingList') as FormArray; -// } - -// async ngOnInit(): Promise { -// 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, -// }) -// ); -// }); - -// // console.log('controls', this.toppingList.controls); - -// // 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); - -// 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(',')), -// }); -// } -// }); - -// // 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; - -// // handle null case -// if (toppingSet.defaultIDSelect == null) { -// toppingSet.defaultIDSelect = 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!); - -// if (isDiff) { -// let newToppingSetList: any[] = []; - -// forEach(value.toppingList!, (toppingSet: any) => { -// // transform value -// toppingSet.defaultIDSelect = parseInt(toppingSet.defaultIDSelect); - -// newToppingSetList.push(toppingSet); -// }); - -// // 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; -// } -// } - -// 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; -// } - -// 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; -// } - -// 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, -// }; -// }); - -// 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(); -// }