From 445d238426d04d0bc353ea180f52a4d3c8502bc9 Mon Sep 17 00:00:00 2001 From: sindhu Date: Wed, 22 May 2024 09:24:18 +0700 Subject: [PATCH] step 9 : add notif saran mcu, perbaikan utils hx include --- handlers/public/surveymcu.handlers.go | 56 ++++--- models/surveymcu.models.go | 9 +- services/public/surveymcu.services.go | 11 +- utils/surveymcu.utils.go | 50 +++++-- views/public/surveymcu/surveymcu.templ | 50 +++---- views/public/surveymcu/surveymcu_templ.go | 171 +++++++++++++++------- 6 files changed, 239 insertions(+), 108 deletions(-) diff --git a/handlers/public/surveymcu.handlers.go b/handlers/public/surveymcu.handlers.go index 3e3be0f..9bed7f1 100644 --- a/handlers/public/surveymcu.handlers.go +++ b/handlers/public/surveymcu.handlers.go @@ -50,11 +50,7 @@ func (lh *SurveyMcuHandler) HandlerShowSurveyMcu(c echo.Context) error { var idClearMsg []models.IdClearErrorMessage if len(dataSurveyMcu) > 0 { - for _, v := range dataSurveyMcu { - if len(v.DataListItemSurveyMcu) > 0 { - hxInclude = utils.ConcatHxIncludeSurveyMcu(v.DataListItemSurveyMcu) - } - } + hxInclude = utils.ConcatHxIncludeSurveyMcu(dataSurveyMcu) } si := surveymcu.ShowSurveyMcu("Survey Mcu", @@ -84,13 +80,12 @@ func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { zap.Any("prm", nomorRegistrasi), ) - form := c.Request().PostForm + // form := c.Request().PostForm // stringUrl := "surveymcuproses/" + nomorRegistrasi logger.Info("CEK POST handler", - zap.Any("c.FormValue", c.FormValue(form.Get("radio-1"))), - zap.Any("name dari inputan", form.Get("radio-1")), + zap.Any("c.FormValue Saran", c.FormValue("saranmcu-11")), ) // proses validasi @@ -103,8 +98,11 @@ func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { var idSaranMcuAlert string = "" // var idSaranMcuClear string = "" + hasError := false + if len(dataSurveyMcu) > 0 { for _, v := range dataSurveyMcu { + // radio button if len(v.DataListItemSurveyMcu) > 0 { for _, x := range v.DataListItemSurveyMcu { @@ -113,27 +111,44 @@ func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { } if "default-"+x.NameRadioButton == c.FormValue("default-"+x.NameRadioButton) && len(c.FormValue("radio-"+x.IDItemSurvey)) == 0 { - stringMessage += "Pertanyaan ke-" + x.IDItemSurvey + " wajib diisi," - idFormKosong += utils.GetIdSurveyMcu(x.IDItemSurvey) + stringMessage = "Pertanyaan ke-" + x.IDItemSurvey + " wajib diisi," + idFormKosong = utils.GetIdSurveyMcu(x.IDItemSurvey) isFormEmpty = true + hasError = true break } } } + + if hasError { + break + } } } - // if len(c.FormValue("saranMcu")) == 0 { - // isFormEmpty = true - // stringMessage += " Kemudian Saran Mcu Wajib Diisi" - // idSaranMcuAlert = "alertSaranMcu" - // } + // saran mcu + if !hasError && len(dataSurveyMcu) > 0 { + for _, v := range dataSurveyMcu { + if len(v.DataListItemSurveyMcuSaran) > 0 { + for _, x := range v.DataListItemSurveyMcuSaran { + if len(c.FormValue("saranmcu-"+x.IDItemSurveyMcuSaran)) > 0 { + idClearMsg = append(idClearMsg, models.IdClearErrorMessage{IdItem: x.IDItemSurveyMcuSaran}) + } - // if len(c.FormValue("saranMcu")) > 0 { - // isFormEmpty = false - // stringMessage += "" - // idSaranMcuAlert = "alertSaranMcu" - // } + if "default-"+x.NameSurveyMcuSaran == c.FormValue("default-"+x.NameSurveyMcuSaran) && len(c.FormValue("saranmcu-"+x.IDItemSurveyMcuSaran)) == 0 { + stringMessage = "Saran Wajib Diisi" + idFormKosong = utils.GetIdSurveyMcu(x.IDItemSurveyMcuSaran) + isFormEmpty = true + hasError = true + break + } + } + } + if hasError { + break + } + } + } if isFormEmpty { si = surveymcu.ErrorMessageSurveyMcu(stringMessage, idFormKosong, idClearMsg, idSaranMcuAlert) @@ -141,7 +156,6 @@ func (lh *SurveyMcuHandler) HandlerProcessSurveyMcu(c echo.Context) error { // surveymcu.MainContentSurveyMcuLayout(dataSurveyMcu, nomorRegistrasi, surveymcu.ErrorMessageSurveyMcu(stringMessage, idFormKosong)), surveymcu.CssSurveyMcu(), surveymcu.JsSurveyMcu()) // si = surveymcu.FormSurvey(dataSurveyMcu, stringUrl) } else { - // var idClearMsgEmpty []models.IdClearErrorMessage si = surveymcu.ErrorMessageSurveyMcu("", "", idClearMsg, "") } diff --git a/models/surveymcu.models.go b/models/surveymcu.models.go index 2aaebec..a546cbe 100644 --- a/models/surveymcu.models.go +++ b/models/surveymcu.models.go @@ -1,7 +1,8 @@ package models type SurveyMcu struct { - DataListItemSurveyMcu []ItemSurveyMcu `json:"dataListItemSurveyMcu"` + DataListItemSurveyMcu []ItemSurveyMcu `json:"dataListItemSurveyMcu"` + DataListItemSurveyMcuSaran []ItemSurveyMcuSaran `json:"datalistitemsurveymcusaran"` } type ItemSurveyMcu struct { @@ -14,6 +15,12 @@ type ItemSurveyMcu struct { ErrorMessage string `json:"errorMessage"` } +type ItemSurveyMcuSaran struct { + IDItemSurveyMcuSaran string `json:"iditemsurveymcusaran"` + NameSurveyMcuSaran string `json:"namesurveymcusaran"` + ErrorMessageSurveyMcuSaran string `json:"errormessagesurveymcusaran"` +} + type IdClearErrorMessage struct { IdItem string `json:"iditem"` } diff --git a/services/public/surveymcu.services.go b/services/public/surveymcu.services.go index 678e384..5bd11a1 100644 --- a/services/public/surveymcu.services.go +++ b/services/public/surveymcu.services.go @@ -119,9 +119,18 @@ func (su *SurveyMcuService) GetSurveyMcuByNoreg(nomorRegistrasi string) ([]model }, } + dataItemSurveyMcuSaran := []models.ItemSurveyMcuSaran{ + { + IDItemSurveyMcuSaran: "11", + NameSurveyMcuSaran: "saranmcu-11", + ErrorMessageSurveyMcuSaran: "", + }, + } + surveymcu := []models.SurveyMcu{ { - DataListItemSurveyMcu: dataItemSurveyMcu, + DataListItemSurveyMcu: dataItemSurveyMcu, + DataListItemSurveyMcuSaran: dataItemSurveyMcuSaran, }, } diff --git a/utils/surveymcu.utils.go b/utils/surveymcu.utils.go index 120e136..ae02f94 100644 --- a/utils/surveymcu.utils.go +++ b/utils/surveymcu.utils.go @@ -1,24 +1,52 @@ package utils -import "cpone/models" +import ( + "cpone/models" + "strings" +) func GetIdSurveyMcu(id string) string { return id } -func ConcatHxIncludeSurveyMcu(data []models.ItemSurveyMcu) string { - var stringx string +// func ConcatHxIncludeSurveyMcu(data []models.ItemSurveyMcu) string { +// var stringx string - if len(data) > 0 { - for i, v := range data { - if i > 0 { - stringx += ", " +// 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 + + if len(dataSurveyMcu) > 0 { + for _, x := range dataSurveyMcu { + // radio button + if len(x.DataListItemSurveyMcu) > 0 { + for _, v := range x.DataListItemSurveyMcu { + elements = append(elements, "[name='radio-"+v.IDItemSurvey+"']", "[name='default-radio-"+v.IDItemSurvey+"']", "[name='id-radio']") + } + } + + // saran + if len(x.DataListItemSurveyMcuSaran) > 0 { + for _, v := range x.DataListItemSurveyMcuSaran { + elements = append(elements, "[name='saranmcu-"+v.IDItemSurveyMcuSaran+"']", "[name='default-saranmcu-"+v.IDItemSurveyMcuSaran+"']", "[name='id-saran']") + } } - stringx += "[name='radio-" + v.IDItemSurvey + "'], [name='default-radio-" + v.IDItemSurvey + "'], [name='id-radio']" } } - stringx += ",[name='saranMcu']" - - return stringx + // Gabungkan semua elemen dengan koma + return strings.Join(elements, ", ") } diff --git a/views/public/surveymcu/surveymcu.templ b/views/public/surveymcu/surveymcu.templ index 32b2071..c49b13c 100644 --- a/views/public/surveymcu/surveymcu.templ +++ b/views/public/surveymcu/surveymcu.templ @@ -5,14 +5,6 @@ import ( "cpone/layout" ) -func concatNameRadioButtonBaik(idPertanyaan string) string { - return "radio-baik-" + idPertanyaan -} - -func concatNameRadioButtonKurang(idPertanyaan string) string { - return "radio-kurang-" + idPertanyaan -} - func concatIdErrorMessage(idPertanyaan string) string { return "errorMessage-" + idPertanyaan } @@ -42,6 +34,7 @@ templ MainContentSurveyMcuLayout(dataSurveyMcu []models.SurveyMcu, urlPost strin
if len(dataSurveyMcu) > 0 { for _, v := range dataSurveyMcu { + // radio button if len(v.DataListItemSurveyMcu) > 0 { for _, k := range v.DataListItemSurveyMcu { @@ -98,25 +91,32 @@ templ MainContentSurveyMcuLayout(dataSurveyMcu []models.SurveyMcu, urlPost strin } } + // text area + if len(v.DataListItemSurveyMcuSaran) > 0 { + for _, q := range v.DataListItemSurveyMcuSaran { + + + + + + + } + } } } - - - -