Bilder als Antworten hinzugefügt
This commit is contained in:
parent
2b9d9d7656
commit
404e079343
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
tmp
|
tmp
|
||||||
test.sql
|
test.sql
|
||||||
|
static/test.jpg
|
||||||
|
@ -97,7 +97,7 @@ INSERT INTO questions (
|
|||||||
( 'Was ist 1+1?', '1', '2', '3', '4', '2' ),
|
( 'Was ist 1+1?', '1', '2', '3', '4', '2' ),
|
||||||
( 'Was ist 1+2?', '1', '2', '3', '4', '3' ),
|
( 'Was ist 1+2?', '1', '2', '3', '4', '3' ),
|
||||||
( 'Was ist 2+2?', '1', '2', '3', '4', '4' ),
|
( 'Was ist 2+2?', '1', '2', '3', '4', '4' ),
|
||||||
( 'Was ist 0+1?', '1', '2', '3', '4', '1' );
|
( 'Was ist 0+1?', '1', '2', '3', 'file://static/test.jpg', '1' );
|
||||||
--
|
--
|
||||||
--INSERT INTO given_answers (
|
--INSERT INTO given_answers (
|
||||||
-- briefing_id, participant_id, question_id, given_answer
|
-- briefing_id, participant_id, question_id, given_answer
|
||||||
|
@ -40,8 +40,9 @@ type Briefing struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Answer struct {
|
type Answer struct {
|
||||||
ID int64
|
ID int64
|
||||||
Text string
|
Text string
|
||||||
|
IsImage bool // TODO: relocate to sessionStructs if possible
|
||||||
}
|
}
|
||||||
|
|
||||||
type Question struct {
|
type Question struct {
|
||||||
|
@ -15,8 +15,10 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
)
|
)
|
||||||
@ -71,7 +73,9 @@ func makeHTMLQuestions(sq []data.Question, givenAnswers []int) []resultQuestion
|
|||||||
questions[i].Answers = make([]resultAnswer, len(q.Answers))
|
questions[i].Answers = make([]resultAnswer, len(q.Answers))
|
||||||
|
|
||||||
for j := range q.Answers {
|
for j := range q.Answers {
|
||||||
|
questions[i].Answers[j].ID = q.Answers[j].ID
|
||||||
questions[i].Answers[j].Text = q.Answers[j].Text
|
questions[i].Answers[j].Text = q.Answers[j].Text
|
||||||
|
questions[i].Answers[j].IsImage = q.Answers[j].IsImage
|
||||||
|
|
||||||
if j+1 == q.Correct {
|
if j+1 == q.Correct {
|
||||||
questions[i].Answers[j].Correct = true
|
questions[i].Answers[j].Correct = true
|
||||||
@ -89,3 +93,29 @@ func makeHTMLQuestions(sq []data.Question, givenAnswers []int) []resultQuestion
|
|||||||
|
|
||||||
return questions
|
return questions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Session) getQuestions(db *data.DB) {
|
||||||
|
questionIDs := make([]string, 4)
|
||||||
|
|
||||||
|
for i := 0; i < len(questionIDs); i++ {
|
||||||
|
questionIDs[i] = fmt.Sprint(i + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
s.Questions, err = db.GetQuestions(questionIDs)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: ggf. weniger komplex durch Pointer machen
|
||||||
|
for i := range s.Questions {
|
||||||
|
for j := range s.Questions[i].Answers {
|
||||||
|
if parts := strings.Split(s.Questions[i].Answers[j].Text, ":/"); parts[0] == "file" {
|
||||||
|
s.Questions[i].Answers[j].Text = parts[1]
|
||||||
|
s.Questions[i].Answers[j].IsImage = true
|
||||||
|
} else {
|
||||||
|
s.Questions[i].Answers[j].IsImage = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -33,9 +33,11 @@ type questionHTMLData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type resultAnswer struct {
|
type resultAnswer struct {
|
||||||
|
ID int64
|
||||||
Text string
|
Text string
|
||||||
Correct bool
|
Correct bool
|
||||||
Chosen bool
|
Chosen bool
|
||||||
|
IsImage bool // TODO: relocate to sessionStructs if possible
|
||||||
}
|
}
|
||||||
|
|
||||||
type resultQuestion struct {
|
type resultQuestion struct {
|
||||||
|
@ -13,7 +13,6 @@ package session
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
@ -42,17 +41,7 @@ func (mux *Mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session)
|
|||||||
for s := range cs {
|
for s := range cs {
|
||||||
(*ss) = append((*ss), s)
|
(*ss) = append((*ss), s)
|
||||||
participantChan := make(chan *BriefingParticipant)
|
participantChan := make(chan *BriefingParticipant)
|
||||||
questionIDs := make([]string, 4)
|
s.getQuestions(db)
|
||||||
|
|
||||||
for i := 0; i < len(questionIDs); i++ {
|
|
||||||
questionIDs[i] = fmt.Sprint(i + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
s.Questions, err = db.GetQuestions(questionIDs)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mux.HandleFunc("/search/"+fmt.Sprint(s.ID)+"/", s.HandleSearch(db))
|
mux.HandleFunc("/search/"+fmt.Sprint(s.ID)+"/", s.HandleSearch(db))
|
||||||
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.ID)+"/", s.HandleNewBriefing())
|
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.ID)+"/", s.HandleNewBriefing())
|
||||||
|
@ -13,7 +13,11 @@
|
|||||||
{{range .Question.Answers}}
|
{{range .Question.Answers}}
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" name="answer" id="answer-{{.ID}}" value="{{.ID}}" />
|
<input type="radio" name="answer" id="answer-{{.ID}}" value="{{.ID}}" />
|
||||||
|
{{if .IsImage}}
|
||||||
|
<img src="{{.Text}}" alt="{{.Text}}" />
|
||||||
|
{{else}}
|
||||||
<label for="answer-{{.ID}}">{{.Text}}</label>
|
<label for="answer-{{.ID}}">{{.Text}}</label>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -11,11 +11,18 @@
|
|||||||
|
|
||||||
{{define "answers"}}
|
{{define "answers"}}
|
||||||
{{range .Answers}}
|
{{range .Answers}}
|
||||||
|
{{if .IsImage}}
|
||||||
|
<span class="{{if and .Chosen .Correct}} correct {{else if and .Chosen (not .Correct)}} incorrect {{end}}">
|
||||||
|
{{.ID}}.
|
||||||
|
</span>
|
||||||
|
<img src="{{.Text}}" alt="{{.Text}}" />
|
||||||
|
{{else}}
|
||||||
<p class="{{if and .Chosen .Correct}} correct {{else if and .Chosen (not .Correct)}} incorrect {{end}}">
|
<p class="{{if and .Chosen .Correct}} correct {{else if and .Chosen (not .Correct)}} incorrect {{end}}">
|
||||||
{{.Text}}
|
{{.Text}}
|
||||||
</p>
|
</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<p>{{.BriefingParticipant.NoIncorrect}} Fehler</p>
|
<p>{{.BriefingParticipant.NoIncorrect}} Fehler</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user