admin: Can list independant exercices as theme
This commit is contained in:
parent
d26333c5e2
commit
5e262b75a3
3 changed files with 27 additions and 8 deletions
|
@ -70,13 +70,17 @@ func ThemeHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
theme, err := fic.GetTheme(thid)
|
if thid == 0 {
|
||||||
if err != nil {
|
c.Set("theme", &fic.Theme{Name: "Exercices indépendants", Path: sync.StandaloneExercicesDirectory})
|
||||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Theme not found"})
|
} else {
|
||||||
return
|
theme, err := fic.GetTheme(thid)
|
||||||
}
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Theme not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.Set("theme", theme)
|
c.Set("theme", theme)
|
||||||
|
}
|
||||||
|
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
@ -127,6 +131,10 @@ func listThemes(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if has, _ := fic.HasStandaloneExercice(); has {
|
||||||
|
themes = append([]*fic.Theme{&fic.Theme{Name: "Exercices indépendants", Path: sync.StandaloneExercicesDirectory}}, themes...)
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, themes)
|
c.JSON(http.StatusOK, themes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<form ng-submit="saveTheme()" class="col-4">
|
<form ng-submit="saveTheme()" class="col-4" ng-if="!(theme.id === 0 && theme.path)">
|
||||||
<div ng-class="{'form-group': field != 'locked', 'form-check': field == 'locked'}" ng-repeat="field in fields">
|
<div ng-class="{'form-group': field != 'locked', 'form-check': field == 'locked'}" ng-repeat="field in fields">
|
||||||
<input type="checkbox" class="form-check-input" id="{{ field }}" ng-model="theme[field]" ng-if="field == 'locked'">
|
<input type="checkbox" class="form-check-input" id="{{ field }}" ng-model="theme[field]" ng-if="field == 'locked'">
|
||||||
<label for="{{ field }}">{{ field | capitalize }}</label>
|
<label for="{{ field }}">{{ field | capitalize }}</label>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div ng-if="theme.id" class="col-md-8" ng-controller="ExercicesListController">
|
<div ng-if="theme.id || theme.path" class="col-md-8" ng-class="{'offset-md-2': theme.id === 0 && theme.path}" ng-controller="ExercicesListController">
|
||||||
<h3>
|
<h3>
|
||||||
Exercices ({{ exercices.length }})
|
Exercices ({{ exercices.length }})
|
||||||
<button type="button" ng-click="show('new')" class="float-right btn btn-sm btn-primary ml-2"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un exercice</button>
|
<button type="button" ng-click="show('new')" class="float-right btn btn-sm btn-primary ml-2"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un exercice</button>
|
||||||
|
|
|
@ -645,3 +645,14 @@ func (e *Exercice) IsSolved() (int, *time.Time) {
|
||||||
return *nb, tm
|
return *nb, tm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HasStandaloneExercice() (bool, error) {
|
||||||
|
var nb int
|
||||||
|
|
||||||
|
err := DBQueryRow("SELECT COUNT(id_exercice) FROM exercices WHERE id_theme IS NULL").Scan(&nb)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
} else {
|
||||||
|
return nb > 0, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue