step 2 : add data group result with form validation
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"
|
||||
globalservices "cpone/services"
|
||||
"cpone/utils"
|
||||
groupresult "cpone/views/dev/groupresult"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/labstack/echo/v4"
|
||||
@@ -28,7 +30,8 @@ type GroupResultService interface {
|
||||
// EditUserGroup(id string, code string, name string) (models.UserGroupV1, error)
|
||||
// DeleteUserGroup(id string) (models.UserGroupV1, error)
|
||||
GetListGroupResult(search string, currentPage int, rowPerPage int) ([]models.GroupResult, int, error)
|
||||
// GetUserGroupByIDV1(id string) (models.UserGroupV1, error)
|
||||
GetGroupResultResumeMcu() ([]models.GroupResultResumeMcu, error)
|
||||
AddGroupResult(groupresultname string, groupresultflagpertest string, groupresultflagnonlab string, groupresultresumemcu string) (models.GroupResult, error)
|
||||
}
|
||||
|
||||
func NewGroupResultHandler(us GroupResultService) *GroupResultHandler {
|
||||
@@ -98,6 +101,62 @@ func (lh *GroupResultHandler) HandlerShowGroupResultPaginationV1(c echo.Context)
|
||||
return utils.ViewMulti(c, retval)
|
||||
}
|
||||
|
||||
// HANDLE CLOSE BUTTON
|
||||
func (lh *GroupResultHandler) HandleCloseForm(c echo.Context) error {
|
||||
// #dialogAddBodyID, #dialogAddID
|
||||
|
||||
logger, _ := zap.NewProduction()
|
||||
defer logger.Sync()
|
||||
|
||||
// listItem
|
||||
dataResultMcu, err := lh.GroupResultService.GetGroupResultResumeMcu()
|
||||
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 := groupresult.ItemDropdown(dataResultMcu, 0)
|
||||
|
||||
dialogAddBodyID := c.FormValue("dialogAddBodyID")
|
||||
form := groupresult.DialogNewBodyV1(
|
||||
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, groupresult.HandleJSModalAddGR(""))
|
||||
return utils.View(c, form)
|
||||
}
|
||||
|
||||
// LISTING FUNCTION INITIAL
|
||||
func (lh *GroupResultHandler) HandlerShowGroupResultV1(c echo.Context) error {
|
||||
|
||||
@@ -178,8 +237,72 @@ func (lh *GroupResultHandler) HandlerShowGroupResultV1(c echo.Context) error {
|
||||
// sidebar
|
||||
sidebaruserprofileComponent := sidebaruserprofile.Navbaruserprofile(dataUser)
|
||||
|
||||
// listItem
|
||||
dataResultMcu, err := lh.GroupResultService.GetGroupResultResumeMcu()
|
||||
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
|
||||
}
|
||||
|
||||
defer logger.Sync()
|
||||
logger.Info("LOAD BREADCRUMB DEV",
|
||||
zap.Any("data", dataBreadCrumb),
|
||||
)
|
||||
|
||||
// Component Dropdown MCU
|
||||
listItemResultMcuComponent := groupresult.ItemDropdown(dataResultMcu, 0)
|
||||
|
||||
//Component modal add usergroup
|
||||
modaladdcomponent := groupresult.EmptyDiv1()
|
||||
// modaladdcomponent := groupresult.EmptyDiv1()
|
||||
modaladdcomponent := groupresult.GroupResultForm(models.GroupResultFormComponent{
|
||||
IDComponent: "formgroupresult",
|
||||
Link: "/dev/groupresult/add",
|
||||
HxTarget: "#" + dialogAddBodyID,
|
||||
HxSwap: "outerHTML",
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
|
||||
ModalID: dialogAddID,
|
||||
ModalTitle: "New-Group Result",
|
||||
DialogBody: groupresult.DialogNewBodyV1(
|
||||
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,
|
||||
dialogAddBodyID, groupresult.HandleJSModalAddGR("")),
|
||||
DialogAction: groupresult.DialogNewActionV1("/dev/groupresulthandlecloseform", "#"+dialogAddBodyID, "outerHTML", "#"+dialogAddID),
|
||||
ButtonCLose: groupresult.BtnCloseNewV1("/dev/groupresulthandlecloseform", "#"+dialogAddBodyID, "outerHTML", "#"+dialogAddID),
|
||||
})
|
||||
|
||||
//Component modal edit usergroup
|
||||
modalEditcomponent := groupresult.EmptyDiv1()
|
||||
@@ -255,6 +378,304 @@ func (lh *GroupResultHandler) HandlerShowGroupResultV1(c echo.Context) error {
|
||||
return utils.View(c, si)
|
||||
}
|
||||
|
||||
// PROSES ADD DATA
|
||||
func (lh *GroupResultHandler) AddUserGroup(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
|
||||
|
||||
// OTHER
|
||||
tableID := c.FormValue("tableID")
|
||||
paginationID := c.FormValue("paginationID")
|
||||
|
||||
// groupresultid := c.FormValue("groupresultid")
|
||||
searchID := c.FormValue("searchID")
|
||||
search := c.FormValue("search")
|
||||
currPagePrm := c.FormValue("currpage" + paginationID)
|
||||
// #dialogAddBodyID, #dialogAddID
|
||||
dialogAddBodyID := c.FormValue("dialogAddBodyID")
|
||||
dialogAddID := c.FormValue("dialogAddID")
|
||||
dialogEditBodyID := c.FormValue("dialogEditBodyID")
|
||||
// dialogEditID := c.FormValue("dialogEditID")
|
||||
dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
|
||||
// dialogDeleteID := c.FormValue("dialogDeleteID")
|
||||
|
||||
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.GroupResultService.GetGroupResultResumeMcu()
|
||||
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 := groupresult.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 := groupresult.DialogNewBodyV1(
|
||||
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, groupresult.HandleJSModalAddGR(""),
|
||||
)
|
||||
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"
|
||||
}
|
||||
|
||||
//Form Validation
|
||||
if strings.TrimSpace(groupresultname) == "" {
|
||||
// Component Dropdown MCU
|
||||
listItemResultMcuComponent := groupresult.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
|
||||
test := groupresult.DialogNewBodyV1(
|
||||
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, groupresult.HandleJSModalAddGR(""),
|
||||
)
|
||||
coba := utils.ViewMulti(c, []templ.Component{
|
||||
customtoastv2.CustomToastV2Show("Warning", "Group Result Name Kosong", "warning"),
|
||||
test})
|
||||
return coba
|
||||
|
||||
}
|
||||
|
||||
//Add user group service
|
||||
dataGroupResultAdd, err := lh.GroupResultService.AddGroupResult(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),
|
||||
)
|
||||
|
||||
test := groupresult.DialogNewBodyV1(
|
||||
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, groupresult.HandleJSModalAddGR(""))
|
||||
coba := utils.ViewMulti(c, []templ.Component{
|
||||
customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
|
||||
test})
|
||||
return coba
|
||||
}
|
||||
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 data table current page
|
||||
dataGroupResultList, totalpage, err := lh.GroupResultService.GetListGroupResult(search, currPage, 5)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR GET USER GROUP",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
//New add form
|
||||
newForm := groupresult.DialogNewBodyV1(
|
||||
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, groupresult.HandleJSModalAddGR("#"+dialogAddID))
|
||||
|
||||
//new table listing
|
||||
contentUserGroupComponent := groupresult.TableGroupResult(
|
||||
dataGroupResultList, tableID,
|
||||
"/dev/usergroupshoweditform",
|
||||
"#"+dialogEditBodyID,
|
||||
"outerHTML",
|
||||
"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"/dev/usergroupshowdeleteform",
|
||||
"#"+dialogDeleteBodyID,
|
||||
"outerHTML",
|
||||
"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")
|
||||
|
||||
//new pagination
|
||||
userGroupPaginationComponent := pagination.PaginationV2(totalpage,
|
||||
1,
|
||||
"/dev/groupresultv1pagination",
|
||||
paginationID,
|
||||
"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"#"+paginationID, "outerHTML", "", "true")
|
||||
|
||||
toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success add group result "+groupresultname, "success")
|
||||
|
||||
retval := []templ.Component{toastSuccess, contentUserGroupComponent, userGroupPaginationComponent, newForm}
|
||||
|
||||
return utils.ViewMulti(c, retval)
|
||||
}
|
||||
|
||||
// SEARCH PROSES
|
||||
func (lh *GroupResultHandler) HandlerShowGroupResultSearchV1(c echo.Context) error {
|
||||
search := c.QueryParam("search")
|
||||
|
||||
@@ -238,4 +238,8 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) {
|
||||
dev.GET("/groupresult", devGRhandlers.HandlerShowGroupResultV1)
|
||||
dev.GET("/searchgroupresultv1", devGRhandlers.HandlerShowGroupResultSearchV1)
|
||||
dev.GET("/groupresultv1pagination", devGRhandlers.HandlerShowGroupResultPaginationV1)
|
||||
dev.POST("/groupresulthandlecloseform", devGRhandlers.HandleCloseForm)
|
||||
// form add
|
||||
dev.POST("/groupresult/add", devGRhandlers.AddUserGroup)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user