Merge: model: is_accessor
[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('doc.entity.grades', {
24 url: '/grades',
25 templateUrl: 'views/doc/grades.html',
26 resolve: {
27 metrics: function(Feedback, $q, $stateParams, $state) {
28 var d = $q.defer();
29 Feedback.loadEntityStars($stateParams.id, d.resolve,
30 function() {
31 $state.go('404', null, { location: false })
32 });
33 return d.promise;
34 }
35 },
36 controller: function(mentity, metrics) {
37 this.mentity = mentity;
38 this.metrics = metrics;
39 },
40 controllerAs: 'vm',
41 })
42 .state('grades', {
43 url: '/grades',
44 templateUrl: 'views/grades.html',
45 controller: 'GradesCtrl',
46 controllerAs: 'gradesCtrl'
47 })
48 })
49
50 .factory('Feedback', [ '$http', function($http) {
51 return {
52 loadEntityStars: function(id, cb, cbErr) {
53 $http.get('/api/feedback/stars/' + id)
54 .success(cb)
55 .error(cbErr);
56 },
57 loadEntityStarsDimension: function(id, dimension, cb, cbErr) {
58 $http.get('/api/feedback/stars/' + id + '/dimension/' + dimension)
59 .success(cb)
60 .error(cbErr);
61 },
62 postEntityStarDimension: function(id, dimension, rating, cb, cbErr) {
63 $http.post('/api/feedback/stars/' + id + '/dimension/' + dimension,
64 {rating: rating})
65 .success(cb)
66 .error(cbErr);
67 },
68 loadMostRated: function(cb, cbErr) {
69 $http.get('/api/feedback/grades/most')
70 .success(cb)
71 .error(cbErr);
72 },
73 loadBestRated: function(cb, cbErr) {
74 $http.get('/api/feedback/grades/best')
75 .success(cb)
76 .error(cbErr);
77 },
78 loadWorstRated: function(cb, cbErr) {
79 $http.get('/api/feedback/grades/worst')
80 .success(cb)
81 .error(cbErr);
82 },
83 loadUsersRatings: function(cb, cbErr) {
84 $http.get('/api/feedback/grades/users')
85 .success(cb)
86 .error(cbErr);
87 },
88 }
89 }])
90
91 .controller('GradesCtrl', ['Feedback', '$scope', function(Feedback, $scope) {
92
93 this.loadMostRated = function() {
94 Feedback.loadMostRated(
95 function(data) {
96 $scope.most = data;
97 }, function(err) {
98 $scope.error = err;
99 });
100 };
101
102 this.loadBestRated = function() {
103 Feedback.loadBestRated(
104 function(data) {
105 $scope.best = data;
106 }, function(err) {
107 $scope.error = err;
108 });
109 };
110 this.loadWorstRated = function() {
111 Feedback.loadWorstRated(
112 function(data) {
113 $scope.worst = data;
114 }, function(err) {
115 $scope.error = err;
116 });
117 };
118 this.loadUsersRatings = function() {
119 Feedback.loadUsersRatings(
120 function(data) {
121 $scope.ratings = data;
122 }, function(err) {
123 $scope.error = err;
124 });
125 };
126
127 this.loadMostRated();
128 this.loadBestRated();
129 this.loadWorstRated();
130 this.loadUsersRatings();
131 }])
132 })();