From f6ac4944e8a80359b93ee80f3b3c7e7a0604d3be Mon Sep 17 00:00:00 2001 From: Hanan Askarim Date: Sat, 25 May 2024 21:10:18 +0700 Subject: [PATCH 1/5] master unit listing --- handlers/dev/md.natunit.handlers.go | 228 ++++++++++++++++++++ handlers/routes.go | 6 + models/natunit.models.go | 11 + services/dev/md.natunit.services.go | 106 +++++++++ views/dev/mdnatunit/mdnatunit.templ | 101 +++++++++ views/dev/mdnatunit/mdnatunit_templ.go | 183 ++++++++++++++++ views/dev/mdnatunit/mdnatunittable.templ | 33 +++ views/dev/mdnatunit/mdnatunittable_templ.go | 123 +++++++++++ 8 files changed, 791 insertions(+) create mode 100644 handlers/dev/md.natunit.handlers.go create mode 100644 models/natunit.models.go create mode 100644 services/dev/md.natunit.services.go create mode 100644 views/dev/mdnatunit/mdnatunit.templ create mode 100644 views/dev/mdnatunit/mdnatunit_templ.go create mode 100644 views/dev/mdnatunit/mdnatunittable.templ create mode 100644 views/dev/mdnatunit/mdnatunittable_templ.go diff --git a/handlers/dev/md.natunit.handlers.go b/handlers/dev/md.natunit.handlers.go new file mode 100644 index 0000000..7a535e2 --- /dev/null +++ b/handlers/dev/md.natunit.handlers.go @@ -0,0 +1,228 @@ +package dev_handlers + +import ( + breadcrumadmin "cpone/component/breadcrumbadmin" + customtextfieldsearch "cpone/component/customtextfieldsearch" + navbarmenu "cpone/component/navbar" + "cpone/component/pagination" + sidebaruserprofile "cpone/component/sidebar_user_profile" + "cpone/models" + "cpone/services" + "cpone/utils" + dev_mdnatunitview "cpone/views/dev/mdnatunit" + "fmt" + "strconv" + + "github.com/a-h/templ" + "github.com/labstack/echo/v4" + "go.uber.org/zap" +) + +type MdNatUnitServices interface { + GetListMdNatUnit(search string, currentPage int, rowPerPage int) ([]models.NatUnit, int, error) + GetMdNatUnitBreadCrumb(title string) (models.BreadCrumbV1, error) +} + +func NeWMdNatUnitHandler(nu MdNatUnitServices) *MdNatUnitHandler { + return &MdNatUnitHandler{ + MdNatUnitServices: nu, + } +} + +type MdNatUnitHandler struct { + MdNatUnitServices MdNatUnitServices +} + +func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { + logger, _ := zap.NewProduction() + + tableID := utils.GenerateRandomID("tablebody") + paginationID := utils.GenerateRandomID("paginationid") + searchID := utils.GenerateRandomID("searchid") + dataMenu, err := services.GetMenu() + fmt.Println(dataMenu) + fmt.Println(err) + if err != nil { + fmt.Println(dataMenu) + return err + } + + //get user login + dataUser, err := services.GetUserLogin() + fmt.Println(dataUser) + fmt.Println(err) + if err != nil { + fmt.Println(dataUser) + return err + } + defer logger.Sync() + logger.Info("LOAD USER DEV", + zap.Any("data", dataUser), + ) + + title := "Master Unit" + + dataBreadCrumb, err := nh.MdNatUnitServices.GetMdNatUnitBreadCrumb(title) + fmt.Println(dataBreadCrumb) + fmt.Println(err) + if err != nil { + defer logger.Sync() + logger.Info("ERROR BREADCRUMB DEV", + zap.Any("error", err), + ) + fmt.Println(dataBreadCrumb) + return err + } + + defer logger.Sync() + logger.Info("LOAD BREADCRUMB DEV", + zap.Any("data", dataBreadCrumb), + ) + //Breadcrumb component + breadcrumbComponent := breadcrumadmin.MainBreadcrumbAdminV1(dataBreadCrumb) + // navbar menu + navbarmenuComponent := navbarmenu.NavbarMenu(dataMenu) + + // navbar user + navbaruserComponent := navbarmenu.Navbar(dataUser) + + // sidebar + sidebaruserprofileComponent := sidebaruserprofile.Navbaruserprofile(dataUser) + + //Table component + dataNatUnit, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit("", 1, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNTI", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + + tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, + tableID, + ) + + //filter user group component + natUnitFilterComponent := customtextfieldsearch.MainCustomTextFieldSearchV2(searchID, + "search", + "Cari Kode/Nama", + "text", + "/dev/md/natunit/filter", + "input changed delay:500ms, search", + "#"+paginationID, "", "", "outerHTML", "#tableID, #paginationID, #searchID") + + //Pagination + natUnitPaginationComponent := pagination.PaginationV2( + totalPage, + 1, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID", + "#"+paginationID, + "outerHTML", "", "", + ) + + // content, css, js + content := dev_mdnatunitview.MdNatUnitScreen( + tableID, + paginationID, + searchID, + breadcrumbComponent, + tableComponent, + natUnitFilterComponent, + natUnitPaginationComponent, + ) + css := dev_mdnatunitview.CssMdNatUnit() + js := dev_mdnatunitview.JsMdNatUnit() + + view := dev_mdnatunitview.ShowMdNatUnitScreen( + title, + content, + css, + js, + navbarmenuComponent, + navbaruserComponent, + sidebaruserprofileComponent, + ) + + return utils.View(c, view) +} + +func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { + search := c.QueryParam("search") + searchID := c.QueryParam("searchID") + tableID := c.QueryParam("tableID") + paginationID := c.QueryParam("paginationID") + var retval []templ.Component + logger, _ := zap.NewProduction() + + dataNatUnit, totalpage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, 1, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNTI", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, + tableID) + natUnitPaginationComponent := pagination.PaginationV2( + totalpage, + 1, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID", + "#"+paginationID, + "outerHTML", "", "", + ) + retval = append(retval, tableComponent) + retval = append(retval, natUnitPaginationComponent) + return utils.ViewMulti(c, retval) +} + +func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { + search := c.QueryParam("search") + pageparam := c.QueryParam("page") + tableID := c.QueryParam("tableID") + searchID := c.QueryParam("searchID") + paginationID := c.QueryParam("paginationID") + + var retval []templ.Component + logger, _ := zap.NewProduction() + page, err := strconv.Atoi(pageparam) + if err != nil { + defer logger.Sync() + logger.Info("ERROR CONVERT PAGE PARAM", + zap.Any("page", page), + zap.Any("error ", err), + ) + return err + } + + dataNatUnit, totalpage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, page, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNIT", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, + tableID) + natUnitPaginationComponent := pagination.PaginationV2( + totalpage, + page, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID", + "#"+paginationID, + "outerHTML", "", "", + ) + retval = append(retval, tableComponent) + retval = append(retval, natUnitPaginationComponent) + return utils.ViewMulti(c, retval) +} diff --git a/handlers/routes.go b/handlers/routes.go index 84520a4..54d5ed4 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -247,4 +247,10 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { dev.POST("/md/usergroupv2/closedeleteform", devMdUserGroupHandlers.HandleCloseFormDelete) dev.POST("/md/usergroupv2/delete", devMdUserGroupHandlers.HandleDeleteUserGroup) + // masterdata nat unit + devMdNatUnitServices := dev_services.NewMdNatUnitServices(appStore) + devMdNatUnitHandlers := dev_handlers.NeWMdNatUnitHandler(devMdNatUnitServices) + dev.GET("/md/natunit", devMdNatUnitHandlers.HandleShowMdNatUnitScreen) + dev.GET("/md/natunit/filter", devMdNatUnitHandlers.HandleFilterMdNatUnit) + dev.GET("/md/natunit/changepage", devMdNatUnitHandlers.HandlerChangePageMdNatUnit) } diff --git a/models/natunit.models.go b/models/natunit.models.go new file mode 100644 index 0000000..f5cf236 --- /dev/null +++ b/models/natunit.models.go @@ -0,0 +1,11 @@ +package models + +type NatUnit struct { + Nomor string `db:"nomor"` + Nat_UnitID int `db:"Nat_UnitID"` + Nat_UnitCode string `db:"Nat_UnitCode"` + Nat_UnitName string `db:"Nat_UnitName"` + Nat_UnitCreated string `db:"Nat_UnitCreated"` + Nat_UnitLastUpdated string `db:"Nat_UnitLastUpdated"` + Nat_UnitIsActive string `db:"Nat_UnitIsActive"` +} diff --git a/services/dev/md.natunit.services.go b/services/dev/md.natunit.services.go new file mode 100644 index 0000000..43f024c --- /dev/null +++ b/services/dev/md.natunit.services.go @@ -0,0 +1,106 @@ +package dev_services + +import ( + "cpone/db" + "cpone/models" + dbx "cpone/package/database" + "fmt" + "math" + "strings" +) + +func NewMdNatUnitServices(uStore db.AppStore) *MdNatUnitServices { + return &MdNatUnitServices{ + MdNatUnitStore: uStore, + } +} + +type MdNatUnitServices struct { + MdNatUnitStore db.AppStore +} + +func (nu *MdNatUnitServices) GetListMdNatUnit(search string, currentPage int, rowPerPage int) ([]models.NatUnit, int, error) { + var natUnitList []models.NatUnit + var totalData int + offset := (currentPage - 1) * rowPerPage + prm := "%" + strings.TrimSpace(search) + "%" + querytotal := `SELECT COUNT(*) + FROM nat_unit + WHERE Nat_UnitIsActive = 'Y' + AND (Nat_UnitCode LIKE ? OR Nat_UnitName LIKE ?)` + + if err := dbx.Handlex.Get(&totalData, querytotal, prm, prm); err != nil { + return nil, 0, fmt.Errorf("error querying database: %v", err) + } + + query := `SELECT ROW_NUMBER() OVER (ORDER BY Nat_UnitID DESC) AS nomor, + Nat_UnitID, + Nat_UnitCode, + Nat_UnitName, + Nat_UnitCreated, + Nat_UnitLastUpdated, + Nat_UnitIsActive + FROM nat_unit + WHERE Nat_UnitIsActive = 'Y' + AND (Nat_UnitCode LIKE ? OR Nat_UnitName LIKE ?) + ORDER BY Nat_UnitID DESC + LIMIT ? OFFSET ?` + + if err := dbx.Handlex.Select(&natUnitList, query, prm, prm, rowPerPage, offset); err != nil { + return nil, 0, fmt.Errorf("error querying database: %v", err) + } + totalPage := int(math.Ceil(float64(totalData) / float64(rowPerPage))) + + return natUnitList, totalPage, nil +} + +func (nu *MdNatUnitServices) GetMdNatUnitBreadCrumb(title string) (models.BreadCrumbV1, error) { + var ret models.BreadCrumbV1 + + dummyBreadcrumb := []models.BreadCrumbV1{ + { + Title: "Master Unit", + Item: []models.ItemBreadCrumbV1{ + { + Item: "Dashboard", + Url: "/dev/dashboard", + }, + { + Item: "Master", + Url: "/dev/master", + }, + { + Item: "Unit", + Url: "", + }, + }, + }, + + { + Title: "Master User", + Item: []models.ItemBreadCrumbV1{ + { + Item: "Dashboard", + Url: "/dev/dashboard", + }, + { + Item: "Master", + Url: "/dev/master", + }, + { + Item: "User", + Url: "", + }, + }, + }, + } + + for _, breadcrumb := range dummyBreadcrumb { + if breadcrumb.Title == title { + ret = breadcrumb + return ret, nil + } + } + + return ret, nil +} diff --git a/views/dev/mdnatunit/mdnatunit.templ b/views/dev/mdnatunit/mdnatunit.templ new file mode 100644 index 0000000..51c3544 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunit.templ @@ -0,0 +1,101 @@ +package dev_mdnatunitview + +import ( + "cpone/layout" + "cpone/component/customtextfield" + "cpone/models" +) + +templ MdNatUnitScreen( + tableID string, + paginationID string, + searchID string, + breadcrumb templ.Component, + tablecontent templ.Component, + filterComponent templ.Component, + paginationComponent templ.Component) { +
+ @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", + Name: "tableID", + Type: "hidden", + Value: tableID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "paginationID", + Name: "paginationID", + Type: "hidden", + Value: paginationID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "searchID", + Name: "searchID", + Type: "hidden", + Value: searchID}) +
+
+ @breadcrumb +
+
+ //
+
+ +
+
+
+ +
+
+ @filterComponent + @tablecontent + @paginationComponent +
+} + +templ CssMdNatUnit() { + + + + +} + +templ JsMdNatUnit() { +} + +templ ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, js templ.Component, + navbarmenu templ.Component, + navbaruser templ.Component, + userprofile templ.Component) { + @layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile) { + @cmp + } +} diff --git a/views/dev/mdnatunit/mdnatunit_templ.go b/views/dev/mdnatunit/mdnatunit_templ.go new file mode 100644 index 0000000..800ab15 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunit_templ.go @@ -0,0 +1,183 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_mdnatunitview + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "cpone/component/customtextfield" + "cpone/layout" + "cpone/models" +) + +func MdNatUnitScreen( + tableID string, + paginationID string, + searchID string, + breadcrumb templ.Component, + tablecontent templ.Component, + filterComponent templ.Component, + paginationComponent templ.Component) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", + Name: "tableID", + Type: "hidden", + Value: tableID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "paginationID", + Name: "paginationID", + Type: "hidden", + Value: paginationID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "searchID", + Name: "searchID", + Type: "hidden", + Value: searchID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = breadcrumb.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = filterComponent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tablecontent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = paginationComponent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func CssMdNatUnit() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func JsMdNatUnit() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, js templ.Component, + navbarmenu templ.Component, + navbaruser templ.Component, + userprofile templ.Component) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var5 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Err = cmp.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/views/dev/mdnatunit/mdnatunittable.templ b/views/dev/mdnatunit/mdnatunittable.templ new file mode 100644 index 0000000..4e4edd3 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunittable.templ @@ -0,0 +1,33 @@ +package dev_mdnatunitview + +import ( + "cpone/component/table" + "cpone/models" +) + +templ TableNatUnit(data []models.NatUnit, + tableID string, +) { +
+ @tablecomponent.TableV3([]string{"KODE", "UNIT", "AKSI"}, + []string{"40%", "40%", "20%"}, + RowNatUnit(data)) +
+} + +templ RowNatUnit(data []models.NatUnit) { + if len(data) == 0 { + + Data Tidak Ditemukan + + } + for _, v := range data { + + { v.Nat_UnitCode } + { v.Nat_UnitName } + + Action + + + } +} diff --git a/views/dev/mdnatunit/mdnatunittable_templ.go b/views/dev/mdnatunit/mdnatunittable_templ.go new file mode 100644 index 0000000..271aa07 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunittable_templ.go @@ -0,0 +1,123 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_mdnatunitview + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "cpone/component/table" + "cpone/models" +) + +func TableNatUnit(data []models.NatUnit, + tableID string, +) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tablecomponent.TableV3([]string{"KODE", "UNIT", "AKSI"}, + []string{"40%", "40%", "20%"}, + RowNatUnit(data)).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func RowNatUnit(data []models.NatUnit) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if len(data) == 0 { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Data Tidak Ditemukan") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + for _, v := range data { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitCode) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 26, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitName) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 27, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Action\r") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} From 5b2c63a4d4bc1b9b87379b7724e820abb7e8d0ef Mon Sep 17 00:00:00 2001 From: Hanan Askarim Date: Mon, 27 May 2024 09:58:55 +0700 Subject: [PATCH 2/5] add loading search dan pagination --- handlers/dev/md.natunit.handlers.go | 18 ++++-- views/dev/mdnatunit/mdnatunit.templ | 77 +++++++++++++++++++++++++- views/dev/mdnatunit/mdnatunit_templ.go | 44 ++++++++++++++- 3 files changed, 131 insertions(+), 8 deletions(-) diff --git a/handlers/dev/md.natunit.handlers.go b/handlers/dev/md.natunit.handlers.go index 7a535e2..fc2491b 100644 --- a/handlers/dev/md.natunit.handlers.go +++ b/handlers/dev/md.natunit.handlers.go @@ -105,16 +105,18 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { ) //filter user group component - natUnitFilterComponent := customtextfieldsearch.MainCustomTextFieldSearchV2(searchID, + natUnitFilterComponent := customtextfieldsearch.MainCustomTextFieldSearchV3(searchID, "search", "Cari Kode/Nama", "text", "/dev/md/natunit/filter", "input changed delay:500ms, search", - "#"+paginationID, "", "", "outerHTML", "#tableID, #paginationID, #searchID") + "#"+paginationID, "#loadingcontent", "", "outerHTML", "#tableID, #paginationID, #searchID", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent()) //Pagination - natUnitPaginationComponent := pagination.PaginationV2( + natUnitPaginationComponent := pagination.PaginationV3( totalPage, 1, "/dev/md/natunit/changepage", @@ -122,6 +124,8 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { "#tableID, #searchID, #"+searchID+", #paginationID", "#"+paginationID, "outerHTML", "", "", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), ) // content, css, js @@ -169,7 +173,7 @@ func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { } tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, tableID) - natUnitPaginationComponent := pagination.PaginationV2( + natUnitPaginationComponent := pagination.PaginationV3( totalpage, 1, "/dev/md/natunit/changepage", @@ -177,6 +181,8 @@ func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { "#tableID, #searchID, #"+searchID+", #paginationID", "#"+paginationID, "outerHTML", "", "", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), ) retval = append(retval, tableComponent) retval = append(retval, natUnitPaginationComponent) @@ -213,7 +219,7 @@ func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { } tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, tableID) - natUnitPaginationComponent := pagination.PaginationV2( + natUnitPaginationComponent := pagination.PaginationV3( totalpage, page, "/dev/md/natunit/changepage", @@ -221,6 +227,8 @@ func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { "#tableID, #searchID, #"+searchID+", #paginationID", "#"+paginationID, "outerHTML", "", "", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), ) retval = append(retval, tableComponent) retval = append(retval, natUnitPaginationComponent) diff --git a/views/dev/mdnatunit/mdnatunit.templ b/views/dev/mdnatunit/mdnatunit.templ index 51c3544..65a768b 100644 --- a/views/dev/mdnatunit/mdnatunit.templ +++ b/views/dev/mdnatunit/mdnatunit.templ @@ -50,8 +50,17 @@ templ MdNatUnitScreen(
@filterComponent - @tablecontent - @paginationComponent +
+ @tablecontent + @paginationComponent +
+ //
+
+ Loading... +
+
+
+
} @@ -89,6 +98,70 @@ templ CssMdNatUnit() { } templ JsMdNatUnit() { + +} + +script BeforeRequestContent() { + const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.add("overlay"); + loadingParent.classList.add("overlay-block"); + loadingChild.classList.add("overlay-layer"); + loadingSpinner.classList.remove("d-none"); +} + +script AfterRequestContent() { + const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.remove("overlay"); + loadingParent.classList.remove("overlay-block"); + loadingChild.classList.remove("overlay-layer"); + loadingSpinner.classList.add("d-none"); } templ ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, js templ.Component, diff --git a/views/dev/mdnatunit/mdnatunit_templ.go b/views/dev/mdnatunit/mdnatunit_templ.go index 800ab15..532d8e2 100644 --- a/views/dev/mdnatunit/mdnatunit_templ.go +++ b/views/dev/mdnatunit/mdnatunit_templ.go @@ -77,6 +77,10 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } templ_7745c5c3_Err = tablecontent.Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -85,7 +89,7 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Loading...
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -133,6 +137,10 @@ func JsMdNatUnit() templ.Component { templ_7745c5c3_Var3 = templ.NopComponent } ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } if !templ_7745c5c3_IsBuffer { _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) } @@ -140,6 +148,40 @@ func JsMdNatUnit() templ.Component { }) } +func BeforeRequestContent() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_BeforeRequestContent_911f`, + Function: `function __templ_BeforeRequestContent_911f(){const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.add("overlay"); + loadingParent.classList.add("overlay-block"); + loadingChild.classList.add("overlay-layer"); + loadingSpinner.classList.remove("d-none"); +}`, + Call: templ.SafeScript(`__templ_BeforeRequestContent_911f`), + CallInline: templ.SafeScriptInline(`__templ_BeforeRequestContent_911f`), + } +} + +func AfterRequestContent() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_AfterRequestContent_6cc0`, + Function: `function __templ_AfterRequestContent_6cc0(){const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.remove("overlay"); + loadingParent.classList.remove("overlay-block"); + loadingChild.classList.remove("overlay-layer"); + loadingSpinner.classList.add("d-none"); +}`, + Call: templ.SafeScript(`__templ_AfterRequestContent_6cc0`), + CallInline: templ.SafeScriptInline(`__templ_AfterRequestContent_6cc0`), + } +} + func ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, js templ.Component, navbarmenu templ.Component, navbaruser templ.Component, From 04460bac003ad17c9093b7076917c6e9fd8f9d08 Mon Sep 17 00:00:00 2001 From: Hanan Askarim Date: Mon, 27 May 2024 11:27:07 +0700 Subject: [PATCH 3/5] add feature tambah data --- handlers/dev/md.natunit.handlers.go | 250 ++++++++++ handlers/routes.go | 2 + models/natunit.models.go | 18 + services/dev/md.natunit.services.go | 74 +++ views/dev/mdnatunit/mdnatunit.templ | 16 +- views/dev/mdnatunit/mdnatunit_templ.go | 73 ++- views/dev/mdnatunit/mdnatunitformmodal.templ | 134 ++++++ .../dev/mdnatunit/mdnatunitformmodal_templ.go | 447 ++++++++++++++++++ 8 files changed, 1000 insertions(+), 14 deletions(-) create mode 100644 views/dev/mdnatunit/mdnatunitformmodal.templ create mode 100644 views/dev/mdnatunit/mdnatunitformmodal_templ.go diff --git a/handlers/dev/md.natunit.handlers.go b/handlers/dev/md.natunit.handlers.go index fc2491b..443e756 100644 --- a/handlers/dev/md.natunit.handlers.go +++ b/handlers/dev/md.natunit.handlers.go @@ -6,12 +6,15 @@ import ( navbarmenu "cpone/component/navbar" "cpone/component/pagination" sidebaruserprofile "cpone/component/sidebar_user_profile" + customtoastv2 "cpone/component/toastbootstrap" "cpone/models" "cpone/services" "cpone/utils" dev_mdnatunitview "cpone/views/dev/mdnatunit" + dev_mdusergroupview "cpone/views/dev/mdusergroup" "fmt" "strconv" + "strings" "github.com/a-h/templ" "github.com/labstack/echo/v4" @@ -21,6 +24,7 @@ import ( type MdNatUnitServices interface { GetListMdNatUnit(search string, currentPage int, rowPerPage int) ([]models.NatUnit, int, error) GetMdNatUnitBreadCrumb(title string) (models.BreadCrumbV1, error) + AddMdNatUnit(code string, name string) (models.NatUnit, error) } func NeWMdNatUnitHandler(nu MdNatUnitServices) *MdNatUnitHandler { @@ -39,6 +43,8 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { tableID := utils.GenerateRandomID("tablebody") paginationID := utils.GenerateRandomID("paginationid") searchID := utils.GenerateRandomID("searchid") + dialogAddID := utils.GenerateRandomID("dialogaddID") + dialogAddBodyID := utils.GenerateRandomID("dialogaddbodyID") dataMenu, err := services.GetMenu() fmt.Println(dataMenu) fmt.Println(err) @@ -128,15 +134,67 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { dev_mdnatunitview.AfterRequestContent(), ) + // modal add form + dialogAddBodyCmp := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal(""), + ) + + modalActionAddCmp := dev_mdnatunitview.ActionFormNatUnit( + "/dev/md/natunit/closeaddform", + "#"+dialogAddBodyID, + "outerHTML", + "#"+dialogAddID, + ) + + btnCloseModalAdd := dev_mdnatunitview.BtnCloseFormNatUnit( + "/dev/md/natunit/closeaddform", + "#"+dialogAddBodyID, + "outerHTML", + "#"+dialogAddID, + ) + + modalAddFormComponent := dev_mdnatunitview.NatUnitForm( + models.NatUnitFormComponent{ + IDComponent: "formnatunit", + Link: "/dev/md/natunit/add", + HxTarget: "#" + dialogAddBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogAddID, + ModalTitle: "New - Unit", + DialogBody: dialogAddBodyCmp, + DialogAction: modalActionAddCmp, + ButtonCLose: btnCloseModalAdd, + }, + ) + // content, css, js content := dev_mdnatunitview.MdNatUnitScreen( tableID, paginationID, searchID, + dialogAddID, + dialogAddBodyID, breadcrumbComponent, tableComponent, natUnitFilterComponent, natUnitPaginationComponent, + modalAddFormComponent, ) css := dev_mdnatunitview.CssMdNatUnit() js := dev_mdnatunitview.JsMdNatUnit() @@ -234,3 +292,195 @@ func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { retval = append(retval, natUnitPaginationComponent) return utils.ViewMulti(c, retval) } + +func (nh *MdNatUnitHandler) HandlerCloseFormAdd(c echo.Context) error { + dialogAddBodyID := c.FormValue("dialogAddBodyID") + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdusergroupview.JsHideModal("")) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + // prm form addnatunit + code := c.FormValue("natunitcode") + name := c.FormValue("natunitname") + tableID := c.FormValue("tableID") + paginationID := c.FormValue("paginationID") + searchID := c.FormValue("searchID") + search := c.FormValue("search") + currPagePrm := c.FormValue("currpage" + paginationID) + dialogAddBodyID := c.FormValue("dialogAddBodyID") + dialogAddID := c.FormValue("dialogAddID") + + currPage, err := strconv.Atoi(currPagePrm) + if err != nil { + return err + } + logger.Info("ADD UNIT PARAM", + zap.Any("code", code), + zap.Any("nama", name), + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPage), + ) + + formValidation := "" + codeValidation := "" + nameValidation := "" + if strings.TrimSpace(code) == "" { + formValidation = "Code unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "" + } + if strings.TrimSpace(name) == "" { + formValidation = "Nama unit tidak boleh kosong" + codeValidation = "" + nameValidation = "Nama unit tidak boleh kosong" + } + if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" { + formValidation = "Code dan nama unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "Nama unit tidak boleh kosong" + + } + + if formValidation != "" || codeValidation != "" || nameValidation != "" { + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm}) + } + + // add nat unit service + dataNatUnit, err := nh.MdNatUnitServices.AddMdNatUnit(code, name) + if err != nil { + logger.Info("Error", + zap.Any("Error", err), + zap.Any("code", code), + zap.Any("name", name), + ) + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{ + customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), + newForm}) + } + logger.Info("ADD UNIT", + zap.Any("return", dataNatUnit), + zap.Any("code", code), + zap.Any("name", name), + ) + + // get list nat unit for table + dataNatUnitList, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET UNIT", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + + // table component + tableComponent := dev_mdnatunitview.TableNatUnit( + dataNatUnitList, + tableID, + ) + + // pagination component + natUnitPaginationComponent := pagination.PaginationV3( + totalPage, + currPage, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal("#"+dialogAddID)) + toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil insert unit "+name, "success") + + return utils.ViewMulti(c, []templ.Component{ + toastSuccess, + tableComponent, + natUnitPaginationComponent, + newForm, + }) +} diff --git a/handlers/routes.go b/handlers/routes.go index 54d5ed4..4c2c317 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -253,4 +253,6 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { dev.GET("/md/natunit", devMdNatUnitHandlers.HandleShowMdNatUnitScreen) dev.GET("/md/natunit/filter", devMdNatUnitHandlers.HandleFilterMdNatUnit) dev.GET("/md/natunit/changepage", devMdNatUnitHandlers.HandlerChangePageMdNatUnit) + dev.POST("/md/natunit/closeaddform", devMdNatUnitHandlers.HandlerCloseFormAdd) + dev.POST("/md/natunit/add", devMdNatUnitHandlers.HandlerAddNatUnit) } diff --git a/models/natunit.models.go b/models/natunit.models.go index f5cf236..2f5301f 100644 --- a/models/natunit.models.go +++ b/models/natunit.models.go @@ -1,5 +1,7 @@ package models +import "github.com/a-h/templ" + type NatUnit struct { Nomor string `db:"nomor"` Nat_UnitID int `db:"Nat_UnitID"` @@ -9,3 +11,19 @@ type NatUnit struct { Nat_UnitLastUpdated string `db:"Nat_UnitLastUpdated"` Nat_UnitIsActive string `db:"Nat_UnitIsActive"` } + +type NatUnitFormComponent struct { + IDComponent string + Link string + HxTarget string + HxSwap string + HxInclude string + ModalID string + ModalTitle string + InputName CustomTextFieldv2Prm + InputCode CustomTextFieldv2Prm + InputID CustomTextFieldv2Prm + DialogBody templ.Component + DialogAction templ.Component + ButtonCLose templ.Component +} diff --git a/services/dev/md.natunit.services.go b/services/dev/md.natunit.services.go index 43f024c..cde45fb 100644 --- a/services/dev/md.natunit.services.go +++ b/services/dev/md.natunit.services.go @@ -6,7 +6,10 @@ import ( dbx "cpone/package/database" "fmt" "math" + "strconv" "strings" + + "go.uber.org/zap" ) func NewMdNatUnitServices(uStore db.AppStore) *MdNatUnitServices { @@ -104,3 +107,74 @@ func (nu *MdNatUnitServices) GetMdNatUnitBreadCrumb(title string) (models.BreadC return ret, nil } + +func (nu *MdNatUnitServices) GetMdNatUnitByID(id string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + + var data models.NatUnit + err := dbx.Handlex.Get(&data, `SELECT * FROM nat_unit + WHERE Nat_UnitID = ?`, id) + + if err != nil { + defer logger.Sync() + logger.Error("Error get data unit by id", + zap.String("ID", id), + zap.Error(err), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} + +func (nu *MdNatUnitServices) AddMdNatUnit(code string, name string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + var data models.NatUnit + var datacek []models.NatUnit + + qryCek := `SELECT Nat_UnitCode FROM nat_unit + WHERE Nat_UnitCode = ? AND Nat_UnitIsActive = 'Y'` + err := dbx.Handlex.Select(&datacek, qryCek, code) + + if err != nil { + defer logger.Sync() + logger.Error("Error cek data by code", + zap.String("code", code), + zap.Any("datacek", datacek), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + if len(datacek) > 0 { + defer logger.Sync() + logger.Error("Code already taken by another data", + zap.String("code", code), + ) + return data, fmt.Errorf("code sudah dipakai") + } + + qry := `INSERT INTO nat_unit + (Nat_UnitCode, + Nat_UnitName) VALUES(?,?)` + rst := dbx.Handlex.MustExec(qry, code, name) + insertedID, err := rst.LastInsertId() + if err != nil { + defer logger.Sync() + logger.Error("Error Insert natunit", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + s := strconv.Itoa(int(insertedID)) + data, err = nu.GetMdNatUnitByID(s) + if err != nil { + defer logger.Sync() + logger.Error("Error get natunit by id", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} diff --git a/views/dev/mdnatunit/mdnatunit.templ b/views/dev/mdnatunit/mdnatunit.templ index 65a768b..332d399 100644 --- a/views/dev/mdnatunit/mdnatunit.templ +++ b/views/dev/mdnatunit/mdnatunit.templ @@ -10,10 +10,13 @@ templ MdNatUnitScreen( tableID string, paginationID string, searchID string, + dialogAddID string, + dialogAddBodyID string, breadcrumb templ.Component, tablecontent templ.Component, filterComponent templ.Component, - paginationComponent templ.Component) { + paginationComponent templ.Component, + modalAddForm templ.Component) {
@customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", Name: "tableID", @@ -27,6 +30,14 @@ templ MdNatUnitScreen( Name: "searchID", Type: "hidden", Value: searchID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddID", + Name: "dialogAddID", + Type: "hidden", + Value: dialogAddID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddBodyID", + Name: "dialogAddBodyID", + Type: "hidden", + Value: dialogAddBodyID})
@breadcrumb @@ -38,6 +49,7 @@ templ MdNatUnitScreen( type="button" class="btn btn-primary" data-toggle="modal" + data-target={ "#" + dialogAddID } >Add New
@@ -46,6 +58,7 @@ templ MdNatUnitScreen( type="button" class="btn btn-primary btn-block" data-toggle="modal" + data-target={ "#" + dialogAddID } >Add New
@@ -53,6 +66,7 @@ templ MdNatUnitScreen(
@tablecontent @paginationComponent + @modalAddForm
//
diff --git a/views/dev/mdnatunit/mdnatunit_templ.go b/views/dev/mdnatunit/mdnatunit_templ.go index 532d8e2..16c114c 100644 --- a/views/dev/mdnatunit/mdnatunit_templ.go +++ b/views/dev/mdnatunit/mdnatunit_templ.go @@ -20,10 +20,13 @@ func MdNatUnitScreen( tableID string, paginationID string, searchID string, + dialogAddID string, + dialogAddBodyID string, breadcrumb templ.Component, tablecontent templ.Component, filterComponent templ.Component, - paginationComponent templ.Component) templ.Component { + paginationComponent templ.Component, + modalAddForm templ.Component) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -61,6 +64,20 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddID", + Name: "dialogAddID", + Type: "hidden", + Value: dialogAddID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddBodyID", + Name: "dialogAddBodyID", + Type: "hidden", + Value: dialogAddBodyID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -69,7 +86,33 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -89,6 +132,10 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = modalAddForm.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Loading...
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -108,9 +155,9 @@ func CssMdNatUnit() templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var2 := templ.GetChildren(ctx) - if templ_7745c5c3_Var2 == nil { - templ_7745c5c3_Var2 = templ.NopComponent + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") @@ -132,9 +179,9 @@ func JsMdNatUnit() templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var3 := templ.GetChildren(ctx) - if templ_7745c5c3_Var3 == nil { - templ_7745c5c3_Var3 = templ.NopComponent + templ_7745c5c3_Var5 := templ.GetChildren(ctx) + if templ_7745c5c3_Var5 == nil { + templ_7745c5c3_Var5 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") @@ -193,12 +240,12 @@ func ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var4 := templ.GetChildren(ctx) - if templ_7745c5c3_Var4 == nil { - templ_7745c5c3_Var4 = templ.NopComponent + templ_7745c5c3_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var5 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var7 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { templ_7745c5c3_Buffer = templ.GetBuffer() @@ -213,7 +260,7 @@ func ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile).Render(templ.WithChildren(ctx, templ_7745c5c3_Var7), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/dev/mdnatunit/mdnatunitformmodal.templ b/views/dev/mdnatunit/mdnatunitformmodal.templ new file mode 100644 index 0000000..2422185 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunitformmodal.templ @@ -0,0 +1,134 @@ +package dev_mdnatunitview + +import "cpone/models" +import "cpone/component/modal" +import "cpone/component/customtextfield" + +templ NatUnitForm(data models.NatUnitFormComponent) { +
+
+ @modalcomponent.Modal(data.ModalID, + data.ModalTitle, + data.DialogBody, + data.DialogAction, + data.ButtonCLose) +
+
+} + +script HandleFormBeforeRequest() { + console.log("handle disable btn add"); + const btnActCancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + for (let i = 0; i < btnActCancel.length; i++) { + btnActCancel[i].setAttribute('disabled', 'true'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].setAttribute('disabled', 'true'); + + } +} + +script HandleFormAfterRequest() { + console.log("handle enable btn add"); + + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +} + +templ BodyFormNatUnit(inputId models.CustomTextFieldv2Prm, + inputCode models.CustomTextFieldv2Prm, + inputName models.CustomTextFieldv2Prm, + componentID string, + hxOnLoad templ.ComponentScript) { +
+ @customtextfield.CustomTextFieldv2( + inputId) + @customtextfield.CustomTextFieldv2( + inputCode) + @customtextfield.CustomTextFieldv2( + inputName) +
+} + +script JsHideModal(modalID string) { + $(modalID).modal('hide') +} + +script JsShowModal(modalID string) { + $(modalID).modal('show') + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +} + +templ ActionFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) { +
+ + +
+} + +templ BtnCloseFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) { + +} diff --git a/views/dev/mdnatunit/mdnatunitformmodal_templ.go b/views/dev/mdnatunit/mdnatunitformmodal_templ.go new file mode 100644 index 0000000..03ba642 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunitformmodal_templ.go @@ -0,0 +1,447 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_mdnatunitview + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import "cpone/models" +import "cpone/component/modal" +import "cpone/component/customtextfield" + +func NatUnitForm(data models.NatUnitFormComponent) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, HandleFormBeforeRequest(), HandleFormAfterRequest()) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = modalcomponent.Modal(data.ModalID, + data.ModalTitle, + data.DialogBody, + data.DialogAction, + data.ButtonCLose).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func HandleFormBeforeRequest() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleFormBeforeRequest_2922`, + Function: `function __templ_HandleFormBeforeRequest_2922(){console.log("handle disable btn add"); + const btnActCancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + for (let i = 0; i < btnActCancel.length; i++) { + btnActCancel[i].setAttribute('disabled', 'true'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].setAttribute('disabled', 'true'); + + } +}`, + Call: templ.SafeScript(`__templ_HandleFormBeforeRequest_2922`), + CallInline: templ.SafeScriptInline(`__templ_HandleFormBeforeRequest_2922`), + } +} + +func HandleFormAfterRequest() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleFormAfterRequest_956b`, + Function: `function __templ_HandleFormAfterRequest_956b(){console.log("handle enable btn add"); + + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +}`, + Call: templ.SafeScript(`__templ_HandleFormAfterRequest_956b`), + CallInline: templ.SafeScriptInline(`__templ_HandleFormAfterRequest_956b`), + } +} + +func BodyFormNatUnit(inputId models.CustomTextFieldv2Prm, + inputCode models.CustomTextFieldv2Prm, + inputName models.CustomTextFieldv2Prm, + componentID string, + hxOnLoad templ.ComponentScript) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, hxOnLoad) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2( + inputId).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2( + inputCode).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2( + inputName).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func JsHideModal(modalID string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_JsHideModal_da6c`, + Function: `function __templ_JsHideModal_da6c(modalID){$(modalID).modal('hide') +}`, + Call: templ.SafeScript(`__templ_JsHideModal_da6c`, modalID), + CallInline: templ.SafeScriptInline(`__templ_JsHideModal_da6c`, modalID), + } +} + +func JsShowModal(modalID string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_JsShowModal_b74d`, + Function: `function __templ_JsShowModal_b74d(modalID){$(modalID).modal('show') + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +}`, + Call: templ.SafeScript(`__templ_JsShowModal_b74d`, modalID), + CallInline: templ.SafeScriptInline(`__templ_JsShowModal_b74d`, modalID), + } +} + +func ActionFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var12 := templ.GetChildren(ctx) + if templ_7745c5c3_Var12 == nil { + templ_7745c5c3_Var12 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, JsHideModal(modalID)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func BtnCloseFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var17 := templ.GetChildren(ctx) + if templ_7745c5c3_Var17 == nil { + templ_7745c5c3_Var17 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, JsHideModal(modalID)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} From a3005c3b6aa421482b8aedd3e67b93ddfa96d9e0 Mon Sep 17 00:00:00 2001 From: Hanan Askarim Date: Mon, 27 May 2024 14:58:10 +0700 Subject: [PATCH 4/5] add feature edit --- handlers/dev/md.natunit.handlers.go | 337 +++++++++++++++++++- handlers/routes.go | 3 + services/dev/md.natunit.services.go | 54 ++++ views/dev/mdnatunit/mdnatunit.templ | 14 +- views/dev/mdnatunit/mdnatunit_templ.go | 27 +- views/dev/mdnatunit/mdnatunittable.templ | 76 ++++- views/dev/mdnatunit/mdnatunittable_templ.go | 217 ++++++++++++- 7 files changed, 710 insertions(+), 18 deletions(-) diff --git a/handlers/dev/md.natunit.handlers.go b/handlers/dev/md.natunit.handlers.go index 443e756..e6a245b 100644 --- a/handlers/dev/md.natunit.handlers.go +++ b/handlers/dev/md.natunit.handlers.go @@ -11,7 +11,6 @@ import ( "cpone/services" "cpone/utils" dev_mdnatunitview "cpone/views/dev/mdnatunit" - dev_mdusergroupview "cpone/views/dev/mdusergroup" "fmt" "strconv" "strings" @@ -25,6 +24,8 @@ type MdNatUnitServices interface { GetListMdNatUnit(search string, currentPage int, rowPerPage int) ([]models.NatUnit, int, error) GetMdNatUnitBreadCrumb(title string) (models.BreadCrumbV1, error) AddMdNatUnit(code string, name string) (models.NatUnit, error) + GetMdNatUnitByID(id string) (models.NatUnit, error) + EditMdNatUnit(id string, code string, name string) (models.NatUnit, error) } func NeWMdNatUnitHandler(nu MdNatUnitServices) *MdNatUnitHandler { @@ -45,6 +46,8 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { searchID := utils.GenerateRandomID("searchid") dialogAddID := utils.GenerateRandomID("dialogaddID") dialogAddBodyID := utils.GenerateRandomID("dialogaddbodyID") + dialogEditID := utils.GenerateRandomID("dialogEditID") + dialogEditBodyID := utils.GenerateRandomID("dialogEditbodyID") dataMenu, err := services.GetMenu() fmt.Println(dataMenu) fmt.Println(err) @@ -108,9 +111,13 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID", ) - //filter user group component + //filter nat unit component natUnitFilterComponent := customtextfieldsearch.MainCustomTextFieldSearchV3(searchID, "search", "Cari Kode/Nama", @@ -183,6 +190,55 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { }, ) + // modal edit form + dialogEditBodyCmp := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal(""), + ) + + modalActionEditCmp := dev_mdnatunitview.ActionFormNatUnit( + "/dev/md/natunit/closeeditform", + "#"+dialogEditBodyID, + "outerHTML", + "#"+dialogEditID, + ) + + btnCloseModalEdit := dev_mdnatunitview.BtnCloseFormNatUnit( + "/dev/md/natunit/closeeditform", + "#"+dialogEditBodyID, + "outerHTML", + "#"+dialogEditID, + ) + + modalEditFormComponent := dev_mdnatunitview.NatUnitForm( + models.NatUnitFormComponent{ + IDComponent: "formnatunit", + Link: "dev/md/natunit/edit", + HxTarget: "#" + dialogEditBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogEditID, + ModalTitle: "New - Unit", + DialogBody: dialogEditBodyCmp, + DialogAction: modalActionEditCmp, + ButtonCLose: btnCloseModalEdit, + }, + ) + // content, css, js content := dev_mdnatunitview.MdNatUnitScreen( tableID, @@ -190,11 +246,14 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { searchID, dialogAddID, dialogAddBodyID, + dialogEditID, + dialogEditBodyID, breadcrumbComponent, tableComponent, natUnitFilterComponent, natUnitPaginationComponent, modalAddFormComponent, + modalEditFormComponent, ) css := dev_mdnatunitview.CssMdNatUnit() js := dev_mdnatunitview.JsMdNatUnit() @@ -217,6 +276,7 @@ func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { searchID := c.QueryParam("searchID") tableID := c.QueryParam("tableID") paginationID := c.QueryParam("paginationID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") var retval []templ.Component logger, _ := zap.NewProduction() @@ -230,7 +290,11 @@ func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { return err } tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, - tableID) + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID") natUnitPaginationComponent := pagination.PaginationV3( totalpage, 1, @@ -253,6 +317,7 @@ func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { tableID := c.QueryParam("tableID") searchID := c.QueryParam("searchID") paginationID := c.QueryParam("paginationID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") var retval []templ.Component logger, _ := zap.NewProduction() @@ -276,7 +341,12 @@ func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { return err } tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, - tableID) + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID", + ) natUnitPaginationComponent := pagination.PaginationV3( totalpage, page, @@ -311,7 +381,7 @@ func (nh *MdNatUnitHandler) HandlerCloseFormAdd(c echo.Context) error { Name: "natunitid", Placeholder: "Kode Unit", Type: "hidden", ID: "natunitinputid"}, - dialogAddBodyID, dev_mdusergroupview.JsHideModal("")) + dialogAddBodyID, dev_mdnatunitview.JsHideModal("")) return utils.View(c, newForm) } @@ -329,6 +399,7 @@ func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { currPagePrm := c.FormValue("currpage" + paginationID) dialogAddBodyID := c.FormValue("dialogAddBodyID") dialogAddID := c.FormValue("dialogAddID") + dialogEditBodyID := c.FormValue("dialogEditBodyID") currPage, err := strconv.Atoi(currPagePrm) if err != nil { @@ -441,6 +512,10 @@ func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { tableComponent := dev_mdnatunitview.TableNatUnit( dataNatUnitList, tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID", ) // pagination component @@ -484,3 +559,255 @@ func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { newForm, }) } + +func (nh *MdNatUnitHandler) HandlerOpenEditForm(c echo.Context) error { + id := c.QueryParam("id") + dialogEditID := c.QueryParam("dialogEditID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") + + dataNatUnit, err := nh.MdNatUnitServices.GetMdNatUnitByID(id) + if err != nil { + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get unit error", "danger"), newForm}) + } + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Value: dataNatUnit.Nat_UnitCode, + Type: "text", + ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitname", + Placeholder: "Kode Unit", + Value: dataNatUnit.Nat_UnitName, + Type: "text", + ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Value: strconv.Itoa(dataNatUnit.Nat_UnitID), + Type: "hidden", + ID: "natunitinputid"}, + + dialogEditBodyID, dev_mdnatunitview.JsShowModal("#"+dialogEditID)) + + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerCloseFormEdit(c echo.Context) error { + dialogEditBodyID := c.FormValue("dialogEditBodyID") + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerEditNatUnit(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + // prm form addnatunit + code := c.FormValue("natunitcode") + name := c.FormValue("natunitname") + id := c.FormValue("natunitid") + tableID := c.FormValue("tableID") + paginationID := c.FormValue("paginationID") + searchID := c.FormValue("searchID") + search := c.FormValue("search") + currPagePrm := c.FormValue("currpage" + paginationID) + // dialogAddBodyID := c.FormValue("dialogAddBodyID") + dialogEditID := c.FormValue("dialogEditID") + dialogEditBodyID := c.FormValue("dialogEditBodyID") + // dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + + currPage, err := strconv.Atoi(currPagePrm) + if err != nil { + return err + } + logger.Info("ADD NAT UNIT PARAM", + zap.Any("code", code), + zap.Any("nama", name), + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPage), + ) + + formValidation := "" + codeValidation := "" + nameValidation := "" + if strings.TrimSpace(code) == "" { + formValidation = "Code unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "" + } + if strings.TrimSpace(name) == "" { + formValidation = "Nama unit tidak boleh kosong" + codeValidation = "" + nameValidation = "Nama unit tidak boleh kosong" + } + if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" { + formValidation = "Code dan nama unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "Nama unit tidak boleh kosong" + + } + + if formValidation != "" || codeValidation != "" || nameValidation != "" { + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm}) + } + + // edit nat unit service + dataNatUnit, err := nh.MdNatUnitServices.EditMdNatUnit(id, code, name) + if err != nil { + logger.Info("Error", + zap.Any("Error", err), + zap.Any("code", code), + zap.Any("name", name), + ) + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{ + customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), newForm}) + } + + logger.Info("ADD NAT UNIT", + zap.Any("return", dataNatUnit), + zap.Any("code", code), + zap.Any("name", name), + ) + + // get list nat unit for table + dataNatUnitList, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNIT", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + + // table component + tableComponent := dev_mdnatunitview.TableNatUnit( + dataNatUnitList, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID", + ) + + // pagination component + natUnitPaginationComponent := pagination.PaginationV3( + totalPage, + currPage, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + + var retVal []templ.Component + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("#"+dialogEditID)) + toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil edit Unit "+name, "success") + retVal = append(retVal, toastSuccess) + retVal = append(retVal, tableComponent) + retVal = append(retVal, natUnitPaginationComponent) + retVal = append(retVal, newForm) + return utils.ViewMulti(c, retVal) +} diff --git a/handlers/routes.go b/handlers/routes.go index 4c2c317..d4929b0 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -255,4 +255,7 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { dev.GET("/md/natunit/changepage", devMdNatUnitHandlers.HandlerChangePageMdNatUnit) dev.POST("/md/natunit/closeaddform", devMdNatUnitHandlers.HandlerCloseFormAdd) dev.POST("/md/natunit/add", devMdNatUnitHandlers.HandlerAddNatUnit) + dev.GET("/md/natunit/openedit", devMdNatUnitHandlers.HandlerOpenEditForm) + dev.POST("/md/natunit/closeeditform", devMdNatUnitHandlers.HandlerCloseFormEdit) + dev.POST("/md/natunit/edit", devMdNatUnitHandlers.HandlerEditNatUnit) } diff --git a/services/dev/md.natunit.services.go b/services/dev/md.natunit.services.go index cde45fb..2ccdb79 100644 --- a/services/dev/md.natunit.services.go +++ b/services/dev/md.natunit.services.go @@ -178,3 +178,57 @@ func (nu *MdNatUnitServices) AddMdNatUnit(code string, name string) (models.NatU } return data, nil } + +func (nu *MdNatUnitServices) EditMdNatUnit(id string, code string, name string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + var data models.NatUnit + var datacek []models.NatUnit + + qryCek := `SELECT Nat_UnitCode FROM nat_unit + WHERE Nat_UnitCode = ? AND Nat_UnitIsActive = 'Y' AND Nat_UnitID <> ?` + err := dbx.Handlex.Select(&datacek, qryCek, code, id) + + if err != nil { + defer logger.Sync() + logger.Error("Error cek data by code", + zap.String("code", code), + zap.Any("datacek", datacek), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + if len(datacek) > 0 { + defer logger.Sync() + logger.Error("Code already taken by another data", + zap.String("code", code), + ) + return data, fmt.Errorf("code sudah dipakai") + } + + qry := `UPDATE nat_unit + SET Nat_UnitCode = ?, + Nat_UnitName = ?, + Nat_UnitLastUpdated = NOW() + WHERE Nat_UnitID = ?` + rst := dbx.Handlex.MustExec(qry, code, name, id) + _, err = rst.RowsAffected() + if err != nil { + defer logger.Sync() + logger.Error("Error Update natunit", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + data, err = nu.GetMdNatUnitByID(id) + if err != nil { + defer logger.Sync() + logger.Error("Error get natunit by id", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} diff --git a/views/dev/mdnatunit/mdnatunit.templ b/views/dev/mdnatunit/mdnatunit.templ index 332d399..ea20950 100644 --- a/views/dev/mdnatunit/mdnatunit.templ +++ b/views/dev/mdnatunit/mdnatunit.templ @@ -12,11 +12,14 @@ templ MdNatUnitScreen( searchID string, dialogAddID string, dialogAddBodyID string, + dialogEditID string, + dialogEditBodyID string, breadcrumb templ.Component, tablecontent templ.Component, filterComponent templ.Component, paginationComponent templ.Component, - modalAddForm templ.Component) { + modalAddForm templ.Component, + modalEditForm templ.Component) {
@customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", Name: "tableID", @@ -38,6 +41,14 @@ templ MdNatUnitScreen( Name: "dialogAddBodyID", Type: "hidden", Value: dialogAddBodyID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditID", + Name: "dialogEditID", + Type: "hidden", + Value: dialogEditID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditBodyID", + Name: "dialogEditBodyID", + Type: "hidden", + Value: dialogEditBodyID})
@breadcrumb @@ -67,6 +78,7 @@ templ MdNatUnitScreen( @tablecontent @paginationComponent @modalAddForm + @modalEditForm
//
diff --git a/views/dev/mdnatunit/mdnatunit_templ.go b/views/dev/mdnatunit/mdnatunit_templ.go index 16c114c..4582648 100644 --- a/views/dev/mdnatunit/mdnatunit_templ.go +++ b/views/dev/mdnatunit/mdnatunit_templ.go @@ -22,11 +22,14 @@ func MdNatUnitScreen( searchID string, dialogAddID string, dialogAddBodyID string, + dialogEditID string, + dialogEditBodyID string, breadcrumb templ.Component, tablecontent templ.Component, filterComponent templ.Component, paginationComponent templ.Component, - modalAddForm templ.Component) templ.Component { + modalAddForm templ.Component, + modalEditForm templ.Component) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -78,6 +81,20 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditID", + Name: "dialogEditID", + Type: "hidden", + Value: dialogEditID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditBodyID", + Name: "dialogEditBodyID", + Type: "hidden", + Value: dialogEditBodyID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -93,7 +110,7 @@ func MdNatUnitScreen( var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 52, Col: 37} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 63, Col: 37} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -106,7 +123,7 @@ func MdNatUnitScreen( var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 61, Col: 36} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 72, Col: 36} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -136,6 +153,10 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = modalEditForm.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Loading...
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err diff --git a/views/dev/mdnatunit/mdnatunittable.templ b/views/dev/mdnatunit/mdnatunittable.templ index 4e4edd3..7f86cf4 100644 --- a/views/dev/mdnatunit/mdnatunittable.templ +++ b/views/dev/mdnatunit/mdnatunittable.templ @@ -3,19 +3,34 @@ package dev_mdnatunitview import ( "cpone/component/table" "cpone/models" + "strconv" ) templ TableNatUnit(data []models.NatUnit, tableID string, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, ) {
@tablecomponent.TableV3([]string{"KODE", "UNIT", "AKSI"}, []string{"40%", "40%", "20%"}, - RowNatUnit(data)) + RowNatUnit(data, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + ))
} -templ RowNatUnit(data []models.NatUnit) { +templ RowNatUnit(data []models.NatUnit, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, +) { if len(data) == 0 { Data Tidak Ditemukan @@ -26,8 +41,63 @@ templ RowNatUnit(data []models.NatUnit) { { v.Nat_UnitCode } { v.Nat_UnitName } - Action + @TableAction(v.Nat_UnitID, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + ) } } + +templ TableAction( + id int, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, +) { + +} + +script HandleBeforeRequestRow(id string) { + var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.add('disabled'); + } + // console.log(id) +} + +script HandleAfterRequestRow(id string) { + var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.remove('disabled'); + } + // console.log(id) +} diff --git a/views/dev/mdnatunit/mdnatunittable_templ.go b/views/dev/mdnatunit/mdnatunittable_templ.go index 271aa07..9f9d167 100644 --- a/views/dev/mdnatunit/mdnatunittable_templ.go +++ b/views/dev/mdnatunit/mdnatunittable_templ.go @@ -13,10 +13,15 @@ import "bytes" import ( "cpone/component/table" "cpone/models" + "strconv" ) func TableNatUnit(data []models.NatUnit, tableID string, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, ) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) @@ -37,7 +42,7 @@ func TableNatUnit(data []models.NatUnit, var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(tableID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 11, Col: 18} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 16, Col: 18} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -49,7 +54,12 @@ func TableNatUnit(data []models.NatUnit, } templ_7745c5c3_Err = tablecomponent.TableV3([]string{"KODE", "UNIT", "AKSI"}, []string{"40%", "40%", "20%"}, - RowNatUnit(data)).Render(ctx, templ_7745c5c3_Buffer) + RowNatUnit(data, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + )).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -64,7 +74,12 @@ func TableNatUnit(data []models.NatUnit, }) } -func RowNatUnit(data []models.NatUnit) templ.Component { +func RowNatUnit(data []models.NatUnit, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, +) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -91,7 +106,7 @@ func RowNatUnit(data []models.NatUnit) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitCode) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 26, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 41, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -104,13 +119,26 @@ func RowNatUnit(data []models.NatUnit) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitName) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 27, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 42, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Action\r") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = TableAction(v.Nat_UnitID, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + ).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -121,3 +149,180 @@ func RowNatUnit(data []models.NatUnit) templ.Component { return templ_7745c5c3_Err }) } + +func TableAction( + id int, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, +) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, HandleBeforeRequestRow(strconv.Itoa(id)), HandleAfterRequestRow(strconv.Itoa(id))) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" Edit\r Hapus\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func HandleBeforeRequestRow(id string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleBeforeRequestRow_9a4e`, + Function: `function __templ_HandleBeforeRequestRow_9a4e(id){var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.add('disabled'); + } + // console.log(id) +}`, + Call: templ.SafeScript(`__templ_HandleBeforeRequestRow_9a4e`, id), + CallInline: templ.SafeScriptInline(`__templ_HandleBeforeRequestRow_9a4e`, id), + } +} + +func HandleAfterRequestRow(id string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleAfterRequestRow_9e81`, + Function: `function __templ_HandleAfterRequestRow_9e81(id){var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.remove('disabled'); + } + // console.log(id) +}`, + Call: templ.SafeScript(`__templ_HandleAfterRequestRow_9e81`, id), + CallInline: templ.SafeScriptInline(`__templ_HandleAfterRequestRow_9e81`, id), + } +} From b68a2ed2ec140f6201680f1012c14a41c331ecca Mon Sep 17 00:00:00 2001 From: Hanan Askarim Date: Mon, 27 May 2024 16:44:06 +0700 Subject: [PATCH 5/5] add feature delete --- handlers/dev/md.natunit.handlers.go | 251 +++++++++++++++++- handlers/routes.go | 3 + services/dev/md.natunit.services.go | 28 ++ views/dev/mdnatunit/mdnatunit.templ | 14 +- views/dev/mdnatunit/mdnatunit_templ.go | 27 +- views/dev/mdnatunit/mdnatunitformmodal.templ | 53 ++++ .../dev/mdnatunit/mdnatunitformmodal_templ.go | 202 ++++++++++++++ views/dev/mdnatunit/mdnatunittable.templ | 27 ++ views/dev/mdnatunit/mdnatunittable_templ.go | 135 +++++++++- 9 files changed, 710 insertions(+), 30 deletions(-) diff --git a/handlers/dev/md.natunit.handlers.go b/handlers/dev/md.natunit.handlers.go index e6a245b..4df537b 100644 --- a/handlers/dev/md.natunit.handlers.go +++ b/handlers/dev/md.natunit.handlers.go @@ -26,6 +26,7 @@ type MdNatUnitServices interface { AddMdNatUnit(code string, name string) (models.NatUnit, error) GetMdNatUnitByID(id string) (models.NatUnit, error) EditMdNatUnit(id string, code string, name string) (models.NatUnit, error) + DeleteMdNatUnit(id string) (models.NatUnit, error) } func NeWMdNatUnitHandler(nu MdNatUnitServices) *MdNatUnitHandler { @@ -48,6 +49,8 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { dialogAddBodyID := utils.GenerateRandomID("dialogaddbodyID") dialogEditID := utils.GenerateRandomID("dialogEditID") dialogEditBodyID := utils.GenerateRandomID("dialogEditbodyID") + dialogDeleteID := utils.GenerateRandomID("dialogDeleteID") + dialogDeleteBodyID := utils.GenerateRandomID("dialogDeletebodyID") dataMenu, err := services.GetMenu() fmt.Println(dataMenu) fmt.Println(err) @@ -114,7 +117,11 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { "/dev/md/natunit/openedit", "#"+dialogEditBodyID, "outerHTML", - "#dialogEditBodyID, #dialogEditID", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", ) //filter nat unit component @@ -124,7 +131,7 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { "text", "/dev/md/natunit/filter", "input changed delay:500ms, search", - "#"+paginationID, "#loadingcontent", "", "outerHTML", "#tableID, #paginationID, #searchID", + "#"+paginationID, "#loadingcontent", "", "outerHTML", "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", dev_mdnatunitview.BeforeRequestContent(), dev_mdnatunitview.AfterRequestContent()) @@ -134,7 +141,7 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { 1, "/dev/md/natunit/changepage", paginationID, - "#tableID, #searchID, #"+searchID+", #paginationID", + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", "#"+paginationID, "outerHTML", "", "", dev_mdnatunitview.BeforeRequestContent(), @@ -181,7 +188,7 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { Link: "/dev/md/natunit/add", HxTarget: "#" + dialogAddBodyID, HxSwap: "outerHTML", - HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #" + searchID + ", #currpage" + paginationID, + HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID, ModalID: dialogAddID, ModalTitle: "New - Unit", DialogBody: dialogAddBodyCmp, @@ -230,7 +237,7 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { Link: "dev/md/natunit/edit", HxTarget: "#" + dialogEditBodyID, HxSwap: "outerHTML", - HxInclude: "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID, + HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID, ModalID: dialogEditID, ModalTitle: "New - Unit", DialogBody: dialogEditBodyCmp, @@ -239,6 +246,49 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { }, ) + // modal delete form + dialogDeleteBodyCmp := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogDeleteBodyID, dev_mdnatunitview.JsHideModal("")) + modalActionDeleteCmp := dev_mdnatunitview.ActionFormNatUnit( + "/dev/md/natunit/closedeleteform", + "#"+dialogDeleteBodyID, + "outerHTML", + "#"+dialogDeleteID) + btnCloaseModalDelete := dev_mdnatunitview.BtnCloseFormNatUnit( + "/dev/md/natunit/closedeleteform", + "#"+dialogDeleteBodyID, + "outerHTML", + "#"+dialogDeleteID) + modalDeleteFormComponent := dev_mdnatunitview.NatUnitForm( + models.NatUnitFormComponent{ + IDComponent: "formnatunit", + Link: "/dev/md/natunit/delete", + HxTarget: "#" + dialogDeleteBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogDeleteID, + ModalTitle: "New - Unit", + DialogBody: dialogDeleteBodyCmp, + DialogAction: modalActionDeleteCmp, + ButtonCLose: btnCloaseModalDelete, + }, + ) + // content, css, js content := dev_mdnatunitview.MdNatUnitScreen( tableID, @@ -248,12 +298,15 @@ func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { dialogAddBodyID, dialogEditID, dialogEditBodyID, + dialogDeleteID, + dialogDeleteBodyID, breadcrumbComponent, tableComponent, natUnitFilterComponent, natUnitPaginationComponent, modalAddFormComponent, modalEditFormComponent, + modalDeleteFormComponent, ) css := dev_mdnatunitview.CssMdNatUnit() js := dev_mdnatunitview.JsMdNatUnit() @@ -277,6 +330,7 @@ func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { tableID := c.QueryParam("tableID") paginationID := c.QueryParam("paginationID") dialogEditBodyID := c.QueryParam("dialogEditBodyID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") var retval []templ.Component logger, _ := zap.NewProduction() @@ -294,13 +348,17 @@ func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { "/dev/md/natunit/openedit", "#"+dialogEditBodyID, "outerHTML", - "#dialogEditBodyID, #dialogEditID") + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID") natUnitPaginationComponent := pagination.PaginationV3( totalpage, 1, "/dev/md/natunit/changepage", paginationID, - "#tableID, #searchID, #"+searchID+", #paginationID", + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", "#"+paginationID, "outerHTML", "", "", dev_mdnatunitview.BeforeRequestContent(), @@ -318,6 +376,7 @@ func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { searchID := c.QueryParam("searchID") paginationID := c.QueryParam("paginationID") dialogEditBodyID := c.QueryParam("dialogEditBodyID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") var retval []templ.Component logger, _ := zap.NewProduction() @@ -345,14 +404,18 @@ func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { "/dev/md/natunit/openedit", "#"+dialogEditBodyID, "outerHTML", - "#dialogEditBodyID, #dialogEditID", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", ) natUnitPaginationComponent := pagination.PaginationV3( totalpage, page, "/dev/md/natunit/changepage", paginationID, - "#tableID, #searchID, #"+searchID+", #paginationID", + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", "#"+paginationID, "outerHTML", "", "", dev_mdnatunitview.BeforeRequestContent(), @@ -400,6 +463,7 @@ func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { dialogAddBodyID := c.FormValue("dialogAddBodyID") dialogAddID := c.FormValue("dialogAddID") dialogEditBodyID := c.FormValue("dialogEditBodyID") + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") currPage, err := strconv.Atoi(currPagePrm) if err != nil { @@ -515,7 +579,11 @@ func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { "/dev/md/natunit/openedit", "#"+dialogEditBodyID, "outerHTML", - "#dialogEditBodyID, #dialogEditID", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", ) // pagination component @@ -524,7 +592,7 @@ func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { currPage, "/dev/md/natunit/changepage", paginationID, - "#tableID, #searchID, #"+searchID+", #paginationID", + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", "#"+paginationID, "outerHTML", "", "true", dev_mdnatunitview.BeforeRequestContent(), @@ -652,7 +720,7 @@ func (nh *MdNatUnitHandler) HandlerEditNatUnit(c echo.Context) error { // dialogAddBodyID := c.FormValue("dialogAddBodyID") dialogEditID := c.FormValue("dialogEditID") dialogEditBodyID := c.FormValue("dialogEditBodyID") - // dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") currPage, err := strconv.Atoi(currPagePrm) if err != nil { @@ -768,7 +836,11 @@ func (nh *MdNatUnitHandler) HandlerEditNatUnit(c echo.Context) error { "/dev/md/natunit/openedit", "#"+dialogEditBodyID, "outerHTML", - "#dialogEditBodyID, #dialogEditID", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", ) // pagination component @@ -777,7 +849,7 @@ func (nh *MdNatUnitHandler) HandlerEditNatUnit(c echo.Context) error { currPage, "/dev/md/natunit/changepage", paginationID, - "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID", + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", "#"+paginationID, "outerHTML", "", "true", dev_mdnatunitview.BeforeRequestContent(), @@ -811,3 +883,154 @@ func (nh *MdNatUnitHandler) HandlerEditNatUnit(c echo.Context) error { retVal = append(retVal, newForm) return utils.ViewMulti(c, retVal) } + +func (nh *MdNatUnitHandler) HandlerOpenDeleteForm(c echo.Context) error { + id := c.QueryParam("id") + dialogDeleteID := c.QueryParam("dialogDeleteID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") + + dataNatUnit, err := nh.MdNatUnitServices.GetMdNatUnitByID(id) + if err != nil { + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: strconv.Itoa(dataNatUnit.Nat_UnitID)}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsShowModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get unit error", "danger"), newForm}) + } + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: strconv.Itoa(dataNatUnit.Nat_UnitID)}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{dataNatUnit.Nat_UnitCode, dataNatUnit.Nat_UnitName}, + dev_mdnatunitview.JsShowModal("#"+dialogDeleteID)) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerCloseFormDelete(c echo.Context) error { + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsShowModal("")) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerDeleteNatUnit(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + // prm form addnatunit + id := c.FormValue("natunitid") + tableID := c.FormValue("tableID") + paginationID := c.FormValue("paginationID") + searchID := c.FormValue("searchID") + search := c.FormValue("search") + currPagePrm := c.FormValue("currpage" + paginationID) + // dialogAddBodyID := c.FormValue("dialogAddBodyID") + dialogDeleteID := c.FormValue("dialogDeleteID") + dialogEditBodyID := c.FormValue("dialogEditBodyID") + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + + currPage, err := strconv.Atoi(currPagePrm) + if err != nil { + return err + } + logger.Info("ADD NAT UNIT PARAM", + + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPage), + ) + + // edit nat unit service + dataNatUnit, err := nh.MdNatUnitServices.DeleteMdNatUnit(id) + if err != nil { + logger.Info("Error", + zap.Any("Error", err), + ) + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsShowModal("")) + return utils.ViewMulti(c, []templ.Component{ + customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), + newForm}) + } + logger.Info("ADD Unit", + zap.Any("return", dataNatUnit), + ) + + // get list nat unit fo table + dataNatUnitList, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET Unit", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + if len(dataNatUnitList) == 0 && totalPage > 1 { + currPage = currPage - 1 + dataNatUnitList, _, err = nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET UNIT", + zap.Any("error", err), + ) + return err + } + } + + // table component + tableComponent := dev_mdnatunitview.TableNatUnit( + dataNatUnitList, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + + // pagination component + natUnitPaginationComponent := pagination.PaginationV3( + totalPage, + currPage, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + + var retVal []templ.Component + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsHideModal("#"+dialogDeleteID)) + toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil delete Unit ", "success") + retVal = append(retVal, toastSuccess) + retVal = append(retVal, tableComponent) + retVal = append(retVal, natUnitPaginationComponent) + retVal = append(retVal, newForm) + return utils.ViewMulti(c, retVal) +} diff --git a/handlers/routes.go b/handlers/routes.go index d4929b0..7b37a85 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -258,4 +258,7 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { dev.GET("/md/natunit/openedit", devMdNatUnitHandlers.HandlerOpenEditForm) dev.POST("/md/natunit/closeeditform", devMdNatUnitHandlers.HandlerCloseFormEdit) dev.POST("/md/natunit/edit", devMdNatUnitHandlers.HandlerEditNatUnit) + dev.GET("/md/natunit/opendelete", devMdNatUnitHandlers.HandlerOpenDeleteForm) + dev.POST("/md/natunit/closedeleteform", devMdNatUnitHandlers.HandlerCloseFormDelete) + dev.POST("/md/natunit/delete", devMdNatUnitHandlers.HandlerDeleteNatUnit) } diff --git a/services/dev/md.natunit.services.go b/services/dev/md.natunit.services.go index 2ccdb79..94fc76d 100644 --- a/services/dev/md.natunit.services.go +++ b/services/dev/md.natunit.services.go @@ -232,3 +232,31 @@ func (nu *MdNatUnitServices) EditMdNatUnit(id string, code string, name string) } return data, nil } + +func (nu *MdNatUnitServices) DeleteMdNatUnit(id string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + var data models.NatUnit + qry := `UPDATE nat_unit + SET Nat_UnitLastUpdated = NOW(), + Nat_UnitIsActive = 'N' + WHERE Nat_UnitID = ?` + rst := dbx.Handlex.MustExec(qry, id) + _, err := rst.RowsAffected() + if err != nil { + defer logger.Sync() + logger.Error("Error delete nat unit", + zap.String("id", id), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + data, err = nu.GetMdNatUnitByID(id) + if err != nil { + defer logger.Sync() + logger.Error("Error get nat unit by id", + zap.String("id", id), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} diff --git a/views/dev/mdnatunit/mdnatunit.templ b/views/dev/mdnatunit/mdnatunit.templ index ea20950..8553193 100644 --- a/views/dev/mdnatunit/mdnatunit.templ +++ b/views/dev/mdnatunit/mdnatunit.templ @@ -14,12 +14,15 @@ templ MdNatUnitScreen( dialogAddBodyID string, dialogEditID string, dialogEditBodyID string, + dialogDeleteID string, + dialogDeleteBodyID string, breadcrumb templ.Component, tablecontent templ.Component, filterComponent templ.Component, paginationComponent templ.Component, modalAddForm templ.Component, - modalEditForm templ.Component) { + modalEditForm templ.Component, + modalDeleteForm templ.Component) {
@customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", Name: "tableID", @@ -49,6 +52,14 @@ templ MdNatUnitScreen( Name: "dialogEditBodyID", Type: "hidden", Value: dialogEditBodyID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteID", + Name: "dialogDeleteID", + Type: "hidden", + Value: dialogDeleteID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteBodyID", + Name: "dialogDeleteBodyID", + Type: "hidden", + Value: dialogDeleteBodyID})
@breadcrumb @@ -79,6 +90,7 @@ templ MdNatUnitScreen( @paginationComponent @modalAddForm @modalEditForm + @modalDeleteForm
//
diff --git a/views/dev/mdnatunit/mdnatunit_templ.go b/views/dev/mdnatunit/mdnatunit_templ.go index 4582648..0cd19d8 100644 --- a/views/dev/mdnatunit/mdnatunit_templ.go +++ b/views/dev/mdnatunit/mdnatunit_templ.go @@ -24,12 +24,15 @@ func MdNatUnitScreen( dialogAddBodyID string, dialogEditID string, dialogEditBodyID string, + dialogDeleteID string, + dialogDeleteBodyID string, breadcrumb templ.Component, tablecontent templ.Component, filterComponent templ.Component, paginationComponent templ.Component, modalAddForm templ.Component, - modalEditForm templ.Component) templ.Component { + modalEditForm templ.Component, + modalDeleteForm templ.Component) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -95,6 +98,20 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteID", + Name: "dialogDeleteID", + Type: "hidden", + Value: dialogDeleteID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteBodyID", + Name: "dialogDeleteBodyID", + Type: "hidden", + Value: dialogDeleteBodyID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -110,7 +127,7 @@ func MdNatUnitScreen( var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 63, Col: 37} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 74, Col: 37} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -123,7 +140,7 @@ func MdNatUnitScreen( var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 72, Col: 36} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunit.templ`, Line: 83, Col: 36} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -157,6 +174,10 @@ func MdNatUnitScreen( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = modalDeleteForm.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Loading...
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err diff --git a/views/dev/mdnatunit/mdnatunitformmodal.templ b/views/dev/mdnatunit/mdnatunitformmodal.templ index 2422185..f0d47b0 100644 --- a/views/dev/mdnatunit/mdnatunitformmodal.templ +++ b/views/dev/mdnatunit/mdnatunitformmodal.templ @@ -132,3 +132,56 @@ templ BtnCloseFormNatUnit(LinkClose string, targetClose string, hxSwapClose stri } + +templ DeleteConfirmationBody(inputId models.CustomTextFieldv2Prm, + componentID string, + message string, + datHeader []string, + dataText []string, + hxOnLoad templ.ComponentScript) { +
+

{ message }

+
+
+
+ for _, v := range datHeader { +
{ v }
+ } +
+
+ for _, v := range dataText { +
+ { v } +
+ } +
+
+
+ @customtextfield.CustomTextFieldv2(inputId) +
+} + +templ ActionFormUserGroupDelete(LinkClose string, targetClose string, hxSwapClose string, modalID string) { +
+ + +
+} diff --git a/views/dev/mdnatunit/mdnatunitformmodal_templ.go b/views/dev/mdnatunit/mdnatunitformmodal_templ.go index 03ba642..3e93fcd 100644 --- a/views/dev/mdnatunit/mdnatunitformmodal_templ.go +++ b/views/dev/mdnatunit/mdnatunitformmodal_templ.go @@ -445,3 +445,205 @@ func BtnCloseFormNatUnit(LinkClose string, targetClose string, hxSwapClose strin return templ_7745c5c3_Err }) } + +func DeleteConfirmationBody(inputId models.CustomTextFieldv2Prm, + componentID string, + message string, + datHeader []string, + dataText []string, + hxOnLoad templ.ComponentScript) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var22 := templ.GetChildren(ctx) + if templ_7745c5c3_Var22 == nil { + templ_7745c5c3_Var22 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, hxOnLoad) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(message) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunitformmodal.templ`, Line: 143, Col: 14} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, v := range datHeader { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(v) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunitformmodal.templ`, Line: 148, Col: 68} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, v := range dataText { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var27 string + templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(v) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunitformmodal.templ`, Line: 154, Col: 10} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(inputId).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func ActionFormUserGroupDelete(LinkClose string, targetClose string, hxSwapClose string, modalID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var28 := templ.GetChildren(ctx) + if templ_7745c5c3_Var28 == nil { + templ_7745c5c3_Var28 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, JsHideModal(modalID)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/views/dev/mdnatunit/mdnatunittable.templ b/views/dev/mdnatunit/mdnatunittable.templ index 7f86cf4..ef93b98 100644 --- a/views/dev/mdnatunit/mdnatunittable.templ +++ b/views/dev/mdnatunit/mdnatunittable.templ @@ -12,6 +12,10 @@ templ TableNatUnit(data []models.NatUnit, hxTargetEdit string, hxSwapEdit string, hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, ) {
@tablecomponent.TableV3([]string{"KODE", "UNIT", "AKSI"}, @@ -21,6 +25,10 @@ templ TableNatUnit(data []models.NatUnit, hxTargetEdit, hxSwapEdit, hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, ))
} @@ -30,6 +38,10 @@ templ RowNatUnit(data []models.NatUnit, hxTargetEdit string, hxSwapEdit string, hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, ) { if len(data) == 0 { @@ -46,6 +58,10 @@ templ RowNatUnit(data []models.NatUnit, hxTargetEdit, hxSwapEdit, hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, ) @@ -58,6 +74,10 @@ templ TableAction( hxTargetEdit string, hxSwapEdit string, hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, ) {
Hapus diff --git a/views/dev/mdnatunit/mdnatunittable_templ.go b/views/dev/mdnatunit/mdnatunittable_templ.go index 9f9d167..e0eaa9b 100644 --- a/views/dev/mdnatunit/mdnatunittable_templ.go +++ b/views/dev/mdnatunit/mdnatunittable_templ.go @@ -22,6 +22,10 @@ func TableNatUnit(data []models.NatUnit, hxTargetEdit string, hxSwapEdit string, hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, ) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) @@ -42,7 +46,7 @@ func TableNatUnit(data []models.NatUnit, var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(tableID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 16, Col: 18} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 20, Col: 18} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -59,6 +63,10 @@ func TableNatUnit(data []models.NatUnit, hxTargetEdit, hxSwapEdit, hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, )).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -79,6 +87,10 @@ func RowNatUnit(data []models.NatUnit, hxTargetEdit string, hxSwapEdit string, hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, ) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) @@ -106,7 +118,7 @@ func RowNatUnit(data []models.NatUnit, var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitCode) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 41, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 53, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -119,7 +131,7 @@ func RowNatUnit(data []models.NatUnit, var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitName) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 42, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 54, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -134,6 +146,10 @@ func RowNatUnit(data []models.NatUnit, hxTargetEdit, hxSwapEdit, hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, ).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -156,6 +172,10 @@ func TableAction( hxTargetEdit string, hxSwapEdit string, hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, ) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) @@ -184,7 +204,7 @@ func TableAction( var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(hxGetEdit + "?id=" + strconv.Itoa(id)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 66, Col: 49} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 86, Col: 49} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -197,7 +217,7 @@ func TableAction( var templ_7745c5c3_Var8 string templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(hxTargetEdit) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 67, Col: 27} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 87, Col: 27} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { @@ -210,7 +230,7 @@ func TableAction( var templ_7745c5c3_Var9 string templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapEdit) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 68, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 88, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { @@ -223,7 +243,7 @@ func TableAction( var templ_7745c5c3_Var10 string templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(hxIncludeEdit) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 69, Col: 29} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 89, Col: 29} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) if templ_7745c5c3_Err != nil { @@ -236,7 +256,7 @@ func TableAction( var templ_7745c5c3_Var11 string templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs("#spnredt" + strconv.Itoa(id)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 70, Col: 47} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 90, Col: 47} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { @@ -267,25 +287,116 @@ func TableAction( var templ_7745c5c3_Var14 string templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs("spnredt" + strconv.Itoa(id)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 74, Col: 42} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 94, Col: 42} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"htmx-indicator spinner-border spinner-border-sm\" role=\"status\" aria-hidden=\"true\"> Edit\r Edit\r ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, HandleBeforeRequestRow(strconv.Itoa(id)), HandleAfterRequestRow(strconv.Itoa(id))) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" Hapus\r
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err