Bilder als Antworten hinzugefügt
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1,3 @@ | ||||
| tmp | ||||
| test.sql | ||||
| static/test.jpg | ||||
|   | ||||
| @@ -97,7 +97,7 @@ INSERT INTO questions ( | ||||
|   ( 'Was ist 1+1?', '1', '2', '3', '4', '2' ), | ||||
|   ( 'Was ist 1+2?', '1', '2', '3', '4', '3' ), | ||||
|   ( '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 ( | ||||
| --  briefing_id, participant_id, question_id, given_answer | ||||
|   | ||||
| @@ -40,8 +40,9 @@ type Briefing struct { | ||||
| } | ||||
|  | ||||
| type Answer struct { | ||||
| 	ID   int64 | ||||
| 	Text string | ||||
| 	ID      int64 | ||||
| 	Text    string | ||||
| 	IsImage bool // TODO: relocate to sessionStructs if possible | ||||
| } | ||||
|  | ||||
| type Question struct { | ||||
|   | ||||
| @@ -15,8 +15,10 @@ import ( | ||||
| 	"crypto/rand" | ||||
| 	"encoding/hex" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"net/http" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"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)) | ||||
|  | ||||
| 		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].IsImage = q.Answers[j].IsImage | ||||
|  | ||||
| 			if j+1 == q.Correct { | ||||
| 				questions[i].Answers[j].Correct = true | ||||
| @@ -89,3 +93,29 @@ func makeHTMLQuestions(sq []data.Question, givenAnswers []int) []resultQuestion | ||||
|  | ||||
| 	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 { | ||||
| 	ID      int64 | ||||
| 	Text    string | ||||
| 	Correct bool | ||||
| 	Chosen  bool | ||||
| 	IsImage bool // TODO: relocate to sessionStructs if possible | ||||
| } | ||||
|  | ||||
| type resultQuestion struct { | ||||
|   | ||||
| @@ -13,7 +13,6 @@ package session | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"net/http" | ||||
|  | ||||
| 	"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 { | ||||
| 		(*ss) = append((*ss), s) | ||||
| 		participantChan := make(chan *BriefingParticipant) | ||||
| 		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) | ||||
| 		} | ||||
| 		s.getQuestions(db) | ||||
|  | ||||
| 		mux.HandleFunc("/search/"+fmt.Sprint(s.ID)+"/", s.HandleSearch(db)) | ||||
| 		mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.ID)+"/", s.HandleNewBriefing()) | ||||
|   | ||||
| @@ -13,7 +13,11 @@ | ||||
| {{range .Question.Answers}} | ||||
| <div> | ||||
|   <input type="radio" name="answer" id="answer-{{.ID}}" value="{{.ID}}" /> | ||||
|   {{if .IsImage}} | ||||
|   <img src="{{.Text}}" alt="{{.Text}}" /> | ||||
|   {{else}} | ||||
|   <label for="answer-{{.ID}}">{{.Text}}</label> | ||||
|   {{end}} | ||||
| </div> | ||||
| {{end}} | ||||
| {{end}} | ||||
|   | ||||
| @@ -11,11 +11,18 @@ | ||||
|  | ||||
| {{define "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}}"> | ||||
|   {{.Text}} | ||||
| </p> | ||||
| {{end}} | ||||
| {{end}} | ||||
| {{end}} | ||||
|  | ||||
| {{define "content"}} | ||||
| <p>{{.BriefingParticipant.NoIncorrect}} Fehler</p> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user