From 7a93a4994ae875bca5dcfc0ed826c1e2ee615b24 Mon Sep 17 00:00:00 2001 From: sindhu Date: Thu, 16 May 2024 17:20:23 +0700 Subject: [PATCH] toast handle error dan toast show in input search --- .../asset-corporate-portal/css/sas.bundle.css | 5 + component/table/tablev2.templ | 8 +- component/table/tablev2_templ.go | 6 +- component/toastbootstrap/customtoastv2.templ | 86 +++++++ .../toastbootstrap/customtoastv2_templ.go | 175 ++++++++++++++ handlers/dev/mastermenuusergroup.handlers.go | 127 ++++++++-- handlers/public/tools.handlers.go | 74 ++++++ handlers/routes.go | 6 + layout/layout_corporate.templ | 22 +- layout/layout_corporate_templ.go | 2 +- .../mastermenuusergroupv1.templ | 5 +- .../mastermenuusergroupv1_templ.go | 3 +- .../mastermenuusergroupv1.templ | 6 +- .../mastermenuusergroupv1_templ.go | 3 +- views/public/toast/toastpublicv1.templ | 100 ++++++++ views/public/toast/toastpublicv1_templ.go | 221 ++++++++++++++++++ 16 files changed, 822 insertions(+), 27 deletions(-) create mode 100644 component/toastbootstrap/customtoastv2.templ create mode 100644 component/toastbootstrap/customtoastv2_templ.go create mode 100644 handlers/public/tools.handlers.go create mode 100644 views/public/toast/toastpublicv1.templ create mode 100644 views/public/toast/toastpublicv1_templ.go diff --git a/assets/asset-corporate-portal/css/sas.bundle.css b/assets/asset-corporate-portal/css/sas.bundle.css index 35dd29b..e57cbd7 100644 --- a/assets/asset-corporate-portal/css/sas.bundle.css +++ b/assets/asset-corporate-portal/css/sas.bundle.css @@ -5200,6 +5200,11 @@ a.text-hover-tosca:hover .svg-icon svg:hover g [fill], height: auto; } +/* ### TOAST FONT SIZE */ +.toast { + font-size: 1.1rem; +} + /* ### BUTTON HOVER TEXT */ /* ### */ /* ## PRIMARY */ diff --git a/component/table/tablev2.templ b/component/table/tablev2.templ index a187755..971db2f 100644 --- a/component/table/tablev2.templ +++ b/component/table/tablev2.templ @@ -1,6 +1,6 @@ package tablecomponent -templ TableV2(thName []string, thWidth []string, trComponent templ.Component, pagination templ.Component, idunique string, inputanSearch templ.Component) { +templ TableV2(thName []string, thWidth []string, trComponent templ.Component, pagination templ.Component, idunique string, inputanSearch templ.Component, toastX templ.Component) { if len(thName) != len(thWidth) {
length array thname berbeda dengan array thwidth
} else { @@ -23,10 +23,10 @@ templ TableV2(thName []string, thWidth []string, trComponent templ.Component, pa @pagination + @toastX } } templ DivEmpty() { -
-
-} \ No newline at end of file +
+} diff --git a/component/table/tablev2_templ.go b/component/table/tablev2_templ.go index 5ca7e4b..48943c6 100644 --- a/component/table/tablev2_templ.go +++ b/component/table/tablev2_templ.go @@ -10,7 +10,7 @@ import "context" import "io" import "bytes" -func TableV2(thName []string, thWidth []string, trComponent templ.Component, pagination templ.Component, idunique string, inputanSearch templ.Component) templ.Component { +func TableV2(thName []string, thWidth []string, trComponent templ.Component, pagination templ.Component, idunique string, inputanSearch templ.Component, toastX templ.Component) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -102,6 +102,10 @@ func TableV2(thName []string, thWidth []string, trComponent templ.Component, pag if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = toastX.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } } if !templ_7745c5c3_IsBuffer { _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) diff --git a/component/toastbootstrap/customtoastv2.templ b/component/toastbootstrap/customtoastv2.templ new file mode 100644 index 0000000..63db879 --- /dev/null +++ b/component/toastbootstrap/customtoastv2.templ @@ -0,0 +1,86 @@ +package customtoastv1 + +// kalau eror => bg nya danger +// kalau sukses => bgnya success +// kalau warning => bgnya warning + +func toastBackground(typeToast string) string { + return "bg-" + typeToast +} + +func toastBody(typeToastBody string) string { + return "bg-" + typeToastBody + "-transparent" +} + +func toastIcon(typeToast string) string { + var stringx string + if typeToast == "success" { + stringx = "solar:check-circle-broken" + } else { + if typeToast == "danger" { + stringx = "solar:close-circle-broken" + } else { + if typeToast == "warning" { + stringx = "solar:shield-warning-bold" + } else { + if typeToast == "information" { + stringx = "solar:info-square-broken" + } + } + } + } + + return stringx +} + +templ CustomToastV2Show(title string, message string, typeToast string) { + +} + +templ CustomToastV2Hide() { + +} diff --git a/component/toastbootstrap/customtoastv2_templ.go b/component/toastbootstrap/customtoastv2_templ.go new file mode 100644 index 0000000..ca03e98 --- /dev/null +++ b/component/toastbootstrap/customtoastv2_templ.go @@ -0,0 +1,175 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package customtoastv1 + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +// kalau eror => bg nya danger +// kalau sukses => bgnya success +// kalau warning => bgnya warning + +func toastBackground(typeToast string) string { + return "bg-" + typeToast +} + +func toastBody(typeToastBody string) string { + return "bg-" + typeToastBody + "-transparent" +} + +func toastIcon(typeToast string) string { + var stringx string + if typeToast == "success" { + stringx = "solar:check-circle-broken" + } else { + if typeToast == "danger" { + stringx = "solar:close-circle-broken" + } else { + if typeToast == "warning" { + stringx = "solar:shield-warning-bold" + } else { + if typeToast == "information" { + stringx = "solar:info-square-broken" + } + } + } + } + + return stringx +} + +func CustomToastV2Show(title string, message string, typeToast string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 = []any{"toast-header", toastBackground(typeToast), "text-white"} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `component\toastbootstrap\customtoastv2.templ`, Line: 54, Col: 34} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 = []any{"toast-body", toastBody(typeToast)} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var6...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(message) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `component\toastbootstrap\customtoastv2.templ`, Line: 60, Col: 12} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func CustomToastV2Hide() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Success just now
This is a success toast.\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/handlers/dev/mastermenuusergroup.handlers.go b/handlers/dev/mastermenuusergroup.handlers.go index c247909..17118f1 100644 --- a/handlers/dev/mastermenuusergroup.handlers.go +++ b/handlers/dev/mastermenuusergroup.handlers.go @@ -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() diff --git a/handlers/public/tools.handlers.go b/handlers/public/tools.handlers.go new file mode 100644 index 0000000..f976a60 --- /dev/null +++ b/handlers/public/tools.handlers.go @@ -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) +} diff --git a/handlers/routes.go b/handlers/routes.go index 5f25680..7b7f1cd 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -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) diff --git a/layout/layout_corporate.templ b/layout/layout_corporate.templ index 36e969b..6603edf 100644 --- a/layout/layout_corporate.templ +++ b/layout/layout_corporate.templ @@ -1,7 +1,7 @@ package layout // LAYOUT PLAYGROUND -templ CorporateLayout(title string, css templ.Component, js templ.Component, navbarmenu templ.Component, +templ CorporateLayout(title string, css templ.Component, js templ.Component, navbarmenu templ.Component, navbaruser templ.Component, sidebaruserprofile templ.Component) {
+ // toast +
+ + +
+ // end toast + { children... }
diff --git a/layout/layout_corporate_templ.go b/layout/layout_corporate_templ.go index fffd952..c051324 100644 --- a/layout/layout_corporate_templ.go +++ b/layout/layout_corporate_templ.go @@ -62,7 +62,7 @@ func CorporateLayout(title string, css templ.Component, js templ.Component, navb if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Success just now
This is a success toast.\r
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/dev/mastermenuusergroup/mastermenuusergroupv1.templ b/views/dev/mastermenuusergroup/mastermenuusergroupv1.templ index c1dbd05..768943b 100644 --- a/views/dev/mastermenuusergroup/mastermenuusergroupv1.templ +++ b/views/dev/mastermenuusergroup/mastermenuusergroupv1.templ @@ -211,8 +211,9 @@ templ JsMasterMenuUserGroupV1x() { templ ShowMasterMenuUserGroupV1x(title string, cmp templ.Component, css templ.Component, js templ.Component, navbarmenu templ.Component, navbaruser templ.Component, - userprofile templ.Component) { - @layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile) { + userprofile templ.Component, + ) { + @layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile,) { @cmp } } diff --git a/views/dev/mastermenuusergroup/mastermenuusergroupv1_templ.go b/views/dev/mastermenuusergroup/mastermenuusergroupv1_templ.go index adee32d..b6fa333 100644 --- a/views/dev/mastermenuusergroup/mastermenuusergroupv1_templ.go +++ b/views/dev/mastermenuusergroup/mastermenuusergroupv1_templ.go @@ -321,7 +321,8 @@ func JsMasterMenuUserGroupV1x() templ.Component { func ShowMasterMenuUserGroupV1x(title string, cmp templ.Component, css templ.Component, js templ.Component, navbarmenu templ.Component, navbaruser templ.Component, - userprofile templ.Component) templ.Component { + userprofile templ.Component, +) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { diff --git a/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1.templ b/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1.templ index 928aa27..06512ae 100644 --- a/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1.templ +++ b/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1.templ @@ -211,8 +211,10 @@ templ JsMasterMenuUserGroupV1x() { templ ShowMasterMenuUserGroupV1x(title string, cmp templ.Component, css templ.Component, js templ.Component, navbarmenu templ.Component, navbaruser templ.Component, - userprofile templ.Component) { - @layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile) { + userprofile templ.Component, + ) { + @layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile, + ) { @cmp } } diff --git a/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1_templ.go b/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1_templ.go index 6e1833e..db20c8a 100644 --- a/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1_templ.go +++ b/views/dev/mastermenuusergrouptryandy/mastermenuusergroupv1_templ.go @@ -323,7 +323,8 @@ func JsMasterMenuUserGroupV1x() templ.Component { func ShowMasterMenuUserGroupV1x(title string, cmp templ.Component, css templ.Component, js templ.Component, navbarmenu templ.Component, navbaruser templ.Component, - userprofile templ.Component) templ.Component { + userprofile templ.Component, +) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { diff --git a/views/public/toast/toastpublicv1.templ b/views/public/toast/toastpublicv1.templ new file mode 100644 index 0000000..ff5e872 --- /dev/null +++ b/views/public/toast/toastpublicv1.templ @@ -0,0 +1,100 @@ +package public_toast + +import ( + "cpone/layout" +) + +// kalau eror => bg nya danger +// kalau sukses => bgnya success +// kalau warning => bgnya warning + +func toastBackground(typeToast string) string { + return "bg-" + typeToast +} + +func toastBody(typeToastBody string) string { + return "bg-" + typeToastBody + "-transparent" +} + +func toastIcon(typeToast string) string { + var stringx string + if typeToast == "success" { + stringx = "solar:check-circle-broken" + } else { + if typeToast == "danger" { + stringx = "solar:close-circle-broken" + } else { + if typeToast == "warning" { + stringx = "solar:shield-warning-bold" + } else { + if typeToast == "information" { + stringx = "solar:info-square-broken" + } + } + } + } + + return stringx +} + +templ PublicToastV1Show(title string, message string, typeToast string) { + +} + +templ PublicToastV1Hide() { + +} + +templ ShowToast(title string, cmp templ.Component, css templ.Component, js templ.Component, + navbarmenu templ.Component, + navbaruser templ.Component, + userprofile templ.Component) { + @layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile) { + @cmp + } +} diff --git a/views/public/toast/toastpublicv1_templ.go b/views/public/toast/toastpublicv1_templ.go new file mode 100644 index 0000000..62252dc --- /dev/null +++ b/views/public/toast/toastpublicv1_templ.go @@ -0,0 +1,221 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package public_toast + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "cpone/layout" +) + +// kalau eror => bg nya danger +// kalau sukses => bgnya success +// kalau warning => bgnya warning + +func toastBackground(typeToast string) string { + return "bg-" + typeToast +} + +func toastBody(typeToastBody string) string { + return "bg-" + typeToastBody + "-transparent" +} + +func toastIcon(typeToast string) string { + var stringx string + if typeToast == "success" { + stringx = "solar:check-circle-broken" + } else { + if typeToast == "danger" { + stringx = "solar:close-circle-broken" + } else { + if typeToast == "warning" { + stringx = "solar:shield-warning-bold" + } else { + if typeToast == "information" { + stringx = "solar:info-square-broken" + } + } + } + } + + return stringx +} + +func PublicToastV1Show(title string, message string, typeToast string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 = []any{"toast-header", toastBackground(typeToast), "text-white"} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\public\toast\toastpublicv1.templ`, Line: 58, Col: 34} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 = []any{"toast-body", toastBody(typeToast)} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var6...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(message) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\public\toast\toastpublicv1.templ`, Line: 64, Col: 12} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func PublicToastV1Hide() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Success just now
This is a success toast.\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func ShowToast(title string, cmp templ.Component, css templ.Component, js templ.Component, + navbarmenu templ.Component, + navbaruser templ.Component, + userprofile templ.Component) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var10 := templ.GetChildren(ctx) + if templ_7745c5c3_Var10 == nil { + templ_7745c5c3_Var10 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var11 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Err = cmp.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile).Render(templ.WithChildren(ctx, templ_7745c5c3_Var11), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +}