admin: implement MCQ edition in interface
This commit is contained in:
parent
92ba880006
commit
3a65363ebb
3 changed files with 137 additions and 0 deletions
|
|
@ -222,6 +222,11 @@ angular.module("FICApp")
|
|||
return $resource("/api/exercices/:exerciceId/keys/:keyId", { exerciceId: '@idExercice', keyId: '@id' }, {
|
||||
update: {method: 'PUT'}
|
||||
})
|
||||
})
|
||||
.factory("ExerciceMCQKey", function($resource) {
|
||||
return $resource("/api/exercices/:exerciceId/quiz/:mcqId", { exerciceId: '@idExercice', mcqId: '@id' }, {
|
||||
update: {method: 'PUT'}
|
||||
})
|
||||
});
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
|
|
@ -1127,6 +1132,35 @@ angular.module("FICApp")
|
|||
};
|
||||
})
|
||||
|
||||
.controller("ExerciceMCQKeysController", function($scope, ExerciceMCQKey, $routeParams, $rootScope, $http) {
|
||||
$scope.quiz = ExerciceMCQKey.query({ exerciceId: $routeParams.exerciceId });
|
||||
|
||||
$scope.addQuiz = function() {
|
||||
$scope.quiz.push(new ExerciceMCQKey());
|
||||
}
|
||||
$scope.deleteQuiz = function() {
|
||||
this.q.$delete(function() {
|
||||
$scope.quiz.splice($scope.quiz.indexOf(this.q), 1);
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when trying to delete flag:', response.data);
|
||||
});
|
||||
}
|
||||
$scope.saveQuiz = function() {
|
||||
if (this.q.id) {
|
||||
this.q.$update();
|
||||
} else {
|
||||
this.q.$save({ exerciceId: $routeParams.exerciceId });
|
||||
}
|
||||
}
|
||||
|
||||
$scope.addChoice = function() {
|
||||
this.quiz[this.qk].entries.push({label: "", response: false})
|
||||
}
|
||||
$scope.deleteChoice = function() {
|
||||
this.quiz[this.qk].entries.splice(this.quiz[this.qk].entries.indexOf(this.choice), 1);
|
||||
}
|
||||
})
|
||||
|
||||
.controller("TeamsListController", function($scope, Team, $location) {
|
||||
$scope.teams = Team.query();
|
||||
$scope.fields = ["id", "name"];
|
||||
|
|
|
|||
|
|
@ -110,6 +110,44 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-success mt-2" ng-controller="ExerciceMCQKeysController">
|
||||
<div class="card-header bg-success text-light">
|
||||
<button ng-click="addQuiz()" class="float-right btn btn-sm btn-primary" style="margin-left: 7px"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
|
||||
<h4>Quizz</h4>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<form ng-submit="saveQuiz()" class="list-group-item form-horizontal bg-light text-dark" 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>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
Reference in a new issue