add edit func sample station
This commit is contained in:
@@ -771,6 +771,440 @@ func (mdss *MDSampleStationHandler) HandleAddMDSampleStation(c echo.Context) err
|
||||
})
|
||||
}
|
||||
|
||||
// Edit Modal form
|
||||
func (mdss *MDSampleStationHandler) HandleOpenEditForm(c echo.Context) error {
|
||||
logger, _ := zap.NewProduction()
|
||||
defer logger.Sync()
|
||||
|
||||
id := c.QueryParam("id")
|
||||
dialogEditID := c.QueryParam("dialogEditID")
|
||||
dialogEditBodyID := c.QueryParam("dialogEditBodyID")
|
||||
|
||||
// list item dropdown
|
||||
dataGroupDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR EDIT GET ITEM DROPDOWN", zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, 0)
|
||||
|
||||
// get data by id
|
||||
dataSS, err := mdss.MDSampleStationServices.GetMDSampleStationByID(id)
|
||||
if err != nil {
|
||||
newForm := 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",
|
||||
},
|
||||
itemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "error get data sample station result", "danger"), newForm})
|
||||
}
|
||||
|
||||
// init dropdown
|
||||
var idSelected int = 0
|
||||
for _, x := range dataGroupDropdown {
|
||||
if x.Group == dataSS.T_SampleStationIsNonLab {
|
||||
idSelected = x.ID
|
||||
}
|
||||
}
|
||||
|
||||
selectedDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, idSelected)
|
||||
|
||||
newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogEditBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
Value: strconv.Itoa(dataSS.T_SampleStationID),
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
Value: dataSS.T_SampleStationCode,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
Value: dataSS.T_SampleStationName,
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
selectedDropdown,
|
||||
dev_mdsamplestationview.JSShowModal("#"+dialogEditID),
|
||||
)
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
func (mdss *MDSampleStationHandler) HandleCloseEditForm(c echo.Context) error {
|
||||
logger, _ := zap.NewProduction()
|
||||
|
||||
dialogEditBodyID := c.FormValue("dialogEditBodyID")
|
||||
|
||||
dataGroupDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR EDIT GET ITEM DROPDOWN", zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, 0)
|
||||
|
||||
newForm := 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",
|
||||
},
|
||||
itemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
func (mdss *MDSampleStationHandler) HandleEditMDSS(c echo.Context) error {
|
||||
logger, _ := zap.NewProduction()
|
||||
defer logger.Sync()
|
||||
|
||||
id := c.FormValue("samplestationid")
|
||||
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)
|
||||
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 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(
|
||||
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",
|
||||
},
|
||||
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(
|
||||
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",
|
||||
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})
|
||||
}
|
||||
|
||||
// Edit data sample station
|
||||
dataSS, err := mdss.MDSampleStationServices.EditMDSampleStation(id, code, name, group)
|
||||
if err != nil {
|
||||
dropdownItem := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, idSelectedGroup)
|
||||
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(
|
||||
dialogEditBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
Value: id,
|
||||
},
|
||||
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",
|
||||
},
|
||||
dropdownItem,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), newForm})
|
||||
}
|
||||
logger.Info("Add to DB",
|
||||
zap.Any("resp", dataSS),
|
||||
zap.Any("code", code),
|
||||
zap.Any("name", name),
|
||||
zap.Any("group", group),
|
||||
)
|
||||
|
||||
// re-initialize 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(),
|
||||
)
|
||||
|
||||
currItemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, idSelectedGroup)
|
||||
|
||||
var retVal []templ.Component
|
||||
newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogEditBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
Value: id,
|
||||
},
|
||||
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",
|
||||
},
|
||||
currItemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal("#"+dialogEditID),
|
||||
)
|
||||
toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil edit Group Result "+name, "success")
|
||||
|
||||
retVal = append(retVal, toastSuccess)
|
||||
retVal = append(retVal, tableComp)
|
||||
retVal = append(retVal, paginationComp)
|
||||
retVal = append(retVal, newForm)
|
||||
|
||||
return utils.ViewMulti(c, retVal)
|
||||
}
|
||||
|
||||
// Delete Modal form
|
||||
func (mdss *MDSampleStationHandler) HandleOpenDeleteForm(c echo.Context) error {
|
||||
id := c.QueryParam("id")
|
||||
|
||||
@@ -274,6 +274,9 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) {
|
||||
dev.GET("/md/samplestation/opendelete", devMDSampleStationHandlers.HandleOpenDeleteForm)
|
||||
dev.POST("/md/samplestation/closedeleteform", devMDSampleStationHandlers.HandleCloseFormDelete)
|
||||
dev.POST("/md/samplestation/delete", devMDSampleStationHandlers.HandleDeleteMDSS)
|
||||
dev.GET("/md/samplestation/openedit", devMDSampleStationHandlers.HandleOpenEditForm)
|
||||
dev.POST("/md/samplestation/edit", devMDSampleStationHandlers.HandleEditMDSS)
|
||||
dev.POST("/md/samplestation/closeeditform", devMDSampleStationHandlers.HandleCloseEditForm)
|
||||
|
||||
// masterdata nat unit
|
||||
devMdNatUnitServices := dev_services.NewMdNatUnitServices(appStore)
|
||||
|
||||
@@ -198,6 +198,10 @@ func (ss *MDSampleStationServices) EditMDSampleStation(id string, code string, n
|
||||
logger, _ := zap.NewProduction()
|
||||
var ret models.MDSampleStation
|
||||
|
||||
if strings.ToUpper(group) == "LAB" {
|
||||
group = " "
|
||||
}
|
||||
|
||||
// cek existeing code & name
|
||||
var count int
|
||||
var prmCode = "%" + code + "%"
|
||||
@@ -209,7 +213,7 @@ func (ss *MDSampleStationServices) EditMDSampleStation(id string, code string, n
|
||||
AND T_SampleStationIsActive = 'Y'
|
||||
AND T_SampleStationID <> ?
|
||||
`
|
||||
err := dbx.Handlex.Get(count, q, prmCode, prmName, id)
|
||||
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))
|
||||
@@ -218,7 +222,7 @@ func (ss *MDSampleStationServices) EditMDSampleStation(id string, code string, n
|
||||
if count > 0 {
|
||||
defer logger.Sync()
|
||||
logger.Error("duplicate data", zap.Any("code", code), zap.Any("name", name))
|
||||
return ret, fmt.Errorf("query failed")
|
||||
return ret, fmt.Errorf("duplicate kode atau nama")
|
||||
}
|
||||
|
||||
// update data
|
||||
|
||||
Reference in New Issue
Block a user