diff --git a/handlers/public/kartukontrol.handlers.go b/handlers/public/kartukontrol.handlers.go index 62b6eee..660f473 100644 --- a/handlers/public/kartukontrol.handlers.go +++ b/handlers/public/kartukontrol.handlers.go @@ -4,6 +4,7 @@ import ( "cpone/models" "cpone/utils" kartukontrol "cpone/views/public/kartukontrol" + public_toast "cpone/views/public/toast" "github.com/a-h/templ" "github.com/labstack/echo/v4" @@ -24,9 +25,25 @@ type KartuKontrolHandler struct { KartuKontrolService KartuKontrolService } +func (lh *KartuKontrolHandler) HandlerHideToast(c echo.Context) error { + toastComponent := public_toast.PublicToastV1KartuKontrolHide() + + si := toastComponent + + return utils.View(c, si) +} + func (lh *KartuKontrolHandler) HandlerShowKartuKontrol(c echo.Context) error { + var flagxError bool = true + var msgx string = "" + nomorRegistrasi := c.Param("nomorRegistrasi") + + urlSurveyMcu := "redirectsurveymcu" + + // urlSurveyMcu := "redirectsurveymcu" + // nomorRegistrasi := "1" logger, _ := zap.NewProduction() defer logger.Sync() @@ -38,21 +55,27 @@ func (lh *KartuKontrolHandler) HandlerShowKartuKontrol(c echo.Context) error { zap.Any("Error", err), zap.Any("prm", nomorRegistrasi), ) - return err + // return err + if flagxError { + msgx = "Error Get Kartu Kontrol" + si := public_toast.PublicToastV1KartuKontrolShow("Error", msgx, "danger") + return utils.View(c, si) + } } logger.Info("SHOW DATA KARTU KONTROL handler", zap.Any("return", dataKartuKontrol), zap.Any("prm", nomorRegistrasi), ) + flagxError = false var si templ.Component var isShowSurveyMcu bool = true if isShowSurveyMcu { - si = kartukontrol.ShowKartuKontrol("Kartu Kontrol", kartukontrol.MainContentKartuKontrolLayout(dataKartuKontrol, "/modalsurveykartukontrol", "load delay:3s", "modalWordingSurveyMcu"), kartukontrol.CssKartuKontrol(), kartukontrol.JsKartuKontrol()) + si = kartukontrol.ShowKartuKontrol("Kartu Kontrol", kartukontrol.MainContentKartuKontrolLayout(dataKartuKontrol, "/modalsurveykartukontrol", "load delay:3s", "modalWordingSurveyMcu", urlSurveyMcu, nomorRegistrasi), kartukontrol.CssKartuKontrol(), kartukontrol.JsKartuKontrol()) } else { si = kartukontrol.ShowKartuKontrol("Kartu Kontrol", - kartukontrol.MainContentKartuKontrolLayout(dataKartuKontrol, "", "", "modalWordingSurveyMcu"), kartukontrol.CssKartuKontrol(), kartukontrol.JsKartuKontrol()) + kartukontrol.MainContentKartuKontrolLayout(dataKartuKontrol, "", "", "modalWordingSurveyMcu", urlSurveyMcu, nomorRegistrasi), kartukontrol.CssKartuKontrol(), kartukontrol.JsKartuKontrol()) } return utils.View(c, si) @@ -60,10 +83,36 @@ func (lh *KartuKontrolHandler) HandlerShowKartuKontrol(c echo.Context) error { func (lh *KartuKontrolHandler) HandlerShowWordingModalSurveyMcu(c echo.Context) error { + stringUrlToSurveyMcu := c.QueryParam("urlSurveyMcu") + // var dataKartuKontrol []models.KartuKontrolModel si := kartukontrol.ShowKartuKontrol( "Kartu Kontrol", - kartukontrol.ModalMcuWordingShow("modalWordingSurveyMcu", "Silahkan isi questioner untuk membantu peningkatan layanan kami. Terima kasih."), kartukontrol.CssKartuKontrol(), kartukontrol.JsKartuKontrol()) + kartukontrol.ModalMcuWordingShow("modalWordingSurveyMcu", "Silahkan isi questioner untuk membantu peningkatan layanan kami. Terima kasih.", stringUrlToSurveyMcu), kartukontrol.CssKartuKontrol(), kartukontrol.JsKartuKontrol()) + + return utils.View(c, si) +} + +func (lh *KartuKontrolHandler) HandlerRedirectToSurveyMcu(c echo.Context) error { + + nomorRegistrasi := c.QueryParam("nomorRegistrasi") + stringUrlToSurveyMcu := "/surveymcu/" + nomorRegistrasi + + logger, _ := zap.NewProduction() + defer logger.Sync() + + if len(stringUrlToSurveyMcu) > 0 { + // redirect ke kartu kontrol + logger.Info("redirect SURVEY MCU", + zap.Any("redirect SURVEY MCU", stringUrlToSurveyMcu), + ) + c.Response().Header().Set("HX-Redirect", stringUrlToSurveyMcu) + // return c.NoContent(http.StatusOK) + } + + si := kartukontrol.ShowKartuKontrol( + "Kartu Kontrol", + kartukontrol.ModalMcuWordingShow("modalWordingSurveyMcu", "Silahkan isi questioner untuk membantu peningkatan layanan kami. Terima kasih.", ""), kartukontrol.CssKartuKontrol(), kartukontrol.JsKartuKontrol()) return utils.View(c, si) } diff --git a/handlers/public/surveymcu.handlers.go b/handlers/public/surveymcu.handlers.go index 9a4ac42..60d4fb5 100644 --- a/handlers/public/surveymcu.handlers.go +++ b/handlers/public/surveymcu.handlers.go @@ -4,6 +4,7 @@ import ( "cpone/models" "cpone/utils" surveymcu "cpone/views/public/surveymcu" + public_toast "cpone/views/public/toast" "github.com/a-h/templ" "github.com/labstack/echo/v4" @@ -26,6 +27,9 @@ type SurveyMcuHandler struct { func (lh *SurveyMcuHandler) HandlerShowSurveyMcu(c echo.Context) error { + var flagxError bool = true + var msgx string = "" + nomorRegistrasi := c.Param("nomorRegistrasi") // nomorRegistrasi := "1" logger, _ := zap.NewProduction() @@ -38,8 +42,15 @@ func (lh *SurveyMcuHandler) HandlerShowSurveyMcu(c echo.Context) error { zap.Any("Error", err), zap.Any("prm", nomorRegistrasi), ) - return err + // return err + if flagxError { + msgx = "Error Get Survey MCU By No Reg" + si := public_toast.PublicToastV1KartuKontrolShow("Error", msgx, "danger") + return utils.View(c, si) + } } + + flagxError = false logger.Info("SHOW DATA SURVEY MCU handler", zap.Any("return", dataSurveyMcu), zap.Any("prm", nomorRegistrasi), @@ -54,14 +65,18 @@ func (lh *SurveyMcuHandler) HandlerShowSurveyMcu(c echo.Context) error { } si := surveymcu.ShowSurveyMcu("Survey Mcu", - surveymcu.MainContentSurveyMcuLayout(dataSurveyMcu, stringUrl, surveymcu.ErrorMessageSurveyMcu("", "", idClearMsg, "alertSaranMcu"), hxInclude), surveymcu.CssSurveyMcu(), surveymcu.JsSurveyMcu()) + surveymcu.MainContentSurveyMcuLayout(dataSurveyMcu, stringUrl, surveymcu.ErrorMessageSurveyMcu("", "", idClearMsg, "alertSaranMcu", public_toast.PublicToastV1KartuKontrolHide()), hxInclude), surveymcu.CssSurveyMcu(), surveymcu.JsSurveyMcu()) return utils.View(c, si) } func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { + var flagxError bool = true + var msgx string = "" + nomorRegistrasi := c.Param("nomorRegistrasi") + stringUrlBackToKartuKontrol := "/kartukontrol/" + nomorRegistrasi // nomorRegistrasi := "1" logger, _ := zap.NewProduction() defer logger.Sync() @@ -73,8 +88,14 @@ func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { zap.Any("Error", err), zap.Any("prm", nomorRegistrasi), ) - return err + // return err + if flagxError { + msgx = "Error Get Survey MCU By No Reg" + si := public_toast.PublicToastV1KartuKontrolShow("Error", msgx, "danger") + return utils.View(c, si) + } } + logger.Info("SHOW DATA SURVEY MCU handler", zap.Any("return", dataSurveyMcu), zap.Any("prm", nomorRegistrasi), @@ -115,6 +136,7 @@ func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { idFormKosong = utils.GetIdSurveyMcu(x.IDItemSurvey) isFormEmpty = true hasError = true + flagxError = true break } } @@ -151,18 +173,22 @@ func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { } if isFormEmpty { - si = surveymcu.ErrorMessageSurveyMcu(stringMessage, idFormKosong, idClearMsg, idSaranMcuAlert) - // si = surveymcu.ShowSurveyMcu("Survey Mcu", - // surveymcu.MainContentSurveyMcuLayout(dataSurveyMcu, nomorRegistrasi, surveymcu.ErrorMessageSurveyMcu(stringMessage, idFormKosong)), surveymcu.CssSurveyMcu(), surveymcu.JsSurveyMcu()) - // si = surveymcu.FormSurvey(dataSurveyMcu, stringUrl) + // if flagxError { + // msgx = "Error Get Survey MCU By No Reg" + // si := public_toast.PublicToastV1KartuKontrolShow("Error", msgx, "danger") + // return utils.View(c, si) + // } + si = surveymcu.ErrorMessageSurveyMcu(stringMessage, idFormKosong, idClearMsg, idSaranMcuAlert, public_toast.PublicToastV1KartuKontrolShow("Error", stringMessage, "danger")) } else { - si = surveymcu.ErrorMessageSurveyMcu("", "", idClearMsg, "") + flagxError = false + si = surveymcu.ErrorMessageSurveyMcu("", "", idClearMsg, "", public_toast.PublicToastV1KartuKontrolHide()) + logger.Info("redirect", + zap.Any("redirect", stringUrlBackToKartuKontrol), + ) + + // redirect ke kartu kontrol + c.Response().Header().Set("HX-Redirect", stringUrlBackToKartuKontrol) } - // stringMessage += fmt.Sprintf("Pertanyaan ke-%s", x.IDItemSurvey, " wajib diisi") - - // si := surveymcu.ShowSurveyMcu("Survey Mcu", - // surveymcu.MainContentSurveyMcuLayout(dataSurveyMcu, nomorRegistrasi), surveymcu.CssSurveyMcu(), surveymcu.JsSurveyMcu()) - return utils.View(c, si) } diff --git a/handlers/routes.go b/handlers/routes.go index 21b7490..4dc81b0 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -9,7 +9,6 @@ import ( corporate_services "cpone/services/corporate" dev_services "cpone/services/dev" public_services "cpone/services/public" - "net/http" "cpone/db" @@ -83,13 +82,14 @@ func SetupRoutesPublic(app *echo.Echo, appStore db.AppStore) { publicSurveyMcuhandlers := public_handlers.NewSurveyMcuHandler(publicSurveyMcuServices) public.GET("surveymcu/:nomorRegistrasi", publicSurveyMcuhandlers.HandlerShowSurveyMcu) - // contoh penggunaan header location spt php - app.GET("/redirectsurveymcu", func(c echo.Context) error { - return c.Redirect(http.StatusFound, "surveymcu/:nomorRegistrasi") - }) + // hide toast + public.GET("hidetoastkartukontrol", publicKartuKontrolhandlers.HandlerHideToast) // surveymcuproses public.POST("surveymcuproses/:nomorRegistrasi", publicSurveyMcuhandlers.HandlerProcessSurveyMcu) + + // redirect to survey mcu page + public.GET("redirectsurveymcu", publicKartuKontrolhandlers.HandlerRedirectToSurveyMcu) } func SetupRoutesCorporate(app *echo.Echo, appStore db.AppStore) { public := app.Group("/corp") diff --git a/utils/surveymcu.utils.go b/utils/surveymcu.utils.go index ae02f94..cf4c46d 100644 --- a/utils/surveymcu.utils.go +++ b/utils/surveymcu.utils.go @@ -9,23 +9,6 @@ func GetIdSurveyMcu(id string) string { return id } -// func ConcatHxIncludeSurveyMcu(data []models.ItemSurveyMcu) string { -// var stringx string - -// if len(data) > 0 { -// for i, v := range data { -// if i > 0 { -// stringx += ", " -// } -// stringx += "[name='radio-" + v.IDItemSurvey + "'], [name='default-radio-" + v.IDItemSurvey + "'], [name='id-radio']" -// } -// } - -// stringx += ",[name='saranMcu']" - -// return stringx -// } - func ConcatHxIncludeSurveyMcu(dataSurveyMcu []models.SurveyMcu) string { var elements []string diff --git a/views/public/kartukontrol/kartukontrol.templ b/views/public/kartukontrol/kartukontrol.templ index 9bfbe08..06f7ec8 100644 --- a/views/public/kartukontrol/kartukontrol.templ +++ b/views/public/kartukontrol/kartukontrol.templ @@ -5,7 +5,31 @@ import ( "cpone/layout" ) -templ MainContentKartuKontrolLayout(dataKartuKontrol []models.KartuKontrolModel, hxGet string, hxTrigger string, idModal string) { +templ MainContentKartuKontrolLayout(dataKartuKontrol []models.KartuKontrolModel, hxGet string, hxTrigger string, idModal string, urlSurveyMcu string, nomorRegistrasi string) { + // toast +
+ + +
+ // end toast
if len(dataKartuKontrol) > 0 { @@ -14,7 +38,7 @@ templ MainContentKartuKontrolLayout(dataKartuKontrol []models.KartuKontrolModel, }
- @ModalMcuWordingProcessShow(hxTrigger, hxGet, idModal) + @ModalMcuWordingProcessShow(hxTrigger, hxGet, idModal, urlSurveyMcu, nomorRegistrasi) } templ ContentDataPasienList(dataPasienList []models.DataPasien) { @@ -119,12 +143,14 @@ templ ContentPengambilanSampleList(dataPemeriksaanPengambilanSample []models.Dat
} -templ ModalMcuWordingProcessShow(hxTrigger string, hxGet string, idModal string) { -
+templ ModalMcuWordingProcessShow(hxTrigger string, hxGet string, idModal string, urlSurveyMcu string, nomorRegistrasi string) { + + +
} -templ ModalMcuWordingShow(idModal string, messageWording string) { +templ ModalMcuWordingShow(idModal string, messageWording string, urlSurvey string) { ") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -536,9 +575,9 @@ func CssKartuKontrol() templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var26 := templ.GetChildren(ctx) - if templ_7745c5c3_Var26 == nil { - templ_7745c5c3_Var26 = templ.NopComponent + templ_7745c5c3_Var29 := templ.GetChildren(ctx) + if templ_7745c5c3_Var29 == nil { + templ_7745c5c3_Var29 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") @@ -560,9 +599,9 @@ func JsKartuKontrol() templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var27 := templ.GetChildren(ctx) - if templ_7745c5c3_Var27 == nil { - templ_7745c5c3_Var27 = templ.NopComponent + templ_7745c5c3_Var30 := templ.GetChildren(ctx) + if templ_7745c5c3_Var30 == nil { + templ_7745c5c3_Var30 = templ.NopComponent } ctx = templ.ClearChildren(ctx) if !templ_7745c5c3_IsBuffer { @@ -580,12 +619,12 @@ func ShowKartuKontrol(title string, cmp templ.Component, css templ.Component, js defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var28 := templ.GetChildren(ctx) - if templ_7745c5c3_Var28 == nil { - templ_7745c5c3_Var28 = templ.NopComponent + templ_7745c5c3_Var31 := templ.GetChildren(ctx) + if templ_7745c5c3_Var31 == nil { + templ_7745c5c3_Var31 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var29 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var32 := 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() @@ -600,7 +639,7 @@ func ShowKartuKontrol(title string, cmp templ.Component, css templ.Component, js } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = layout.PlaygroundLayout(title, css, js).Render(templ.WithChildren(ctx, templ_7745c5c3_Var29), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = layout.PlaygroundLayout(title, css, js).Render(templ.WithChildren(ctx, templ_7745c5c3_Var32), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/public/surveymcu/surveymcu.templ b/views/public/surveymcu/surveymcu.templ index 7f80ca5..48a67f6 100644 --- a/views/public/surveymcu/surveymcu.templ +++ b/views/public/surveymcu/surveymcu.templ @@ -23,6 +23,30 @@ func isIDInClearList(IDItemSurvey string, idclear []models.IdClearErrorMessage) } templ MainContentSurveyMcuLayout(dataSurveyMcu []models.SurveyMcu, urlPost string, errorComp templ.Component, hxInclude string) { + // toast +
+ + +
+ // end toast
@@ -58,8 +82,8 @@ templ MainContentSurveyMcuLayout(dataSurveyMcu []models.SurveyMcu, urlPost strin
- - + +