nitweb/angular: introduce Catalog model
[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 search: function(q, n, cb, cbErr) {
33 $http.get(apiUrl + '/search?q=' + q + '&n=' + n)
34 .success(cb)
35 .error(cbErr);
36 }
37 };
38 }])
39
40 .factory('Catalog', [ '$http', function($http) {
41 return {
42 loadHightlighted: function(cb, cbErr) {
43 $http.get(apiUrl + '/catalog/highlighted')
44 .success(cb)
45 .error(cbErr);
46 },
47
48 loadMostRequired: function(cb, cbErr) {
49 $http.get(apiUrl + '/catalog/required')
50 .success(cb)
51 .error(cbErr);
52 },
53
54 loadByTags: function(cb, cbErr) {
55 $http.get(apiUrl + '/catalog/bytags')
56 .success(cb)
57 .error(cbErr);
58 },
59
60 loadStats: function(cb, cbErr) {
61 $http.get(apiUrl + '/catalog/stats')
62 .success(cb)
63 .error(cbErr);
64 },
65
66 loadContributors: function(cb, cbErr) {
67 $http.get(apiUrl + '/catalog/contributors')
68 .success(cb)
69 .error(cbErr);
70 },
71 }
72 }])
73 })();