diff --git a/admin/static/js/app.js b/admin/static/js/app.js index d78f79ca..5c48d8ef 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -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 }); diff --git a/admin/static/views/exercice-flags.html b/admin/static/views/exercice-flags.html new file mode 100644 index 00000000..3b701808 --- /dev/null +++ b/admin/static/views/exercice-flags.html @@ -0,0 +1,159 @@ +
+ +

+ {{exercice.title}} Flags +
+ + +
+

+ +
+
+ +

Drapeaux

+
+
+
+
+
+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+
+ + +
+
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+ Dépendances : +
    + +
+ sans +
+
+
+ +
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+ Aucun choix +
+
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +

Quizz

+
+
+
+
+ +
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+ Dépendances : +
    + +
+ sans +
+
+
+
+
diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index af825ddf..2f0e2b93 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -5,8 +5,9 @@ - Vidéo - + Vidéo + Flags +
diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index fad7eee9..5bc47192 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -1,51 +1,3 @@ -var alertNbLines = true; - -function treatFlagKey(flag) { - if (flag.values !== undefined) { - if (flag.separator) { - for (var i = flag.values.length - 1; i >= 0; i--) { - if (flag.nb_lines && (flag.values[i] == undefined || !flag.values[i].length)) { - if (alertNbLines) { - alertNbLines = false; - if (!confirm("Lorsque plusieurs flags sont attendus pour une même question, ceux-ci ne sont pas validés un par un. Ils ne sont validés qu'une fois tous les champs remplis correctement. (Sauf mention contraire, l'ordre n'importe pas)")) - console.log(flag.values[9999].length); // Launch exception here to avoid form validation - } - } - else if (!flag.values[i].length) { - flag.values.splice(i, 1); - } - } - - if (flag.ignore_order) - flag.value = flag.values.slice().sort().join(flag.separator) + flag.separator; - else - flag.value = flag.values.join(flag.separator) + flag.separator; - - if (flag.values.length == 0) - flag.values = [""]; - } - else - flag.value = flag.values[0]; - } - - if (flag.found == null && flag.soluce !== undefined) { - if (flag.value && flag.soluce) { - if (flag.ignore_case) - flag.value = flag.value.toLowerCase(); - if (flag.validator_regexp) { - var re = new RegExp(flag.validator_regexp, flag.ignore_case?'ui':'u'); - var match = re.exec(flag.value); - match.shift(); - flag.value = match.join("+"); - } - - if (flag.soluce == b2sum(flag.value)) - flag.found = new Date(); - } - } - return flag.found !== undefined && flag.found !== false; -} - angular.module("FICApp", ["ngRoute", "ngSanitize"]) .config(function($routeProvider, $locationProvider) { $routeProvider @@ -126,43 +78,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) $rootScope.notify_field = 0; }); }) - .component('flagKey', { - bindings: { - kid: '=', - key: '=', - settings: '=', - wantchoices: '=', - }, - controller: function() { - this.additem = function(key) { - this.key.values.push(""); - }; - }, - template: ` -
- - -
- - - -
- -
-
- -
-
- - -
- ` - }) .controller("DataController", function($sce, $scope, $http, $rootScope, $interval, $location) { var actMenu = function() { if ($scope.my && $scope.themes) { diff --git a/frontend/static/js/common.js b/frontend/static/js/common.js index 98de08cf..6f3a0371 100644 --- a/frontend/static/js/common.js +++ b/frontend/static/js/common.js @@ -1,3 +1,51 @@ +var alertNbLines = true; + +function treatFlagKey(flag) { + if (flag.values !== undefined) { + if (flag.separator) { + for (var i = flag.values.length - 1; i >= 0; i--) { + if (flag.nb_lines && (flag.values[i] == undefined || !flag.values[i].length)) { + if (alertNbLines) { + alertNbLines = false; + if (!confirm("Lorsque plusieurs flags sont attendus pour une même question, ceux-ci ne sont pas validés un par un. Ils ne sont validés qu'une fois tous les champs remplis correctement. (Sauf mention contraire, l'ordre n'importe pas)")) + console.log(flag.values[9999].length); // Launch exception here to avoid form validation + } + } + else if (!flag.values[i].length) { + flag.values.splice(i, 1); + } + } + + if (flag.ignore_order) + flag.value = flag.values.slice().sort().join(flag.separator) + flag.separator; + else + flag.value = flag.values.join(flag.separator) + flag.separator; + + if (flag.values.length == 0) + flag.values = [""]; + } + else + flag.value = flag.values[0]; + } + + if (flag.found == null && flag.soluce !== undefined) { + if (flag.value && flag.soluce) { + if (flag.ignore_case) + flag.value = flag.value.toLowerCase(); + if (flag.validator_regexp) { + var re = new RegExp(flag.validator_regexp, flag.ignore_case?'ui':'u'); + var match = re.exec(flag.value); + match.shift(); + flag.value = match.join("+"); + } + + if (flag.soluce == b2sum(flag.value)) + flag.found = new Date(); + } + } + return flag.found !== undefined && flag.found !== false; +} + String.prototype.capitalize = function() { return this .toLowerCase() @@ -130,6 +178,45 @@ angular.module("FICApp") } }); +angular.module("FICApp") + .component('flagKey', { + bindings: { + kid: '=', + key: '=', + settings: '=', + wantchoices: '=', + }, + controller: function() { + this.additem = function(key) { + this.key.values.push(""); + }; + }, + template: ` +
+ + +
+ + + +
+ +
+
+ +
+
+ + +
+ ` + }); + angular.module("FICApp") .controller("CountdownController", function($scope, $rootScope, $interval) { var time;