Project

General

Profile

1
/**
2
 * Created by sandro on 6/19/15.
3
 */
4

    
5

    
6

    
7
dliApp.factory('queryService', ['$http', function ($http) {
8

    
9
    var factory = {}
10
    factory.query = function (query, page, filter, value) {
11
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
12
        if (page === null){
13
            return $http.post('/api/post/', $.param({'action': "query", 'query': query, 'filter':filter, 'value':value}));
14
        }
15
        else {
16
            return $http.post('/api/post/', $.param({'action': "query", 'query': query, 'start': (page - 1) * 10, 'filter':filter, 'value':value}));
17
        }
18
    };
19

    
20
    factory.queryPid = function (pid) {
21
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
22
        console.log("Make query for PID "+pid)
23
        return $http.post('/api/queryPid/', $.param({ 'pid': pid}));
24
    };
25

    
26
    factory.getStatsDetail = function () {
27
        //$http.defaults.headers.get["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
28
        return $http.get('currentStats.json');
29
    };
30

    
31
    factory.getStats = function () {
32
        //$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
33
        return $http.get('stats2.json');
34
    };
35

    
36
    factory.getDatasources = function() {
37
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
38
        return $http.post('/api/ds_info/');
39
    };
40

    
41

    
42
    factory.getItem = function (identifier) {
43
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
44
        return $http.post('/api/item/' + identifier);
45
    };
46

    
47
    factory.getItem = function (identifier, type, from) {
48
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
49
        return $http.post('/api/item/' + identifier, $.param({'type': type, 'from': from}));
50
    };
51

    
52
    factory.getDsInfo = function (identifier, name) {
53
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
54
        return $http.post('/api/ds_info/', $.param({'id': identifier, 'name':name}));
55
    };
56

    
57

    
58
    factory.resolveIdentifier = function (pid, pid_type) {
59
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
60
        return $http.post('api/resolveId/', $.param({'pid': pid, 'pid_type':pid_type}));
61
    };
62

    
63
    return factory;
64
}]);
(6-6/7)