PageSourceSearch

https://www.hvl.no/internett/js/controllers/study-search-controlle…eojtLJQAoIK7Hkh7y42dLZBp_LcqcVhaYLfzos_5Ul8

js hvl.no collected 2026-09-24 08:40:19 UTC 8,646 bytes, 246 lines download raw bytes

1(function (angular) {
2
3    var module = angular.module("studysearchmodule", ['ngSanitize']);
4
5    module.controller('studysearchcontroller', ["$scope", "$http", "$timeout", "$sce", function ($scope, $http, $timeout, $sce) {
6        $scope.searchResult = {};
7        $scope.language = "nn-NO";
8        $scope.searchString = "";
9        $scope.pagename = "";
10        $scope.pageurl = "";
11        $scope.selectedFilters = [];
12        $scope.openFilters = [];
13        $scope.fromTravelPage = false;
14
15        $scope.toHtml = function (html) {
16            return $sce.trustAsHtml(html);
17        };
18
19        $scope.init = function (searchString, language, pagename, filters, pageurl, fromTravelPage) {
20            $scope.searchString = searchString;
21            $scope.fromTravelPage = fromTravelPage;
22            $scope.language = language;
23            $scope.pagename = pagename;
24            $scope.pageurl = pageurl;
25            $scope.search(JSON.parse(filters));
26        };
27
28        $scope.showFilterGroup = function (filter) {
29            var filtersWithHits = 0;
30            filter.filterItems.forEach(function (a) {
31                if (a.hits > 0) {
32                    filtersWithHits += 1;
33                }
34            });
35
36            return (filtersWithHits > 1);
37        };
38
39        $scope.itemVisible = function (item) {
40            return function (item) {
41                var hasFagomraadeFilter = false;
42                $.each($scope.searchResult.fagomraadeFilters, function (index, value) {
43                    var _fagomraadeFilter = value;
44
45                    $.each(item.filters, function (index, value) {
46                        if (value === _fagomraadeFilter.id) {
47                            hasFagomraadeFilter = true;
48                        }
49                    });
50                });
51
52                return hasFagomraadeFilter && item.visible;
53            }
54        }
55
56        $scope.filterVisible = function (filter) {
57            return filter.hits > 0;
58        };
59
60        $scope.showHideActiveFilters = function () {
61            if ($scope.selectedFilters.length === 0) {
62                return 'active-filters--hidden';
63            } else {
64                return '';
65            }
66        }
67
68        $scope.classFilterIsActive = function (input) {
69            return input ? 'is-active' : '';
70        };
71
72        $scope.filterSelected = function (input) {
73            return input.selected;
74        };
75
76        $scope.removeAllFilterSelected = function (event) {
77            $scope.selectedFilters = [];
78            $scope.searchResult.filters.forEach(function (f) {
79                if (f.name !== "Fields") {
80                    f.isOpen = false;
81                }
82            });
83            $scope.search($scope.selectedFilters);
84            event.preventDefault();
85        };
86
87        $scope.filterItemClick = function (filteritem, event) {
88            filteritem.selected = !filteritem.selected;
89
90            // Add or remove the filter form array
91            if (filteritem.selected === true) {
92                $scope.selectedFilters.push(filteritem);
93            } else {
94                $.each($scope.selectedFilters, function (i) {
95                    if ($scope.selectedFilters[i].id === filteritem.id) {
96                        $scope.selectedFilters.splice(i, 1);
97                        return false;
98                    }
99                });
100            }
101            $scope.search($scope.selectedFilters);
102            event.preventDefault();
103           
104        };
105
106        $scope.filterListClick = function (filterlist, event) {
107            filterlist.isOpen = !filterlist.isOpen;
108            event.preventDefault();
109            
110        }
111
112        $scope.appendStudyPointsPrefix = function (item) {
113            return !isNaN(item.studyPoints);
114        }
115
116        $scope.getOrganizationItems = function (item) {
117            if (item.trim().length == 0) {
118                return [];
119            }
120
121            return item.split(',');
122        }
123
124        $scope.numberOfHits = function () {
125            return $('.item__elem').length;
126        };
127
128        $scope.changeUrl = function () {
129            var filters = "";
130            $.each($scope.selectedFilters, function (index, value) {
131                if (index === $scope.selectedFilters.length - 1) {
132                    filters += value.id;
133                } else {
134                    filters += value.id + ",";
135                }
136            });
137
138            var searchString = "";
139            var filterString = "";
140            var travelString = "";
141
142            if ($scope.searchString.length > 0) {
143                searchString = "?query=" + $scope.searchString;
144                if (filters.length > 0) {
145                    searchString += "&";
146                }
147            }
148
149            if (filters.length > 0) {
150                if (searchString.length === 0) {
151                    filterString = "?";
152                }
153                filterString += "filters=" + filters;
154            }
155            
156            if ($scope.fromTravelPage==="True") {
157                if (searchString.length === 0 && filterString.length === 0) {
158                    travelString = "?reise=true";
159                } else {
160                    travelString += "&reise=true";
161                }
162            }
163            var page = $scope.pagename;
164            var url = $scope.pageurl + searchString + filterString + travelString;
165            
166            if (typeof (history.replaceState) !== "undefined") {
167                var obj = { Page: page, Url: url };
168                history.pushState(obj, obj.Page, obj.Url);
169            } else {
170                return false;
171            }
172        };
173
174        $scope.search = function (filterlist) {
175            if ($scope.searchString === null || !$scope.searchString) {
176                $scope.searchString = "";
177            }
178            $scope.openFilters = [];
179            if ($scope.searchResult.filters) {
180                $scope.searchResult.filters.forEach(function(f) {
181                    if (f.isOpen) {
182                        $scope.openFilters.push(f);
183                    }
184                });
185            }
186            var searchString = $scope.searchString;
187            var filters = "";
188
189            $.each(filterlist, function (index, value) {
190                if (index === filterlist.length - 1) {
191                    filters += value.id;
192                } else {
193                    filters += value.id + ",";
194                }
195            });
196
197            if ($scope.fromTravelPage === "True") {
198                if (filters.length > 0) {
199                    filters += ",Reise";
200                } else {
201                    filters = "Reise";
202                }
203            }
204
205            if (filters.length > 0 && searchString.length === 0) {
206                searchString = "[empty]";
207            }
208
209            var url = "/service/search/study/" + $scope.language + "/" + searchString;
210            
211            if (searchString.length > 0 && filters.length > 0) {
212                url += "/" + filters;
213            }
214
215            $http.get(url)
216                .then(function (result) {
217                    $scope.searchResult = result.data;
218                    $scope.selectedFilters = [];
219                        $scope.searchResult.filters.forEach(function(f) {
220                            if (f.isOpen && !$scope.openFilters.indexOf(f)>-1) {
221                                $scope.openFilters.push(f);
222                            } else if (!f.isOpen) {
223                                $scope.openFilters.forEach(function (o) {
224                                    if (o.id === f.id) {
225                                        f.isOpen = true;
226                                    }
227                                });
228                            }
229                        });
230
231                    $.each($scope.searchResult.filters, function (index, value) {
232                        $.each(value.filterItems, function (index, value) {
233                            if (value.selected === true) {
234                                $scope.selectedFilters.push(value);
235                            }
236                        });
237                    });
238
239                    $scope.changeUrl();
240                    },
241                function () {
242                    console.log("Missing data");
243                });
244        }
245    }]);
246}(window.angular));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.