Add correction steps
This commit is contained in:
parent
1d8c4a375c
commit
7201c3d02a
5 changed files with 577 additions and 29 deletions
|
@ -34,6 +34,11 @@ angular.module("AtsebaytApp")
|
|||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("CorrectionTemplate", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/questions/:questId/corrections/:correctId", { surveyId: '@id', questId: '@id', correctId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("MyResponse", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/responses/:respId", { surveyId: '@id', respId: '@id' })
|
||||
})
|
||||
|
@ -135,7 +140,8 @@ angular.module("AtsebaytApp")
|
|||
<td class="bg-success" ng-if="survey.end_availability < $ctrl.now && survey.corrected">Corrigé</td>
|
||||
<td ng-if="survey.start_availability > $ctrl.now">{{ survey.start_availability | date: "medium" }} <svg class="bi bi-arrow-bar-right" width="1em" height="1em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M12.146 6.646a.5.5 0 01.708 0l3 3a.5.5 0 010 .708l-3 3a.5.5 0 01-.708-.708L14.793 10l-2.647-2.646a.5.5 0 010-.708z" clip-rule="evenodd"></path><path fill-rule="evenodd" d="M8 10a.5.5 0 01.5-.5H15a.5.5 0 010 1H8.5A.5.5 0 018 10zm-2.5 6a.5.5 0 01-.5-.5v-11a.5.5 0 011 0v11a.5.5 0 01-.5.5z" clip-rule="evenodd"></path></svg></td>
|
||||
<td ng-if="survey.start_availability <= $ctrl.now"><svg class="bi bi-arrow-bar-left" width="1em" height="1em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M7.854 6.646a.5.5 0 00-.708 0l-3 3a.5.5 0 000 .708l3 3a.5.5 0 00.708-.708L5.207 10l2.647-2.646a.5.5 0 000-.708z" clip-rule="evenodd"></path><path fill-rule="evenodd" d="M12 10a.5.5 0 00-.5-.5H5a.5.5 0 000 1h6.5a.5.5 0 00.5-.5zm2.5 6a.5.5 0 01-.5-.5v-11a.5.5 0 011 0v11a.5.5 0 01-.5.5z" clip-rule="evenodd"></path></svg> {{ survey.end_availability | date: "medium" }}</td>
|
||||
<td ng-if="$ctrl.islogged">N/A</td>
|
||||
<td ng-if="$ctrl.islogged && !survey.corrected">N/A</td>
|
||||
<td ng-if="$ctrl.islogged && survey.corrected" ng-controller="ScoreController">{{ score.score }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot ng-if="$ctrl.isadmin">
|
||||
|
@ -276,19 +282,43 @@ angular.module("AtsebaytApp")
|
|||
})
|
||||
|
||||
.controller("ScoreController", function($scope, SurveyScore) {
|
||||
$scope.score = SurveyScore.get({ surveyId: $scope.survey.id, questId: $scope.question.id })
|
||||
$scope.score = SurveyScore.get({ surveyId: $scope.survey.id })
|
||||
})
|
||||
|
||||
.controller("QuestionController", function($scope, Survey, SurveyQuest, SurveyQuest, AllResponses, $http, $routeParams) {
|
||||
.controller("QuestionController", function($scope, Survey, SurveyQuest, SurveyQuest, AllResponses, CorrectionTemplate, $http, $routeParams) {
|
||||
$scope.survey = Survey.get({ surveyId: $routeParams.surveyId });
|
||||
$scope.survey.$promise.then(function(survey) {
|
||||
survey.start_availability = Date.parse(survey.start_availability)
|
||||
survey.end_availability = Date.parse(survey.end_availability)
|
||||
})
|
||||
$scope.question = SurveyQuest.get({ surveyId: $routeParams.surveyId, questId: $routeParams.questId });
|
||||
$scope.responses = AllResponses.query({ surveyId: $routeParams.surveyId, questId: $routeParams.questId });
|
||||
$scope.responses = AllResponses.query({ surveyId: $routeParams.surveyId, questId: $routeParams.questId }, function (responses) {
|
||||
$scope.users_corrected = {}
|
||||
|
||||
responses.forEach(function(r) {
|
||||
$http({
|
||||
url: "/api/users/" + r.id_user + "/questions/" + $routeParams.questId
|
||||
}).then(function(response) {
|
||||
$scope.users_corrected[r.id_user] = response.data
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
$scope.submitCorrection = function() {
|
||||
if ($scope.users_corrected[this.response.id_user]) {
|
||||
if (this.response.score === undefined)
|
||||
this.response.score = $scope.users_corrected[this.response.id_user].score
|
||||
if ($scope.users_corrected[this.response.id_user].score_explaination && (!this.response.score_explaination || this.response.score_explaination.indexOf($scope.users_corrected[this.response.id_user].score_explaination) == -1)) {
|
||||
if (this.response.score_explaination)
|
||||
this.response.score_explaination += '\n' + $scope.users_corrected[this.response.id_user].score_explaination
|
||||
else
|
||||
this.response.score_explaination = $scope.users_corrected[this.response.id_user].score_explaination
|
||||
}
|
||||
}
|
||||
|
||||
this.response.id_corrector = $scope.user.id
|
||||
if (!this.response.time_scored)
|
||||
this.response.time_scored = (new Date()).toISOString()
|
||||
this.response.$update()
|
||||
}
|
||||
$scope.submitCorrections = function() {
|
||||
|
@ -296,6 +326,76 @@ angular.module("AtsebaytApp")
|
|||
response.$update()
|
||||
})
|
||||
}
|
||||
|
||||
$scope.templates = CorrectionTemplate.query({ surveyId: $routeParams.surveyId, questId: $routeParams.questId }, function (tpls) {
|
||||
$scope.template_corrected = {}
|
||||
tpls.forEach(function(tpl) {
|
||||
$scope.template_corrected[tpl.id] = {}
|
||||
|
||||
CorrectionTemplate.query({ surveyId: $routeParams.surveyId, questId: $routeParams.questId, correctId: tpl.id }, function (cts) {
|
||||
cts.forEach(function(ct) {
|
||||
$scope.template_corrected[tpl.id][ct.id_user] = ct
|
||||
})
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
$scope.changeCorrection = function(id_user) {
|
||||
var tpl = this.template
|
||||
if ($scope.template_corrected[tpl.id] && $scope.template_corrected[tpl.id][id_user]) {
|
||||
$http({
|
||||
url: "/api/users/" + id_user + "/corrections/" + $scope.template_corrected[tpl.id][id_user].id,
|
||||
method: "DELETE"
|
||||
}).then(function(response) {
|
||||
$scope.template_corrected[tpl.id][id_user] = false
|
||||
$scope.users_corrected[id_user] = response.data
|
||||
})
|
||||
} else {
|
||||
$http({
|
||||
url: "/api/users/" + id_user + "/corrections",
|
||||
data: {id_template: tpl.id},
|
||||
method: "POST"
|
||||
}).then(function(response) {
|
||||
if ($scope.template_corrected[tpl.id] === undefined)
|
||||
$scope.template_corrected[tpl.id] = {}
|
||||
$scope.template_corrected[tpl.id][id_user] = { id: response.data.last_id, id_template: tpl.id }
|
||||
$scope.users_corrected[id_user] = response.data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
$scope.deleteTemplate = function() {
|
||||
var template = new CorrectionTemplate({
|
||||
id: $('#tcid').val() == "" ? null : parseInt($('#tcid').val()),
|
||||
})
|
||||
|
||||
template.$remove({ surveyId: $scope.survey.id, questId: $scope.question.id, correctId: template.id }, function() {
|
||||
$scope.templates = CorrectionTemplate.query({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
angular.element('#correctionTemplateModal').modal('hide')
|
||||
});
|
||||
}
|
||||
|
||||
$scope.saveTemplate = function() {
|
||||
var template = new CorrectionTemplate({
|
||||
id: $('#tcid').val() == "" ? null : parseInt($('#tcid').val()),
|
||||
id_question: parseInt($('#tcidquestion').val()),
|
||||
label: $('#tclabel').val(),
|
||||
score: parseInt($('#tcscore').val()),
|
||||
score_explaination: $('#tcexplaination').val()
|
||||
})
|
||||
|
||||
if (template.id) {
|
||||
template.$update({ surveyId: $scope.survey.id, questId: $scope.question.id, correctId: template.id }, function () {
|
||||
$scope.templates = CorrectionTemplate.query({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
angular.element('#correctionTemplateModal').modal('hide')
|
||||
});
|
||||
} else {
|
||||
template.$save({ surveyId: $scope.survey.id, questId: $scope.question.id }, function () {
|
||||
$scope.templates = CorrectionTemplate.query({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
angular.element('#correctionTemplateModal').modal('hide')
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.controller("QuestionsController", function($scope, SurveyQuest, MyResponse, $http, $location) {
|
||||
|
@ -424,3 +524,24 @@ angular.module("AtsebaytApp")
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
.controller("CorrectionsTemplateController", function($scope, CorrectionTemplate) {
|
||||
$scope.addTemplate = function() {
|
||||
var element = angular.element('#correctionTemplateModal');
|
||||
var tpl = new CorrectionTemplate({id_question: $scope.question.id})
|
||||
if (element.data('bs.modal'))
|
||||
element.data('bs.modal')._config.template = tpl
|
||||
element.modal({
|
||||
template: tpl
|
||||
});
|
||||
}
|
||||
|
||||
$scope.editTemplate = function() {
|
||||
var element = angular.element('#correctionTemplateModal');
|
||||
if (element.data('bs.modal'))
|
||||
element.data('bs.modal')._config.template = this.template
|
||||
element.modal({
|
||||
template: this.template
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
Reference in a new issue