Project

General

Profile

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

    
5

    
6
dliApp.controller('detailController', ['$scope', '$routeParams', '$location', 'queryService', function ($scope, $routeParams, $location, queryService) {
7
    $scope.identifier = $routeParams['id'];
8
    $scope.activeTabName ="";
9
    $scope.currentDatasetPage =1
10
    $scope.currentPublicationPage =1
11
    $scope.currentUnknownPage =1
12

    
13

    
14
    queryService.getItem($scope.identifier).success(function (data) {
15
        if ('result' in data) {
16
            if ('hits' in data.result && data.result['hits'] != null && data.result['hits'].length >0  ) {
17

    
18
                var summary = data.result.hits[0];
19
                var relations = data.result.hits[1];
20

    
21
                relPubs = summary['relatedPublications']
22
                relData = summary['relatedDatasets']
23
                relUnk = summary['relatedUnknown']
24

    
25
                $scope.item = summary;
26
                $scope.relations = relations;
27

    
28
                    $('#myTabs a').click(function (e) {
29
                        e.preventDefault()
30
                        $(this).tab('show')
31
                        });
32
            }
33
            else {
34
                $scope.item = {};
35
                $scope.nf =true                       
36
            }
37
        }
38
    }).error(function (data) {
39
        $scope.hideSpinner();
40
    });
41

    
42
    $scope.showDate = function (dates) {
43
        var nArray = [];
44

    
45
        if (dates== null)
46
            return [];
47

    
48
        for (item in dates){
49
            var current = dates[item];
50
            if (current != null && current.length > 4) {
51
                nArray.push(current.substr(0, 4));
52
            }
53
        }
54
        return nArray;
55
    }
56

    
57

    
58
    $scope.startSearch= function (type, nextPage) {
59
        queryService.getItem($scope.identifier, type, nextPage).success(function (data) {
60
        if ('result' in data) {
61
            if ('hits' in data.result) {
62

    
63
                var summary = data.result.hits[0];
64
                var relations = data.result.hits[1];
65

    
66
                $scope.item = summary;
67
                $scope.relations = relations;
68

    
69
                    $('#myTabs a').click(function (e) {
70
                        e.preventDefault()
71
                        $(this).tab('show')
72
                        });
73
            }
74
        }
75
    }).error(function (data) {
76
        $scope.hideSpinner();
77
    });
78
    }
79

    
80
    $scope.nextPage = function (type) {
81
        var nextPage = 0;
82
        if (type === 'dataset'){
83
            nextPage = ++$scope.currentDatasetPage * 10;
84
        }
85
        if (type === 'publication'){
86
            nextPage = ++$scope.currentPublicationPage * 10;
87
        }
88
        if (type === 'unknown'){
89
            nextPage = ++$scope.currentUnknownPage *10;
90
        }
91
        $scope.startSearch(type, nextPage)
92
    }
93

    
94
    $scope.prevPage = function (type) {
95
        var prevPage = 0;
96
        if (type === 'dataset'){
97
            prevPage = --$scope.currentDatasetPage * 10;
98
        }
99
        if (type === 'publication'){
100
            prevPage = --$scope.currentPublicationPage * 10;
101
        }
102
        if (type === 'unknown'){
103
            prevPage = --$scope.currentUnknownPage *10;
104
        }
105
        $scope.startSearch(type, prevPage)
106
    }
107

    
108

    
109

    
110
    $scope.activeClass = function(name) {
111
        if (name === $scope.activeTabName)
112
            return "active";
113
        return "";
114
    }
115

    
116
}]);
117

    
118

    
119

    
120

    
121
dliApp.controller('queryController', ['$scope', '$routeParams', '$location', 'queryService', function ($scope, $routeParams, $location, queryService) {
122

    
123
    //TO DO Titolo non più lungo di 240 caratteri in caso aggiungere puntini
124
    // Oltre il quarto autore aggiungere puntini
125

    
126
    $scope.makeQuery= function () {
127
        $location.path("/query/q=" + $scope.query);
128
    };
129

    
130

    
131
    $scope.arguments = $location.$$search;
132

    
133
    $scope.pidQuery = null;
134

    
135
    if ('pid' in $scope.arguments) {
136
        $scope.pidQuery =$scope.arguments['pid']
137
    }
138

    
139

    
140

    
141
    $scope.query = $routeParams['q'];
142
    $scope.searching = true;
143

    
144
    $scope.filterType = $routeParams['f'];
145
    $scope.filters = []
146

    
147

    
148

    
149
    $scope.calculateFilter= function(ftype, fValue) {
150
        if ($scope.filterType != null && $scope.filterType.length >0 ) {
151
            return $scope.filterType +"__"+ftype+"_"+fValue;
152
        } else
153
            return ftype+"_"+fValue;
154

    
155
    }
156

    
157

    
158
    if ($scope.query == null || $scope.query.length == 0) {
159
        $location.path("/")
160
    }
161
    $scope.page = $routeParams['page'];
162
    $scope.filter = $routeParams['f'];
163
    $scope.total = 0;
164
    $scope.pageFrom = 1;
165
    $scope.pageto = 6;
166

    
167

    
168
    $scope.filterPath = function () {
169
        if ($scope.filterType != null && $scope.filterType.length >0 ) {
170
            return $scope.filterType+ "/";
171
        }
172
        return"";
173
    }
174

    
175
    if ($scope.page != null) {
176
        $scope.page = parseInt($scope.page);
177
        $scope.pageFrom = Math.max(1, $scope.page - 4);
178
        $scope.pageto = $scope.page + 4;
179
    }
180
    $scope.pageRange = [];
181
    $scope.activePage = function (n) {
182
        if (n == $scope.page)
183
            return "active";
184
        return ""
185
    };
186
    $scope.doSomething = function () {
187
        $location.path("/query/q=" + $scope.query);
188
    };
189

    
190

    
191
    $scope.showDate = function (dates) {
192
        var nArray = [];
193

    
194
        if (dates== null)
195
            return [];
196

    
197
        for (item in dates){
198
            var current = dates[item];
199
            if (current != null && current.length > 4) {
200
                nArray.push(current.substr(0, 4));
201
            }
202
        }
203
        return nArray;
204
    }
205

    
206

    
207
    if ($scope.pidQuery == null) {
208

    
209
        queryService.query($scope.query, $scope.page, $scope.filter).success(function (data) {
210
            $scope.searching = false;
211

    
212
            $scope.result_query = data['result']['hits'];
213
            $scope.facet = data['result']['facet'];
214
            $scope.total = data['result']['total'];
215

    
216
            var totalPages = Math.round($scope.total / 10);
217

    
218
            if ($scope.total > 10 && $scope.total % 10)
219
                totalPages += 1;
220

    
221
            $scope.totalPages = totalPages ;
222

    
223
            $scope.lastPage = Math.min($scope.pageto, totalPages - 1);
224

    
225

    
226
            if ($scope.page != null)
227
                $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), $scope.page);
228
            else {
229
                $scope.page = 1;
230
                $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), 1);
231
            }
232
            $scope.pageRange = [];
233
            for (var i = $scope.pageFrom; i <= $scope.pageto; i++) {
234
                $scope.pageRange.push(i)
235
            }
236
        }).error(function (data) {
237

    
238
            console.log(data)
239
            window.alert("ERROR")
240
        })
241

    
242
    }
243

    
244
    else {
245
        console.log("dovrei essere qui!")
246
        queryService.queryPid($scope.pidQuery).success(function (data) {
247
             $scope.searching = false;
248

    
249
            $scope.result_query = data['result']['hits'];
250
            $scope.facet = data['result']['facet'];
251
            $scope.total = data['result']['total'];
252

    
253
            var totalPages = Math.round($scope.total / 10);
254

    
255
            if ($scope.total > 10 && $scope.total % 10)
256
                totalPages += 1;
257

    
258
            $scope.totalPages = totalPages ;
259

    
260
            $scope.lastPage = Math.min($scope.pageto, totalPages - 1);
261

    
262

    
263
            if ($scope.page != null)
264
                $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), $scope.page);
265
            else {
266
                $scope.page = 1;
267
                $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), 1);
268
            }
269
            $scope.pageRange = [];
270
            for (var i = $scope.pageFrom; i <= $scope.pageto; i++) {
271
                $scope.pageRange.push(i)
272
            }
273
        })
274
    }
275

    
276

    
277

    
278
}]);
(5-5/7)