From 0fa59dd858d93f51daa9fd50a5012bcec6c00b83 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 30 Nov 2020 09:26:34 +0100 Subject: [PATCH 1/2] Readd function to display survey mean --- grades.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/grades.go b/grades.go index b6d762c..b79c7a4 100644 --- a/grades.go +++ b/grades.go @@ -28,6 +28,15 @@ func init() { })(ps, body) })(uauth, ps, body) }, loggedUser)) + router.GET("/api/surveys/:sid/grades", apiAuthHandler(surveyAuthHandler(func(s Survey, uauth *User, _ []byte) HTTPResponse { + if scores, err := s.GetGrades(); err != nil { + return APIErrorResponse{err: err} + } else if scores == nil { + return APIResponse{"N/A"} + } else { + return APIResponse{scores} + } + }), adminRestricted)) router.GET("/api/grades", apiAuthHandler(func(uauth *User, ps httprouter.Params, body []byte) HTTPResponse { if uauth != nil && uauth.IsAdmin { if score, err := GetAllGrades(); err != nil { From dabc01ea113d8ae29cd311e55fffb64b1cade7ab Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 30 Nov 2020 10:31:38 +0100 Subject: [PATCH 2/2] List not yet corrected users --- htdocs/js/atsebayt.js | 41 +++++++++++++++++++++++++++++++------ htdocs/views/responses.html | 27 +++++++++++++++++++++++- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/htdocs/js/atsebayt.js b/htdocs/js/atsebayt.js index 8810178..def21a9 100644 --- a/htdocs/js/atsebayt.js +++ b/htdocs/js/atsebayt.js @@ -58,7 +58,7 @@ angular.module("AtsebaytApp") .factory("MyResponse", function($resource) { return $resource("/api/surveys/:surveyId/responses/:respId", { surveyId: '@id', respId: '@id' }) }) - .factory("UserResponse", function($resource) { + .factory("UserResponses", function($resource) { return $resource("/api/users/:userId/surveys/:surveyId/responses/:respId", { userId: '@id', surveyId: '@id', respId: '@id' }) }) .factory("Grades", function($resource) { @@ -333,8 +333,25 @@ angular.module("AtsebaytApp") }) }) - .controller("ResponsesController", function($scope, AllResponses) { + .controller("ResponsesController", function($scope, AllResponses, $rootScope, $location) { $scope.responses = AllResponses.query({ surveyId: $scope.survey.id, questId: $scope.question.id }); + $scope.responses.$promise.then(function (responses) { + if (!$rootScope.usersResponses) { + $rootScope.usersResponses = {} + } + responses.forEach(function (response) { + if (!response.time_scored) { + if ($rootScope.usersResponses[response.id_user] === undefined) { + $rootScope.usersResponses[response.id_user] = [] + } + $rootScope.usersResponses[response.id_user].push(response.id_question) + } + }); + }) + + $rootScope.showUserSurvey = function () { + $location.url("users/" + this.id_user + "/surveys/" + this.survey.id); + } }) .controller("ScoreController", function($scope, SurveyScore) { @@ -388,7 +405,11 @@ angular.module("AtsebaytApp") .controller("UserController", function($scope, $routeParams, $rootScope, User) { $rootScope.qactive = false; $rootScope.uactive = true; - $scope.user = User.get({ userId: $routeParams.userId}) + if ($scope.id_user) { + $scope.user = User.get({ userId: $scope.id_user}) + } else { + $scope.user = User.get({ userId: $routeParams.userId}) + } }) .controller("QuestionController", function($scope, Survey, SurveyQuest, AllResponses, UserResponses, CorrectionTemplate, $http, $routeParams) { @@ -522,9 +543,17 @@ angular.module("AtsebaytApp") } }) - .controller("QuestionsController", function($scope, SurveyQuest, MyResponse, UserResponse, $http, $routeParams, $location) { + .controller("QuestionsController", function($scope, SurveyQuest, MyResponse, UserResponses, $http, $routeParams, $location, $rootScope) { + $rootScope.usersResponses = null; $scope.questions = SurveyQuest.query({ surveyId: $scope.survey.id }); - $scope.questions.$promise.then(function (questions) {$scope.showSubmit = true;}, function (response) { + $scope.questions.$promise.then(function (questions) { + $scope.showSubmit = true; + var mapQuestions = {}; + questions.forEach(function (question) { + mapQuestions[question.id] = question; + }); + $scope.mapQuestions = mapQuestions; + }, function (response) { $scope.addToast({ variant: "danger", title: $scope.survey.title, @@ -535,7 +564,7 @@ angular.module("AtsebaytApp") if ($routeParams.userId == null) { $scope.myresponses = MyResponse.query({ surveyId: $scope.survey.id }); } else { - $scope.myresponses = UserResponse.query({ userId: $routeParams.userId, surveyId: $scope.survey.id }); + $scope.myresponses = UserResponses.query({ userId: $routeParams.userId, surveyId: $scope.survey.id }); } $scope.myresponses.$promise.then(function (responses) { $scope.questions.$promise.then(function (questions) { diff --git a/htdocs/views/responses.html b/htdocs/views/responses.html index d03cfbe..894b559 100644 --- a/htdocs/views/responses.html +++ b/htdocs/views/responses.html @@ -7,7 +7,9 @@ - +
+ +
@@ -28,3 +30,26 @@
Question
+ +
+

Restant à corriger

+ + + + + + + + + + + + + +
ÉtudiantQuestions
{{ user.login }} +
+ {{ mapQuestions[question].title }} +
+
+
+