Project

General

Profile

1
dliApp.controller('datasourceDetailController', ['$scope', '$routeParams', '$location', 'queryService', function ($scope, $routeParams, $location, queryService) {
2

    
3
    $scope.id = $routeParams['id'];
4
    $scope.name = $routeParams['name'];
5

    
6
    function extractLastStats() {
7
        if ($scope.datasource == null || $scope.datasource.stats == null)
8
            return;
9

    
10

    
11
        var maxDate = null;
12
        var currentKey = null;
13
        for (var key in $scope.datasource.stats) {
14
            try {
15
                var d = new Date(key);
16
                if (maxDate == null) {
17
                    maxDate = d;
18
                    currentKey = key;
19
                }
20
                else if (d > maxDate) {
21
                    maxDate = d;
22
                    currentKey = key;
23
                }
24
            } catch (err) {
25
                console.log(err.message);
26
            }
27
        }
28
        if (currentKey != null) {
29
            $scope.lastStats = $scope.datasource.stats[currentKey];
30
        }
31

    
32
    }
33
    function extractHistoryLinks() {
34
        x =["x"]
35

    
36
        d= ["Datasets"];
37
        r= ["Publications"];
38
        p= ["Links"];
39

    
40
        for (var key in $scope.datasource.stats) {
41
            x.push(key.substr(0, 10));
42
            d.push($scope.datasource.stats[key]['numberOfDatasets'])
43
            r.push($scope.datasource.stats[key]['numberOfRelations'])
44
            p.push($scope.datasource.stats[key]['numberOfPublication'])
45
        }
46

    
47
        $scope.historylinks =[x,d,r,p];
48

    
49

    
50
        var chart = c3.generate({
51
            bindto: '#chart_history_links',
52
            data: {
53
                x: 'x',
54
//        xFormat: '%Y%m%d', // 'xFormat' can be used as custom format of 'x'
55
                columns: $scope.historylinks
56
            },
57
            axis: {
58
                x: {
59
                    type: 'timeseries',
60
                    height: 60,
61

    
62
                    tick: {
63
                        format: '%Y-%m-%d',
64
                        rotate: -45
65

    
66

    
67
                    }
68
                }
69
            }
70
        });
71

    
72

    
73

    
74
    }
75

    
76

    
77
    function retrieveQuery(){
78
        queryService.query('entitytype:"dataset" AND provenance:"'+$scope.datasource.officialName+'"',1).success(function(data){
79
             $scope.result_dataset = data['result']['objects'];
80
        }).error(function () {
81
            console.log("Error on querying data");
82
        });
83

    
84
        queryService.query('entitytype:"publication" AND provenance:"'+$scope.datasource.officialName+'"', 1).success(function(data){
85
             $scope.result_publication = data['result']['objects'];
86
        }).error(function () {
87
            console.log("Error on querying data");
88
        });
89
    }
90

    
91

    
92
    queryService.getDsInfo($scope.id, $scope.name).success(function (data) {
93
        $scope.datasource = data['info'];
94
        retrieveQuery();
95
        extractLastStats();
96
        extractHistoryLinks();
97
    }).error(function (data) {});
98

    
99
}]);
100

    
101
dliApp.controller('datasourcesController', ['$scope', '$routeParams', '$location', 'queryService', function ($scope, $routeParams, $location, queryService) {
102
    queryService.getDatasources().success(function (data) {
103

    
104
        $scope.my_markers = [];
105
        if ("info" in data) {
106
            for (var x in data.info) {
107
                var current = data.info[x];
108
                var tmp = {
109
                    latLng: [current.latitude, current.longitude],
110
                    name: current.officialName, weburl: "#/datasource/id/" + current.namespacePrefix
111
                }
112

    
113
                $scope.my_markers.push(tmp);
114
            }
115
            map.addMarkers($scope.my_markers, []);
116
        }
117

    
118
    }).error(function () {
119
        console.log("An error happen")
120
    });
121

    
122

    
123
    var map;
124
    $scope.focusOn = function (name) {
125
        for (var i = 0; i < $scope.my_markers.length; i++) {
126
            var current = $scope.my_markers[i];
127
            if (current.name === name) {
128

    
129
                map.setFocus({lat: current.latLng[0], lng: current.latLng[1], scale: 8, animate: true});
130
            }
131
        }
132
    }
133
    map = new jvm.Map({
134
        container: $('#world-map'),
135
        map: 'world_mill', backgroundColor: "#FFFFFF",
136

    
137
        regionStyle: {
138
            initial: {
139
                fill: '#296494',
140
                "fill-opacity": 1,
141
                stroke: 'none',
142
                "stroke-width": 0,
143
                "stroke-opacity": 1
144
            },
145
            hover: {
146
                "fill-opacity": 0.8,
147
                cursor: 'pointer'
148
            },
149
            selected: {
150
                fill: 'yellow'
151
            },
152
            selectedHover: {}
153
        },
154
        markerStyle: {
155
            initial: {
156
                fill: 'yellow',
157
                stroke: '#505050',
158
                "fill-opacity": 1,
159
                "stroke-width": 1,
160
                "stroke-opacity": 1,
161
                r: 8
162
            },
163
            hover: {
164
                stroke: 'black',
165
                "stroke-width": 1,
166
                cursor: 'pointer'
167
            },
168
            selectedHover: {}
169
        },
170
        markersSelectable: true,
171
        onMarkerClick: function (events, index) {
172
            $(location).attr('href', my_markers[index].weburl);
173
        },
174

    
175
        markers: []
176

    
177
    });
178

    
179

    
180
}]);
181

    
182

    
183

    
(2-2/7)