Merge: modelize_class: Refactor
[nit.git] / share / nitweb / javascripts / grades.js
1 /*
2 * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 (function() {
18 angular
19 .module('grades', ['ngSanitize'])
20
21 .config(function($stateProvider, $locationProvider) {
22 $stateProvider
23 .state('grades', {
24 url: '/grades',
25 templateUrl: 'views/grades.html',
26 controller: 'GradesCtrl',
27 controllerAs: 'gradesCtrl'
28 })
29 })
30
31 .factory('Feedback', [ '$http', function($http) {
32 return {
33 loadEntityStars: function(id, cb, cbErr) {
34 $http.get('/api/feedback/stars/' + id)
35 .success(cb)
36 .error(cbErr);
37 },
38 loadEntityStarsDimension: function(id, dimension, cb, cbErr) {
39 $http.get('/api/feedback/stars/' + id + '/dimension/' + dimension)
40 .success(cb)
41 .error(cbErr);
42 },
43 postEntityStarDimension: function(id, dimension, rating, cb, cbErr) {
44 $http.post('/api/feedback/stars/' + id + '/dimension/' + dimension,
45 {rating: rating})
46 .success(cb)
47 .error(cbErr);
48 },
49 loadMostRated: function(cb, cbErr) {
50 $http.get('/api/feedback/grades/most')
51 .success(cb)
52 .error(cbErr);
53 },
54 loadBestRated: function(cb, cbErr) {
55 $http.get('/api/feedback/grades/best')
56 .success(cb)
57 .error(cbErr);
58 },
59 loadWorstRated: function(cb, cbErr) {
60 $http.get('/api/feedback/grades/worst')
61 .success(cb)
62 .error(cbErr);
63 },
64 loadUsersRatings: function(cb, cbErr) {
65 $http.get('/api/feedback/grades/users')
66 .success(cb)
67 .error(cbErr);
68 },
69 }
70 }])
71
72 .controller('GradesCtrl', ['Feedback', '$scope', function(Feedback, $scope) {
73
74 this.loadMostRated = function() {
75 Feedback.loadMostRated(
76 function(data) {
77 $scope.most = data;
78 }, function(err) {
79 $scope.error = err;
80 });
81 };
82
83 this.loadBestRated = function() {
84 Feedback.loadBestRated(
85 function(data) {
86 $scope.best = data;
87 }, function(err) {
88 $scope.error = err;
89 });
90 };
91 this.loadWorstRated = function() {
92 Feedback.loadWorstRated(
93 function(data) {
94 $scope.worst = data;
95 }, function(err) {
96 $scope.error = err;
97 });
98 };
99 this.loadUsersRatings = function() {
100 Feedback.loadUsersRatings(
101 function(data) {
102 $scope.ratings = data;
103 }, function(err) {
104 $scope.error = err;
105 });
106 };
107
108 this.loadMostRated();
109 this.loadBestRated();
110 this.loadWorstRated();
111 this.loadUsersRatings();
112 }])
113 })();