Use markdown to format questions' descriptions
This commit is contained in:
parent
5fd17156fb
commit
42b15a1546
@ -64,8 +64,8 @@
|
|||||||
<h4 class="card-title" ng-if="!question.edit">{{qid + 1}}. {{ question.title }}</h4>
|
<h4 class="card-title" ng-if="!question.edit">{{qid + 1}}. {{ question.title }}</h4>
|
||||||
<div class="card-title form-group row" ng-if="question.edit"><label for="q{{qid}}title" class="col-auto col-form-label font-weight-bold">Titre :</label><div class="col"><input id="q{{qid}}title" class="form-control" ng-model="question.title"></div></div>
|
<div class="card-title form-group row" ng-if="question.edit"><label for="q{{qid}}title" class="col-auto col-form-label font-weight-bold">Titre :</label><div class="col"><input id="q{{qid}}title" class="form-control" ng-model="question.title"></div></div>
|
||||||
|
|
||||||
<p class="card-text" style="white-space: pre-line" ng-bind-html="question.description" ng-if="!question.edit"></p>
|
<p class="card-text" ng-bind-html="question.description" ng-if="!question.edit"></p>
|
||||||
<textarea class="form-control mb-2" ng-if="question.edit" ng-model="question.description" placeholder="Description de la question"></textarea>
|
<textarea class="form-control mb-2" ng-if="question.edit" ng-model="question.desc_raw" placeholder="Description de la question"></textarea>
|
||||||
|
|
||||||
<div class="form-group row" ng-if="question.edit">
|
<div class="form-group row" ng-if="question.edit">
|
||||||
<label class="col-2 col-form-label" for="q{{qid}}kind">Type de réponse</label>
|
<label class="col-2 col-form-label" for="q{{qid}}kind">Type de réponse</label>
|
||||||
|
20
questions.go
20
questions.go
@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
"gopkg.in/russross/blackfriday.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -35,7 +36,7 @@ func init() {
|
|||||||
return APIErrorResponse{err: err}
|
return APIErrorResponse{err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatApiResponse(s.NewQuestion(new.Title, new.Description, new.Placeholder, new.Kind))
|
return formatApiResponse(s.NewQuestion(new.Title, new.DescriptionRaw, new.Placeholder, new.Kind))
|
||||||
}), adminRestricted))
|
}), adminRestricted))
|
||||||
router.GET("/api/questions/:qid", apiHandler(questionHandler(
|
router.GET("/api/questions/:qid", apiHandler(questionHandler(
|
||||||
func(s Question, _ []byte) HTTPResponse {
|
func(s Question, _ []byte) HTTPResponse {
|
||||||
@ -124,6 +125,7 @@ type Question struct {
|
|||||||
IdSurvey int64 `json:"id_survey"`
|
IdSurvey int64 `json:"id_survey"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
DescriptionRaw string `json:"desc_raw,omitempty"`
|
||||||
Placeholder string `json:"placeholder,omitempty"`
|
Placeholder string `json:"placeholder,omitempty"`
|
||||||
Kind string `json:"kind"`
|
Kind string `json:"kind"`
|
||||||
}
|
}
|
||||||
@ -136,9 +138,10 @@ func getQuestions() (questions []Question, err error) {
|
|||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var q Question
|
var q Question
|
||||||
if err = rows.Scan(&q.Id, &q.IdSurvey, &q.Title, &q.Description, &q.Placeholder, &q.Kind); err != nil {
|
if err = rows.Scan(&q.Id, &q.IdSurvey, &q.Title, &q.DescriptionRaw, &q.Placeholder, &q.Kind); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
q.Description = string(blackfriday.Run([]byte(q.DescriptionRaw)))
|
||||||
questions = append(questions, q)
|
questions = append(questions, q)
|
||||||
}
|
}
|
||||||
if err = rows.Err(); err != nil {
|
if err = rows.Err(); err != nil {
|
||||||
@ -157,9 +160,10 @@ func (s *Survey) GetQuestions() (questions []Question, err error) {
|
|||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var q Question
|
var q Question
|
||||||
if err = rows.Scan(&q.Id, &q.IdSurvey, &q.Title, &q.Description, &q.Placeholder, &q.Kind); err != nil {
|
if err = rows.Scan(&q.Id, &q.IdSurvey, &q.Title, &q.DescriptionRaw, &q.Placeholder, &q.Kind); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
q.Description = string(blackfriday.Run([]byte(q.DescriptionRaw)))
|
||||||
questions = append(questions, q)
|
questions = append(questions, q)
|
||||||
}
|
}
|
||||||
if err = rows.Err(); err != nil {
|
if err = rows.Err(); err != nil {
|
||||||
@ -171,12 +175,14 @@ func (s *Survey) GetQuestions() (questions []Question, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getQuestion(id int) (q Question, err error) {
|
func getQuestion(id int) (q Question, err error) {
|
||||||
err = DBQueryRow("SELECT id_question, id_survey, title, description, placeholder, kind FROM survey_quests WHERE id_question=?", id).Scan(&q.Id, &q.IdSurvey, &q.Title, &q.Description, &q.Placeholder, &q.Kind)
|
err = DBQueryRow("SELECT id_question, id_survey, title, description, placeholder, kind FROM survey_quests WHERE id_question=?", id).Scan(&q.Id, &q.IdSurvey, &q.Title, &q.DescriptionRaw, &q.Placeholder, &q.Kind)
|
||||||
|
q.Description = string(blackfriday.Run([]byte(q.DescriptionRaw)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Survey) GetQuestion(id int) (q Question, err error) {
|
func (s *Survey) GetQuestion(id int) (q Question, err error) {
|
||||||
err = DBQueryRow("SELECT id_question, id_survey, title, description, placeholder, kind FROM survey_quests WHERE id_question=? AND id_survey=?", id, s.Id).Scan(&q.Id, &q.IdSurvey, &q.Title, &q.Description, &q.Placeholder, &q.Kind)
|
err = DBQueryRow("SELECT id_question, id_survey, title, description, placeholder, kind FROM survey_quests WHERE id_question=? AND id_survey=?", id, s.Id).Scan(&q.Id, &q.IdSurvey, &q.Title, &q.DescriptionRaw, &q.Placeholder, &q.Kind)
|
||||||
|
q.Description = string(blackfriday.Run([]byte(q.DescriptionRaw)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +192,7 @@ func (s *Survey) NewQuestion(title string, description string, placeholder strin
|
|||||||
} else if qid, err := res.LastInsertId(); err != nil {
|
} else if qid, err := res.LastInsertId(); err != nil {
|
||||||
return Question{}, err
|
return Question{}, err
|
||||||
} else {
|
} else {
|
||||||
return Question{qid, s.Id, title, description, placeholder, kind}, nil
|
return Question{qid, s.Id, title, string(blackfriday.Run([]byte(description))), description, placeholder, kind}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +201,7 @@ func (q Question) GetSurvey() (Survey, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q Question) Update() (Question, error) {
|
func (q Question) Update() (Question, error) {
|
||||||
if _, err := DBExec("UPDATE survey_quests SET id_survey = ?, title = ?, description = ?, placeholder = ?, kind = ? WHERE id_question = ?", q.IdSurvey, q.Title, q.Description, q.Placeholder, q.Kind, q.Id); err != nil {
|
if _, err := DBExec("UPDATE survey_quests SET id_survey = ?, title = ?, description = ?, placeholder = ?, kind = ? WHERE id_question = ?", q.IdSurvey, q.Title, q.DescriptionRaw, q.Placeholder, q.Kind, q.Id); err != nil {
|
||||||
return Question{}, err
|
return Question{}, err
|
||||||
} else {
|
} else {
|
||||||
return q, err
|
return q, err
|
||||||
|
Reference in New Issue
Block a user