From d21f3b0b8301c6441d0eac69e05dea69b5aa82d5 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Mon, 24 Sep 2018 10:00:17 +0200 Subject: [PATCH] Rename Exercice's Keys as Flags --- admin/api/exercice.go | 58 ++++++------ admin/api/handlers.go | 10 +- admin/api/theme.go | 6 +- admin/api/version.go | 2 +- admin/static/js/app.js | 46 ++++----- admin/static/views/exercice-list.html | 4 +- admin/static/views/exercice.html | 28 +++--- admin/sync/exercice_keys.go | 10 +- admin/sync/full.go | 2 +- libfic/db.go | 16 ++-- libfic/exercice.go | 20 ++-- libfic/file.go | 12 +-- libfic/flag.go | 129 ++++++++++++++++++++++++++ libfic/key.go | 129 -------------------------- libfic/reset.go | 6 +- libfic/team.go | 6 +- libfic/team_history.go | 6 +- libfic/team_my.go | 14 +-- 18 files changed, 252 insertions(+), 252 deletions(-) create mode 100644 libfic/flag.go delete mode 100644 libfic/key.go diff --git a/admin/api/exercice.go b/admin/api/exercice.go index 2923d83e..ffd57b5d 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -30,11 +30,11 @@ func init() { router.PUT("/api/exercices/:eid/hints/:hid", apiHandler(hintHandler(updateExerciceHint))) router.DELETE("/api/exercices/:eid/hints/:hid", apiHandler(hintHandler(deleteExerciceHint))) - router.GET("/api/exercices/:eid/keys", apiHandler(exerciceHandler(listExerciceKeys))) - router.POST("/api/exercices/:eid/keys", apiHandler(exerciceHandler(createExerciceKey))) - router.GET("/api/exercices/:eid/keys/:kid", apiHandler(keyHandler(showExerciceKey))) - router.PUT("/api/exercices/:eid/keys/:kid", apiHandler(keyHandler(updateExerciceKey))) - router.DELETE("/api/exercices/:eid/keys/:kid", apiHandler(keyHandler(deleteExerciceKey))) + router.GET("/api/exercices/:eid/flags", apiHandler(exerciceHandler(listExerciceFlags))) + router.POST("/api/exercices/:eid/flags", apiHandler(exerciceHandler(createExerciceFlag))) + router.GET("/api/exercices/:eid/flags/:kid", apiHandler(flagHandler(showExerciceFlag))) + router.PUT("/api/exercices/:eid/flags/:kid", apiHandler(flagHandler(updateExerciceFlag))) + router.DELETE("/api/exercices/:eid/flags/:kid", apiHandler(flagHandler(deleteExerciceFlag))) router.GET("/api/exercices/:eid/quiz", apiHandler(exerciceHandler(listExerciceQuiz))) router.GET("/api/exercices/:eid/quiz/:qid", apiHandler(quizHandler(showExerciceQuiz))) @@ -50,9 +50,9 @@ func init() { func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceHints(sync.GlobalImporter, exercice), nil }))) - router.POST("/api/sync/exercices/:eid/keys", apiHandler(exerciceHandler( + router.POST("/api/sync/exercices/:eid/flags", apiHandler(exerciceHandler( func(exercice fic.Exercice, _ []byte) (interface{}, error) { - return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil + return sync.SyncExerciceFlags(sync.GlobalImporter, exercice), nil }))) router.POST("/api/sync/exercices/:eid/fixurlid", apiHandler(exerciceHandler( @@ -77,8 +77,8 @@ func listExerciceHints(exercice fic.Exercice, body []byte) (interface{}, error) return exercice.GetHints() } -func listExerciceKeys(exercice fic.Exercice, body []byte) (interface{}, error) { - return exercice.GetKeys() +func listExerciceFlags(exercice fic.Exercice, body []byte) (interface{}, error) { + return exercice.GetFlags() } func listExerciceQuiz(exercice fic.Exercice, body []byte) (interface{}, error) { @@ -188,56 +188,56 @@ func deleteExerciceHint(hint fic.EHint, _ []byte) (interface{}, error) { return hint.Delete() } -type uploadedKey struct { +type uploadedFlag struct { Label string Help string ICase bool - Key string + Flag string Hash []byte } -func createExerciceKey(exercice fic.Exercice, body []byte) (interface{}, error) { - var uk uploadedKey +func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error) { + var uk uploadedFlag if err := json.Unmarshal(body, &uk); err != nil { return nil, err } - if len(uk.Key) == 0 { - return nil, errors.New("Key not filled") + if len(uk.Flag) == 0 { + return nil, errors.New("Flag not filled") } - return exercice.AddRawKey(uk.Label, uk.Help, uk.ICase, uk.Key) + return exercice.AddRawFlag(uk.Label, uk.Help, uk.ICase, uk.Flag) } -func showExerciceKey(key fic.Key, _ fic.Exercice, body []byte) (interface{}, error) { - return key, nil +func showExerciceFlag(flag fic.Flag, _ fic.Exercice, body []byte) (interface{}, error) { + return flag, nil } -func updateExerciceKey(key fic.Key, exercice fic.Exercice, body []byte) (interface{}, error) { - var uk uploadedKey +func updateExerciceFlag(flag fic.Flag, exercice fic.Exercice, body []byte) (interface{}, error) { + var uk uploadedFlag if err := json.Unmarshal(body, &uk); err != nil { return nil, err } if len(uk.Label) == 0 { - key.Label = "Flag" + flag.Label = "Flag" } else { - key.Label = uk.Label + flag.Label = uk.Label } - key.Help = uk.Help - key.IgnoreCase = uk.ICase - key.Checksum = uk.Hash + flag.Help = uk.Help + flag.IgnoreCase = uk.ICase + flag.Checksum = uk.Hash - if _, err := key.Update(); err != nil { + if _, err := flag.Update(); err != nil { return nil, err } - return key, nil + return flag, nil } -func deleteExerciceKey(key fic.Key, _ fic.Exercice, _ []byte) (interface{}, error) { - return key.Delete() +func deleteExerciceFlag(flag fic.Flag, _ fic.Exercice, _ []byte) (interface{}, error) { + return flag.Delete() } func showExerciceQuiz(quiz fic.MCQ, _ fic.Exercice, body []byte) (interface{}, error) { diff --git a/admin/api/handlers.go b/admin/api/handlers.go index ff10ea81..0d6b22fb 100644 --- a/admin/api/handlers.go +++ b/admin/api/handlers.go @@ -165,7 +165,7 @@ func hintHandler(f func(fic.EHint, []byte) (interface{}, error)) func(httprouter } } -func keyHandler(f func(fic.Key, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) { +func flagHandler(f func(fic.Flag, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) { return func(ps httprouter.Params, body []byte) (interface{}, error) { var exercice fic.Exercice exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) { @@ -175,12 +175,12 @@ func keyHandler(f func(fic.Key, fic.Exercice, []byte) (interface{}, error)) func if kid, err := strconv.Atoi(string(ps.ByName("kid"))); err != nil { return nil, err - } else if keys, err := exercice.GetKeys(); err != nil { + } else if flags, err := exercice.GetFlags(); err != nil { return nil, err } else { - for _, key := range keys { - if key.Id == int64(kid) { - return f(key, exercice, body) + for _, flag := range flags { + if flag.Id == int64(kid) { + return f(flag, exercice, body) } } return nil, errors.New("Unable to find the requested key") diff --git a/admin/api/theme.go b/admin/api/theme.go index 4c8c6503..39717ca0 100644 --- a/admin/api/theme.go +++ b/admin/api/theme.go @@ -35,8 +35,8 @@ func init() { router.GET("/api/themes/:thid/exercices/:eid/hints", apiHandler(exerciceHandler(listExerciceHints))) router.POST("/api/themes/:thid/exercices/:eid/hints", apiHandler(exerciceHandler(createExerciceHint))) - router.GET("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(listExerciceKeys))) - router.POST("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(createExerciceKey))) + router.GET("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(listExerciceFlags))) + router.POST("/api/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(createExerciceFlag))) // Remote router.GET("/api/remote/themes", apiHandler(sync.ApiListRemoteThemes)) @@ -66,7 +66,7 @@ func init() { }))) router.POST("/api/sync/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler( func(exercice fic.Exercice, _ []byte) (interface{}, error) { - return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil + return sync.SyncExerciceFlags(sync.GlobalImporter, exercice), nil }))) router.POST("/api/sync/themes/:thid/fixurlid", apiHandler(themeHandler( diff --git a/admin/api/version.go b/admin/api/version.go index a65f9c85..fc57f96e 100644 --- a/admin/api/version.go +++ b/admin/api/version.go @@ -9,5 +9,5 @@ func init() { } func showVersion(_ httprouter.Params, body []byte) (interface{}, error) { - return map[string]interface{}{"version": 0.5}, nil + return map[string]interface{}{"version": 0.6}, nil } diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 972c97f3..95013394 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -218,12 +218,12 @@ angular.module("FICApp") update: {method: 'PUT'} }) }) - .factory("ExerciceKey", function($resource) { - return $resource("/api/exercices/:exerciceId/keys/:keyId", { exerciceId: '@idExercice', keyId: '@id' }, { + .factory("ExerciceFlag", function($resource) { + return $resource("/api/exercices/:exerciceId/flags/:flagId", { exerciceId: '@idExercice', flagId: '@id' }, { update: {method: 'PUT'} }) }) - .factory("ExerciceMCQKey", function($resource) { + .factory("ExerciceMCQFlag", function($resource) { return $resource("/api/exercices/:exerciceId/quiz/:mcqId", { exerciceId: '@idExercice', mcqId: '@id' }, { update: {method: 'PUT'} }) @@ -995,8 +995,8 @@ angular.module("FICApp") work.push("/api/sync/exercices/" + ex.id + "/files"); if ($scope.syncHints) work.push("/api/sync/exercices/" + ex.id + "/hints"); - if ($scope.syncKeys) - work.push("/api/sync/exercices/" + ex.id + "/keys"); + if ($scope.syncFlags) + work.push("/api/sync/exercices/" + ex.id + "/flags"); }); $scope.total = work.length; go(); @@ -1004,7 +1004,7 @@ angular.module("FICApp") }; $scope.syncFiles = true; $scope.syncHints = true; - $scope.syncKeys = true; + $scope.syncFlags = true; }) .controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) { $scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId }); @@ -1106,35 +1106,35 @@ angular.module("FICApp") }; }) - .controller("ExerciceKeysController", function($scope, ExerciceKey, $routeParams, $rootScope, $http) { - $scope.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId }); + .controller("ExerciceFlagsController", function($scope, ExerciceFlag, $routeParams, $rootScope, $http) { + $scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId }); - $scope.addKey = function() { - $scope.keys.push(new ExerciceKey()); + $scope.addFlag = function() { + $scope.flags.push(new ExerciceFlag()); } - $scope.deleteKey = function() { - this.key.$delete(function() { - $scope.keys.splice($scope.keys.indexOf(this.key), 1); + $scope.deleteFlag = function() { + this.flag.$delete(function() { + $scope.flags.splice($scope.flags.indexOf(this.flag), 1); }, function(response) { $rootScope.newBox('danger', 'An error occurs when trying to delete flag:', response.data); }); } - $scope.saveKey = function() { - if (this.key.id) { - this.key.$update(); + $scope.saveFlag = function() { + if (this.flag.id) { + this.flag.$update(); } else { - this.key.$save({ exerciceId: $routeParams.exerciceId }); + this.flag.$save({ exerciceId: $routeParams.exerciceId }); } } $scope.inSync = false; - $scope.syncKeys = function() { + $scope.syncFlags = function() { $scope.inSync = true; $http({ - url: "/api/sync/exercices/" + $routeParams.exerciceId + "/keys", + url: "/api/sync/exercices/" + $routeParams.exerciceId + "/flags", method: "POST" }).then(function(response) { $scope.inSync = false; - $scope.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId }); + $scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId }); if (response.data) $rootScope.newBox('danger', response.data); else @@ -1146,11 +1146,11 @@ angular.module("FICApp") }; }) - .controller("ExerciceMCQKeysController", function($scope, ExerciceMCQKey, $routeParams, $rootScope, $http) { - $scope.quiz = ExerciceMCQKey.query({ exerciceId: $routeParams.exerciceId }); + .controller("ExerciceMCQFlagsController", function($scope, ExerciceMCQFlag, $routeParams, $rootScope, $http) { + $scope.quiz = ExerciceMCQFlag.query({ exerciceId: $routeParams.exerciceId }); $scope.addQuiz = function() { - $scope.quiz.push(new ExerciceMCQKey()); + $scope.quiz.push(new ExerciceMCQFlag()); } $scope.deleteQuiz = function() { this.q.$delete(function() { diff --git a/admin/static/views/exercice-list.html b/admin/static/views/exercice-list.html index ced277ee..b8bd9698 100644 --- a/admin/static/views/exercice-list.html +++ b/admin/static/views/exercice-list.html @@ -8,8 +8,8 @@ -