admin: New button to delete tries for a flag
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b409fa6806
commit
08a31898df
@ -63,6 +63,7 @@ func declareExercicesRoutes(router *gin.RouterGroup) {
|
||||
apiFlagsRoutes.DELETE("/", deleteExerciceFlag)
|
||||
apiFlagsRoutes.GET("/dependancies", showExerciceFlagDeps)
|
||||
apiFlagsRoutes.GET("/statistics", showExerciceFlagStats)
|
||||
apiFlagsRoutes.DELETE("/tries", deleteExerciceFlagTries)
|
||||
apiFlagsRoutes.GET("/choices/", listFlagChoices)
|
||||
apiFlagsChoicesRoutes := apiExercicesRoutes.Group("/choices/:cid")
|
||||
apiFlagsChoicesRoutes.Use(FlagChoiceHandler)
|
||||
@ -79,6 +80,7 @@ func declareExercicesRoutes(router *gin.RouterGroup) {
|
||||
apiQuizRoutes.DELETE("", deleteExerciceQuiz)
|
||||
apiQuizRoutes.GET("/dependancies", showExerciceQuizDeps)
|
||||
apiQuizRoutes.GET("/statistics", showExerciceQuizStats)
|
||||
apiQuizRoutes.DELETE("/tries", deleteExerciceQuizTries)
|
||||
|
||||
apiExercicesRoutes.GET("/tags", listExerciceTags)
|
||||
apiExercicesRoutes.POST("/tags", addExerciceTag)
|
||||
@ -896,6 +898,18 @@ func showExerciceFlagStats(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func deleteExerciceFlagTries(c *gin.Context) {
|
||||
flag := c.MustGet("flag-key").(*fic.FlagKey)
|
||||
|
||||
err := flag.DeleteTries()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.AbortWithStatusJSON(http.StatusOK, true)
|
||||
}
|
||||
|
||||
func tryExerciceFlag(c *gin.Context) {
|
||||
flag := c.MustGet("flag-key").(*fic.FlagKey)
|
||||
|
||||
@ -1108,6 +1122,18 @@ func showExerciceQuizStats(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func deleteExerciceQuizTries(c *gin.Context) {
|
||||
quiz := c.MustGet("flag-quiz").(*fic.MCQ)
|
||||
|
||||
err := quiz.DeleteTries()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.AbortWithStatusJSON(http.StatusOK, true)
|
||||
}
|
||||
|
||||
func updateExerciceQuiz(c *gin.Context) {
|
||||
quiz := c.MustGet("flag-quiz").(*fic.MCQ)
|
||||
|
||||
|
@ -2374,10 +2374,16 @@ angular.module("FICApp")
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExerciceFlagStatsController", function ($scope, $routeParams, ExerciceFlagStats) {
|
||||
.controller("ExerciceFlagStatsController", function ($scope, $routeParams, ExerciceFlagStats, $http) {
|
||||
$scope.init = function (flag) {
|
||||
$scope.flag_id = flag.id;
|
||||
$scope.stats = ExerciceFlagStats.get({ exerciceId: $routeParams.exerciceId, flagId: flag.id });
|
||||
}
|
||||
$scope.deleteTries = function () {
|
||||
$http.delete(`/api/exercices/${$routeParams.exerciceId}/flags/${$scope.flag_id}/tries`).then(function () {
|
||||
$scope.stats = ExerciceFlagStats.get({ exerciceId: $routeParams.exerciceId, flagId: $scope.flag_id });
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExerciceMCQFlagsController", function ($scope, ExerciceMCQFlag, $routeParams, $rootScope) {
|
||||
@ -2417,10 +2423,16 @@ angular.module("FICApp")
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExerciceMCQStatsController", function ($scope, $routeParams, ExerciceMCQStats) {
|
||||
.controller("ExerciceMCQStatsController", function ($scope, $routeParams, ExerciceMCQStats, $http) {
|
||||
$scope.init = function (mcq) {
|
||||
$scope.mcq_id = mcq.id;
|
||||
$scope.stats = ExerciceMCQStats.get({ exerciceId: $routeParams.exerciceId, mcqId: mcq.id });
|
||||
}
|
||||
$scope.deleteTries = function () {
|
||||
$http.delete(`/api/exercices/${$routeParams.exerciceId}/quiz/${$scope.mcq_id}/tries`).then(function () {
|
||||
$scope.stats = ExerciceMCQStats.get({ exerciceId: $routeParams.exerciceId, mcqId: $scope.mcq_id });
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
.controller("TeamsListController", function ($scope, $rootScope, Team, $location, $http) {
|
||||
|
@ -84,7 +84,10 @@
|
||||
<strong>Statistiques</strong>
|
||||
<ul>
|
||||
<li>Validés : {{ stats["completed"] }}</li>
|
||||
<li>Tentés : {{ stats["tries"] }}</li>
|
||||
<li>
|
||||
Tentés : {{ stats["tries"] }}
|
||||
<button type="button" ng-click="deleteTries()" class="btn btn-sm btn-danger" ng-if="stats['tries'] > 0"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
|
||||
</li>
|
||||
<li>
|
||||
Équipes :
|
||||
<span ng-if="stats['teams'].length == 0">aucune</span>
|
||||
@ -186,7 +189,10 @@
|
||||
<strong>Statistiques</strong>
|
||||
<ul>
|
||||
<li>Validés : {{ stats["completed"] }}</li>
|
||||
<li>Tentés : {{ stats["tries"] }}</li>
|
||||
<li>
|
||||
Tentés : {{ stats["tries"] }}
|
||||
<button type="button" ng-click="deleteTries()" class="btn btn-sm btn-danger" ng-if="stats['tries'] > 0"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
|
||||
</li>
|
||||
<li>
|
||||
Équipes :
|
||||
<span ng-if="stats['teams'].length == 0">aucune</span>
|
||||
|
@ -16,6 +16,7 @@ type Flag interface {
|
||||
FoundBy(t *Team) error
|
||||
NbTries() (int64, error)
|
||||
TeamsOnIt() ([]int64, error)
|
||||
DeleteTries() error
|
||||
}
|
||||
|
||||
// GetFlag returns a list of flags comming with the challenge.
|
||||
|
@ -255,6 +255,29 @@ func (k *FlagKey) TeamsOnIt() ([]int64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (k *FlagKey) DeleteTries() error {
|
||||
if rows, err := DBQuery("SELECT id_try FROM exercice_tries_flags WHERE id_flag = ?", k.Id); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var idtry int64
|
||||
err = rows.Scan(&idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = DBExec("DELETE FROM exercice_tries WHERE id_try = ?", idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlagKey creates and fills a new struct Flag, from a hashed flag, and registers it into the database.
|
||||
func (k *FlagKey) Create(e *Exercice) (Flag, error) {
|
||||
// Check the regexp compile
|
||||
|
@ -79,6 +79,10 @@ func (k *FlagLabel) TeamsOnIt() ([]int64, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (k *FlagLabel) DeleteTries() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddFlagLabel creates and fills a new struct Flag and registers it into the database.
|
||||
func (k *FlagLabel) Create(e *Exercice) (Flag, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_flag_labels (id_exercice, ordre, label, variant) VALUES (?, ?, ?, ?)", e.Id, k.Order, k.Label, k.Variant); err != nil {
|
||||
|
@ -161,6 +161,29 @@ func (m *MCQ) TeamsOnIt() ([]int64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MCQ) DeleteTries() error {
|
||||
if rows, err := DBQuery("SELECT id_try FROM exercice_tries_mcq WHERE id_mcq = ?", m.Id); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var idtry int64
|
||||
err = rows.Scan(&idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = DBExec("DELETE FROM exercice_tries WHERE id_try = ?", idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Create registers a MCQ into the database and recursively add its entries.
|
||||
func (m *MCQ) Create(e *Exercice) (Flag, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, ordre, title) VALUES (?, ?, ?)", e.Id, m.Order, m.Title); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user