From 5cf0a8b7616c48705243eba93f831c780e64b6f6 Mon Sep 17 00:00:00 2001 From: "pakintada@gmail.com" Date: Thu, 25 Jan 2024 13:39:49 +0700 Subject: [PATCH] add material setting show sample --- .../material-settings.component.html | 98 +++++++++++++++---- .../material-settings.component.ts | 34 +++++-- server/data/data.go | 4 +- server/server.go | 1 + 4 files changed, 107 insertions(+), 30 deletions(-) diff --git a/client/src/app/features/material-settings/material-settings.component.html b/client/src/app/features/material-settings/material-settings.component.html index 317a7b3..03825c9 100644 --- a/client/src/app/features/material-settings/material-settings.component.html +++ b/client/src/app/features/material-settings/material-settings.component.html @@ -1,25 +1,87 @@ -
+
+
+
+ {{ cat }} -
-
- {{ 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 index 1459de9..f5bc4fe 100644 --- a/client/src/app/features/material-settings/material-settings.component.ts +++ b/client/src/app/features/material-settings/material-settings.component.ts @@ -1,5 +1,6 @@ import { CommonModule, NgIf } from '@angular/common'; import { Component, OnInit } from '@angular/core'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MaterialService } from 'src/app/core/services/material.service'; import { getCategories, getMaterialType } from 'src/app/shared/helpers/recipe'; @@ -7,10 +8,7 @@ import { getCategories, getMaterialType } from 'src/app/shared/helpers/recipe'; selector: 'app-material-settings', templateUrl: './material-settings.component.html', standalone: true, - imports: [ - NgIf, - CommonModule - ] + imports: [NgIf, CommonModule, ReactiveFormsModule, FormsModule], }) export class MaterialSettingsComponent implements OnInit { // material settings @@ -22,8 +20,9 @@ export class MaterialSettingsComponent implements OnInit { type: string; }[] | null = []; - allMaterialsGroupedByTypes: { [key: string]: any[] } = {}; + currentMaterialSettings: any = null; + showMaterialSettingModal: boolean = false; constructor(private _materialService: MaterialService) {} @@ -35,8 +34,7 @@ export class MaterialSettingsComponent implements OnInit { }); } - -// ------------------ Functions --------------------- + // ------------------ Functions --------------------- // filter material by type ListCategory = () => { @@ -54,11 +52,11 @@ export class MaterialSettingsComponent implements OnInit { this.allMaterials!.forEach((mat) => { let category = getMaterialType(mat.materialId); // try again - if(category == 'others'){ + 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); + let originalCode = mat.materialId - interCode; // console.log("from",mat.materialId,"interCode", interCode, "originalCode", originalCode); category = getMaterialType(originalCode); @@ -79,6 +77,22 @@ export class MaterialSettingsComponent implements OnInit { // list all categories getCategories = () => { - return getCategories(); + let catList = getCategories(); + catList.push('others'); + return catList; + }; + + // get material settings by id + async getMaterialSettingsById(id: number) { + // Implementation goes here + (await this._materialService.getMaterialSettingById(id)).subscribe( + (data) => { + this.currentMaterialSettings = data; + this.showMaterialSettingModal = true; + console.log('material setting', data); + // console.log("keys of material settings", Object.keys(data)); + console.log('material setting', data.isUse, typeof data.isUse); + } + ); } } diff --git a/server/data/data.go b/server/data/data.go index 8dee1af..8209ffb 100644 --- a/server/data/data.go +++ b/server/data/data.go @@ -437,8 +437,8 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS result := make([]models.MaterialSetting, 0) if countryID == "" { - copy(result, d.currentRecipe[countryID].MaterialSetting) - return result + // copy(result, d.currentRecipe[countryID].MaterialSetting) + return d.currentRecipe[countryID].MaterialSetting } if !strings.Contains(filename, "tmp") { diff --git a/server/server.go b/server/server.go index 51fa37f..b2a4571 100644 --- a/server/server.go +++ b/server/server.go @@ -117,6 +117,7 @@ func (s *Server) createHandler() { _ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "phu", "pakin.t@forth.co.th", "", permissions.SuperAdmin) _ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "wanlop", "wanlop.r@forth.co.th", "", permissions.SuperAdmin) _ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "dawit", "dawit.o@forth.co.th", "", permissions.SuperAdmin) + _ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "narisara", "narisara.k@tao-bin.com", "", permissions.SuperAdmin) // Auth Router r.Group(func(r chi.Router) {