-
Notifications
You must be signed in to change notification settings - Fork 7
/
services.js
executable file
·71 lines (62 loc) · 1.53 KB
/
services.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
/* Services */
// Demonstrate how to register services
// In this case it is a simple value service.
angular.module('myApp.services', [ 'resource' ]).value('version', '0.1');
var app = angular.module('myApp.services', [ 'ngResource' ]);
app.factory('Solr', [ '$resource', function($resource) {
return $resource('solr/:core/search?:query', {}, {
query : {
method : 'GET',
params : {
core : 'core',
query : 'query'
},
isArray : false
}
});
} ]);
app.factory('Hbase', [ '$resource', function($resource) {
var service = {};
service.getter = $resource('hbase/:table/get?rowKey=:rowKey', {}, {
get : {
method : 'GET',
params : {
table : 'table',
rowKey : 'rowKey'
},
isArray : false
}
})
service.scanner = $resource('hbase/:table/scan?startRow=:startRow&endRow=:endRow', {}, {
scan : {
method : 'GET',
params : {
table : 'table',
startRow : 'startRow',
endRow : 'endRow'
},
isArray : true
}
})
return service;
} ]);
app.config(function($httpProvider) {
$httpProvider.responseInterceptors.push('myHttpInterceptor');
var spinnerFunction = function spinnerFunction(data, headersGetter) {
$("#spinner").show();
return data;
};
$httpProvider.defaults.transformRequest.push(spinnerFunction);
});
app.factory('myHttpInterceptor', function($q, $window) {
return function(promise) {
return promise.then(function(response) {
$("#spinner").hide();
return response;
}, function(response) {
$("#spinner").hide();
return $q.reject(response);
});
};
});