Add users and grades display
This commit is contained in:
parent
42b15a1546
commit
c9d64640e2
13 changed files with 432 additions and 17 deletions
|
@ -5,6 +5,10 @@ angular.module("AtsebaytApp", ["ngRoute", "ngResource", "ngSanitize"])
|
|||
controller: "AuthController",
|
||||
templateUrl: "views/auth.html"
|
||||
})
|
||||
.when("/grades", {
|
||||
controller: "GradesController",
|
||||
templateUrl: "views/grades.html"
|
||||
})
|
||||
.when("/surveys", {
|
||||
controller: "SurveysController",
|
||||
templateUrl: "views/surveys.html"
|
||||
|
@ -21,6 +25,14 @@ angular.module("AtsebaytApp", ["ngRoute", "ngResource", "ngSanitize"])
|
|||
controller: "QuestionController",
|
||||
templateUrl: "views/correction.html"
|
||||
})
|
||||
.when("/users", {
|
||||
controller: "UsersController",
|
||||
templateUrl: "views/users.html"
|
||||
})
|
||||
.when("/users/:userId", {
|
||||
controller: "UserController",
|
||||
templateUrl: "views/user.html"
|
||||
})
|
||||
.when("/", {
|
||||
controller: "SurveysController",
|
||||
templateUrl: "views/home.html"
|
||||
|
@ -42,14 +54,26 @@ angular.module("AtsebaytApp")
|
|||
.factory("MyResponse", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/responses/:respId", { surveyId: '@id', respId: '@id' })
|
||||
})
|
||||
.factory("Grades", function($resource) {
|
||||
return $resource("/api/grades")
|
||||
})
|
||||
.factory("Survey", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId", { surveyId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("SurveyGrades", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/grades", { surveyId: '@id' })
|
||||
})
|
||||
.factory("SurveyScore", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/score", { surveyId: '@id' })
|
||||
})
|
||||
.factory("SurveyUserScore", function($resource) {
|
||||
return $resource("/api/users/:userId/surveys/:surveyId/score", { userId: '@id', surveyId: '@id' })
|
||||
})
|
||||
.factory("SurveyUserGrades", function($resource) {
|
||||
return $resource("/api/users/:userId/surveys/:surveyId/grades", { userId: '@id', surveyId: '@id' })
|
||||
})
|
||||
.factory("SurveyQuest", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/questions/:questId", { surveyId: '@id', questId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
|
@ -236,6 +260,7 @@ angular.module("AtsebaytApp")
|
|||
|
||||
.controller("SurveysController", function($scope, $rootScope, Survey, $location) {
|
||||
$rootScope.qactive = $location.$$path == "/surveys";
|
||||
$rootScope.uactive = $location.$$path.indexOf("/users") != -1;
|
||||
$scope.surveys = Survey.query();
|
||||
$scope.surveys.$promise.then(function(data) {
|
||||
data.forEach(function(d,k) {
|
||||
|
@ -247,6 +272,7 @@ angular.module("AtsebaytApp")
|
|||
|
||||
.controller("SurveyController", function($scope, $rootScope, Survey, $routeParams, $location) {
|
||||
$rootScope.qactive = true;
|
||||
$rootScope.uactive = false;
|
||||
$scope.survey = Survey.get({ surveyId: $routeParams.surveyId });
|
||||
$scope.survey.$promise.then(function(survey) {
|
||||
survey.readonly = Date.now() > Date.parse(survey.end_availability)
|
||||
|
@ -277,6 +303,26 @@ angular.module("AtsebaytApp")
|
|||
}
|
||||
})
|
||||
|
||||
.controller("SurveyGradesController", function($scope, SurveyGrades) {
|
||||
$scope.grades = SurveyGrades.get({ surveyId: $scope.survey.id })
|
||||
$scope.mean = 0;
|
||||
$scope.grades.$promise.then(function (grades) {
|
||||
var sum = 0
|
||||
var total = 0
|
||||
for (var gid in grades) {
|
||||
if (parseInt(gid, 10) > 0) {
|
||||
total++
|
||||
if (grades[gid]) {
|
||||
sum += grades[gid]
|
||||
}
|
||||
}
|
||||
}
|
||||
if (total > 0) {
|
||||
$scope.mean = sum/total
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
.controller("ResponsesController", function($scope, AllResponses) {
|
||||
$scope.responses = AllResponses.query({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
})
|
||||
|
@ -285,6 +331,56 @@ angular.module("AtsebaytApp")
|
|||
$scope.score = SurveyScore.get({ surveyId: $scope.survey.id })
|
||||
})
|
||||
|
||||
.controller("UserScoreController", function($scope, SurveyUserScore) {
|
||||
$scope.score = SurveyUserScore.get({ userId: $scope.user.id, surveyId: $scope.survey.id })
|
||||
})
|
||||
|
||||
.controller("UserGradesController", function($scope, SurveyUserGrades) {
|
||||
$scope.grades = SurveyUserGrades.get({ userId: $scope.user.id, surveyId: $scope.survey.id })
|
||||
$scope.avancement = 0;
|
||||
$scope.grades.$promise.then(function (grades) {
|
||||
var answered = 0
|
||||
var total = 0
|
||||
for (var gid in grades) {
|
||||
if (parseInt(gid, 10) > 0) {
|
||||
total++
|
||||
if (grades[gid]) {
|
||||
answered++
|
||||
}
|
||||
}
|
||||
}
|
||||
if (total > 0) {
|
||||
$scope.avancement = answered/total
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
.controller("GradesController", function($scope, $rootScope, Grades, Survey, User, $location) {
|
||||
$scope.users = User.query();
|
||||
$scope.surveys = Survey.query();
|
||||
$scope.grades = Grades.get();
|
||||
|
||||
$scope.showUser = function() {
|
||||
$location.url("users/" + this.user.id);
|
||||
}
|
||||
})
|
||||
|
||||
.controller("UsersController", function($scope, $rootScope, User, $location) {
|
||||
$rootScope.qactive = false;
|
||||
$rootScope.uactive = true;
|
||||
$scope.users = User.query()
|
||||
|
||||
$scope.showUser = function() {
|
||||
$location.url("users/" + this.user.id);
|
||||
}
|
||||
})
|
||||
|
||||
.controller("UserController", function($scope, $routeParams, $rootScope, User) {
|
||||
$rootScope.qactive = false;
|
||||
$rootScope.uactive = true;
|
||||
$scope.user = User.get({ userId: $routeParams.userId})
|
||||
})
|
||||
|
||||
.controller("QuestionController", function($scope, Survey, SurveyQuest, SurveyQuest, AllResponses, CorrectionTemplate, $http, $routeParams) {
|
||||
$scope.notCorrected = true
|
||||
$scope.highlight = ''
|
||||
|
|
Reference in a new issue