1'use strict'; 2 3(function (angular) { 4 angular.module('BruSo.visitor').controller('SelectionsListController', [ 5 '$scope', '$translate', '$timeout', 'Pagination', 'MySelection', 'Search', 'Results', 'TRANSLATE', 'COMMON', '$location', 'notify', 'Exceptions', 'Spinner', 'MyFolders', 6 function($scope, $translate, $timeout, Pagination, MySelection, Search, Results, TRANSLATE, COMMON, $location, notify, Exceptions, Spinner, MyFolders) { 7 8 $scope.allItems = []; 9 $scope.pageSizes = []; 10 $scope.pagination = { 11 currentPage: 1, 12 items: [], 13 lastPage: 1, 14 navPageIndexes: [], 15 pageSize: $scope.isMobile ? 20 : 50 16 }; 17 18 $scope.mustShowPagination = mustShowPagination; 19 $scope.pageFirst = pageFirst; 20 $scope.pageLast = pageLast; 21 $scope.pageNext = pageNext; 22 $scope.pagePrevious = pagePrevious; 23 $scope.pageTo = pageTo; 24 $scope.refreshPagination = refreshPagination; 25 $scope.deleteSelection = deleteSelection; 26 $scope.updateSelection = updateSelection; 27 $scope.runSelectionQuery = runSelectionQuery; 28 $scope.setSelectionIdToEdit = setSelectionIdToEdit; 29 $scope.setSelectionToSendToMyBruso = setSelectionToSendToMyBruso; 30 31 $scope.selection = {}; 32 33 $scope.$watchCollection('myselection.selections', function () { 34 refreshPagination(); 35 }); 36 37 $translate('myselection.selectionDeleteSuccess').then(function (translatedValue) { 38 $scope.selectionDeleteSuccess = translatedValue; 39 }); 40 $translate('myselection.selectionDeleteError').then(function (translatedValue) { 41 $scope.selectionDeleteError = translatedValue; 42 }); 43 44 init(); 45 46 function init() { 47 refreshPagination(); 48 MyFolders.updateMyFolders($scope); 49 } 50 51 function deleteSelection(selectionId){ 52 MySelection.deleteSelection(selectionId).then(function(){ 53 notify({ 54 message: $scope.selectionDeleteSuccess, 55 classes: "alert-warning", 56 position: "right", 57 duration: 2000 58 }); 59 $scope.loadMySelection(); 60 }).catch(function(){ 61 notify({ 62 message: $scope.selectionDeleteError, 63 classes: "alert-danger", 64 position: "right", 65 duration: 2000 66 }); 67 $scope.getMySelection(); 68 }).finally(function () { 69 $scope.goToMySelection(); 70 }); 71 } 72 73 function updateSelection(selectionId, title, description){ 74 return MySelection.updateSelection(selectionId, title, description); 75 } 76 77 function runSelectionQuery(selectionQuery, displayMap){ 78 Spinner.showSpinner(); 79 80 Results.setShowOptions('map', displayMap); 81 82 $scope.filters = angular.fromJson(selectionQuery); 83 Results.setFilters($scope.filters); 84 85 if($scope.filters.organisationName){ 86 Search.searchOrganisationByName($scope.filters.organisationName).then(function (organisations) { 87 Results.setOrganisations(organisations); 88 }).catch(function (rejection) { 89 Results.setOrganisations([]); 90 throw Exceptions.rejection(rejection); 91 }).finally(function () { 92 $scope.goToResults(); 93 }); 94 } else if($scope.filters.activityTerms){ 95 Search.searchCategory({ 96 'activity' : $scope.filters.activityTerms, 97 'allwords' : $scope.filters.activityAllwords 98 }).then(function (categories) { 99 Results.setCategories(categories, $scope.langAffixed('title')); 100 101 var categoryIds = new Array(); 102 if(categories.length > 0){ 103 for(var i = 0 ; i< categories.length ; i++){ 104 categoryIds[i] = categories[i].id; 105 } 106 $scope.filters.categories = categoryIds; 107 searchOrganisationByFilters(); 108 //If Categories were found, the call to $scope.goToResults(); 109 //is delegated to searchOrganisationByFilters(); 110 } else { 111 $scope.goToResults(); 112 } 113 }).catch(function (rejection) { 114 Results.setCategories(null, $scope.langAffixed('title')); 115 $scope.goToResults(); 116 throw Exceptions.rejection(rejection); 117 }); 118 } else { 119 Search.searchOrganisationByFiltersAndCategories($scope.filters).then(function (organisations) { 120 Results.setOrganisations(organisations, $scope.langAffixed('nameOfficial')); 121 }).catch(function (rejection) { 122 Results.setOrganisations([], $scope.langAffixed('nameOfficial')); 123 throw Exceptions.rejection(rejection); 124 }).finally(function () { 125 $scope.goToResults(); 126 }); 127 } 128 } 129 130 function searchOrganisationByFilters(){ 131 132 // Recherche multi-critères d'organisations 133 // Build locations spatialFilters 134 $scope.filters.locations.length = 0; 135 angular.forEach($scope.filters.locatedNear, function(locatedNear) { 136 $scope.filters.locations.push(locatedNear.point.y + "," + locatedNear.point.x); 137 }) 138 139 Search.searchOrganisationByFiltersAndCategories($scope.filters).then(function (organisations) { 140 Results.setOrganisations(organisations, $scope.langAffixed('nameOfficial')); 141 }).catch(function (rejection) { 142 Results.setOrganisations([], $scope.langAffixed('nameOfficial')); 143 throw Exceptions.rejection(rejection); 144 }).finally(function () { 145 $scope.goToResults(); 146 }); 147 } 148 149 150 function mustShowPagination() { 151 return Pagination.mustShowPagination($scope); 152 } 153 154 function pageFirst() { 155 Pagination.pageFirst($scope); 156 } 157 158 function pageLast() { 159 Pagination.pageLast($scope); 160 } 161 162 function pageNext() { 163 Pagination.pageNext($scope); 164 } 165 166 function pagePrevious() { 167 Pagination.pagePrevious($scope); 168 } 169 170 function pageTo(index) { 171 Pagination.pageTo($scope, index); 172 } 173 174 function refreshPagination() { 175 if($scope.myselection){ 176 Pagination.refreshPagination($scope, $scope.myselection.selections); 177 } 178 } 179 180 function setSelectionIdToEdit(selectionId){ 181 $scope.selection.id = selectionId 182 } 183 184 function setSelectionToSendToMyBruso (selection){ 185 var select = angular.copy(selection); 186 select.id = undefined; 187 $scope.selection = angular.extend($scope.selection, select); 188 $scope.selection.query = angular.fromJson(select.query); 189 } 190 }]); 191})(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.