v1 done
This commit is contained in:
parent
f073e69417
commit
0a79763f69
17 changed files with 459 additions and 158 deletions
|
|
@ -13,26 +13,38 @@ angular.module("AtsebaytApp", ["ngRoute", "ngResource", "ngSanitize"])
|
|||
controller: "SurveyController",
|
||||
templateUrl: "views/survey.html"
|
||||
})
|
||||
.when("/users", {
|
||||
controller: "UsersController",
|
||||
templateUrl: "views/users.html"
|
||||
.when("/surveys/:surveyId/responses", {
|
||||
controller: "SurveyController",
|
||||
templateUrl: "views/responses.html"
|
||||
})
|
||||
.when("/users/:userId", {
|
||||
controller: "UserController",
|
||||
templateUrl: "views/user.html"
|
||||
.when("/surveys/:surveyId/responses/:questId", {
|
||||
controller: "QuestionController",
|
||||
templateUrl: "views/correction.html"
|
||||
})
|
||||
.when("/", {
|
||||
controller: "SurveysController",
|
||||
templateUrl: "views/home.html"
|
||||
});
|
||||
$locationProvider.html5Mode(true);
|
||||
});
|
||||
|
||||
angular.module("AtsebaytApp")
|
||||
.factory("AllResponses", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/questions/:questId/responses/:respId", { surveyId: '@id', questId: '@id', respId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("MyResponse", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/responses/:respId", { surveyId: '@id', respId: '@id' })
|
||||
})
|
||||
.factory("Survey", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId", { surveyId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("SurveyScore", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/score", { surveyId: '@id' })
|
||||
})
|
||||
.factory("SurveyQuest", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/questions/:questId", { surveyId: '@id', questId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
|
|
@ -44,6 +56,110 @@ angular.module("AtsebaytApp")
|
|||
})
|
||||
});
|
||||
|
||||
angular.module("AtsebaytApp")
|
||||
.directive('integer', function() {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, ele, attr, ctrl){
|
||||
ctrl.$parsers.unshift(function(viewValue){
|
||||
return parseInt(viewValue, 10);
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
.component('toast', {
|
||||
bindings: {
|
||||
date: '=',
|
||||
msg: '=',
|
||||
title: '=',
|
||||
variant: '=',
|
||||
},
|
||||
controller: function($element) {
|
||||
$element.children(0).toast('show')
|
||||
},
|
||||
template: `<div class="toast mb-2" role="alert" aria-live="assertive" aria-atomic="true" data-delay="7000">
|
||||
<div class="toast-header">
|
||||
<span ng-if="$ctrl.variant" class="badge badge-pill badge-{{ $ctrl.variant }}" style="padding: .25em .66em"> </span>
|
||||
<strong class="mr-auto" ng-bind="$ctrl.title"></strong>
|
||||
<small class="text-muted" ng-bind="$ctrl.date">just now</small>
|
||||
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="toast-body" ng-bind-html="$ctrl.msg"></div>
|
||||
</div>`
|
||||
})
|
||||
|
||||
.component('surveyList', {
|
||||
bindings: {
|
||||
surveys: '=',
|
||||
islogged: '=',
|
||||
isadmin: '=',
|
||||
},
|
||||
controller: function($location, $rootScope) {
|
||||
this.now = Date.now();
|
||||
this.show = function(id) {
|
||||
if ($rootScope.isLogged) {
|
||||
$location.url("surveys/" + id);
|
||||
} else {
|
||||
$rootScope.addToast({
|
||||
variant: "danger",
|
||||
title: "Authentification requise",
|
||||
msg: "Vous devez être connecté pour accéder aux questionnaires.",
|
||||
});
|
||||
$location.url("auth");
|
||||
}
|
||||
};
|
||||
},
|
||||
template: `<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Intitulé</th>
|
||||
<th>État</th>
|
||||
<th>Date</th>
|
||||
<th ng-if="$ctrl.islogged">Score</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody style="cursor: pointer;">
|
||||
<tr ng-repeat="survey in $ctrl.surveys" ng-if="survey.shown" ng-click="$ctrl.show(survey.id)">
|
||||
<td>{{ survey.title }}</td>
|
||||
<td class="bg-info" ng-if="survey.start_availability > $ctrl.now">Prévu</td>
|
||||
<td class="bg-warning" ng-if="survey.start_availability <= $ctrl.now && survey.end_availability >= $ctrl.now">En cours</td>
|
||||
<td class="bg-primary" ng-if="survey.end_availability < $ctrl.now && !survey.corrected">Terminé</td>
|
||||
<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" }}</td>
|
||||
<td ng-if="survey.start_availability <= $ctrl.now">{{ survey.end_availability | date: "medium" }}</td>
|
||||
<td ng-if="$ctrl.islogged">N/A</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot ng-if="$ctrl.isadmin">
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<a href="surveys/new" class="btn btn-sm btn-primary">Ajouter un questionnaire</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>`
|
||||
})
|
||||
|
||||
|
||||
.component('surveyBadges', {
|
||||
bindings: {
|
||||
survey: '=',
|
||||
},
|
||||
controller: function() {
|
||||
var now = Date.now()
|
||||
this.test = function(a, b) {
|
||||
return Date.parse(a) > now;
|
||||
}
|
||||
},
|
||||
template: `<span class="badge badge-danger" ng-if="$ctrl.test($ctrl.survey.start_availability)">Prévu</span>
|
||||
<span class="badge badge-warning" ng-if="!$ctrl.test($ctrl.survey.start_availability) && $ctrl.test($ctrl.survey.end_availability)">En cours</span>
|
||||
<span class="badge badge-primary" ng-if="!$ctrl.test($ctrl.survey.end_availability)">Clos</span>
|
||||
<span class="badge badge-success" ng-if="$ctrl.survey.corrected">Corrigé</span>`
|
||||
});
|
||||
|
||||
angular.module("AtsebaytApp")
|
||||
.run(function($rootScope, $interval, $http) {
|
||||
$rootScope.checkLoginState = function() {
|
||||
|
|
@ -66,6 +182,12 @@ angular.module("AtsebaytApp")
|
|||
$rootScope.user.was_admin = tmp;
|
||||
}
|
||||
|
||||
$rootScope.toasts = [];
|
||||
|
||||
$rootScope.addToast = function(toast) {
|
||||
$rootScope.toasts.unshift(toast);
|
||||
}
|
||||
|
||||
$rootScope.disconnectCurrentUser = function() {
|
||||
$http({
|
||||
method: 'POST',
|
||||
|
|
@ -101,8 +223,8 @@ angular.module("AtsebaytApp")
|
|||
}
|
||||
})
|
||||
|
||||
.controller("SurveysController", function($scope, Survey, $location) {
|
||||
$scope.now = Date.now();
|
||||
.controller("SurveysController", function($scope, $rootScope, Survey, $location) {
|
||||
$rootScope.qactive = $location.$$path == "/surveys";
|
||||
$scope.surveys = Survey.query();
|
||||
$scope.surveys.$promise.then(function(data) {
|
||||
data.forEach(function(d,k) {
|
||||
|
|
@ -110,18 +232,13 @@ angular.module("AtsebaytApp")
|
|||
data[k].end_availability = Date.parse(data[k].end_availability)
|
||||
})
|
||||
})
|
||||
|
||||
$scope.show = function(id) {
|
||||
$location.url("surveys/" + id);
|
||||
};
|
||||
})
|
||||
|
||||
.controller("SurveyController", function($scope, Survey, $routeParams, $location) {
|
||||
$scope.now = Date.now();
|
||||
.controller("SurveyController", function($scope, $rootScope, Survey, $routeParams, $location) {
|
||||
$rootScope.qactive = true;
|
||||
$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)
|
||||
survey.readonly = Date.now() > Date.parse(survey.end_availability)
|
||||
})
|
||||
|
||||
$scope.saveSurvey = function() {
|
||||
|
|
@ -143,10 +260,59 @@ angular.module("AtsebaytApp")
|
|||
$scope.deleteSurvey = function() {
|
||||
this.survey.$remove(function() { $location.url("/surveys/");});
|
||||
}
|
||||
|
||||
$scope.showResponses = function() {
|
||||
$location.url("surveys/" + this.survey.id + "/responses/" + this.question.id );
|
||||
}
|
||||
})
|
||||
|
||||
.controller("QuestionsController", function($scope, SurveyQuest, $http, $location) {
|
||||
.controller("ResponsesController", function($scope, AllResponses) {
|
||||
$scope.responses = AllResponses.query({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
})
|
||||
|
||||
.controller("ScoreController", function($scope, SurveyScore) {
|
||||
$scope.score = SurveyScore.get({ surveyId: $scope.survey.id, questId: $scope.question.id })
|
||||
})
|
||||
|
||||
.controller("QuestionController", function($scope, Survey, SurveyQuest, SurveyQuest, AllResponses, $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.submitCorrection = function() {
|
||||
this.response.$update()
|
||||
}
|
||||
$scope.submitCorrections = function() {
|
||||
this.responses.forEach(function(response) {
|
||||
response.$update()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
.controller("QuestionsController", function($scope, SurveyQuest, MyResponse, $http, $location) {
|
||||
$scope.questions = SurveyQuest.query({ surveyId: $scope.survey.id });
|
||||
$scope.myresponses = MyResponse.query({ surveyId: $scope.survey.id });
|
||||
$scope.myresponses.$promise.then(function (responses) {
|
||||
$scope.questions.$promise.then(function (questions) {
|
||||
var idxquestions = {}
|
||||
questions.forEach(function(question, qid) {
|
||||
idxquestions[question.id] = qid;
|
||||
});
|
||||
|
||||
responses.forEach(function(response) {
|
||||
if (!questions[idxquestions[response.id_question]].response) {
|
||||
if (response.value) {
|
||||
questions[idxquestions[response.id_question]].value = response.value;
|
||||
questions[idxquestions[response.id_question]].response = response;
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
$scope.submitAnswers = function() {
|
||||
$scope.submitInProgress = true;
|
||||
|
|
@ -154,16 +320,24 @@ angular.module("AtsebaytApp")
|
|||
$scope.questions.forEach(function(q) {
|
||||
res.push({"id_question": q.id, "value": q.value})
|
||||
});
|
||||
console.log(res)
|
||||
$http({
|
||||
url: "/api/surveys/" + $scope.survey.id,
|
||||
data: res,
|
||||
method: "POST"
|
||||
}).then(function(response) {
|
||||
$scope.submitInProgress = false;
|
||||
$scope.addToast({
|
||||
variant: "success",
|
||||
title: $scope.survey.title,
|
||||
msg: "Vos réponses ont bien étés sauvegardées.",
|
||||
});
|
||||
}, function(response) {
|
||||
$scope.submitInProgress = false;
|
||||
alert("Une erreur s'est produite durant l'envoie de vos réponses : " + response.data.errmsg + "\nVeuillez réessayer dans quelques instants.");
|
||||
$scope.addToast({
|
||||
variant: "danger",
|
||||
title: $scope.survey.title,
|
||||
msg: "Une erreur s'est produite durant l'envoie de vos réponses : " + (response.data ? response.data.errmsg : "impossible de contacter le serveur") + "<br>Veuillez réessayer dans quelques instants.",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue