toast handle error dan toast show in input search

This commit is contained in:
sindhu
2024-05-16 17:20:23 +07:00
parent 9ab0c7b6f4
commit 7a93a4994a
16 changed files with 822 additions and 27 deletions

View File

@@ -10,6 +10,7 @@ import (
"cpone/component/pagination"
tablecomponent "cpone/component/table"
customtoastv2 "cpone/component/toastbootstrap"
"cpone/models"
"cpone/utils"
mastermenuusergroup "cpone/views/dev/mastermenuusergroup"
@@ -158,13 +159,19 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
// var toastComponent templ.Component
contentIDHtmxExtension := utils.GenerateRandomID("htmxExtmgu")
var flagxError bool = false
var msgx string = ""
logger, _ := zap.NewProduction()
dataMenu, err := lh.MasterMenuUserGroupService.GetMasterMenus()
fmt.Println(dataMenu)
fmt.Println(err)
if err != nil {
fmt.Println(dataMenu)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get Menu"
}
dataUser, err := services.GetUser()
@@ -172,7 +179,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
fmt.Println(err)
if err != nil {
fmt.Println(dataUser)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get User"
}
rowPerPage := 2
@@ -185,7 +195,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
zap.Any("error", err),
)
fmt.Println(dataUserGroup)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get User Group"
}
dataUserGroupAll, err := lh.MasterMenuUserGroupService.GetListMasterUserGroup()
@@ -197,7 +210,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
zap.Any("error", err),
)
fmt.Println(dataUserGroupAll)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get User All"
}
// si := mastermenuusergroup.ListMasterUserGroupInitial(dataUserGroup)
@@ -229,7 +245,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
zap.Any("error", err),
)
fmt.Println(dataBreadCrumb)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get Breadcrumb"
}
// si := mastermenuusergroup.ListMasterUserGroupInitial(dataBreadCrumb)
@@ -239,6 +258,15 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
zap.Any("data", dataBreadCrumb),
)
// IF ERROR OCCURS
if flagxError {
si := customtoastv2.CustomToastV2Show("Error", msgx, "danger")
return utils.View(c, si)
}
// IF ERROR OCCURS
flagxError = false
// navbar menu
navbarmenuComponent := navbarmenu.NavbarMenu(dataMenu)
@@ -262,6 +290,7 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
// toastComponent = customtoast.CustomToastV1("", contentIDHtmxExtension)
// table user group
toastComponent := tablecomponent.DivEmpty()
searchQueryParam := "&q="
tabelusergroupComponent := tablecomponent.TableV2(
@@ -271,6 +300,7 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(c echo.Co
pagination.PaginationV1(totalPages, 1, "/dev/usergroupv1pagination", contentID, searchQueryParam),
contentID,
inputansearchComponent,
toastComponent,
)
si := mastermenuusergroup.ShowMasterMenuUserGroupV1x(
@@ -443,6 +473,8 @@ func (lh *MasterMenuUserGroupHandler) DeleteUserGroup(c echo.Context) error {
func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c echo.Context) error {
search := c.QueryParam("q")
logger, _ := zap.NewProduction()
var flagxError bool = false
var msgx string = ""
// dataUserGroup, err := lh.MasterMenuUserGroupService.GetListMasterUserGroupBySearch(search)
rowPerPage := 2
@@ -454,7 +486,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
zap.Any("page", page),
zap.Any("error ", err),
)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Convert Page Param"
}
currentPageParam := c.QueryParam("currentPage")
@@ -465,7 +500,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
zap.Any("page", page),
zap.Any("error ", err),
)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Convert Current Page Param"
}
dataUserGroup, err := lh.MasterMenuUserGroupService.GetListMasterUserGroupPagination(search, currentPage, rowPerPage)
@@ -478,7 +516,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
zap.Any("search param", search),
)
fmt.Println(dataUserGroup)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get User Group"
}
defer logger.Sync()
@@ -487,6 +528,7 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
)
// data user filtered
dataUserGroupFiltered, err := lh.MasterMenuUserGroupService.GetListMasterUserGroupFilteredBySearch(search)
fmt.Println(dataUserGroupFiltered)
fmt.Println(err)
@@ -497,7 +539,10 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
zap.Any("search param", search),
)
fmt.Println(dataUserGroupFiltered)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get User Search"
}
defer logger.Sync()
@@ -506,6 +551,15 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
)
// si := mastermenuusergroup.ListMasterUserGroupInitial(dataUserGroup)
// IF ERROR OCCURS
if flagxError {
si := customtoastv2.CustomToastV2Show("Error", msgx, "danger")
return utils.View(c, si)
}
// IF ERROR OCCURS
flagxError = false
contentID := utils.GenerateRandomID("tablebody")
// tabelusergroupComponent := mastermenuusergroup.TableRowV1(dataUserGroup)
@@ -519,6 +573,8 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
// inputansearchComponent := customtextfieldsearch.MainCustomTextFieldSearchV1("#"+contentIDSearch, "q", "Cari User Group", "text", "/dev/searchusergroupv1?"+link, "input changed delay:500ms, search", "#"+contentID, "#indicator", search, contentIDHtmxExtension)
inputansearchComponent := tablecomponent.DivEmpty()
toastComponent := customtoastv2.CustomToastV2Show("Success", "Success Loaded", "success")
tabelusergroupComponent := tablecomponent.TableV2(
[]string{"KODE", "USERGROUP", "AKSI"},
[]string{"40%", "40%", "20%"},
@@ -526,6 +582,7 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
pagination.PaginationV1(totalPages, 1, "/dev/usergroupv1pagination", contentID, searchQueryParam),
contentID,
inputansearchComponent,
toastComponent,
)
si := tabelusergroupComponent
@@ -534,6 +591,9 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(c e
}
func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1(c echo.Context) error {
var flagxError bool = false
var msgx string = ""
logger, _ := zap.NewProduction()
search := c.QueryParam("q")
@@ -545,7 +605,11 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
zap.Any("page", page),
zap.Any("error ", err),
)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Convert Page Param"
}
dataUserGroupAll, err := lh.MasterMenuUserGroupService.GetListMasterUserGroup()
@@ -557,7 +621,11 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
zap.Any("error", err),
)
fmt.Println(dataUserGroupAll)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Get User Group"
}
currentPageParam := c.QueryParam("currentPage")
@@ -568,7 +636,11 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
zap.Any("page", page),
zap.Any("error ", err),
)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Convert Current Page Param"
}
rowPerPage := 2
@@ -582,7 +654,11 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
zap.Any("search param", search),
)
fmt.Println(dataUserGroup)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error User Group Search"
}
// si := mastermenuusergroup.ListMasterUserGroupInitial(dataUserGroup)
@@ -603,7 +679,11 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
zap.Any("search param", search),
)
fmt.Println(dataUserGroupFiltered)
return err
// return err
flagxError = true
// msgx = err.Error()
msgx = "Error Search User Group Filtered"
}
defer logger.Sync()
@@ -611,6 +691,15 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
zap.Any("data", dataUserGroupFiltered),
)
// IF ERROR OCCURS
if flagxError {
si := customtoastv2.CustomToastV2Show("Error", msgx, "danger")
return utils.View(c, si)
}
// IF ERROR OCCURS
flagxError = false
contentID := utils.GenerateRandomID("tablebody")
// table user group
@@ -623,6 +712,7 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
// inputansearchComponent := customtextfieldsearch.MainCustomTextFieldSearchV1("#"+contentIDSearch, "q", "Cari User Group", "text", "/dev/searchusergroupv1?"+link, "input changed delay:500ms, search", "#"+contentID, "#indicator", search, contentIDHtmxExtension)
inputansearchComponent := tablecomponent.DivEmpty()
toastComponent := tablecomponent.DivEmpty()
tabelusergroupComponent := tablecomponent.TableV2(
[]string{"KODE", "USERGROUP", "AKSI"},
[]string{"40%", "40%", "20%"},
@@ -630,6 +720,7 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
pagination.PaginationV1(totalPages, currentPage, "/dev/usergroupv1pagination", contentID, searchQueryParam),
contentID,
inputansearchComponent,
toastComponent,
)
// tabelusergroupComponent := mastermenuusergroup.TableRowV1(dataUserGroup)
@@ -639,6 +730,14 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1
return utils.View(c, si)
}
func (lh *MasterMenuUserGroupHandler) HandlerHideToast(c echo.Context) error {
toastComponent := customtoastv2.CustomToastV2Hide()
si := toastComponent
return utils.View(c, si)
}
// Coba Anndy
func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupTryAndy(c echo.Context) error {
logger, _ := zap.NewProduction()

View File

@@ -0,0 +1,74 @@
package public_handlers
import (
"cpone/models"
"cpone/utils"
"cpone/views/dev/mastermenuusergroup"
tablecomponent "cpone/component/table"
public_toast "cpone/views/public/toast"
"github.com/labstack/echo/v4"
)
type ToolsService interface {
}
func NewToolsHandler(us ToolsService) *ToolsHandler {
return &ToolsHandler{
ToolsService: us,
}
}
type ToolsHandler struct {
ToolsService ToolsService
}
func (lh *ToolsHandler) HandlerHideToast(c echo.Context) error {
toastComponent := public_toast.PublicToastV1Hide()
si := toastComponent
return utils.View(c, si)
}
func (lh *ToolsHandler) HandlerShowToast(c echo.Context) error {
inputansearchComponent := tablecomponent.DivEmpty()
toastComponent := public_toast.PublicToastV1Show("Success", "Success Loaded", "success")
pagination := tablecomponent.DivEmpty()
dummyData := []models.UserGroupV1{
{
Nomor: "1",
M_UserGroupID: 1,
M_UserGroupCode: "group1",
M_UserGroupName: "Group 1",
M_UserGroupCreated: "2024-05-16",
M_UserGroupLastUpdated: "2024-05-16",
M_UserGroupIsActive: "Active",
},
}
tabelusergroupComponent := tablecomponent.TableV2(
[]string{"KODE", "USERGROUP", "AKSI"},
[]string{"40%", "40%", "20%"},
mastermenuusergroup.TableRowV1(dummyData),
pagination,
"",
inputansearchComponent,
toastComponent,
)
si := public_toast.ShowToast("",
tabelusergroupComponent,
tabelusergroupComponent,
tabelusergroupComponent,
tabelusergroupComponent,
tabelusergroupComponent,
tabelusergroupComponent,
)
return utils.View(c, si)
}

View File

@@ -70,6 +70,11 @@ func SetupRoutesPublic(app *echo.Echo, appStore db.AppStore) {
public.GET("landingpage", lh.ShowLandingPage)
loginHdr := public_handlers.NewLoginHandler(l)
public.GET("login", loginHdr.HandlerShowLogin)
// FOR TOAST
toastHdr := public_handlers.NewToolsHandler(l)
public.GET("toastpublic", toastHdr.HandlerShowToast)
public.GET("hidetoastpublic", toastHdr.HandlerHideToast)
}
func SetupRoutesCorporate(app *echo.Echo, appStore db.AppStore) {
public := app.Group("/corp")
@@ -192,6 +197,7 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) {
dev.POST("/usergroup/add", devUGhandlers.AddUserGroup)
dev.POST("/usergroup/edit", devUGhandlers.EditUserGroup)
dev.GET("/usergroup/delete/:id", devUGhandlers.DeleteUserGroup)
dev.GET("/hidetoast", devUGhandlers.HandlerHideToast)
// try
dev.GET("/usergroupv1", devUGhandlers.HandlerShowMasterMenuUserGroupV1)