From ac3f9129b23ebba8ec70de1a2034a2bc1b72d032 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 14 Jan 2017 15:03:25 +0100 Subject: [PATCH] frontend: dedicate a field in JSON to file hint --- frontend/static/views/theme.html | 20 +++++++++----------- libfic/hint.go | 22 ++++++++++++---------- libfic/team_my.go | 14 +++++++------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/frontend/static/views/theme.html b/frontend/static/views/theme.html index af62f802..d0c8974e 100644 --- a/frontend/static/views/theme.html +++ b/frontend/static/views/theme.html @@ -30,18 +30,16 @@
Indices
- +

+

Cliquez ici pour télécharger l'indice.

+

Débloquer cet indice vous coûtera .

+
+
diff --git a/libfic/hint.go b/libfic/hint.go index 6dab02b6..a47b3501 100644 --- a/libfic/hint.go +++ b/libfic/hint.go @@ -6,16 +6,18 @@ import ( ) type EHint struct { - Id int64 `json:"id"` - IdExercice int64 `json:"idExercice"` - Title string `json:"title"` + Id int64 `json:"id"` + IdExercice int64 `json:"idExercice"` + Title string `json:"title"` Content string `json:"content"` - Cost int64 `json:"cost"` + File string `json:"file"` + Cost int64 `json:"cost"` } -func treatHintContent(content *string) { - if strings.HasPrefix(*content, "$FILES") { - *content = "$FILES" + path.Join(FilesDir, strings.TrimPrefix(*content, "$FILES")) +func treatHintContent(h *EHint) { + if strings.HasPrefix(h.Content, "$FILES") { + h.File = path.Join(FilesDir, strings.TrimPrefix(h.Content, "$FILES")) + h.Content = "" } } @@ -24,7 +26,7 @@ func GetHint(id int64) (EHint, error) { if err := DBQueryRow("SELECT id_hint, id_exercice, title, content, cost FROM exercice_hints WHERE id_hint = ?", id).Scan(&h.Id, &h.IdExercice, &h.Title, &h.Content, &h.Cost); err != nil { return h, err } - treatHintContent(&h.Content) + treatHintContent(&h) return h, nil } @@ -42,7 +44,7 @@ func (e Exercice) GetHints() ([]EHint, error) { if err := rows.Scan(&h.Id, &h.Title, &h.Content, &h.Cost); err != nil { return nil, err } - treatHintContent(&h.Content) + treatHintContent(&h) hints = append(hints, h) } if err := rows.Err(); err != nil { @@ -59,7 +61,7 @@ func (e Exercice) AddHint(title string, content string, cost int64) (EHint, erro } else if hid, err := res.LastInsertId(); err != nil { return EHint{}, err } else { - return EHint{hid, e.Id, title, content, cost}, nil + return EHint{hid, e.Id, title, content, "", cost}, nil } } diff --git a/libfic/team_my.go b/libfic/team_my.go index 6e5404e9..242d0bb0 100644 --- a/libfic/team_my.go +++ b/libfic/team_my.go @@ -14,11 +14,11 @@ type myTeamFile struct { Size int64 `json:"size"` } type myTeamHint struct { - HintId int64 `json:"id"` - Title string `json:"title"` - Content string `json:"content"` - Cost int64 `json:"cost"` - Unlocked bool `json:"unlocked"` + HintId int64 `json:"id"` + Title string `json:"title"` + Content *string `json:"content"` + File *string `json:"file"` + Cost int64 `json:"cost"` } type myTeamExercice struct { ThemeId int `json:"theme_id"` @@ -99,9 +99,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { } else { for _, h := range hints { if t == nil || t.HasHint(h) { - exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, h.Content, h.Cost, true}) + exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, &h.Content, &h.File, h.Cost}) } else { - exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, "", h.Cost, false}) + exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, nil, nil, h.Cost}) } } }