sync: import heading theme image

This commit is contained in:
nemunaire 2018-11-25 03:35:54 +01:00
parent 0effdbcf5e
commit 3a0c892148
4 changed files with 24 additions and 4 deletions

View File

@ -163,7 +163,7 @@ func createTheme(_ httprouter.Params, body []byte) (interface{}, error) {
return nil, errors.New("Theme's name not filled")
}
return fic.CreateTheme(ut.Name, ut.URLId, "", ut.Authors, ut.Intro)
return fic.CreateTheme(ut.Name, ut.URLId, "", ut.Authors, ut.Intro, "")
}
func updateTheme(theme fic.Theme, body []byte) (interface{}, error) {

View File

@ -929,7 +929,7 @@ angular.module("FICApp")
})
.controller("ThemeController", function($scope, Theme, $routeParams, $location, $rootScope, $http) {
$scope.theme = Theme.get({ themeId: $routeParams.themeId });
$scope.fields = ["name", "urlid", "authors", "intro"];
$scope.fields = ["name", "urlid", "authors", "intro", "image"];
$scope.saveTheme = function() {
if (this.theme.id) {

View File

@ -6,6 +6,7 @@ Tous les textes doivent utiliser l'encodage UTF8.
- Un dossier par thème `IDTEAM-Nom du thème` (`IDTEAM` peut être un mot, sans tiret `-` ; le nom du thème est celui qui sera affiché dans l'interface, soyez créatifs !), contenant :
* `AUTHORS.txt` avec vos noms, tels qu'ils apparraîtront sur le site (voir exemple [plus bas](#exemple-authorstxt))
* `overview.txt` une présentation rapide du scenario (~2-3 phrases d'accroche pour lecture rapide), compréhensible par un décideur, petit schéma à l'appui
* `heading.jpg` une photographie libre de tout droit (également celui de référence) représentant le thème
* Un dossier par challenge : `CHID-Titre du challenge` (avec `CHID` l'identifiant numérique du challenge, typiquement son numéro d'ordre), contenant :
+ `overview.txt` une présentation rapide du challenge (~1-2 phrases d'accroche), compréhensible par un décideur, petit schéma à l'appui si besoin
+ `statement.txt` contenant le scénario du challenge, tel qu'il sera affiché sur le site, à destination des participants

View File

@ -57,6 +57,7 @@ func SyncThemes(i Importer) []string {
for _, tdir := range themes {
var authors []string
var intro string
var image string
var theme fic.Theme
var tname string
@ -73,7 +74,7 @@ func SyncThemes(i Importer) []string {
} else if intro, err = getFileContent(i, path.Join(tdir, "overview.txt")); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to get theme's overview: %s", tname, err))
} else if theme, err = fic.GetThemeByName(tname); err != nil {
if _, err := fic.CreateTheme(tname, fic.ToURLid(tname), tdir, strings.Join(authors, ", "), intro); err != nil {
if _, err := fic.CreateTheme(tname, fic.ToURLid(tname), tdir, strings.Join(authors, ", "), intro, image); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tdir, err))
continue
}
@ -85,10 +86,28 @@ func SyncThemes(i Importer) []string {
// Format overview (markdown)
intro = string(blackfriday.Run([]byte(intro)))
if theme.Name != tname || theme.Authors != authors_str || theme.Intro != intro {
if i.exists(path.Join(tdir, "heading.jpg")) {
image = path.Join(tdir, "heading.jpg")
} else if i.exists(path.Join(tdir, "heading.png")) {
image = path.Join(tdir, "heading.png")
}
if len(image) > 0 {
if _, err := i.importFile(image,
func(filePath string, origin string) (interface{}, error) {
image = strings.TrimPrefix(filePath, fic.FilesDir)
return nil, nil
}); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to import heading image: %s", tdir, err))
continue
}
}
if theme.Name != tname || theme.Authors != authors_str || theme.Intro != intro || theme.Image != image {
theme.Name = tname
theme.Authors = authors_str
theme.Intro = intro
theme.Image = image
theme.Path = tdir
if _, err := theme.Update(); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during update: %s", tdir, err))