admin: add button and route to reset some parts
This commit is contained in:
parent
89eaeef88e
commit
4793d0de4e
4 changed files with 65 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
|
|
@ -16,6 +17,8 @@ var TeamsDir string
|
|||
func init() {
|
||||
router.GET("/api/settings.json", apiHandler(getSettings))
|
||||
router.PUT("/api/settings.json", apiHandler(saveSettings))
|
||||
|
||||
router.POST("/api/reset", apiHandler(reset))
|
||||
}
|
||||
|
||||
func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
|
|
@ -38,3 +41,22 @@ func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return config, err
|
||||
}
|
||||
}
|
||||
|
||||
func reset(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
var m map[string]string
|
||||
if err := json.Unmarshal(body, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if t, ok := m["type"]; !ok {
|
||||
return nil, errors.New("Field type not found")
|
||||
} else if t == "teams" {
|
||||
return true, fic.ResetTeams()
|
||||
} else if t == "challenges" {
|
||||
return true, fic.ResetExercices()
|
||||
} else if t == "game" {
|
||||
return true, fic.ResetGame()
|
||||
} else {
|
||||
return nil, errors.New("Unknown reset type")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,6 +280,13 @@ angular.module("FICApp")
|
|||
var f = new Date(ts + 120000 + this.duration * 60000);
|
||||
this.config.end = f.toISOString();
|
||||
}
|
||||
$scope.reset = function(type) {
|
||||
if (confirm("Êtes-vous sûr ?")) {
|
||||
$http.post("/api/reset", {"type": type}).success(function(time) {
|
||||
$location.url("/");
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
.controller("PublicController", function($scope, Scene, Theme, Teams, Exercice) {
|
||||
|
|
|
|||
|
|
@ -102,3 +102,9 @@
|
|||
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Propager ces paramètres</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="well">
|
||||
<a ng-click="reset('challenges')" class="btn btn-warning" role="button"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Effacer les challenges et les thèmes</a>
|
||||
<a ng-click="reset('teams');" class="btn btn-warning" role="button"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Effacer les équipes</a>
|
||||
<a ng-click="reset('game');" class="btn btn-warning" role="button"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Effacer la partie (tentatives, indices, ...)</a>
|
||||
</div>
|
||||
|
|
|
|||
Reference in a new issue