diff --git a/admin/api/exercice.go b/admin/api/exercice.go index e3104595..c2554269 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -36,9 +36,16 @@ func declareExercicesRoutes(router *gin.RouterGroup) { apiExercicesRoutes.POST("/diff-sync", APIDiffExerciceWithRemote) + apiExercicesRoutes.GET("/history.json", getExerciceHistory) + apiExercicesRoutes.GET("/stats.json", getExerciceStats) - apiExercicesRoutes.GET("/history.json", getExerciceHistory) + apiExercicesRoutes.GET("/tries", listTries) + + apiTriesRoutes := apiExercicesRoutes.Group("/tries/:trid") + apiTriesRoutes.Use(ExerciceTryHandler) + apiTriesRoutes.GET("", getExerciceTry) + apiTriesRoutes.DELETE("", deleteExerciceTry) apiHistoryRoutes := apiExercicesRoutes.Group("/history.json") apiHistoryRoutes.Use(AssigneeCookieHandler) @@ -1619,3 +1626,58 @@ func APIDiffExerciceWithRemote(c *gin.Context) { c.JSON(http.StatusOK, diffs) } + +func listTries(c *gin.Context) { + exercice := c.MustGet("exercice").(*fic.Exercice) + + tries, err := exercice.TriesList() + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()}) + return + } + + c.JSON(http.StatusOK, tries) +} + +func ExerciceTryHandler(c *gin.Context) { + trid, err := strconv.ParseInt(string(c.Params.ByName("trid")), 10, 32) + if err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Invalid try identifier"}) + return + } + + exercice := c.MustGet("exercice").(*fic.Exercice) + try, err := exercice.GetTry(trid) + if err != nil { + c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Try not found"}) + return + } + + c.Set("try", try) + + c.Next() +} + +func getExerciceTry(c *gin.Context) { + try := c.MustGet("try").(*fic.ExerciceTry) + + err := try.FillDetails() + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()}) + return + } + + c.JSON(http.StatusOK, try) +} + +func deleteExerciceTry(c *gin.Context) { + try := c.MustGet("try").(*fic.ExerciceTry) + + _, err := try.Delete() + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()}) + return + } + + c.Status(http.StatusNoContent) +} diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 173df8b1..915de87d 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -320,6 +320,9 @@ angular.module("FICApp") .factory("ExerciceHistory", function ($resource) { return $resource("api/exercices/:exerciceId/history.json", { exerciceId: '@id' }) }) + .factory("ExerciceTries", function ($resource) { + return $resource("api/exercices/:exerciceId/tries/:tryId", { exerciceId: '@idExercice', tryId: '@id' }) + }) .factory("ExercicesStats", function ($resource) { return $resource("api/exercices_stats.json", { themeId: '@id' }) }) @@ -2117,6 +2120,10 @@ angular.module("FICApp") } }) + .controller("SearchTryController", function ($scope, ExerciceTries) { + $scope.tr = ExerciceTries.get({ exerciceId: $scope.exercice.id, tryId: $scope.row.secondary }); + }) + .controller("SubmissionsStatsController", function ($scope, $http, $interval) { var refresh = function () { $http({ diff --git a/admin/static/views/exercice-flags.html b/admin/static/views/exercice-flags.html index f765d9a9..8de3f0ee 100644 --- a/admin/static/views/exercice-flags.html +++ b/admin/static/views/exercice-flags.html @@ -83,6 +83,7 @@
Statistiques