fix: if empty que title not render answers

This commit is contained in:
skeris 2025-06-17 17:21:37 +03:00
parent d0d7b1af55
commit 19cba7f57e
3 changed files with 11 additions and 5 deletions

@ -483,7 +483,7 @@
</tr> </tr>
{{ range .AllAnswers }} {{ range .AllAnswers }}
{{ if index $.QuestionsMap .AnswerID }} {{ if keyExists $.QuestionsMap .AnswerID }}
<tr> <tr>
<td colspan="2" style="padding: 0"> <td colspan="2" style="padding: 0">
<table <table

@ -6,9 +6,10 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"gitea.pena/SQuiz/common/model"
"golang.org/x/net/html" "golang.org/x/net/html"
"html/template" "html/template"
"gitea.pena/SQuiz/common/model" "io"
"strings" "strings"
) )
@ -54,6 +55,10 @@ func generateTextFromTemplate(data TemplateData, tpl string) (string, error) {
} }
var tmplFuncs = template.FuncMap{ var tmplFuncs = template.FuncMap{
"keyExists": func(m map[uint64]string, key uint64) bool {
_, ok := m[key]
return ok
},
"renderImage": RenderImage, "renderImage": RenderImage,
} }
@ -74,7 +79,7 @@ func RenderImage(content string) template.HTML {
if err != nil { if err != nil {
return SplitContent(content) return SplitContent(content)
} else { } else {
builder.WriteString(fmt.Sprintf("<td>%s<br><img class=\"image\" style=\"width:100%%; max-width:250px; max-height:250px\" src=\"%s\"/></td>", res.Description, strings.Replace(res.Image,"http","https",1))) builder.WriteString(fmt.Sprintf("<td>%s<br><img class=\"image\" style=\"width:100%%; max-width:250px; max-height:250px\" src=\"%s\"/></td>", res.Description, strings.Replace(res.Image, "http", "https", 1)))
} }
} }
@ -105,7 +110,7 @@ func sanitizeHTMLData(data TemplateData) TemplateData {
AllAnswers: stripHTMLResultAnswers(data.AllAnswers), AllAnswers: stripHTMLResultAnswers(data.AllAnswers),
QuestionsMap: stripHTMLResultMap(data.QuestionsMap), QuestionsMap: stripHTMLResultMap(data.QuestionsMap),
AnswerTime: StripHTML(data.AnswerTime), AnswerTime: StripHTML(data.AnswerTime),
QuizID: data.QuizID, QuizID: data.QuizID,
} }
return sanitized return sanitized
} }

@ -80,6 +80,7 @@
<tr> <tr>
<td colspan="2" style="height: 100%"> <td colspan="2" style="height: 100%">
<a <a
href="https://quiz.pena.digital/results/{{ .QuizID }}"
style=" style="
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -482,7 +483,7 @@
</tr> </tr>
{{ range .AllAnswers }} {{ range .AllAnswers }}
{{ if index $.QuestionsMap .AnswerID }} {{ if keyExists $.QuestionsMap .AnswerID }}
<tr> <tr>
<td colspan="2" style="padding: 0"> <td colspan="2" style="padding: 0">
<table <table