diff --git a/admin/api/exercice.go b/admin/api/exercice.go index 0e85a77e..3393546a 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -3,6 +3,7 @@ package api import ( "encoding/json" "errors" + "fmt" "strings" "time" @@ -30,6 +31,7 @@ func init() { router.GET("/api/exercices/:eid/hints/:hid", apiHandler(hintHandler(showExerciceHint))) 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/hints/:hid/dependancies", apiHandler(hintHandler(showExerciceHintDeps))) router.GET("/api/exercices/:eid/flags", apiHandler(exerciceHandler(listExerciceFlags))) router.POST("/api/exercices/:eid/flags", apiHandler(exerciceHandler(createExerciceFlag))) @@ -37,6 +39,7 @@ func init() { router.PUT("/api/exercices/:eid/flags/:kid", apiHandler(flagKeyHandler(updateExerciceFlag))) router.POST("/api/exercices/:eid/flags/:kid/try", apiHandler(flagKeyHandler(tryExerciceFlag))) router.DELETE("/api/exercices/:eid/flags/:kid", apiHandler(flagKeyHandler(deleteExerciceFlag))) + router.GET("/api/exercices/:eid/flags/:kid/dependancies", apiHandler(flagKeyHandler(showExerciceFlagDeps))) router.GET("/api/exercices/:eid/flags/:kid/choices/", apiHandler(flagKeyHandler(listFlagChoices))) router.GET("/api/exercices/:eid/flags/:kid/choices/:cid", apiHandler(choiceHandler(showFlagChoice))) router.POST("/api/exercices/:eid/flags/:kid/choices/", apiHandler(flagKeyHandler(createFlagChoice))) @@ -47,6 +50,7 @@ func init() { router.GET("/api/exercices/:eid/quiz/:qid", apiHandler(quizHandler(showExerciceQuiz))) router.PUT("/api/exercices/:eid/quiz/:qid", apiHandler(quizHandler(updateExerciceQuiz))) router.DELETE("/api/exercices/:eid/quiz/:qid", apiHandler(quizHandler(deleteExerciceQuiz))) + router.GET("/api/exercices/:eid/quiz/:qid/dependancies", apiHandler(quizHandler(showExerciceQuizDeps))) router.GET("/api/exercices/:eid/tags", apiHandler(exerciceHandler(listExerciceTags))) router.POST("/api/exercices/:eid/tags", apiHandler(exerciceHandler(addExerciceTag))) @@ -111,6 +115,34 @@ func exportResolutionMovies(_ httprouter.Params, body []byte) (interface{}, erro } } +func loadFlags(n func () ([]fic.Flag, error)) (interface{}, error) { + if flags, err := n(); err != nil { + return nil, err + } else { + var ret []fic.Flag + + for _, flag := range flags { + if f, ok := flag.(fic.FlagKey); ok { + if k, err := fic.GetFlagKey(f.Id); err != nil { + return nil, err + } else { + ret = append(ret, k) + } + } else if f, ok := flag.(fic.MCQ); ok { + if m, err := fic.GetMCQ(f.Id); err != nil { + return nil, err + } else { + ret = append(ret, m) + } + } else { + return nil, errors.New(fmt.Sprintf("Flag type %T not implemented for this flag.", f)) + } + } + + return ret, nil + } +} + func listExerciceHints(exercice fic.Exercice, body []byte) (interface{}, error) { return exercice.GetHints() } @@ -298,6 +330,10 @@ func showExerciceHint(hint fic.EHint, body []byte) (interface{}, error) { return hint, nil } +func showExerciceHintDeps(hint fic.EHint, body []byte) (interface{}, error) { + return loadFlags(hint.GetDepends) +} + func updateExerciceHint(hint fic.EHint, body []byte) (interface{}, error) { var uh fic.EHint if err := json.Unmarshal(body, &uh); err != nil { @@ -354,6 +390,10 @@ func showExerciceFlag(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{ return flag, nil } +func showExerciceFlagDeps(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}, error) { + return loadFlags(flag.GetDepends) +} + func tryExerciceFlag(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}, error) { var uk uploadedFlag if err := json.Unmarshal(body, &uk); err != nil { @@ -457,6 +497,10 @@ func showExerciceQuiz(quiz fic.MCQ, _ fic.Exercice, body []byte) (interface{}, e return quiz, nil } +func showExerciceQuizDeps(quiz fic.MCQ, _ fic.Exercice, body []byte) (interface{}, error) { + return loadFlags(quiz.GetDepends) +} + func updateExerciceQuiz(quiz fic.MCQ, exercice fic.Exercice, body []byte) (interface{}, error) { var uq fic.MCQ if err := json.Unmarshal(body, &uq); err != nil { diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 224a2eb1..8b8d5e7d 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -250,15 +250,27 @@ angular.module("FICApp") update: {method: 'PUT'} }) }) + .factory("ExerciceHintDeps", function($resource) { + return $resource("/api/exercices/:exerciceId/hints/:hintId/dependancies", { exerciceId: '@idExercice', hintId: '@id' }) + }) .factory("ExerciceFlag", function($resource) { return $resource("/api/exercices/:exerciceId/flags/:flagId", { exerciceId: '@idExercice', flagId: '@id' }, { update: {method: 'PUT'} }) }) + .factory("ExerciceFlagChoices", function($resource) { + return $resource("/api/exercices/:exerciceId/flags/:flagId/choices", { exerciceId: '@idExercice', flagId: '@id' }) + }) + .factory("ExerciceFlagDeps", function($resource) { + return $resource("/api/exercices/:exerciceId/flags/:flagId/dependancies", { exerciceId: '@idExercice', flagId: '@id' }) + }) .factory("ExerciceMCQFlag", function($resource) { return $resource("/api/exercices/:exerciceId/quiz/:mcqId", { exerciceId: '@idExercice', mcqId: '@id' }, { update: {method: 'PUT'} }) + }) + .factory("ExerciceMCQDeps", function($resource) { + return $resource("/api/exercices/:exerciceId/quiz/:mcqId/dependancies", { exerciceId: '@idExercice', mcqId: '@id' }) }); angular.module("FICApp") @@ -293,6 +305,21 @@ angular.module("FICApp") } }) + .component('dependancy', { + bindings: { + dep: '=', + deleteDep: '=', + }, + controller: function() {}, + template: ` +
  • + Flag {{ $ctrl.dep.label }} + QCM {{ $ctrl.dep.title }} + +
  • + ` + }) + .directive('color', function() { return { require: 'ngModel', @@ -1542,6 +1569,12 @@ angular.module("FICApp") }; }) + .controller("ExerciceHintDepsController", function($scope, $routeParams, ExerciceHintDeps) { + $scope.init = function(hint) { + $scope.deps = ExerciceHintDeps.query({ exerciceId: $routeParams.exerciceId, hintId: hint.id }); + } + }) + .controller("ExerciceFlagsController", function($scope, ExerciceFlag, $routeParams, $rootScope, $http) { $scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId }); @@ -1604,6 +1637,12 @@ angular.module("FICApp") }; }) + .controller("ExerciceFlagDepsController", function($scope, $routeParams, ExerciceFlagDeps) { + $scope.init = function(flag) { + $scope.deps = ExerciceFlagDeps.query({ exerciceId: $routeParams.exerciceId, flagId: flag.id }); + } + }) + .controller("ExerciceMCQFlagsController", function($scope, ExerciceMCQFlag, $routeParams, $rootScope) { $scope.quiz = ExerciceMCQFlag.query({ exerciceId: $routeParams.exerciceId }); @@ -1635,6 +1674,12 @@ angular.module("FICApp") } }) + .controller("ExerciceMCQDepsController", function($scope, $routeParams, ExerciceMCQDeps) { + $scope.init = function(flag) { + $scope.deps = ExerciceMCQDeps.query({ exerciceId: $routeParams.exerciceId, mcqId: flag.id }); + } + }) + .controller("TeamsListController", function($scope, $rootScope, Team, $location, $http) { $scope.teams = Team.query(); $scope.fields = ["id", "name"]; diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index 6ac39ed1..7156dd68 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -75,11 +75,7 @@ Dépend de la validation de : aucun flag @@ -118,6 +114,13 @@ +
    + Dépendances : + + sans +
    @@ -177,6 +180,13 @@ +
    + Dépendances : + + sans +
    @@ -222,6 +232,13 @@ +
    + Dépendances : + + sans +