step 4 : proses show edit form & edit data
This commit is contained in:
@@ -829,3 +829,466 @@ func (lh *MdGroupResultHandler) HandleAddGroupResult(c echo.Context) error {
|
||||
userGroupPaginationComponent,
|
||||
newForm})
|
||||
}
|
||||
|
||||
// SHOW EDIT
|
||||
func (lh *MdGroupResultHandler) HandleOpenEditForm(c echo.Context) error {
|
||||
logger, _ := zap.NewProduction()
|
||||
defer logger.Sync()
|
||||
|
||||
id := c.QueryParam("id")
|
||||
dialogEditID := c.QueryParam("dialogEditID")
|
||||
dialogEditBodyID := c.QueryParam("dialogEditBodyID")
|
||||
|
||||
// listItem
|
||||
dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
|
||||
fmt.Println(dataResultMcu)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR BREADCRUMB DEV",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
fmt.Println(dataResultMcu)
|
||||
return err
|
||||
}
|
||||
// Component Dropdown MCU default
|
||||
listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)
|
||||
|
||||
// get data by id
|
||||
dataGroupList, err := lh.MdGroupResultServices.GetMdGroupResultByID(id)
|
||||
if err != nil {
|
||||
newForm := dev_mdgroupresultview.BodyFormGroupResult(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result name",
|
||||
Name: "groupresultid",
|
||||
Placeholder: "Group Result name",
|
||||
Type: "hidden",
|
||||
ID: "groupresultid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result Name",
|
||||
Name: "groupresultname",
|
||||
Placeholder: "Group Result Name",
|
||||
Type: "text", ID: "groupresultname"},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagpertest",
|
||||
ID: "groupresultflagpertest",
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagnonlab",
|
||||
ID: "groupresultflagnonlab",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group Result Resume MCU",
|
||||
Name: "groupresultresumemcu",
|
||||
ID: "groupresultresumemcu",
|
||||
},
|
||||
listItemResultMcuComponent,
|
||||
dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get group result error", "danger"), newForm})
|
||||
}
|
||||
|
||||
// Component Dropdown MCU
|
||||
var idSelectedGroupResultResumeMcu int = 0
|
||||
for _, x := range dataResultMcu {
|
||||
if x.Text == dataGroupList.Group_ResultResumeMcu {
|
||||
idSelectedGroupResultResumeMcu = x.ID
|
||||
}
|
||||
}
|
||||
|
||||
listItemResultMcuComponentPopulate := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
|
||||
|
||||
newForm := dev_mdgroupresultview.BodyFormGroupResult(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result name",
|
||||
Name: "groupresultid",
|
||||
Placeholder: "Group Result name",
|
||||
Type: "hidden",
|
||||
ID: "groupresultid",
|
||||
Value: strconv.Itoa(dataGroupList.Group_ResultID),
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result Name",
|
||||
Name: "groupresultname",
|
||||
Placeholder: "Group Result Name",
|
||||
Type: "text", ID: "groupresultname",
|
||||
Value: dataGroupList.Group_ResultName,
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagpertest",
|
||||
ID: "groupresultflagpertest",
|
||||
Value: dataGroupList.Group_ResultFlagPerTest,
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagnonlab",
|
||||
ID: "groupresultflagnonlab",
|
||||
Value: dataGroupList.Group_ResultFlagNonLab,
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group Result Resume MCU",
|
||||
Name: "groupresultresumemcu",
|
||||
ID: "groupresultresumemcu",
|
||||
},
|
||||
listItemResultMcuComponentPopulate,
|
||||
dialogEditBodyID, dev_mdgroupresultview.JsShowModalGroupResult("#"+dialogEditID))
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
// CLOSE EDIT FORM
|
||||
func (lh *MdGroupResultHandler) HandleCloseFormEdit(c echo.Context) error {
|
||||
dialogEditBodyID := c.FormValue("dialogEditBodyID")
|
||||
|
||||
logger, _ := zap.NewProduction()
|
||||
// listItem
|
||||
dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
|
||||
fmt.Println(dataResultMcu)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR RESULT RESUME MCU DEV",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
fmt.Println(dataResultMcu)
|
||||
return err
|
||||
}
|
||||
|
||||
// Component Dropdown MCU
|
||||
listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)
|
||||
|
||||
newForm := dev_mdgroupresultview.BodyFormGroupResult(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result name",
|
||||
Name: "groupresultid",
|
||||
Placeholder: "Group Result name",
|
||||
Type: "hidden",
|
||||
ID: "groupresultid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result Name",
|
||||
Name: "groupresultname",
|
||||
Placeholder: "Group Result Name",
|
||||
Type: "text", ID: "groupresultname"},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagpertest",
|
||||
ID: "groupresultflagpertest",
|
||||
Value: "N",
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagnonlab",
|
||||
ID: "groupresultflagnonlab",
|
||||
Value: "N",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group Result Resume MCU",
|
||||
Name: "groupresultresumemcu",
|
||||
ID: "groupresultresumemcu",
|
||||
},
|
||||
listItemResultMcuComponent,
|
||||
dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
// PROSES EDIT DATA
|
||||
func (lh *MdGroupResultHandler) HandleEditGroupResult(c echo.Context) error {
|
||||
|
||||
logger, _ := zap.NewProduction()
|
||||
defer logger.Sync()
|
||||
|
||||
//prm form addusergroup
|
||||
// DARI FORM ADD NYA
|
||||
groupresultname := c.FormValue("groupresultname")
|
||||
groupresultflagpertest := c.FormValue("groupresultflagpertest")
|
||||
groupresultflagnonlab := c.FormValue("groupresultflagnonlab")
|
||||
groupresultresumemcu := c.FormValue("groupresultresumemcu")
|
||||
|
||||
// setting flag test dan flagnonlab
|
||||
var flagPerTest string = "N"
|
||||
var flagNonLab string = "N"
|
||||
|
||||
id := c.FormValue("groupresultid")
|
||||
tableID := c.FormValue("tableID")
|
||||
paginationID := c.FormValue("paginationID")
|
||||
searchID := c.FormValue("searchID")
|
||||
search := c.FormValue("search")
|
||||
currPagePrm := c.FormValue("currpage" + paginationID)
|
||||
// dialogAddBodyID := c.FormValue("dialogAddBodyID")
|
||||
dialogEditID := c.FormValue("dialogEditID")
|
||||
dialogEditBodyID := c.FormValue("dialogEditBodyID")
|
||||
dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
|
||||
|
||||
currPage, err := strconv.Atoi(currPagePrm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("ADD USER GROUP PARAM",
|
||||
zap.Any("groupresultname", groupresultname),
|
||||
zap.Any("groupresultflagpertest", groupresultflagpertest),
|
||||
zap.Any("groupresultflagnonlab", groupresultflagnonlab),
|
||||
zap.Any("groupresultresumemcu", groupresultresumemcu),
|
||||
zap.Any("tableid", tableID),
|
||||
zap.Any("search", search),
|
||||
zap.Any("currpage", currPage),
|
||||
)
|
||||
|
||||
// listItem
|
||||
dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
|
||||
fmt.Println(dataResultMcu)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR BREADCRUMB DEV",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
fmt.Println(dataResultMcu)
|
||||
return err
|
||||
}
|
||||
|
||||
// Component Dropdown MCU
|
||||
listItemResultMcuComponentInitial := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)
|
||||
|
||||
// check dropdown result mcu
|
||||
var idSelectedGroupResultResumeMcu int
|
||||
idSelectedGroupResultResumeMcu, err = strconv.Atoi(groupresultresumemcu)
|
||||
if err != nil {
|
||||
newForm := dev_mdgroupresultview.BodyFormGroupResult(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result name",
|
||||
Name: "groupresultid",
|
||||
Placeholder: "Group Result name",
|
||||
Type: "hidden",
|
||||
ID: "groupresultid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result Name",
|
||||
Name: "groupresultname",
|
||||
Placeholder: "Group Result Name",
|
||||
Type: "text", ID: "groupresultname"},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagpertest",
|
||||
ID: "groupresultflagpertest",
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagnonlab",
|
||||
ID: "groupresultflagnonlab",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group Result Resume MCU",
|
||||
Name: "groupresultresumemcu",
|
||||
ID: "groupresultresumemcu",
|
||||
},
|
||||
listItemResultMcuComponentInitial,
|
||||
dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "Error converting string to int", "error"), newForm})
|
||||
|
||||
}
|
||||
|
||||
var groupresultresumemcuNew string
|
||||
for _, x := range dataResultMcu {
|
||||
if x.ID == idSelectedGroupResultResumeMcu {
|
||||
groupresultresumemcuNew = x.Text
|
||||
}
|
||||
}
|
||||
|
||||
// check group result flag per test
|
||||
if groupresultflagpertest == "on" {
|
||||
flagPerTest = "Y"
|
||||
}
|
||||
|
||||
// check group result flag non lab
|
||||
if groupresultflagnonlab == "on" {
|
||||
flagNonLab = "Y"
|
||||
}
|
||||
|
||||
formValidation := ""
|
||||
nameValidation := ""
|
||||
|
||||
if strings.TrimSpace(groupresultname) == "" {
|
||||
formValidation = "Group Result Name tidak boleh kosong"
|
||||
nameValidation = "Group Result Name tidak boleh kosong"
|
||||
}
|
||||
|
||||
if formValidation != "" || nameValidation != "" {
|
||||
listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
|
||||
newForm := dev_mdgroupresultview.BodyFormGroupResult(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result name",
|
||||
Name: "groupresultid",
|
||||
Placeholder: "Group Result name",
|
||||
Type: "hidden",
|
||||
ID: "groupresultid",
|
||||
// Value: id,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result Name",
|
||||
Name: "groupresultname",
|
||||
Placeholder: "Group Result Name",
|
||||
ErrorMsg: "Group Result Name Kosong",
|
||||
Value: groupresultname,
|
||||
Type: "text", ID: "groupresultname"},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagpertest",
|
||||
ID: "groupresultflagpertest",
|
||||
Value: groupresultflagpertest,
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagnonlab",
|
||||
ID: "groupresultflagnonlab",
|
||||
Value: groupresultflagnonlab,
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group Result Resume MCU",
|
||||
Name: "groupresultresumemcu",
|
||||
ID: "groupresultresumemcu",
|
||||
},
|
||||
listItemResultMcuComponent,
|
||||
dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
|
||||
}
|
||||
|
||||
//edit user group service
|
||||
dataGroupList, err := lh.MdGroupResultServices.EditMdGroupResult(id, groupresultname, flagPerTest, flagNonLab, groupresultresumemcuNew)
|
||||
if err != nil {
|
||||
listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
|
||||
logger.Info("Error",
|
||||
zap.Any("Error", err),
|
||||
zap.Any("groupresultname", groupresultname),
|
||||
zap.Any("groupresultflagpertest", groupresultflagpertest),
|
||||
zap.Any("groupresultflagnonlab", groupresultflagnonlab),
|
||||
zap.Any("groupresultresumemcu", groupresultresumemcu),
|
||||
)
|
||||
newForm := dev_mdgroupresultview.BodyFormGroupResult(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result name",
|
||||
Name: "groupresultid",
|
||||
Placeholder: "Group Result name",
|
||||
Type: "hidden",
|
||||
ID: "groupresultid",
|
||||
Value: id,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result Name",
|
||||
Name: "groupresultname",
|
||||
Placeholder: "Group Result Name",
|
||||
Value: groupresultname,
|
||||
Type: "text", ID: "groupresultname"},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagpertest",
|
||||
ID: "groupresultflagpertest",
|
||||
Value: groupresultflagpertest,
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagnonlab",
|
||||
ID: "groupresultflagnonlab",
|
||||
Value: groupresultflagnonlab,
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group Result Resume MCU",
|
||||
Name: "groupresultresumemcu",
|
||||
ID: "groupresultresumemcu",
|
||||
},
|
||||
listItemResultMcuComponent,
|
||||
dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.ViewMulti(c, []templ.Component{
|
||||
customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
|
||||
newForm})
|
||||
|
||||
}
|
||||
logger.Info("ADD USER GROUP",
|
||||
zap.Any("return", dataGroupList),
|
||||
zap.Any("groupresultname", groupresultname),
|
||||
zap.Any("groupresultflagpertest", groupresultflagpertest),
|
||||
zap.Any("groupresultflagnonlab", groupresultflagnonlab),
|
||||
zap.Any("groupresultresumemcu", groupresultresumemcu),
|
||||
)
|
||||
//get list user group for table
|
||||
dataUserGroupList, totalPage, err := lh.MdGroupResultServices.GetListMdGroupResult(search, currPage, 5)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR GET USER GROUP",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
fmt.Println(dataGroupList)
|
||||
return err
|
||||
}
|
||||
//table component
|
||||
tableComponent := dev_mdgroupresultview.TableGroupResult(dataUserGroupList,
|
||||
tableID,
|
||||
"/dev/md/groupresultv2/openedit",
|
||||
"#"+dialogEditBodyID,
|
||||
"outerHTML",
|
||||
"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"/dev/md/groupresultv2/opendelete",
|
||||
"#"+dialogDeleteBodyID,
|
||||
"outerHTML",
|
||||
"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID")
|
||||
|
||||
//pagination component
|
||||
//Pagination
|
||||
userGroupPaginationComponent := pagination.PaginationV3(
|
||||
totalPage,
|
||||
currPage,
|
||||
"/dev/md/groupresultv2/changepage",
|
||||
paginationID,
|
||||
"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"#"+paginationID,
|
||||
"outerHTML", "", "true",
|
||||
dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
|
||||
dev_mdgroupresultview.AfterRequestContentMdGroupResult(),
|
||||
)
|
||||
|
||||
listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
|
||||
|
||||
var retVal []templ.Component
|
||||
newForm := dev_mdgroupresultview.BodyFormGroupResult(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result name",
|
||||
Name: "groupresultid",
|
||||
Placeholder: "Group Result name",
|
||||
Type: "hidden",
|
||||
ID: "groupresultid",
|
||||
Value: id,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Group Result Name",
|
||||
Name: "groupresultname",
|
||||
Placeholder: "Group Result Name",
|
||||
Value: groupresultname,
|
||||
Type: "text", ID: "groupresultname"},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagpertest",
|
||||
ID: "groupresultflagpertest",
|
||||
Value: groupresultflagpertest,
|
||||
},
|
||||
models.CustomCheckboxv1Prm{
|
||||
Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
|
||||
Name: "groupresultflagnonlab",
|
||||
ID: "groupresultflagnonlab",
|
||||
Value: groupresultflagnonlab,
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group Result Resume MCU",
|
||||
Name: "groupresultresumemcu",
|
||||
ID: "groupresultresumemcu",
|
||||
},
|
||||
listItemResultMcuComponent,
|
||||
dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult("#"+dialogEditID))
|
||||
toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil edit Group Result "+groupresultname, "success")
|
||||
retVal = append(retVal, toastSuccess)
|
||||
retVal = append(retVal, tableComponent)
|
||||
retVal = append(retVal, userGroupPaginationComponent)
|
||||
retVal = append(retVal, newForm)
|
||||
return utils.ViewMulti(c, retVal)
|
||||
}
|
||||
|
||||
@@ -271,4 +271,8 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) {
|
||||
dev.GET("/md/groupresultv2/changepage", devMdGRhandlers.HandleChangePageMdGroupResult)
|
||||
dev.POST("/md/groupresultv2/closeaddform", devMdGRhandlers.HandleCloseFormAdd)
|
||||
dev.POST("/md/groupresultv2/add", devMdGRhandlers.HandleAddGroupResult)
|
||||
dev.GET("/md/groupresultv2/openedit", devMdGRhandlers.HandleOpenEditForm)
|
||||
dev.POST("/md/groupresultv2/closeeditform", devMdGRhandlers.HandleCloseFormEdit)
|
||||
dev.POST("/md/groupresultv2/edit", devMdGRhandlers.HandleEditGroupResult)
|
||||
// dev.GET("/md/groupresultv2/opendelete", devMdUserGroupHandlers.HandleOpenDeleteForm)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user