Compare commits
2 Commits
56c408282b
...
8b58bf57ef
Author | SHA1 | Date | |
---|---|---|---|
8b58bf57ef | |||
6d271f765b |
@ -33,6 +33,10 @@ angular.module("AtsebaytApp", ["ngRoute", "ngResource", "ngSanitize"])
|
||||
controller: "UserController",
|
||||
templateUrl: "views/user.html"
|
||||
})
|
||||
.when("/users/:userId/surveys/:surveyId", {
|
||||
controller: "SurveyController",
|
||||
templateUrl: "views/survey.html"
|
||||
})
|
||||
.when("/", {
|
||||
controller: "SurveysController",
|
||||
templateUrl: "views/home.html"
|
||||
@ -54,6 +58,9 @@ angular.module("AtsebaytApp")
|
||||
.factory("MyResponse", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/responses/:respId", { surveyId: '@id', respId: '@id' })
|
||||
})
|
||||
.factory("UserResponse", function($resource) {
|
||||
return $resource("/api/users/:userId/surveys/:surveyId/responses/:respId", { userId: '@id', surveyId: '@id', respId: '@id' })
|
||||
})
|
||||
.factory("Grades", function($resource) {
|
||||
return $resource("/api/grades")
|
||||
})
|
||||
@ -268,6 +275,9 @@ angular.module("AtsebaytApp")
|
||||
data[k].end_availability = Date.parse(data[k].end_availability)
|
||||
})
|
||||
})
|
||||
$scope.showUserSurvey = function() {
|
||||
$location.url("users/" + this.user.id + "/surveys/" + this.survey.id);
|
||||
}
|
||||
})
|
||||
|
||||
.controller("SurveyController", function($scope, $rootScope, Survey, $routeParams, $location) {
|
||||
@ -381,7 +391,7 @@ angular.module("AtsebaytApp")
|
||||
$scope.user = User.get({ userId: $routeParams.userId})
|
||||
})
|
||||
|
||||
.controller("QuestionController", function($scope, Survey, SurveyQuest, SurveyQuest, AllResponses, CorrectionTemplate, $http, $routeParams) {
|
||||
.controller("QuestionController", function($scope, Survey, SurveyQuest, AllResponses, UserResponses, CorrectionTemplate, $http, $routeParams) {
|
||||
$scope.notCorrected = true
|
||||
$scope.highlight = ''
|
||||
|
||||
@ -400,7 +410,13 @@ angular.module("AtsebaytApp")
|
||||
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 }, function (responses) {
|
||||
|
||||
if ($routeParams.userId == null) {
|
||||
$scope.responses = AllResponses.query({ surveyId: $routeParams.surveyId, questId: $routeParams.questId });
|
||||
} else {
|
||||
$scope.responses = UserResponses.query({ userId: $routeParams.userId, surveyId: $routeParams.surveyId, questId: $routeParams.questId });
|
||||
}
|
||||
$scope.responses.$promise.then(function (responses) {
|
||||
$scope.users_corrected = {}
|
||||
|
||||
responses.forEach(function(r) {
|
||||
@ -506,7 +522,7 @@ angular.module("AtsebaytApp")
|
||||
}
|
||||
})
|
||||
|
||||
.controller("QuestionsController", function($scope, SurveyQuest, MyResponse, $http, $location) {
|
||||
.controller("QuestionsController", function($scope, SurveyQuest, MyResponse, UserResponse, $http, $routeParams, $location) {
|
||||
$scope.questions = SurveyQuest.query({ surveyId: $scope.survey.id });
|
||||
$scope.questions.$promise.then(function (questions) {$scope.showSubmit = true;}, function (response) {
|
||||
$scope.addToast({
|
||||
@ -516,7 +532,11 @@ angular.module("AtsebaytApp")
|
||||
});
|
||||
$location.url("surveys/")
|
||||
})
|
||||
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.$promise.then(function (responses) {
|
||||
$scope.questions.$promise.then(function (questions) {
|
||||
var idxquestions = {}
|
||||
@ -564,8 +584,12 @@ angular.module("AtsebaytApp")
|
||||
res.push({"id_question": q.id, "value": values.join(",")})
|
||||
}
|
||||
});
|
||||
var url = "/api/surveys/" + $scope.survey.id;
|
||||
if ($routeParams.userId != null) {
|
||||
url = "/api/users/" + $routeParams.userId + "/surveys/" + $scope.survey.id;
|
||||
}
|
||||
$http({
|
||||
url: "/api/surveys/" + $scope.survey.id,
|
||||
url: url,
|
||||
data: res,
|
||||
method: "POST"
|
||||
}).then(function(response) {
|
||||
|
@ -79,7 +79,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<textarea class="form-control" ng-if="!question.edit && question.kind == 'text' && !survey.readonly" rows="6" ng-model="question.value" placeholder="{{ question.placeholder }}"></textarea>
|
||||
<textarea class="form-control" ng-if="!question.edit && question.kind == 'text' && (!survey.readonly || user.is_admin)" rows="6" ng-model="question.value" placeholder="{{ question.placeholder }}"></textarea>
|
||||
<input class="ml-5 col-sm-2 form-control" type="number" ng-if="!question.edit && question.kind == 'int' && !survey.readonly" ng-model="question.value" placeholder="{{ question.placeholder }}">
|
||||
<p class="card-text alert alert-secondary" style="white-space: pre-line" ng-bind="question.value" ng-if="!question.edit && survey.readonly"></p>
|
||||
<div class="form-group row" ng-if="question.edit && (question.kind == 'text' || question.kind == 'int')">
|
||||
|
@ -51,7 +51,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="(sid,survey) in surveys">
|
||||
<tr ng-repeat="(sid,survey) in surveys" ng-click="showUserSurvey()">
|
||||
<td>{{ survey.id }}</td>
|
||||
<td>{{ survey.title }}</td>
|
||||
<td ng-controller="UserGradesController" title="{{ grades }}">{{ avancement * 100 | number:2 }} %</td>
|
||||
|
27
responses.go
27
responses.go
@ -25,10 +25,37 @@ func init() {
|
||||
|
||||
return APIResponse{true}
|
||||
}), loggedUser))
|
||||
router.POST("/api/users/:uid/surveys/:sid", apiAuthHandler(func(u *User, ps httprouter.Params, body []byte) HTTPResponse {
|
||||
return surveyAuthHandler(func(s Survey, u *User, _ []byte) HTTPResponse {
|
||||
return userHandler(func(u User, _ []byte) HTTPResponse {
|
||||
var responses []Response
|
||||
if err := json.Unmarshal(body, &responses); err != nil {
|
||||
return APIErrorResponse{err: err}
|
||||
}
|
||||
|
||||
for _, response := range responses {
|
||||
if len(response.Answer) > 0 {
|
||||
if _, err := s.NewResponse(response.IdQuestion, u.Id, response.Answer); err != nil {
|
||||
return APIErrorResponse{err: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return APIResponse{true}
|
||||
})(ps, body)
|
||||
})(u, ps, body)
|
||||
}, adminRestricted))
|
||||
router.GET("/api/surveys/:sid/responses", apiAuthHandler(surveyAuthHandler(
|
||||
func(s Survey, u *User, _ []byte) HTTPResponse {
|
||||
return formatApiResponse(s.GetMyResponses(u, s.Corrected))
|
||||
}), loggedUser))
|
||||
router.GET("/api/users/:uid/surveys/:sid/responses", apiAuthHandler(func(u *User, ps httprouter.Params, body []byte) HTTPResponse {
|
||||
return surveyAuthHandler(func(s Survey, u *User, _ []byte) HTTPResponse {
|
||||
return userHandler(func(u User, _ []byte) HTTPResponse {
|
||||
return formatApiResponse(s.GetMyResponses(&u, s.Corrected))
|
||||
})(ps, body)
|
||||
})(u, ps, body)
|
||||
}, adminRestricted))
|
||||
router.GET("/api/surveys/:sid/responses/:rid", apiAuthHandler(responseAuthHandler(
|
||||
func(r Response, _ *User, _ []byte) HTTPResponse {
|
||||
return APIResponse{r}
|
||||
|
Reference in New Issue
Block a user