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.query = $routeParams['q'];
128

    
129
    $scope.filterType = $routeParams['f'];
130
    $scope.filters = []
131

    
132

    
133

    
134
    $scope.calculateFilter= function(ftype, fValue) {
135
        if ($scope.filterType != null && $scope.filterType.length >0 ) {
136
            return $scope.filterType +"__"+ftype+"_"+fValue;
137
        } else
138
            return ftype+"_"+fValue;
139

    
140
    }
141

    
142

    
143
    if ($scope.query == null || $scope.query.length == 0) {
144
        $location.path("/")
145
    }
146
    $scope.page = $routeParams['page'];
147
    $scope.filter = $routeParams['f'];
148
    $scope.total = 0;
149
    $scope.pageFrom = 1;
150
    $scope.pageto = 6;
151

    
152

    
153
    $scope.filterPath = function () {
154
        if ($scope.filterType != null && $scope.filterType.length >0 ) {
155
            return $scope.filterType+ "/";
156
        }
157
        return"";
158
    }
159

    
160
    if ($scope.page != null) {
161
        $scope.page = parseInt($scope.page);
162
        $scope.pageFrom = Math.max(1, $scope.page - 4);
163
        $scope.pageto = $scope.page + 4;
164
    }
165
    $scope.pageRange = [];
166
    $scope.activePage = function (n) {
167
        if (n == $scope.page)
168
            return "active";
169
        return ""
170
    };
171
    $scope.doSomething = function () {
172
        $location.path("/query/q=" + $scope.query);
173
    };
174

    
175

    
176
    $scope.showDate = function (dates) {
177
        var nArray = [];
178

    
179
        if (dates== null)
180
            return [];
181

    
182
        for (item in dates){
183
            var current = dates[item];
184
            if (current != null && current.length > 4) {
185
                nArray.push(current.substr(0, 4));
186
            }
187
        }
188
        return nArray;
189
    }
190

    
191
    queryService.query($scope.query, $scope.page, $scope.filter).success(function (data) {
192

    
193
        $scope.result_query = data['result']['hits'];
194
        $scope.facet = data['result']['facet'];
195
        $scope.total = data['result']['total'];
196

    
197
        var totalPages = Math.round($scope.total / 10);
198

    
199
        if ($scope.total > 10 && $scope.total % 10)
200
            totalPages += 1;
201

    
202
        $scope.totalPages = totalPages ;
203

    
204
        $scope.lastPage = Math.min($scope.pageto, totalPages - 1);
205

    
206

    
207
        if ($scope.page != null)
208
            $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), $scope.page);
209
        else {
210
            $scope.page = 1;
211
            $scope.pageto = Math.max(Math.min($scope.pageFrom + 4, $scope.lastPage), 1);
212
        }
213
        $scope.pageRange = [];
214
        for (var i = $scope.pageFrom; i <= $scope.pageto; i++) {
215
            $scope.pageRange.push(i)
216
        }
217
    }).error(function (data) {
218

    
219
    })
220
}]);
(5-5/7)