admin: Add ability to append element to exercice history

This commit is contained in:
nemunaire 2024-03-17 10:19:35 +01:00
commit 977caccc1f
6 changed files with 237 additions and 3 deletions

View file

@ -1908,6 +1908,54 @@ angular.module("FICApp")
});
}
}
$scope.selectedTeam = "";
$scope.validateForTeam = function() {
var flagid = $("#validationModal").data("flagid");
if (!flagid) return;
var target = {
team_id: parseInt($("#tteam").val().replace(/number:/, '')),
kind: $("#validationModal").data("kind"),
secondary: flagid,
};
$http({
url: "api/exercices/" + $scope.exercice.id + "/history.json",
method: "PUT",
data: target
}).then(function(response) {
$rootScope.staticFilesNeedUpdate++;
$("#validationModal").modal('hide');
$scope.addToast('success', 'Flag validé avec succès');
}, function(response) {
$scope.addToast('danger', 'An error occurs when trying to validate flag for team:', response.data.errmsg);
});
}
$scope.historyAppend = function() {
var secondary = null;
if ($("#historyEvent").val() == "hint")
secondary = parseInt($("#historySecondaryHint").val().replace(/number:/, ''));
else if ($("#historyEvent").val() == "wchoices" || $("#historyEvent").val() == "flag_found")
secondary = parseInt($("#historySecondaryFlag").val().replace(/number:/, ''));
else if ($("#historyEvent").val() == "mcq_found")
secondary = parseInt($("#historySecondaryQuiz").val().replace(/number:/, ''));
var target = {
team_id: parseInt($("#tteam").val().replace(/number:/, '')),
kind: $("#historyEvent").val(),
secondary: secondary,
};
$http({
url: "api/exercices/" + $scope.exercice.id + "/history.json",
method: "PUT",
data: target
}).then(function(response) {
$rootScope.staticFilesNeedUpdate++;
$("#appendHistoryModal").modal('hide');
$scope.addToast('success', 'Événement ajouté avec succès');
$scope.refreshHistory();
}, function(response) {
$scope.addToast('danger', 'An error occurs when trying to add event in history:', response.data.errmsg);
});
}
})
.controller("SubmissionsStatsController", function($scope, $http, $interval) {
@ -1983,7 +2031,12 @@ angular.module("FICApp")
})
.controller("ExerciceHistoryController", function($scope, ExerciceHistory, $routeParams, $http, $rootScope) {
$scope.history = ExerciceHistory.query({ exerciceId: $routeParams.exerciceId });
$scope.history = [];
$scope.refreshHistory = function() {
$scope.history = ExerciceHistory.query({ exerciceId: $routeParams.exerciceId });
}
$scope.$parent.refreshHistory = $scope.refreshHistory;
$scope.refreshHistory();
$scope.updHistory = function() {
var target = {
team_id: $("#updHistory").data("idteam"),