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) {
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
        }
34
    }).error(function (data) {
35
        $scope.hideSpinner();
36
    });
37

    
38
    $scope.showDate = function (dates) {
39
        var nArray = [];
40

    
41
        if (dates== null)
42
            return [];
43

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

    
53

    
54
    $scope.startSearch= function (type, nextPage) {
55
        queryService.getItem($scope.identifier, type, nextPage).success(function (data) {
56
        if ('result' in data) {
57
            if ('hits' in data.result) {
58

    
59
                var summary = data.result.hits[0];
60
                var relations = data.result.hits[1];
61

    
62
                $scope.item = summary;
63
                $scope.relations = relations;
64

    
65
                    $('#myTabs a').click(function (e) {
66
                        e.preventDefault()
67
                        $(this).tab('show')
68
                        });
69
            }
70
        }
71
    }).error(function (data) {
72
        $scope.hideSpinner();
73
    });
74
    }
75

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

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

    
104

    
105

    
106
    $scope.activeClass = function(name) {
107
        if (name === $scope.activeTabName)
108
            return "active";
109
        return "";
110
    }
111

    
112
}]);
113

    
114

    
115

    
116

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

    
119
    //TO DO Titolo non più lungo di 240 caratteri in caso aggiungere puntini
120
    // Oltre il quarto autore aggiungere puntini
121

    
122
    $scope.makeQuery= function () {
123
        $location.path("/query/q=" + $scope.query);
124
    };
125

    
126

    
127
    $scope.arguments = $location.$$search;
128

    
129
    $scope.pidQuery = null;
130

    
131
    if ('pid' in $scope.arguments) {
132
        $scope.pidQuery =$scope.arguments['pid']
133
    }
134

    
135

    
136

    
137
    $scope.query = $routeParams['q'];
138
    $scope.searching = true;
139

    
140
    $scope.filterType = $routeParams['f'];
141
    $scope.filters = []
142

    
143

    
144

    
145
    $scope.calculateFilter= function(ftype, fValue) {
146
        if ($scope.filterType != null && $scope.filterType.length >0 ) {
147
            return $scope.filterType +"__"+ftype+"_"+fValue;
148
        } else
149
            return ftype+"_"+fValue;
150

    
151
    }
152

    
153

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

    
163

    
164
    $scope.filterPath = function () {
165
        if ($scope.filterType != null && $scope.filterType.length >0 ) {
166
            return $scope.filterType+ "/";
167
        }
168
        return"";
169
    }
170

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

    
186

    
187
    $scope.showDate = function (dates) {
188
        var nArray = [];
189

    
190
        if (dates== null)
191
            return [];
192

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

    
202

    
203
    if ($scope.pidQuery == null) {
204

    
205
        queryService.query($scope.query, $scope.page, $scope.filter).success(function (data) {
206
            $scope.searching = false;
207

    
208
            $scope.result_query = data['result']['hits'];
209
            $scope.facet = data['result']['facet'];
210
            $scope.total = data['result']['total'];
211

    
212
            var totalPages = Math.round($scope.total / 10);
213

    
214
            if ($scope.total > 10 && $scope.total % 10)
215
                totalPages += 1;
216

    
217
            $scope.totalPages = totalPages ;
218

    
219
            $scope.lastPage = Math.min($scope.pageto, totalPages - 1);
220

    
221

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

    
234
        })
235

    
236
    }
237

    
238
    else {
239
        console.log("dovrei essere qui!")
240
        queryService.queryPid($scope.pidQuery).success(function (data) {
241
             $scope.searching = false;
242

    
243
            $scope.result_query = data['result']['hits'];
244
            $scope.facet = data['result']['facet'];
245
            $scope.total = data['result']['total'];
246

    
247
            var totalPages = Math.round($scope.total / 10);
248

    
249
            if ($scope.total > 10 && $scope.total % 10)
250
                totalPages += 1;
251

    
252
            $scope.totalPages = totalPages ;
253

    
254
            $scope.lastPage = Math.min($scope.pageto, totalPages - 1);
255

    
256

    
257
            if ($scope.page != null)
258
                $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), $scope.page);
259
            else {
260
                $scope.page = 1;
261
                $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), 1);
262
            }
263
            $scope.pageRange = [];
264
            for (var i = $scope.pageFrom; i <= $scope.pageto; i++) {
265
                $scope.pageRange.push(i)
266
            }
267
        })
268
    }
269

    
270

    
271

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