diff --git a/handlers/dev/md.samplestation.handlers.go b/handlers/dev/md.samplestation.handlers.go index 00e2471..6f04ea3 100644 --- a/handlers/dev/md.samplestation.handlers.go +++ b/handlers/dev/md.samplestation.handlers.go @@ -6,12 +6,14 @@ 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_mdsamplestationview "cpone/views/dev/mdsamplestation" "fmt" "strconv" + "strings" "github.com/a-h/templ" "github.com/labstack/echo/v4" @@ -21,6 +23,11 @@ import ( type MDSampleStationServices interface { GetMDSampleStationBreadcrumb() (models.BreadCrumbV1, error) GetListSampleStation(search string, currentPage int, rowPerPage int) ([]models.MDSampleStation, int, error) + GetMDSampleStationByID(id string) (models.MDSampleStation, error) + GetListGroupSampleStation() ([]models.MDSampleStationGroup, error) + AddMDSampleStation(code string, name string, group string) (models.MDSampleStation, error) + EditMDSampleStation(id string, code string, name string, group string) (models.MDSampleStation, error) + DeleteMDSampleStation(id string) (models.MDSampleStation, error) } func NewMDSampleStationHandler(ss MDSampleStationServices) *MDSampleStationHandler { @@ -121,6 +128,201 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte dev_mdsamplestationview.AfterRequestContent(), ) + // list group dropdown + listGroupSS, err := mdss.MDSampleStationServices.GetListGroupSampleStation() + if err != nil { + defer logger.Sync() + logger.Info("ERROR LIST GROUP DEV", zap.Any("error", err)) + return err + } + dropdownGroupItem := dev_mdsamplestationview.ItemGroupDropdown(listGroupSS, 0) + + // modal add form + dialogAddBodyCmp := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogAddBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + dropdownGroupItem, + dev_mdsamplestationview.JSHideModal(""), + ) + + modalActionAddCmp := dev_mdsamplestationview.ActionFormMDSampleStation( + "/dev/md/samplestation/closeaddform", + "#"+dialogAddBodyID, + "outerHTML", + "#"+dialogAddID, + ) + + btnCloseModalAdd := dev_mdsamplestationview.BtnCloseFormMDSampleStation( + "/dev/md/samplestation/closeaddform", + "#"+dialogAddBodyID, + "outerHTML", + "#"+dialogAddID, + ) + + modalAddFormComponent := dev_mdsamplestationview.MDSampleStationForm( + models.MDSampleStationForm{ + IDComponent: "formsamplestation", + Link: "/dev/md/samplestation/add", + HxTarget: "#" + dialogAddBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogAddID, + ModalTitle: "New-Sample Station", + DialogBody: dialogAddBodyCmp, + DialogAction: modalActionAddCmp, + ButtonClose: btnCloseModalAdd, + }, + ) + + // modal edit form + dialogEditFormComp := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogEditBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + dropdownGroupItem, + dev_mdsamplestationview.JSHideModal(""), + ) + + modalActionEditComp := dev_mdsamplestationview.ActionFormMDSampleStation( + "/dev/md/samplestation/closeeditform", + "#"+dialogEditBodyID, + "outerHTML", + "#"+dialogEditID, + ) + + btnCloseModalEdit := dev_mdsamplestationview.BtnCloseFormMDSampleStation( + "/dev/md/samplestation/closeeditform", + "#"+dialogEditBodyID, + "outerHTML", + "#"+dialogEditID, + ) + + modalEditFormComponent := dev_mdsamplestationview.MDSampleStationForm( + models.MDSampleStationForm{ + IDComponent: "formsamplestation", + Link: "/dev/md/samplestation/edit", + HxTarget: "#" + dialogEditBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogEditID, + ModalTitle: "Edit - Sample Station", + DialogBody: dialogEditFormComp, + DialogAction: modalActionEditComp, + ButtonClose: btnCloseModalEdit, + }, + ) + + // modal delete form + dialogDeleteBodyComp := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogDeleteBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + dropdownGroupItem, + dev_mdsamplestationview.JSHideModal(""), + ) + + modalActionDeleteCmp := dev_mdsamplestationview.ActionFormMDSampleStationDelete( + "/dev/md/samplestation/closedeleteform", + "#"+dialogDeleteBodyID, + "outerHTML", + "#"+dialogDeleteID, + ) + + btnCloseModalDelete := dev_mdsamplestationview.BtnCloseFormMDSampleStation( + "/dev/md/samplestation/closedeleteform", + "#"+dialogDeleteBodyID, + "outerHTML", + "#"+dialogDeleteID, + ) + + modalDeleteFormComponent := dev_mdsamplestationview.MDSampleStationForm( + models.MDSampleStationForm{ + IDComponent: "formsamplestation", + Link: "/dev/md/samplestation/delete", + HxTarget: "#" + dialogDeleteBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogDeleteID, + ModalTitle: "Delete - Sample Station", + DialogBody: dialogDeleteBodyComp, + DialogAction: modalActionDeleteCmp, + ButtonClose: btnCloseModalDelete, + }, + ) + content := dev_mdsamplestationview.ContentMDSampleStation( tableID, paginationID, @@ -135,6 +337,9 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte tableComponent, tableFilter, paginationTable, + modalAddFormComponent, + modalEditFormComponent, + modalDeleteFormComponent, ) css := dev_mdsamplestationview.CSSMDSampleStation() js := dev_mdsamplestationview.JSMDSampleStation() @@ -241,3 +446,479 @@ func (mdss *MDSampleStationHandler) HandleChangePageSampleStation(c echo.Context retval = append(retval, paginationComp) return utils.ViewMulti(c, retval) } + +// Add Modal form +func (mdss *MDSampleStationHandler) HandleCloseFormAdd(c echo.Context) error { + logger, _ := zap.NewProduction() + + dataGroupDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation() + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET ITEM DROPDOWN", zap.Any("error", err)) + return err + } + itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, 0) + + dialogAddBodyID := c.FormValue("dialogAddBodyID") + newForm := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogAddBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + itemGroupDropdown, + dev_mdsamplestationview.JSHideModal(""), + ) + return utils.View(c, newForm) +} + +func (mdss *MDSampleStationHandler) HandleAddMDSampleStation(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + code := c.FormValue("samplestationcode") + name := c.FormValue("samplestationname") + group := c.FormValue("samplestationgroup") + + 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") + dialogEditBodyID := c.FormValue("dialogEditBodyID") + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + + currPage, err := strconv.Atoi(currPagePrm) + if err != nil { + return err + } + logger.Info("ADD SAMPLE STATION PARAM", + zap.Any("code", code), + zap.Any("nama", name), + zap.Any("group", group), + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPage), + ) + + // dropdown item + dataItemDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation() + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET ITEM DROPDOWN", zap.Any("error", err)) + return err + } + itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, 0) + + // check item dropdown + var idSelectedGroup int + idSelectedGroup, err = strconv.Atoi(group) + if err != nil { + newForm := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogAddBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + itemGroupDropdown, + dev_mdsamplestationview.JSHideModal(""), + ) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "error convert str to int", "warning"), newForm}) + } + + for _, x := range dataItemDropdown { + if x.ID == idSelectedGroup { + group = x.Group + } + } + + formValidation := "" + codeValidation := "" + nameValidation := "" + groupValidation := "" + + if strings.TrimSpace(code) == "" { + formValidation = "Code sample station tidak boleh kosong" + codeValidation = "Code sample station tidak boleh kosong" + nameValidation = "" + groupValidation = "" + } + if strings.TrimSpace(name) == "" { + formValidation = "Nama sample station tidak boleh kosong" + codeValidation = "" + nameValidation = "Nama sample station tidak boleh kosong" + groupValidation = "" + } + if strings.TrimSpace(group) == "" { + formValidation = "Group sample station tidak boleh kosong" + codeValidation = "" + nameValidation = "" + groupValidation = "Group sample station tidak boleh kosong" + } + if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" && strings.TrimSpace(group) == "" { + formValidation = "Code, Nama, dan Group tidak boleh kosong" + codeValidation = "Code sample station tidak boleh kosong" + nameValidation = "Nama sample station tidak boleh kosong" + groupValidation = "Group sample station tidak boleh kosong" + } + + if formValidation != "" || codeValidation != "" || nameValidation != "" || groupValidation != "" { + newForm := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogAddBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + Value: code, + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + Value: name, + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + itemGroupDropdown, + dev_mdsamplestationview.JSHideModal(""), + ) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm}) + } + + // Add Data to DB + dataResp, err := mdss.MDSampleStationServices.AddMDSampleStation(code, name, group) + if err != nil { + logger.Info("Error Add to DB", + zap.Any("Error", err), + zap.Any("code", code), + zap.Any("name", name), + zap.Any("group", group), + ) + newForm := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogAddBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + Value: code, + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + Value: name, + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + itemGroupDropdown, + dev_mdsamplestationview.JSHideModal(""), + ) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm}) + } + logger.Info("Add Sample Station", + zap.Any("response", dataResp), + zap.Any("code", code), + zap.Any("name", name), + zap.Any("group", group), + ) + + // re-initial page + dataTableSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("error get table data", + zap.Any("error", err), + ) + return err + } + + tableComp := dev_mdsamplestationview.TableSampleStation(dataTableSS, + 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, + currPage, + "/dev/md/samplestation/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdsamplestationview.BeforeRequestContent(), + dev_mdsamplestationview.AfterRequestContent(), + ) + + newForm := dev_mdsamplestationview.BodyFormMDSampleStation( + dialogAddBodyID, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationid", + Placeholder: "Kode Sample Station", + Type: "hidden", + ID: "samplestationinputid", + }, + models.CustomTextFieldv2Prm{ + Label: "Kode Sample Station", + Name: "samplestationcode", + Placeholder: "Kode Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomTextFieldv2Prm{ + Label: "Nama Sample Station", + Name: "samplestationname", + Placeholder: "Nama Sample Station", + Type: "text", + ID: "samplestationinputname", + }, + models.CustomDropdownv1Prm{ + Label: "Group", + Name: "samplestationgroup", + ID: "samplestationinputgroup", + }, + itemGroupDropdown, + dev_mdsamplestationview.JSHideModal("#"+dialogAddID), + ) + toastSucc := customtoastv2.CustomToastV2Show("Success", "Success add group result "+name, "success") + + return utils.ViewMulti(c, []templ.Component{ + toastSucc, + tableComp, + paginationComp, + newForm, + }) +} + +// Delete Modal form +func (mdss *MDSampleStationHandler) HandleOpenDeleteForm(c echo.Context) error { + id := c.QueryParam("id") + dialogDeleteID := c.QueryParam("dialogDeleteID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") + + dataMDSS, err := mdss.MDSampleStationServices.GetMDSampleStationByID(id) + if err != nil { + newForm := dev_mdsamplestationview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{ + Name: "samplestationid", + Type: "hidden", + Value: strconv.Itoa(dataMDSS.T_SampleStationID), + }, + dialogDeleteBodyID, + "Apakah anda yakin menghapus sample station berikut ?", + []string{"Kode", "Nama Sample Station", "Group"}, + []string{"", "", ""}, + dev_mdsamplestationview.JSShowModal(""), + ) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get Sample Station Error", "danger"), newForm}) + } + newForm := dev_mdsamplestationview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{ + Name: "samplestationid", + Type: "hidden", + Value: strconv.Itoa(dataMDSS.T_SampleStationID), + }, + dialogDeleteBodyID, + "Apakah anda yakin menghapus sample station berikut ?", + []string{"Kode", "Nama Sample Station", "Group"}, + []string{dataMDSS.T_SampleStationCode, dataMDSS.T_SampleStationName, dataMDSS.T_SampleStationIsNonLab}, + dev_mdsamplestationview.JSShowModal("#"+dialogDeleteID), + ) + return utils.View(c, newForm) +} + +func (mdss *MDSampleStationHandler) HandleCloseFormDelete(c echo.Context) error { + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + newForm := dev_mdsamplestationview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{ + Name: "samplestationid", + Type: "hidden", + Value: "", + }, + dialogDeleteBodyID, + "Apakah anda yakin menghapus sample station berikut ?", + []string{"Kode", "Nama Sample Station", "Group"}, + []string{"", "", ""}, + dev_mdsamplestationview.JSShowModal(""), + ) + + return utils.View(c, newForm) +} + +func (mdss *MDSampleStationHandler) HandleDeleteMDSS(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + id := c.FormValue("samplestationid") + tableID := c.FormValue("tableID") + paginationID := c.FormValue("paginationID") + searchID := c.FormValue("searchID") + search := c.FormValue("search") + currPagePrm := c.FormValue("currpage" + paginationID) + dialogDeleteID := c.FormValue("dialogDeleteID") + dialogEditBodyID := c.FormValue("dialogEditBodyID") + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + + currPag, err := strconv.Atoi(currPagePrm) + if err != nil { + return err + } + logger.Info("ADD SAMPLE STATION PARAM", + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPag), + ) + + dataSS, err := mdss.MDSampleStationServices.DeleteMDSampleStation(id) + if err != nil { + logger.Info("Error", zap.Any("Error", err)) + + newForm := dev_mdsamplestationview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "samplestationid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus sample station berikut ?", + []string{"Kode", "Nama Sample Station", "Group"}, + []string{"", "", ""}, + dev_mdsamplestationview.JSShowModal(""), + ) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), newForm}) + } + + logger.Info("ADD SAMPLE STATION", + zap.Any("return", dataSS), + ) + + dataSSList, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, currPag, 5) + if err != nil { + return err + } + if len(dataSSList) == 0 && totalPage > 1 { + currPag = currPag - 1 + dataSSList, _, err = mdss.MDSampleStationServices.GetListSampleStation(search, currPag, 5) + if err != nil { + return err + } + } + + tableComponent := dev_mdsamplestationview.TableSampleStation(dataSSList, + 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, + currPag, + "/dev/md/samplestation/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdsamplestationview.BeforeRequestContent(), + dev_mdsamplestationview.AfterRequestContent(), + ) + + var retVal []templ.Component + newForm := dev_mdsamplestationview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "samplestationid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus sample station berikut ?", + []string{"Kode", "Nama Sample Station", "Group"}, + []string{"", "", ""}, + dev_mdsamplestationview.JSHideModal("#"+dialogDeleteID), + ) + toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil menghapus sample station", "success") + retVal = append(retVal, toastSuccess) + retVal = append(retVal, tableComponent) + retVal = append(retVal, tablePagination) + retVal = append(retVal, newForm) + + return utils.ViewMulti(c, retVal) +} diff --git a/handlers/routes.go b/handlers/routes.go index 31ff1c6..2d35f67 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -269,6 +269,12 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { dev.GET("/md/samplestation", devMDSampleStationHandlers.HandleShowMDSampleStationScreen) dev.GET("/md/samplestation/filter", devMDSampleStationHandlers.HandleFilterMDSS) dev.GET("/md/samplestation/changepage", devMDSampleStationHandlers.HandleChangePageSampleStation) + dev.POST("/md/samplestation/add", devMDSampleStationHandlers.HandleAddMDSampleStation) + dev.POST("/md/samplestation/closeaddform", devMDSampleStationHandlers.HandleCloseFormAdd) + dev.GET("/md/samplestation/opendelete", devMDSampleStationHandlers.HandleOpenDeleteForm) + dev.POST("/md/samplestation/closedeleteform", devMDSampleStationHandlers.HandleCloseFormDelete) + dev.POST("/md/samplestation/delete", devMDSampleStationHandlers.HandleDeleteMDSS) + // masterdata nat unit devMdNatUnitServices := dev_services.NewMdNatUnitServices(appStore) devMdNatUnitHandlers := dev_handlers.NeWMdNatUnitHandler(devMdNatUnitServices) diff --git a/models/samplestation.models.go b/models/samplestation.models.go index ef1d089..a9c5550 100644 --- a/models/samplestation.models.go +++ b/models/samplestation.models.go @@ -40,3 +40,8 @@ type MDSampleStationConfirmation struct { DialogAction templ.Component ButtonClose templ.Component } + +type MDSampleStationGroup struct { + ID int `default:"id"` + Group string `default:"group"` +} diff --git a/services/dev/md.samplestation.services.go b/services/dev/md.samplestation.services.go index f95160a..42efa1b 100644 --- a/services/dev/md.samplestation.services.go +++ b/services/dev/md.samplestation.services.go @@ -6,7 +6,10 @@ import ( dbx "cpone/package/database" "fmt" "math" + "strconv" "strings" + + "go.uber.org/zap" ) func NewMDSampleStationServices(uStore db.AppStore) *MDSampleStationServices { @@ -87,3 +90,184 @@ func (ss *MDSampleStationServices) GetListSampleStation(search string, currentPa return sampleStationList, totalPage, nil } + +func (ss *MDSampleStationServices) GetMDSampleStationByID(id string) (models.MDSampleStation, error) { + logger, _ := zap.NewProduction() + + var ret models.MDSampleStation + q := ` + SELECT + T_SampleStationID, + T_SampleStationCode, + T_SampleStationName, + T_SampleStationNat_GroupID, + T_SampleStationIsNonLab, + T_SampleStationIsActive + FROM t_samplestation + WHERE T_SampleStationID = ?` + + err := dbx.Handlex.Get(&ret, q, id) + if err != nil { + defer logger.Sync() + logger.Error("Error get data by ID", zap.String("ID", id), zap.Error(err)) + return ret, fmt.Errorf("query failed") + } + + if len(ret.T_SampleStationIsNonLab) == 0 { + ret.T_SampleStationIsNonLab = "LAB" + } + + return ret, nil +} + +func (ss *MDSampleStationServices) GetListGroupSampleStation() ([]models.MDSampleStationGroup, error) { + data := []models.MDSampleStationGroup{ + { + ID: 1, + Group: "RADIODIAGNOSTIC", + }, + { + ID: 2, + Group: "ELEKTROMEDIS", + }, + { + ID: 3, + Group: "LAB", + }, + { + ID: 4, + Group: "OTHERS", + }, + } + return data, nil +} + +func (ss *MDSampleStationServices) AddMDSampleStation(code string, name string, group string) (models.MDSampleStation, error) { + logger, _ := zap.NewProduction() + var data models.MDSampleStation + + if strings.ToUpper(group) == "LAB" { + group = " " + } + + // cek existing code & name + var count int + var prmCode = "%" + code + "%" + var prmName = "%" + name + "%" + q := ` + SELECT COUNT(*) + FROM t_samplestation + WHERE (T_SampleStationCode LIKE ? OR T_SampleStationName LIKE ?) + AND T_SampleStationIsActive = 'Y' + ` + err := dbx.Handlex.Get(&count, q, prmCode, prmName) + if err != nil { + defer logger.Sync() + logger.Error("cek duplicate", zap.Any("code", prmCode), zap.Any("name", prmName)) + return data, fmt.Errorf("query failed") + } + if count > 0 { + defer logger.Sync() + logger.Error("duplicate data", zap.Any("code", code), zap.Any("name", name)) + return data, fmt.Errorf("query failed") + } + + q = ` + INSERT INTO t_samplestation ( + T_SampleStationCode, + T_SampleStationName, + T_SampleStationIsNonLab, + T_SampleStationCreated, + T_SampleStationCreatedUserID + ) VALUES (?,?,?,NOW(),1); + ` + rst := dbx.Handlex.MustExec(q, code, name, group) + insertedID, err := rst.LastInsertId() + if err != nil { + defer logger.Sync() + logger.Error("error insert data", zap.Any("code", code), zap.Any("name", name), zap.Any("group", group)) + return data, fmt.Errorf("query failed") + } + + s := strconv.Itoa(int(insertedID)) + + return ss.GetMDSampleStationByID(s) +} + +func (ss *MDSampleStationServices) EditMDSampleStation(id string, code string, name string, group string) (models.MDSampleStation, error) { + logger, _ := zap.NewProduction() + var ret models.MDSampleStation + + // cek existeing code & name + var count int + var prmCode = "%" + code + "%" + var prmName = "%" + name + "%" + q := ` + SELECT COUNT(*) + FROM t_samplestation + WHERE (T_SampleStationCode LIKE ? OR T_SampleStationName LIKE ?) + AND T_SampleStationIsActive = 'Y' + AND T_SampleStationID <> ? + ` + err := dbx.Handlex.Get(count, q, prmCode, prmName, id) + if err != nil { + defer logger.Sync() + logger.Error("cek duplicate", zap.Any("code", code), zap.Any("name", name)) + return ret, fmt.Errorf("query failed") + } + if count > 0 { + defer logger.Sync() + logger.Error("duplicate data", zap.Any("code", code), zap.Any("name", name)) + return ret, fmt.Errorf("query failed") + } + + // update data + q = ` + UPDATE t_samplestation SET + T_SampleStationCode = ?, + T_SampleStationName = ?, + T_SampleStationIsNonLab = ?, + T_SampleStationLastUpdated = NOW(), + T_SampleStationLastUpdatedUserID = 1 + WHERE T_SampleStationID = ?; + ` + updt := dbx.Handlex.MustExec(q, code, name, group, id) + _, err = updt.RowsAffected() + if err != nil { + defer logger.Sync() + logger.Error("error update data", zap.Any("code", code), zap.Any("name", name), zap.Any("group", group)) + return ret, fmt.Errorf("query failed") + } + + return ss.GetMDSampleStationByID(id) +} + +func (ss *MDSampleStationServices) DeleteMDSampleStation(id string) (models.MDSampleStation, error) { + logger, _ := zap.NewProduction() + var ret models.MDSampleStation + + q := ` + UPDATE t_samplestation + SET + T_SampleStationIsActive = 'N', + T_SampleStationDeleted = NOW(), + T_SampleStationDeletedUserID = '1' + WHERE T_SampleStationID = ?; + ` + dlt := dbx.Handlex.MustExec(q, id) + _, err := dlt.RowsAffected() + if err != nil { + defer logger.Sync() + logger.Error("Error delete sample station", zap.String("id", id)) + return ret, fmt.Errorf("query failed") + } + + ret, err = ss.GetMDSampleStationByID(id) + if err != nil { + defer logger.Sync() + logger.Error("Error get sample station id", zap.String("id", id)) + return ret, fmt.Errorf("query failed") + } + + return ret, nil +} diff --git a/views/dev/mdsamplestation/mdsamplestation.templ b/views/dev/mdsamplestation/mdsamplestation.templ index 4b92dd1..a7cdd9a 100644 --- a/views/dev/mdsamplestation/mdsamplestation.templ +++ b/views/dev/mdsamplestation/mdsamplestation.templ @@ -20,6 +20,9 @@ templ ContentMDSampleStation( tablecontent templ.Component, filtercomponent templ.Component, paginationtable templ.Component, + modalAddForm templ.Component, + modalEditForm templ.Component, + modalDeleteForm templ.Component, ) {
@customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", @@ -83,6 +86,9 @@ templ ContentMDSampleStation(
@tablecontent @paginationtable + @modalAddForm + @modalEditForm + @modalDeleteForm
Loading... diff --git a/views/dev/mdsamplestation/mdsamplestation_templ.go b/views/dev/mdsamplestation/mdsamplestation_templ.go index 5cae41c..4fcbdbb 100644 --- a/views/dev/mdsamplestation/mdsamplestation_templ.go +++ b/views/dev/mdsamplestation/mdsamplestation_templ.go @@ -30,6 +30,9 @@ func ContentMDSampleStation( tablecontent templ.Component, filtercomponent templ.Component, paginationtable templ.Component, + modalAddForm 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) @@ -125,7 +128,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: 71, Col: 55} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 74, Col: 55} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -138,7 +141,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: 79, Col: 51} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 82, Col: 51} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -164,6 +167,18 @@ func ContentMDSampleStation( 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 = modalEditForm.Render(ctx, templ_7745c5c3_Buffer) + 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/mdsamplestation/mdsamplestationmodal.templ b/views/dev/mdsamplestation/mdsamplestationmodal.templ index 1b4dc60..1e57194 100644 --- a/views/dev/mdsamplestation/mdsamplestationmodal.templ +++ b/views/dev/mdsamplestation/mdsamplestationmodal.templ @@ -4,6 +4,7 @@ import "cpone/models" import "cpone/component/modal" import "cpone/component/customtextfield" import "cpone/component/customdropdown" +import "strconv" templ MDSampleStationForm(data models.MDSampleStationForm) {
@@ -11,7 +12,7 @@ templ MDSampleStationForm(data models.MDSampleStationForm) { id={ data.IDComponent } hx-post={ data.Link } class="form" - hx-target={ data.HxSwap } + hx-target={ data.HxTarget } hx-swap={ data.HxSwap } hx-include={ data.HxInclude } hx-indicator=".formloading" @@ -45,27 +46,47 @@ script HandleFormAfterRequest() { const btnActSaveData = document.querySelectorAll('.btnactsavedata'); for (let i = 0; i < btnActCancel.length; i++) { - btnActCancel[i].setAttribute('disabled'); + btnActCancel[i].removeAttribute('disabled'); } - for (let i = 0; i < document.length; i++) { - btnActSaveData[i].setAttribute('disabled'); + for (let i = 0; i < btnActSaveData.length; i++) { + btnActSaveData[i].removeAttribute('disabled'); } } templ BodyFormMDSampleStation( componentID string, inputID models.CustomTextFieldv2Prm, - inputName models.CustomTextFieldv2Prm, inputCode models.CustomTextFieldv2Prm, + inputName models.CustomTextFieldv2Prm, inputGroup models.CustomDropdownv1Prm, + listGroup templ.Component, hxOnLoad templ.ComponentScript, ) {
@customtextfield.CustomTextFieldv2(inputID) @customtextfield.CustomTextFieldv2(inputCode) @customtextfield.CustomTextFieldv2(inputName) - @customdropdown.MainCustomDropdownV1(inputGroup) + @customdropdown.MainCustomDropdownInput(inputGroup, listGroup)
+ +} + +templ ItemGroupDropdown(itemGroup []models.MDSampleStationGroup, selectedId int) { + if len(itemGroup) == 0 { + + } else { + for _, v := range itemGroup { + if (selectedId == v.ID) { + + } else { + + } + } + } } script JSHideModal(modalID string) { diff --git a/views/dev/mdsamplestation/mdsamplestationmodal_templ.go b/views/dev/mdsamplestation/mdsamplestationmodal_templ.go index c258f74..ef90fa9 100644 --- a/views/dev/mdsamplestation/mdsamplestationmodal_templ.go +++ b/views/dev/mdsamplestation/mdsamplestationmodal_templ.go @@ -14,6 +14,7 @@ import "cpone/models" import "cpone/component/modal" import "cpone/component/customtextfield" import "cpone/component/customdropdown" +import "strconv" func MDSampleStationForm(data models.MDSampleStationForm) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -43,7 +44,7 @@ func MDSampleStationForm(data models.MDSampleStationForm) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(data.IDComponent) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 11, Col: 33} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 12, Col: 33} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -56,7 +57,7 @@ func MDSampleStationForm(data models.MDSampleStationForm) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(data.Link) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 12, Col: 31} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 13, Col: 31} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -67,9 +68,9 @@ func MDSampleStationForm(data models.MDSampleStationForm) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(data.HxSwap) + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(data.HxTarget) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 14, Col: 35} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 15, Col: 37} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -82,7 +83,7 @@ func MDSampleStationForm(data models.MDSampleStationForm) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(data.HxSwap) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 15, Col: 33} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 16, Col: 33} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -95,7 +96,7 @@ func MDSampleStationForm(data models.MDSampleStationForm) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(data.HxInclude) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 16, Col: 39} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 17, Col: 39} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -163,28 +164,29 @@ func HandleFormBeforeRequest() templ.ComponentScript { func HandleFormAfterRequest() templ.ComponentScript { return templ.ComponentScript{ - Name: `__templ_HandleFormAfterRequest_cce9`, - Function: `function __templ_HandleFormAfterRequest_cce9(){const btnActCancel = document.querySelectorAll('.btnactcancel'); + Name: `__templ_HandleFormAfterRequest_cc6f`, + Function: `function __templ_HandleFormAfterRequest_cc6f(){const btnActCancel = document.querySelectorAll('.btnactcancel'); const btnActSaveData = document.querySelectorAll('.btnactsavedata'); for (let i = 0; i < btnActCancel.length; i++) { - btnActCancel[i].setAttribute('disabled'); + btnActCancel[i].removeAttribute('disabled'); } - for (let i = 0; i < document.length; i++) { - btnActSaveData[i].setAttribute('disabled'); + for (let i = 0; i < btnActSaveData.length; i++) { + btnActSaveData[i].removeAttribute('disabled'); } }`, - Call: templ.SafeScript(`__templ_HandleFormAfterRequest_cce9`), - CallInline: templ.SafeScriptInline(`__templ_HandleFormAfterRequest_cce9`), + Call: templ.SafeScript(`__templ_HandleFormAfterRequest_cc6f`), + CallInline: templ.SafeScriptInline(`__templ_HandleFormAfterRequest_cc6f`), } } func BodyFormMDSampleStation( componentID string, inputID models.CustomTextFieldv2Prm, - inputName models.CustomTextFieldv2Prm, inputCode models.CustomTextFieldv2Prm, + inputName models.CustomTextFieldv2Prm, inputGroup models.CustomDropdownv1Prm, + listGroup templ.Component, hxOnLoad templ.ComponentScript, ) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -210,7 +212,7 @@ func BodyFormMDSampleStation( var templ_7745c5c3_Var10 string templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(componentID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 63, Col: 25} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 65, Col: 25} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) if templ_7745c5c3_Err != nil { @@ -241,11 +243,11 @@ func BodyFormMDSampleStation( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = customdropdown.MainCustomDropdownV1(inputGroup).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = customdropdown.MainCustomDropdownInput(inputGroup, listGroup).Render(ctx, templ_7745c5c3_Buffer) 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 } @@ -256,6 +258,98 @@ func BodyFormMDSampleStation( }) } +func ItemGroupDropdown(itemGroup []models.MDSampleStationGroup, selectedId int) 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) + if len(itemGroup) == 0 { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + for _, v := range itemGroup { + if selectedId == v.ID { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + _, 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_4530`, @@ -293,9 +387,9 @@ func ActionFormMDSampleStation(LinkClose string, targetClose string, hxSwapClose 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 + templ_7745c5c3_Var17 := templ.GetChildren(ctx) + if templ_7745c5c3_Var17 == nil { + templ_7745c5c3_Var17 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") @@ -310,8 +404,8 @@ func ActionFormMDSampleStation(LinkClose string, targetClose string, hxSwapClose if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var13 templ.ComponentScript = JSHideModal(modalID) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13.Call) + var templ_7745c5c3_Var18 templ.ComponentScript = JSHideModal(modalID) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var18.Call) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -319,12 +413,12 @@ func ActionFormMDSampleStation(LinkClose string, targetClose string, hxSwapClose if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var14 string - templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 92, Col: 31} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 113, Col: 31} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -332,12 +426,12 @@ func ActionFormMDSampleStation(LinkClose string, targetClose string, hxSwapClose if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var15 string - templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) + var templ_7745c5c3_Var20 string + templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 93, Col: 35} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 114, Col: 35} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -345,12 +439,12 @@ func ActionFormMDSampleStation(LinkClose string, targetClose string, hxSwapClose if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var16 string - templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) + var templ_7745c5c3_Var21 string + templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 94, Col: 33} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 115, Col: 33} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -373,9 +467,9 @@ func BtnCloseFormMDSampleStation(LinkClose string, targetClose string, hxSwapClo 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 + 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, JSHideModal(modalID)) @@ -386,12 +480,12 @@ func BtnCloseFormMDSampleStation(LinkClose string, targetClose string, hxSwapClo if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var18 string - templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) + var templ_7745c5c3_Var23 string + templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 115, Col: 27} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 136, Col: 27} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -399,12 +493,12 @@ func BtnCloseFormMDSampleStation(LinkClose string, targetClose string, hxSwapClo if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var19 string - templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) + var templ_7745c5c3_Var24 string + templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 116, Col: 31} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 137, Col: 31} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -412,12 +506,12 @@ func BtnCloseFormMDSampleStation(LinkClose string, targetClose string, hxSwapClo if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var20 string - templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 117, Col: 29} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 138, Col: 29} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -425,8 +519,8 @@ func BtnCloseFormMDSampleStation(LinkClose string, targetClose string, hxSwapClo if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var21 templ.ComponentScript = JSHideModal(modalID) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21.Call) + var templ_7745c5c3_Var26 templ.ComponentScript = JSHideModal(modalID) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var26.Call) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -456,9 +550,9 @@ func DeleteConfirmationBody( 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 + templ_7745c5c3_Var27 := templ.GetChildren(ctx) + if templ_7745c5c3_Var27 == nil { + templ_7745c5c3_Var27 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, hxOnLoad) @@ -469,12 +563,12 @@ func DeleteConfirmationBody( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var23 string - templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(componentID) + var templ_7745c5c3_Var28 string + templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(componentID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 136, Col: 25} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 157, Col: 25} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -482,8 +576,8 @@ func DeleteConfirmationBody( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var24 templ.ComponentScript = hxOnLoad - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var24.Call) + var templ_7745c5c3_Var29 templ.ComponentScript = hxOnLoad + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29.Call) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -491,12 +585,12 @@ func DeleteConfirmationBody( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var25 string - templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(message) + var templ_7745c5c3_Var30 string + templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(message) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 137, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 158, Col: 20} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -509,12 +603,12 @@ func DeleteConfirmationBody( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var26 string - templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(v) + var templ_7745c5c3_Var31 string + templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(v) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 142, Col: 86} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 163, Col: 86} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -532,12 +626,12 @@ func DeleteConfirmationBody( if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var27 string - templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(v) + var templ_7745c5c3_Var32 string + templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(v) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 147, Col: 67} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 168, Col: 67} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -573,9 +667,9 @@ func ActionFormMDSampleStationDelete(LinkClose string, targetClose string, hxSwa 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 + templ_7745c5c3_Var33 := templ.GetChildren(ctx) + if templ_7745c5c3_Var33 == nil { + templ_7745c5c3_Var33 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") @@ -590,8 +684,8 @@ func ActionFormMDSampleStationDelete(LinkClose string, targetClose string, hxSwa if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var29 templ.ComponentScript = JSHideModal(modalID) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29.Call) + var templ_7745c5c3_Var34 templ.ComponentScript = JSHideModal(modalID) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var34.Call) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -599,12 +693,12 @@ func ActionFormMDSampleStationDelete(LinkClose string, targetClose string, hxSwa if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var30 string - templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) + var templ_7745c5c3_Var35 string + templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 160, Col: 31} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 181, Col: 31} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -612,12 +706,12 @@ func ActionFormMDSampleStationDelete(LinkClose string, targetClose string, hxSwa if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var31 string - templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) + var templ_7745c5c3_Var36 string + templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 161, Col: 35} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 182, Col: 35} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -625,12 +719,12 @@ func ActionFormMDSampleStationDelete(LinkClose string, targetClose string, hxSwa if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var32 string - templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) + var templ_7745c5c3_Var37 string + templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 162, Col: 33} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationmodal.templ`, Line: 183, Col: 33} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/dev/mdsamplestation/mdsamplestationtable.templ b/views/dev/mdsamplestation/mdsamplestationtable.templ index 1071bd3..610713d 100644 --- a/views/dev/mdsamplestation/mdsamplestationtable.templ +++ b/views/dev/mdsamplestation/mdsamplestationtable.templ @@ -116,7 +116,7 @@ script HandleBeforeRequestRow(id string) { var item = cusid_ele[i]; item.classList.add('disabled'); } - console.log(id) + console.log(id) } script HandleAfterRequestRow(id string) { diff --git a/views/dev/mdsamplestation/mdsamplestationtable_templ.go b/views/dev/mdsamplestation/mdsamplestationtable_templ.go index bbbda06..71df51f 100644 --- a/views/dev/mdsamplestation/mdsamplestationtable_templ.go +++ b/views/dev/mdsamplestation/mdsamplestationtable_templ.go @@ -421,16 +421,16 @@ func ItemAction( 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'); + Name: `__templ_HandleBeforeRequestRow_027b`, + Function: `function __templ_HandleBeforeRequestRow_027b(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) + console.log(id) }`, - Call: templ.SafeScript(`__templ_HandleBeforeRequestRow_f90d`, id), - CallInline: templ.SafeScriptInline(`__templ_HandleBeforeRequestRow_f90d`, id), + Call: templ.SafeScript(`__templ_HandleBeforeRequestRow_027b`, id), + CallInline: templ.SafeScriptInline(`__templ_HandleBeforeRequestRow_027b`, id), } }