f29ac4cbff7aec3a64ed903f29d2a553241d9841
[nit.git] / share / nitweb / javascripts / model.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 var apiUrl = '/api';
19
20 angular
21 .module('model', [])
22
23 .factory('Model', [ '$http', function($http) {
24 return {
25
26 loadEntity: function(id, cb, cbErr) {
27 $http.get(apiUrl + '/entity/' + id)
28 .success(cb)
29 .error(cbErr);
30 },
31
32 loadEntityLinearization: function(id, cb, cbErr) {
33 $http.get(apiUrl + '/linearization/' + id)
34 .success(cb)
35 .error(cbErr);
36 },
37
38 loadEntityDefs: function(id, cb, cbErr) {
39 $http.get(apiUrl + '/defs/' + id)
40 .success(cb)
41 .error(cbErr);
42 },
43
44 loadEntityCode: function(id, cb, cbErr) {
45 $http.get(apiUrl + '/code/' + id)
46 .success(cb)
47 .error(cbErr);
48 },
49
50 loadEntityGraph: function(id, cb, cbErr) {
51 $http.get(apiUrl + '/graph/inheritance/' + id + '?cdepth=3')
52 .success(cb)
53 .error(cbErr);
54 },
55
56 search: function(q, n, cb, cbErr) {
57 $http.get(apiUrl + '/search?q=' + q + '&n=' + n)
58 .success(cb)
59 .error(cbErr);
60 }
61 };
62 }])
63
64 .factory('Feedback', [ '$http', function($http) {
65 return {
66 loadEntityStars: function(id, cb, cbErr) {
67 $http.get(apiUrl + '/feedback/stars/' + id)
68 .success(cb)
69 .error(cbErr);
70 },
71 loadEntityStarsDimension: function(id, dimension, cb, cbErr) {
72 $http.get(apiUrl + '/feedback/stars/' + id + '/dimension/' + dimension)
73 .success(cb)
74 .error(cbErr);
75 },
76 postEntityStarDimension: function(id, dimension, rating, cb, cbErr) {
77 $http.post(apiUrl + '/feedback/stars/' + id + '/dimension/' + dimension,
78 {rating: rating})
79 .success(cb)
80 .error(cbErr);
81 },
82 loadMostRated: function(cb, cbErr) {
83 $http.get(apiUrl + '/feedback/grades/most')
84 .success(cb)
85 .error(cbErr);
86 },
87 loadBestRated: function(cb, cbErr) {
88 $http.get(apiUrl + '/feedback/grades/best')
89 .success(cb)
90 .error(cbErr);
91 },
92 loadWorstRated: function(cb, cbErr) {
93 $http.get(apiUrl + '/feedback/grades/worst')
94 .success(cb)
95 .error(cbErr);
96 },
97 loadUsersRatings: function(cb, cbErr) {
98 $http.get(apiUrl + '/feedback/grades/users')
99 .success(cb)
100 .error(cbErr);
101 },
102 }
103 }])
104
105 .factory('DocDown', [ '$http', function($http) {
106 return {
107 postMarkdown: function(md, cb, cbErr) {
108 $http.post(apiUrl + '/docdown', md)
109 .success(cb)
110 .error(cbErr);
111 }
112 }
113 }])
114
115 .factory('Metrics', [ '$http', function($http) {
116 return {
117 loadStructuralMetrics: function(id, cb, cbErr) {
118 $http.get(apiUrl + '/metrics/structural/' + id)
119 .success(cb)
120 .error(cbErr);
121 }
122 }
123 }])
124
125 .factory('User', [ '$http', function($http) {
126 return {
127 loadUser: function(cb, cbErr) {
128 $http.get(apiUrl + '/user')
129 .success(cb)
130 .error(cbErr);
131 },
132 loadUserStars: function(cb, cbErr) {
133 $http.get(apiUrl + '/feedback/user/stars')
134 .success(cb)
135 .error(cbErr);
136 },
137 }
138 }])
139 })();