admin: new page to display exercices flags
This commit is contained in:
parent
15ae32090f
commit
3f692984c7
5 changed files with 304 additions and 88 deletions
|
@ -29,6 +29,10 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"])
|
|||
controller: "ExerciceController",
|
||||
templateUrl: "views/exercice.html"
|
||||
})
|
||||
.when("/exercices/:exerciceId/flags", {
|
||||
controller: "ExerciceController",
|
||||
templateUrl: "views/exercice-flags.html"
|
||||
})
|
||||
.when("/exercices/:exerciceId/resolution", {
|
||||
controller: "ExerciceController",
|
||||
templateUrl: "views/exercice-resolution.html"
|
||||
|
@ -262,7 +266,9 @@ angular.module("FICApp")
|
|||
})
|
||||
})
|
||||
.factory("ExerciceFlagChoices", function($resource) {
|
||||
return $resource("/api/exercices/:exerciceId/flags/:flagId/choices", { exerciceId: '@idExercice', flagId: '@id' })
|
||||
return $resource("/api/exercices/:exerciceId/flags/:flagId/choices/:choiceId", { exerciceId: '@idExercice', flagId: '@idFlag', choiceId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("ExerciceFlagDeps", function($resource) {
|
||||
return $resource("/api/exercices/:exerciceId/flags/:flagId/dependancies", { exerciceId: '@idExercice', flagId: '@id' })
|
||||
|
@ -1632,6 +1638,12 @@ angular.module("FICApp")
|
|||
.controller("ExerciceFlagsController", function($scope, ExerciceFlag, $routeParams, $rootScope, $http) {
|
||||
$scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId });
|
||||
|
||||
$scope.flags.$promise.then(function(flags) {
|
||||
flags.forEach(function(flag, fid) {
|
||||
flags[fid].values = [''];
|
||||
});
|
||||
});
|
||||
|
||||
$scope.changeValue = function(flag) {
|
||||
flag.value = undefined;
|
||||
flag.show_raw = true;
|
||||
|
@ -1656,6 +1668,13 @@ angular.module("FICApp")
|
|||
$rootScope.staticFilesNeedUpdate++;
|
||||
}
|
||||
$scope.testFlag = function(flag) {
|
||||
if (flag.values) {
|
||||
var val = flag.value;
|
||||
treatFlagKey(flag);
|
||||
flag.test_str = flag.value;
|
||||
flag.value = val;
|
||||
}
|
||||
|
||||
if (flag.test_str) {
|
||||
$http({
|
||||
url: "/api/exercices/" + $routeParams.exerciceId + "/flags/" + flag.id + "/try",
|
||||
|
@ -1691,6 +1710,41 @@ angular.module("FICApp")
|
|||
};
|
||||
})
|
||||
|
||||
.controller("ExerciceFlagChoicesController", function($scope, ExerciceFlagChoices, $routeParams) {
|
||||
$scope.choices = ExerciceFlagChoices.query({ exerciceId: $routeParams.exerciceId, flagId: $scope.flag.id })
|
||||
|
||||
$scope.flag.wantchoices = function() {
|
||||
$scope.flag.choices = {};
|
||||
$scope.choices.forEach(function(choice) {
|
||||
$scope.flag.choices[choice.value] = choice.label
|
||||
})
|
||||
}
|
||||
$scope.choices.$promise.then(function(choices) {
|
||||
if ($scope.flag.choices_cost == 0 && choices.length > 0) {
|
||||
$scope.flag.wantchoices()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
$scope.addChoice = function() {
|
||||
$scope.choices.push(new ExerciceFlagChoices())
|
||||
}
|
||||
|
||||
$scope.saveChoice = function() {
|
||||
if (this.choice.id)
|
||||
this.choice.$update({exerciceId: $routeParams.exerciceId, flagId: this.flag.id})
|
||||
else
|
||||
this.choice.$save({exerciceId: $routeParams.exerciceId, flagId: this.flag.id})
|
||||
}
|
||||
|
||||
$scope.deleteChoice = function() {
|
||||
if (this.choice.id)
|
||||
this.choice.$delete({exerciceId: $routeParams.exerciceId, flagId: this.flag.id}, function() {
|
||||
$scope.choices = ExerciceFlagChoices.query({ exerciceId: $routeParams.exerciceId, flagId: $scope.flag.id })
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExerciceFlagDepsController", function($scope, $routeParams, ExerciceFlagDeps) {
|
||||
$scope.init = function(flag) {
|
||||
$scope.deps = ExerciceFlagDeps.query({ exerciceId: $routeParams.exerciceId, flagId: flag.id });
|
||||
|
|
Reference in a new issue