Themes can have header image
This commit is contained in:
parent
26295dd978
commit
0effdbcf5e
@ -10,7 +10,7 @@
|
||||
|
||||
<div class="card-columns">
|
||||
<div class="card" ng-repeat="(k,theme) in themes">
|
||||
<img class="card-img-top" src=".../100px180/" alt="">
|
||||
<img class="card-img-top" src="{{ theme.image }}" alt="">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
<a ng-href="/{{ theme.urlid }}">{{ theme.name }}</a>
|
||||
|
@ -73,6 +73,7 @@ CREATE TABLE IF NOT EXISTS themes(
|
||||
url_id VARCHAR(191) NOT NULL UNIQUE,
|
||||
path VARCHAR(191) NOT NULL UNIQUE,
|
||||
intro TEXT NOT NULL,
|
||||
image VARCHAR(255) NOT NULL,
|
||||
authors TEXT NOT NULL
|
||||
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
||||
`); err != nil {
|
||||
|
@ -10,11 +10,12 @@ type Theme struct {
|
||||
Path string `json:"path"`
|
||||
Authors string `json:"authors,omitempty"`
|
||||
Intro string `json:"intro,omitempty"`
|
||||
Image string `json:"image,omitempty"`
|
||||
}
|
||||
|
||||
// GetThemes returns a list of registered Themes from the database.
|
||||
func GetThemes() ([]Theme, error) {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, url_id, path, authors, intro FROM themes"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, url_id, path, authors, intro, image FROM themes"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
@ -22,7 +23,7 @@ func GetThemes() ([]Theme, error) {
|
||||
var themes = make([]Theme, 0)
|
||||
for rows.Next() {
|
||||
var t Theme
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro); err != nil {
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Image); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
themes = append(themes, t)
|
||||
@ -38,7 +39,7 @@ func GetThemes() ([]Theme, error) {
|
||||
// GetTheme retrieves a Theme from its identifier.
|
||||
func GetTheme(id int) (Theme, error) {
|
||||
var t Theme
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, image FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Image); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
@ -48,7 +49,7 @@ func GetTheme(id int) (Theme, error) {
|
||||
// GetThemeByName retrieves a Theme from its title
|
||||
func GetThemeByName(name string) (Theme, error) {
|
||||
var t Theme
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, image FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Image); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
@ -56,13 +57,13 @@ func GetThemeByName(name string) (Theme, error) {
|
||||
}
|
||||
|
||||
// CreateTheme creates and fills a new struct Theme and registers it into the database.
|
||||
func CreateTheme(name string, url_id string, path string, authors string, intro string) (Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, url_id, authors, path, intro) VALUES (?, ?, ?, ?, ?)", name, url_id, authors, path, intro); err != nil {
|
||||
func CreateTheme(name string, url_id string, path string, authors string, intro string, image string) (Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, url_id, authors, path, intro, image) VALUES (?, ?, ?, ?, ?, ?)", name, url_id, authors, path, intro, image); err != nil {
|
||||
return Theme{}, err
|
||||
} else if tid, err := res.LastInsertId(); err != nil {
|
||||
return Theme{}, err
|
||||
} else {
|
||||
return Theme{tid, name, url_id, path, authors, intro}, nil
|
||||
return Theme{tid, name, url_id, path, authors, intro, image}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ func (t *Theme) FixURLId() bool {
|
||||
|
||||
// Update applies modifications back to the database.
|
||||
func (t Theme) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE themes SET name = ?, url_id = ?, authors = ?, path = ?, intro = ? WHERE id_theme = ?", t.Name, t.URLId, t.Authors, t.Path, t.Intro, t.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE themes SET name = ?, url_id = ?, authors = ?, path = ?, intro = ?, image = ? WHERE id_theme = ?", t.Name, t.URLId, t.Authors, t.Path, t.Intro, t.Image, t.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
@ -2,6 +2,7 @@ package fic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
)
|
||||
|
||||
// exportedExercice is a structure representing a challenge, as exposed to players.
|
||||
@ -21,6 +22,7 @@ type exportedTheme struct {
|
||||
URLId string `json:"urlid"`
|
||||
Authors string `json:"authors"`
|
||||
Intro string `json:"intro"`
|
||||
Image string `json:"image,omitempty"`
|
||||
Exercices map[string]exportedExercice `json:"exercices"`
|
||||
}
|
||||
|
||||
@ -47,11 +49,18 @@ func ExportThemes() (interface{}, error) {
|
||||
exercice.TriedTeamCount(),
|
||||
}
|
||||
}
|
||||
|
||||
imgpath := ""
|
||||
if len(theme.Image) > 0 {
|
||||
imgpath = path.Join(FilesDir, theme.Image)
|
||||
}
|
||||
|
||||
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
|
||||
theme.Name,
|
||||
theme.URLId,
|
||||
theme.Authors,
|
||||
theme.Intro,
|
||||
imgpath,
|
||||
exos,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user