diff --git a/handlers/dev/md.samplestation.handlers.go b/handlers/dev/md.samplestation.handlers.go index 9b5eff2..00e2471 100644 --- a/handlers/dev/md.samplestation.handlers.go +++ b/handlers/dev/md.samplestation.handlers.go @@ -2,6 +2,7 @@ package dev_handlers import ( breadcrumbadmin "cpone/component/breadcrumbadmin" + "cpone/component/customtextfieldsearch" navbarmenu "cpone/component/navbar" "cpone/component/pagination" sidebaruserprofile "cpone/component/sidebar_user_profile" @@ -36,13 +37,15 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte logger, _ := zap.NewProduction() title := "Master Sample Station" - tableID := utils.GenerateRandomID("tableID") - paginationID := utils.GenerateRandomID("paginationID") - dialogAddID := utils.GenerateRandomID("dialogAddID") - // dialogEditID := utils.GenerateRandomID("dialogEditID") - // dialogEditBodyID := utils.GenerateRandomID("dialogEditBodyID") - // dialogDeleteID := utils.GenerateRandomID("dialogDeleteID") - // dialogDeleteBodyID := utils.GenerateRandomID("dialogDeleteBodyID") + tableID := utils.GenerateRandomID("tableid") + paginationID := utils.GenerateRandomID("paginationid") + searchID := utils.GenerateRandomID("searchid") + dialogAddID := utils.GenerateRandomID("dialogaddid") + dialogAddBodyID := utils.GenerateRandomID("dialogaddbodyid") + dialogEditID := utils.GenerateRandomID("dialogeditid") + dialogEditBodyID := utils.GenerateRandomID("dialogeditbodyid") + dialogDeleteID := utils.GenerateRandomID("dialogdeleteid") + dialogDeleteBodyID := utils.GenerateRandomID("dialogdeletebodyid") dataMenu, err := services.GetMenu() if err != nil { @@ -62,6 +65,9 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte logger.Info("ERROR BREADCRUMB DEV", zap.Any("error", err)) return err } + defer logger.Sync() + logger.Info("LOAD BREADCRUMB DEV", zap.Any("data", dataBreadcrumb)) + navbarmenuComp := navbarmenu.NavbarMenu(dataMenu) navbaruserComp := navbarmenu.Navbar(dataUser) breadcrumbComp := breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadcrumb) @@ -76,25 +82,58 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte } fmt.Println("data sample station", dataTable) - tableComponent := dev_mdsamplestationview.TableSampleStation(dataTable, tableID) + tableComponent := dev_mdsamplestationview.TableSampleStation(dataTable, + tableID, + "/dev/md/samplestation/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/samplestation/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + + tableFilter := customtextfieldsearch.MainCustomTextFieldSearchV3(searchID, + "search", + "Cari Kode/Nama", + "text", + "/dev/md/samplestation/filter", + "input changed delay:500ms, search", + "#"+paginationID, + "#loadingcontent", "", + "outerHTML", + "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + dev_mdsamplestationview.BeforeRequestContent(), + dev_mdsamplestationview.AfterRequestContent(), + ) // pagination table - paginationTable := pagination.PaginationV2( + paginationTable := pagination.PaginationV3( totalPage, 1, "/dev/md/samplestation/changepage", paginationID, - "#tableID, #paginationID", + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", "#"+paginationID, "outerHTML", "", "", + dev_mdsamplestationview.BeforeRequestContent(), + dev_mdsamplestationview.AfterRequestContent(), ) content := dev_mdsamplestationview.ContentMDSampleStation( tableID, - dialogAddID, paginationID, + searchID, + dialogAddID, + dialogAddBodyID, + dialogEditID, + dialogEditBodyID, + dialogDeleteID, + dialogDeleteBodyID, breadcrumbComp, tableComponent, + tableFilter, paginationTable, ) css := dev_mdsamplestationview.CSSMDSampleStation() @@ -104,10 +143,60 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte return utils.View(c, view) } -func (mdss *MDSampleStationHandler) HandleChangePageSampleStation(c echo.Context) error { - pageparam := c.QueryParam("page") +func (mdss *MDSampleStationHandler) HandleFilterMDSS(c echo.Context) error { + search := c.QueryParam("search") + searchID := c.QueryParam("searchID") tableID := c.QueryParam("tableID") paginationID := c.QueryParam("paginationID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") + var retval []templ.Component + logger, _ := zap.NewProduction() + + dataSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, 1, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET SAMPLE STATION", zap.Any("error", err)) + return err + } + + tableComp := dev_mdsamplestationview.TableSampleStation(dataSS, + tableID, + "/dev/md/samplestation/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/samplestation/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + + tablePagination := pagination.PaginationV3( + totalPage, + 1, + "/dev/md/samplestation/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "", + dev_mdsamplestationview.BeforeRequestContent(), + dev_mdsamplestationview.AfterRequestContent(), + ) + + retval = append(retval, tableComp) + retval = append(retval, tablePagination) + return utils.ViewMulti(c, retval) +} + +func (mdss *MDSampleStationHandler) HandleChangePageSampleStation(c echo.Context) error { + search := c.QueryParam("search") + pageparam := c.QueryParam("page") + tableID := c.QueryParam("tableID") + searchID := c.QueryParam("searchID") + paginationID := c.QueryParam("paginationID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") var retval []templ.Component logger, _ := zap.NewProduction() @@ -118,22 +207,35 @@ func (mdss *MDSampleStationHandler) HandleChangePageSampleStation(c echo.Context return err } - dataSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation("", page, 5) + dataSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, page, 5) if err != nil { defer logger.Sync() logger.Info("ERROR GET DATA", zap.Any("error", err)) return err } - tableComp := dev_mdsamplestationview.TableSampleStation(dataSS, tableID) - paginationComp := pagination.PaginationV2( + tableComp := dev_mdsamplestationview.TableSampleStation(dataSS, + tableID, + "/dev/md/samplestation/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/samplestation/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + paginationComp := pagination.PaginationV3( totalPage, page, "/dev/md/samplestation/changepage", paginationID, - "#tableID, #paginationID", + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", "#"+paginationID, - "outerHTML", "", "") + "outerHTML", "", "", + dev_mdsamplestationview.BeforeRequestContent(), + dev_mdsamplestationview.AfterRequestContent(), + ) retval = append(retval, tableComp) retval = append(retval, paginationComp) diff --git a/handlers/routes.go b/handlers/routes.go index 357c7ac..b85749b 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -282,6 +282,7 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { devMDSampleStationServices := dev_services.NewMDSampleStationServices(appStore) devMDSampleStationHandlers := dev_handlers.NewMDSampleStationHandler(devMDSampleStationServices) dev.GET("/md/samplestation", devMDSampleStationHandlers.HandleShowMDSampleStationScreen) + dev.GET("/md/samplestation/filter", devMDSampleStationHandlers.HandleFilterMDSS) dev.GET("/md/samplestation/changepage", devMDSampleStationHandlers.HandleChangePageSampleStation) // masterdata nat unit devMdNatUnitServices := dev_services.NewMdNatUnitServices(appStore) diff --git a/services/dev/md.samplestation.services.go b/services/dev/md.samplestation.services.go index 5ddaf06..f95160a 100644 --- a/services/dev/md.samplestation.services.go +++ b/services/dev/md.samplestation.services.go @@ -76,13 +76,14 @@ func (ss *MDSampleStationServices) GetListSampleStation(search string, currentPa if err := dbx.Handlex.Select(&sampleStationList, query, prm, prm, rowPerPage, offset); err != nil { return nil, 0, fmt.Errorf("error query database: %v", err) } - totalPage := int(math.Ceil(float64(totalData) / float64(rowPerPage))) - for _, d := range sampleStationList { - if len(d.T_SampleStationIsNonLab) == 0 { - d.T_SampleStationIsNonLab = "Lab" + for i := range sampleStationList { + if len(sampleStationList[i].T_SampleStationIsNonLab) == 0 { + sampleStationList[i].T_SampleStationIsNonLab = "LAB" } } + totalPage := int(math.Ceil(float64(totalData) / float64(rowPerPage))) + return sampleStationList, totalPage, nil } diff --git a/views/dev/mdsamplestation/mdsamplestation.templ b/views/dev/mdsamplestation/mdsamplestation.templ index 6f81ee0..4b92dd1 100644 --- a/views/dev/mdsamplestation/mdsamplestation.templ +++ b/views/dev/mdsamplestation/mdsamplestation.templ @@ -8,10 +8,17 @@ import ( templ ContentMDSampleStation( tableID string, - dialogAddID string, paginationID string, + searchID string, + dialogAddID string, + dialogAddBodyID string, + dialogEditID string, + dialogEditBodyID string, + dialogDeleteID string, + dialogDeleteBodyID string, breadcrumb templ.Component, tablecontent templ.Component, + filtercomponent templ.Component, paginationtable templ.Component, ) {
@@ -23,10 +30,34 @@ templ ContentMDSampleStation( Name: "paginationID", Type: "hidden", Value: paginationID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "searchID", + 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}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditID", + Name: "dialogEditID", + Type: "hidden", + Value: dialogEditID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditBodyID", + 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 @@ -48,8 +79,17 @@ templ ContentMDSampleStation( data-target={ "#" + dialogAddID }>Add New
- @tablecontent - @paginationtable + @filtercomponent +
+ @tablecontent + @paginationtable +
+
+ Loading... +
+
+
+
} @@ -84,7 +124,45 @@ templ CSSMDSampleStation() { } templ JSMDSampleStation() { + +} + +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 ShowMDSampleStation( diff --git a/views/dev/mdsamplestation/mdsamplestation_templ.go b/views/dev/mdsamplestation/mdsamplestation_templ.go index 64b4b05..5cae41c 100644 --- a/views/dev/mdsamplestation/mdsamplestation_templ.go +++ b/views/dev/mdsamplestation/mdsamplestation_templ.go @@ -18,10 +18,17 @@ import ( func ContentMDSampleStation( tableID string, - dialogAddID string, paginationID string, + searchID string, + dialogAddID string, + dialogAddBodyID string, + dialogEditID string, + dialogEditBodyID string, + dialogDeleteID string, + dialogDeleteBodyID string, breadcrumb templ.Component, tablecontent templ.Component, + filtercomponent templ.Component, paginationtable templ.Component, ) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -54,6 +61,13 @@ func ContentMDSampleStation( 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 = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddID", Name: "dialogAddID", Type: "hidden", @@ -61,6 +75,41 @@ func ContentMDSampleStation( 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 = 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 = 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 @@ -76,7 +125,7 @@ func ContentMDSampleStation( 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\mdsamplestation\mdsamplestation.templ`, Line: 40, Col: 55} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 71, Col: 55} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -89,7 +138,7 @@ func ContentMDSampleStation( 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\mdsamplestation\mdsamplestation.templ`, Line: 48, Col: 51} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 79, Col: 51} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -99,6 +148,14 @@ func ContentMDSampleStation( 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 = 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 @@ -107,7 +164,7 @@ func ContentMDSampleStation( 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 } @@ -155,6 +212,10 @@ func JSMDSampleStation() templ.Component { templ_7745c5c3_Var5 = 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) } @@ -162,6 +223,40 @@ func JSMDSampleStation() templ.Component { }) } +func BeforeRequestContent() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_BeforeRequestContent_5717`, + Function: `function __templ_BeforeRequestContent_5717(){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_5717`), + CallInline: templ.SafeScriptInline(`__templ_BeforeRequestContent_5717`), + } +} + +func AfterRequestContent() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_AfterRequestContent_848c`, + Function: `function __templ_AfterRequestContent_848c(){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_848c`), + CallInline: templ.SafeScriptInline(`__templ_AfterRequestContent_848c`), + } +} + func ShowMDSampleStation( title string, cmp templ.Component, diff --git a/views/dev/mdsamplestation/mdsamplestationtable.templ b/views/dev/mdsamplestation/mdsamplestationtable.templ index 80def24..1071bd3 100644 --- a/views/dev/mdsamplestation/mdsamplestationtable.templ +++ b/views/dev/mdsamplestation/mdsamplestationtable.templ @@ -2,16 +2,45 @@ package dev_mdsamplestationview import "cpone/models" import "cpone/component/table" +import "strconv" -templ TableSampleStation(data []models.MDSampleStation, tableID string) { -
+templ TableSampleStation(data []models.MDSampleStation, + tableID string, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) { +
@tablecomponent.TableV3([]string{"KODE", "NAMA STATION", "GROUP", "AKSI"}, []string{"20%", "30%", "30%", "20%"}, - ItemRow(data)) + ItemRow(data, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + ))
} -templ ItemRow(data []models.MDSampleStation) { +templ ItemRow(data []models.MDSampleStation, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) { if len(data) == 0 { Data Tidak Ditemukan @@ -23,29 +52,78 @@ templ ItemRow(data []models.MDSampleStation) { { v.T_SampleStationName } { v.T_SampleStationIsNonLab } - @ItemAction() + @ItemAction(v.T_SampleStationID, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + ) } } -templ ItemAction() { +templ ItemAction( + id int, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) {
Edit + class="btnactionmdss col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5 btn btn-light-tosca mb-2 btn-sm" + hx-get={ hxGetEdit +"?id=" + strconv.Itoa(id) } + hx-target={ hxTargetEdit } + hx-swap={ hxSwapEdit } + hx-include={ hxIncludeEdit } + hx-indicator={ "#spnredt" + strconv.Itoa(id) } + hx-on::before-request={ HandleBeforeRequestRow(strconv.Itoa(id)) } + hx-on::after-request={ HandleAfterRequestRow(strconv.Itoa(id)) } + > + + Edit + Hapus + class="btnactionmdss col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5 btn btn-light-danger mb-2 btn-sm" + hx-get={ hxGetDelete +"?id=" + strconv.Itoa(id) } + hx-target={ hxTargetDelete } + hx-swap={ hxSwapDelete } + hx-include={ hxIncludeDelete } + hx-indicator={ "#spnrdel" + strconv.Itoa(id) } + hx-on::before-request={ HandleBeforeRequestRow(strconv.Itoa(id)) } + hx-on::after-request={ HandleAfterRequestRow(strconv.Itoa(id)) } + > + + Hapus +
+} + +script HandleBeforeRequestRow(id string) { + var cusid_ele = document.getElementsByClassName('btnactionmdss'); + 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('btnactionmdss'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.remove('disabled'); + } + console.log(id) } \ No newline at end of file diff --git a/views/dev/mdsamplestation/mdsamplestationtable_templ.go b/views/dev/mdsamplestation/mdsamplestationtable_templ.go index 6bbe226..bbbda06 100644 --- a/views/dev/mdsamplestation/mdsamplestationtable_templ.go +++ b/views/dev/mdsamplestation/mdsamplestationtable_templ.go @@ -12,8 +12,19 @@ import "bytes" import "cpone/models" import "cpone/component/table" +import "strconv" -func TableSampleStation(data []models.MDSampleStation, tableID string) templ.Component { +func TableSampleStation(data []models.MDSampleStation, + tableID string, + hxGetEdit string, + 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) if !templ_7745c5c3_IsBuffer { @@ -33,19 +44,28 @@ func TableSampleStation(data []models.MDSampleStation, tableID string) templ.Com 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\mdsamplestation\mdsamplestationtable.templ`, Line: 7, Col: 21} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 18, Col: 21} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-swab-oob=\"true\">") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-swap-oob=\"true\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = tablecomponent.TableV3([]string{"KODE", "NAMA STATION", "GROUP", "AKSI"}, []string{"20%", "30%", "30%", "20%"}, - ItemRow(data)).Render(ctx, templ_7745c5c3_Buffer) + ItemRow(data, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + )).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -60,7 +80,16 @@ func TableSampleStation(data []models.MDSampleStation, tableID string) templ.Com }) } -func ItemRow(data []models.MDSampleStation) templ.Component { +func ItemRow(data []models.MDSampleStation, + hxGetEdit string, + 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) if !templ_7745c5c3_IsBuffer { @@ -87,7 +116,7 @@ func ItemRow(data []models.MDSampleStation) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(v.T_SampleStationCode) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 22, Col: 39} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 51, Col: 39} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -100,7 +129,7 @@ func ItemRow(data []models.MDSampleStation) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(v.T_SampleStationName) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 23, Col: 39} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 52, Col: 39} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -113,7 +142,7 @@ func ItemRow(data []models.MDSampleStation) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(v.T_SampleStationIsNonLab) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 24, Col: 43} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 53, Col: 43} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -123,7 +152,16 @@ func ItemRow(data []models.MDSampleStation) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = ItemAction().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = ItemAction(v.T_SampleStationID, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + ).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -139,7 +177,17 @@ func ItemRow(data []models.MDSampleStation) templ.Component { }) } -func ItemAction() templ.Component { +func ItemAction( + id int, + hxGetEdit string, + 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) if !templ_7745c5c3_IsBuffer { @@ -152,7 +200,215 @@ func ItemAction() templ.Component { templ_7745c5c3_Var7 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Edit Hapus
") + _, 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 ") + 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 } @@ -162,3 +418,33 @@ func ItemAction() templ.Component { return templ_7745c5c3_Err }) } + +func HandleBeforeRequestRow(id string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleBeforeRequestRow_f90d`, + Function: `function __templ_HandleBeforeRequestRow_f90d(id){var cusid_ele = document.getElementsByClassName('btnactionmdss'); + 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_f90d`, id), + CallInline: templ.SafeScriptInline(`__templ_HandleBeforeRequestRow_f90d`, id), + } +} + +func HandleAfterRequestRow(id string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleAfterRequestRow_792d`, + Function: `function __templ_HandleAfterRequestRow_792d(id){var cusid_ele = document.getElementsByClassName('btnactionmdss'); + 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_792d`, id), + CallInline: templ.SafeScriptInline(`__templ_HandleAfterRequestRow_792d`, id), + } +}