admin: new page to display exercices flags

This commit is contained in:
nemunaire 2020-01-28 14:05:00 +01:00
parent 15ae32090f
commit 3f692984c7
5 changed files with 304 additions and 88 deletions

View file

@ -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 });

View file

@ -0,0 +1,159 @@
<div ng-controller="ExerciceFlagsController">
<button type="button" ng-click="syncFlags()" class="btn btn-light float-right"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Synchroniser</button>
<h2>
<a href="exercices/{{exercice.id}}">{{exercice.title}}</a> <small class="text-muted">Flags</small>
<div class="btn-group" role="group" ng-if="themes[exercice.id_theme].exercices[exercice.id]">
<a href="exercices/{{ themes[exercice.id_theme].exercices[exercice.id].previous }}/flags" title="Exercice précédent" ng-class="{'disabled': !themes[exercice.id_theme].exercices[exercice.id].previous}" class="btn btn-sm btn-light"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></a>
<a href="exercices/{{ themes[exercice.id_theme].exercices[exercice.id].next }}/flags" title="Exercice suivant" ng-class="{'disabled': !themes[exercice.id_theme].exercices[exercice.id].next}" class="btn btn-sm btn-light"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a>
</div>
</h2>
<div class="card border-success mb-3">
<div class="card-header bg-success text-light">
<button type="button" ng-click="addFlag()" class="btn btn-primary float-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter</button>
<h4 class="m-0">Drapeaux</h4>
</div>
<div class="list-group">
<div ng-repeat="flag in flags" class="list-group-item">
<div class="row">
<div class="col-4">
<form ng-submit="saveFlag()" class="form-horizontal" id="flag-{{flag.id}}">
<div class="form-group">
<div class="float-right" ng-show="flag.id">
<button type="submit" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button>
</div>
<label for="klabel{{flag.id}}" class="col-form-label-sm">Intitulé</label>
<input type="text" id="klabel{{flag.id}}" ng-model="flag.label" class="form-control form-control-sm" placeholder="Intitulé" title="Intitulé">
</div>
<div class="form-group">
<div class="float-right">
<button type="button" ng-click="deleteFlag()" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
</div>
<label for="khelp{{flag.id}}" class="col-form-label-sm">Placeholder</label>
<input type="text" id="khelp{{flag.id}}" ng-model="flag.help" class="form-control form-control-sm" placeholder="Indication de formatage" title="Indication de formatage">
</div>
<div class="form-group">
<label for="kvalue{{flag.id}}" class="col-form-label-sm">Valeur</label>
<div class="input-group" ng-if="flag.id && !flag.show_raw">
<input type="text" id="kvalue{{flag.id}}" ng-model="flag.value" class="form-control form-control-sm" placeholder="Condensat" title="Condensat">
<div class="input-group-append">
<button class="btn btn-sm btn-outline-secondary" ng-click="changeValue(flag)" title="Cliquez pour éditer la valeur brute du flag, au lieu du checksum" type="button"><span class="glyphicon glyphicon-erase" aria-hidden="true"></span></button>
</div>
</div>
<input type="text" id="kflag{{flag.id}}" ng-model="flag.flag" class="form-control form-control-sm" placeholder="Chaîne brute à valider" ng-if="!flag.id || flag.show_raw" title="Chaîne brute à valider">
</div>
<div class="form-group">
<label for="kvre{{flag.id}}" class="col-form-label-sm">Validator regexp</label>
<input type="text" id="kvre{{flag.id}}" ng-model="flag.validator_regexp" class="form-control form-control-sm" placeholder="Regexp selecting validation string" title="Regexp selecting validation string">
</div>
<div class="form-group row">
<div class="col-auto custom-control custom-checkbox ml-1">
<input type="checkbox" class="custom-control-input" id="kicase{{flag.id}}" ng-model="flag.ignorecase">
<label class="custom-control-label" for="kicase{{flag.id}}">Ignore case</label>
</div>
<div class="col-auto custom-control custom-checkbox ml-1">
<input type="checkbox" class="custom-control-input" id="kmline{{flag.id}}" ng-model="flag.multiline">
<label class="custom-control-label" for="kmline{{flag.id}}">Multiline</label>
</div>
<div class="col-4">
<input type="text" id="kccost{{flag.id}}" ng-model="flag.choices_cost" class="form-control form-control-sm" placeholder="Choices cost" title="Choices cost" integer>
</div>
</div>
</form>
</div>
<div class="col-4">
<div ng-controller="ExerciceFlagDepsController" ng-init="init(flag)">
Dépendances&nbsp;:
<ul ng-if="deps.length > 0">
<dependancy ng-repeat="dep in deps" dep="dep"></dependancy>
</ul>
<span ng-if="deps.length == 0"> sans</span>
</div>
</div>
<div class="col-4" ng-controller="ExerciceFlagChoicesController">
<div class="btn-toolbar justify-content-end mb-2" role="toolbar">
<div class="btn-group" role="group">
<button type="button" ng-click="addChoice()" class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter choix</button>
</div>
</div>
<div ng-repeat="choice in choices" ng-if="choices.length > 0">
<div class="row">
<label for="clabel_{{choice.id}}" class="col-sm-3 col-form-label-sm">Intitulé</label>
<div class="col-sm-7">
<input type="text" id="clabel_{{choice.id}}" ng-model="choice.label" class="form-control form-control-sm">
</div>
<div class="col-sm-2">
<button type="button" ng-click="saveChoice()" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button>
</div>
</div>
<div class="row">
<label for="cvalue_{{choice.id}}" class="col-sm-3 col-form-label-sm">Valeur</label>
<div class="col-sm-7">
<input type="text" id="cvalue_{{choice.id}}" ng-model="choice.value" class="form-control form-control-sm">
</div>
<div class="col-sm-2">
<button type="button" ng-click="deleteChoice()" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
</div>
</div>
<hr ng-if="!$last">
</div>
<span ng-if="choices.length == 0">Aucun choix</span>
</div>
</div>
<form ng-submit="testFlag(flag)" class="row bg-dark" style="border-radius: 5px; padding: 5px 0">
<div class="col-11">
<flag-key kid="flag.id" key="flag" settings="{'wchoiceCurrentCoefficient': 1.0}" wantchoices="flag.wantchoices"></flag-key>
</div>
<div class="col-1">
<button class="btn btn-warning" type="submit"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></button>
</div>
</form>
</div>
</div>
</div>
<div class="card border-success mb-3" ng-controller="ExerciceMCQFlagsController">
<div class="card-header bg-success text-light">
<button type="button" ng-click="addQuizz()" class="btn btn-primary float-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter</button>
<h4 class="m-0">Quizz</h4>
</div>
<div class="list-group">
<form ng-submit="saveQuiz()" class="list-group-item" ng-repeat="(qk,q) in quiz">
<div class="form-group row" id="quiz-{{q.id}}">
<input type="text" id="qlabel{{q.id}}" ng-model="q.title" class="col form-control" placeholder="Intitulé">
<div class="col-auto" ng-show="q.id">
<button type="button" ng-click="deleteQuiz()" class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
</div>
</div>
<div class="form-group row" ng-repeat="(ck,choice) in q.entries">
<div class="col form-check">
<label class="custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" ng-model="choice.response">
<span class="custom-control-label">
<input type="text" id="kchoice{{q.id}}-{{choice.id}}" ng-model="choice.label" class="form-control form-control-sm" placeholder="Intitulé">
</span>
</label>
</div>
<div class="col-auto">
<button type="button" ng-click="deleteChoice()" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</div>
</div>
<div class="form-group row">
<div class="col-auto">
<button type="button" ng-click="addChoice()" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un choix</button>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button>
</div>
</div>
<div ng-controller="ExerciceMCQDepsController" ng-init="init(q)">
Dépendances&nbsp;:
<ul ng-if="deps.length > 0">
<dependancy ng-repeat="dep in deps" dep="dep"></dependancy>
</ul>
<span ng-if="deps.length == 0"> sans</span>
</div>
</form>
</div>
</div>
</div>

