admin: Add exercice's tags: sync, api, interface done
This commit is contained in:
parent
665fd301c6
commit
f183985982
10 changed files with 166 additions and 20 deletions
|
@ -69,6 +69,7 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||
// Handle score gain
|
||||
var gain int64
|
||||
var depend *fic.Exercice
|
||||
var tags []string
|
||||
if p, err := parseExerciceParams(i, path.Join(theme.Path, edir)); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: %s", edir, err))
|
||||
continue
|
||||
|
@ -76,6 +77,7 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: Undefined gain for challenge", edir))
|
||||
} else {
|
||||
gain = p.Gain
|
||||
tags = p.Tags
|
||||
|
||||
// Handle dependency
|
||||
if len(p.Dependencies) > 0 {
|
||||
|
@ -110,12 +112,11 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||
statement = string(blackfriday.Run([]byte(statement)))
|
||||
overview = string(blackfriday.Run([]byte(overview)))
|
||||
|
||||
if e, err := theme.GetExerciceByTitle(ename); err != nil {
|
||||
if ex, err := theme.AddExercice(ename, fic.ToURLid(ename), path.Join(theme.Path, edir), statement, overview, depend, gain, videoURI); err != nil {
|
||||
e, err := theme.GetExerciceByTitle(ename)
|
||||
if err != nil {
|
||||
if e, err = theme.AddExercice(ename, fic.ToURLid(ename), path.Join(theme.Path, edir), statement, overview, depend, gain, videoURI); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error on exercice add: %s", edir, err))
|
||||
continue
|
||||
} else {
|
||||
dmap[int64(eid)] = ex
|
||||
}
|
||||
} else if e.Title != ename || e.URLId == "" || e.Statement != statement || e.Overview != overview || e.Gain != gain || e.VideoURI != videoURI {
|
||||
e.Title = ename
|
||||
|
@ -127,11 +128,18 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||
if _, err := e.Update(); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error on exercice update: %s", edir, err))
|
||||
continue
|
||||
} else {
|
||||
dmap[int64(eid)] = e
|
||||
}
|
||||
} else {
|
||||
dmap[int64(eid)] = e
|
||||
}
|
||||
dmap[int64(eid)] = e
|
||||
|
||||
if _, err := e.WipeTags(); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: Unable to wipe tags: %s", edir, err))
|
||||
}
|
||||
for _, tag := range tags {
|
||||
if _, err := e.AddTag(tag); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: Unable to add tag: %s", edir, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue