step 3 : proses add data
This commit is contained in:
@@ -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_mdgroupresultview "cpone/views/dev/mdgroupresult"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/labstack/echo/v4"
|
||||
@@ -532,3 +534,298 @@ func (lh *MdGroupResultHandler) HandleCloseFormAdd(c echo.Context) error {
|
||||
dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
// PROSES ADD DATA
|
||||
func (lh *MdGroupResultHandler) HandleAddGroupResult(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"
|
||||
// var mcuResumeSelectedValue int = 0
|
||||
|
||||
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 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
|
||||
listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)
|
||||
|
||||
// check dropdown result mcu
|
||||
var idSelectedGroupResultResumeMcu int
|
||||
idSelectedGroupResultResumeMcu, err = strconv.Atoi(groupresultresumemcu)
|
||||
if err != nil {
|
||||
// Tangani kesalahan konversi
|
||||
fmt.Println("Error converting string to int:", err)
|
||||
// return
|
||||
test := 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,
|
||||
dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""),
|
||||
)
|
||||
coba := utils.ViewMulti(c, []templ.Component{
|
||||
customtoastv2.CustomToastV2Show("Error", "Error converting string to int", "error"),
|
||||
test})
|
||||
return coba
|
||||
}
|
||||
|
||||
var groupresultresumemcuNew string
|
||||
for _, x := range dataResultMcu {
|
||||
if x.ID == idSelectedGroupResultResumeMcu {
|
||||
groupresultresumemcuNew = x.Text
|
||||
// mcuResumeSelectedValue = x.ID
|
||||
}
|
||||
}
|
||||
|
||||
// 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 != "" {
|
||||
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",
|
||||
Value: groupresultname,
|
||||
ErrorMsg: "Group Result Name Kosong",
|
||||
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,
|
||||
dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
|
||||
}
|
||||
//Add user group service
|
||||
dataGroupResultAdd, err := lh.MdGroupResultServices.AddMdGroupResult(groupresultname, flagPerTest, flagNonLab, groupresultresumemcuNew)
|
||||
|
||||
if err != nil {
|
||||
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",
|
||||
},
|
||||
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,
|
||||
dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
|
||||
return utils.ViewMulti(c, []templ.Component{
|
||||
customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
|
||||
newForm})
|
||||
|
||||
}
|
||||
logger.Info("ADD USER GROUP",
|
||||
zap.Any("return", dataGroupResultAdd),
|
||||
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 GROUP RESULT",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
fmt.Println(dataUserGroupList)
|
||||
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(),
|
||||
)
|
||||
|
||||
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,
|
||||
dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult("#"+dialogAddID))
|
||||
toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success add group result "+groupresultname, "success")
|
||||
|
||||
return utils.ViewMulti(c, []templ.Component{
|
||||
toastSuccess,
|
||||
tableComponent,
|
||||
userGroupPaginationComponent,
|
||||
newForm})
|
||||
}
|
||||
|
||||
@@ -270,4 +270,5 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) {
|
||||
dev.GET("/md/groupresultv2/filter", devMdGRhandlers.HandleFilterMdGroupResult)
|
||||
dev.GET("/md/groupresultv2/changepage", devMdGRhandlers.HandleChangePageMdGroupResult)
|
||||
dev.POST("/md/groupresultv2/closeaddform", devMdGRhandlers.HandleCloseFormAdd)
|
||||
dev.POST("/md/groupresultv2/add", devMdGRhandlers.HandleAddGroupResult)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user