View file

@ -5,8 +5,9 @@
<a href="exercices/{{ themes[exercice.id_theme].exercices[exercice.id].previous }}" title="Exercice précédent" ng-class="{'disabled': !themes[exercice.id_theme].exercices[exercice.id].previous}" class="btn btn-sm btn-light"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></a>
<a href="exercices/{{ themes[exercice.id_theme].exercices[exercice.id].next }}" title="Exercice suivant" ng-class="{'disabled': !themes[exercice.id_theme].exercices[exercice.id].next}" class="btn btn-sm btn-light"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a>
</div>
<a href="exercices/{{exercice.id}}/resolution" ng-disabled="!exercice.videoURI" class="float-right btn btn-sm btn-info"><span class="glyphicon glyphicon-facetime-video" aria-hidden="true"></span> Vidéo</a>
<button type="button" ng-click="syncExo()" ng-class="{'disabled': inSync}" class="float-right btn btn-sm btn-light"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Synchroniser</button>
<a href="exercices/{{exercice.id}}/resolution" ng-disabled="!exercice.videoURI" class="float-right ml-2 btn btn-sm btn-info"><span class="glyphicon glyphicon-facetime-video" aria-hidden="true"></span> Vidéo</a>
<a href="exercices/{{exercice.id}}/flags" class="float-right ml-2 btn btn-sm btn-success"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Flags</a>
<button type="button" ng-click="syncExo()" ng-class="{'disabled': inSync}" class="float-right ml-2 btn btn-sm btn-light"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Synchroniser</button>
</h2>
<div class="row mb-5">