1angular.module('IotaSmart.controller') 2 3 .controller('geofenceCtrl', function ($scope, $rootScope, LoginService, $uibModal, GeofenceService) { 4 if (!LoginService.getSession()) 5 $rootScope.logout(); 6 7 $scope.pageTitle = "Geofence" 8 $scope.geofence = { "name": "", "area": "", "description": "" }; 9 $scope.loading = true; 10 $scope.geofenceList = []; 11 12 $scope.lat = 28.548702; 13 $scope.lng = 77.250597; 14 15 $scope.$on('mapInitialized', function (event, map) { 16 $scope.geofenceMap = map; 17 18 $scope.searchBoxDetails(); 19 getGeofence(); 20 }); 21 $scope.polyList = []; 22 $scope.$on('$stateChangeStart', function ($evt) { 23 for (var i = 0; i < $scope.polyList.length; i++) { 24 $scope.polyList[i].setMap(null); 25 } 26 if ($scope.newPoly) 27 $scope.newPoly.setMap(null); 28 }); 29 30 var getGeofence = function () { 31 for (var i = 0; i < $scope.polyList.length; i++) { 32 $scope.polyList[i].setMap(null); 33 } 34 if ($scope.newPoly) 35 $scope.newPoly.setMap(null); 36 GeofenceService.getAllGeofence($rootScope.user.id) 37 .then(function successCallback(res) { 38 $scope.loading = false; 39 if (res.status == 200) { 40 $scope.geofenceList = res.data; 41 for (var j = 0; j < $scope.geofenceList.length; j++) { 42 var geofence = $scope.geofenceList[j]; 43 if (geofence.name == "Parking") { 44 continue; 45 } 46 var str = geofence.area.substring(8, geofence.area.length - 1); 47 var allCoordArr = str.split(", "); 48 var coordArr; 49 var coordStr; 50 var coords = []; 51 for (var i = 0; i < allCoordArr.length; i++) { 52 coordStr = allCoordArr[i]; 53 coordArr = coordStr.split(" "); 54 coords.push({ "lat": parseFloat(coordArr[0].trim()), "lng": parseFloat(coordArr[1].trim()) }); 55 } 56 57 var poly = new google.maps.Polygon({ 58 paths: coords 59 }); 60 poly.setMap($scope.geofenceMap); 61 $scope.polyList.push(poly); 62 } 63 } 64 }, function errorCallback(err) { 65 66 }); 67 } 68 69 $scope.selectedgeofence = function (index) { 70 71 var geofence = $scope.geofenceList[index]; 72 73 var str = geofence.area.substring(8, geofence.area.length - 1); 74 var allCoordArr = str.split(", "); 75 var coordArr; 76 var coordStr; 77 var coords; 78 var bounds = new google.maps.LatLngBounds(); 79 for (var i = 0; i < allCoordArr.length; i++) { 80 coordStr = allCoordArr[i]; 81 coordArr = coordStr.split(" "); 82 var myPlace = new google.maps.LatLng(parseFloat(coordArr[0].trim()), parseFloat(coordArr[1].trim())); 83 bounds.extend(myPlace); 84 } 85 86 $scope.geofenceMap.fitBounds(bounds); 87 console.log(bounds); 88 } 89 90 $scope.onMapOverlayCompleted = function (e) { 91 if ($scope.newPoly) 92 $scope.newPoly.setMap(null); 93 $scope.newPoly = e.overlay; 94 95 $scope.geofence.area = "POLYGON("; 96 var len = $scope.newPoly.getPath().getLength(); 97 for (var i = 0; i < len; i++) { 98 if (i == 0) 99 $scope.geofence.area += $scope.newPoly.getPath().getAt(i).lat() + " " + $scope.newPoly.getPath().getAt(i).lng(); 100 else 101 $scope.geofence.area += ", " + $scope.newPoly.getPath().getAt(i).lat() + " " + $scope.newPoly.getPath().getAt(i).lng(); 102 } 103 $scope.geofence.area += ")"; 104 $scope.showUpdateGeo(); 105 }; 106 107 $scope.showUpdateGeo = function () { 108 var data = {}; 109 data.geofenceList = $scope.geofenceList; 110 data.polyList = $scope.polyList; 111 data.geofence = $scope.geofence; 112 data.newPoly = $scope.newPoly; 113 var modalInstance = $uibModal.open({ 114 animation: true, 115 templateUrl: 'views/modal/add-geofence.html', 116 controller: 'addGeofenceCtrl', 117 backdrop: 'static', 118 resolve: { 119 data: function () { 120 return data; 121 } 122 } 123 }); 124 }; 125 126 // $scope.isEnabling = false; 127 // $scope.disableGeofence = function () { 128 // if ($scope.isEnabling) 129 // return; 130 // $scope.isEnabling = true; 131 // GeofenceService.disableGeofence($scope.device.id, !$scope.device.geofenceEnable) 132 // .then(function successCallback(res) { 133 // $scope.isEnabling = false; 134 // if (res.status == 200) { 135 // if ($scope.device.geofenceEnable) { 136 // $scope.device.geofenceEnable = !$scope.device.geofenceEnable; 137 // alert('Geofence disabled!'); 138 // } 139 // else { 140 // $scope.device.geofenceEnable = !$scope.device.geofenceEnable; 141 // alert('Geofence enabled!'); 142 // } 143 // } 144 // else { 145 // alert('Error occured! please try again.'); 146 // } 147 // }, function errorCallback(err) { 148 // $scope.isEnabling = false; 149 // alert('Error occured! please try again.'); 150 // }); 151 // } 152 153 $scope.updateGeofence = function (index) { 154 var data = $scope.geofenceList[index]; 155 var modalInstance = $uibModal.open({ 156 animation: true, 157 templateUrl: 'views/modal/update-geofence.html', 158 controller: 'updateGeofenceCtrl', 159 backdrop: 'static', 160 resolve: { 161 data: function () { 162 return data; 163 } 164 } 165 }); 166 }; 167 168 $scope.deleteGeofence = function (index) { 169 var geofence = $scope.geofenceList[index]; 170 console.log(geofence); 171 if (confirm("Are you sure want to remove geofence?")) { 172 GeofenceService.deleteGeofence(geofence.id) 173 .then(function successCallback(res) { 174 if (res.status == 200) { 175 getGeofence(); 176 } 177 if (res.status != 200) { 178 alert("Unable to delete geofence!"); 179 } 180 }, function errorCallback(err) { 181 alert("Unable to delete geofence!"); 182 }); 183 } 184 } 185 186 $scope.searchBoxDetails = function () { 187 const input = document.getElementById("searchInput"); 188 console.log($scope.searchInput); 189 const searchBox = new google.maps.places.SearchBox(input); 190 $scope.geofenceMap.controls[google.maps.ControlPosition.TOP_LEFT].push(input); 191 // Bias the SearchBox results towards current map's viewport. 192 $scope.geofenceMap.addListener("bounds_changed", () => { 193 searchBox.setBounds($scope.geofenceMap.getBounds()); 194 }); 195 let markers = []; 196 // Listen for the event fired when the user selects a prediction and retrieve 197 // more details for that place. 198 searchBox.addListener("places_changed", () => { 199 const places = searchBox.getPlaces(); 200 console.log(places); 201 if (places.length == 0) { 202 return; 203 } 204 // Clear out the old markers.
205 markers.forEach(marker => { 206 marker.setMap(null); 207 }); 208 markers = []; 209 // For each place, get the icon, name and location. 210 const bounds = new google.maps.LatLngBounds(); 211 places.forEach(place => { 212 if (!place.geometry) { 213 console.log("Returned place contains no geometry"); 214 return; 215 } 216 const icon = { 217 url: place.icon, 218 size: new google.maps.Size(71, 71), 219 origin: new google.maps.Point(0, 0), 220 anchor: new google.maps.Point(17, 34), 221 scaledSize: new google.maps.Size(25, 25) 222 }; 223 // Create a marker for each place. 224 var marker = new google.maps.Marker({ 225 226 icon, 227 title: place.name, 228 position: place.geometry.location 229 }) 230 marker.setMap($scope.geofenceMap); 231 markers.push(marker); 232 233 console.log(markers); 234 if (place.geometry.viewport) { 235 // Only geocodes have viewport. 236 bounds.union(place.geometry.viewport); 237 } else { 238 bounds.extend(place.geometry.location); 239 } 240 }); 241 $scope.geofenceMap.fitBounds(bounds); 242 }); 243 } 244 245 $scope.assignGeofence = function (index) { 246 var data = $scope.geofenceList[index]; 247 var modalInstance = $uibModal.open({ 248 animation: true, 249 templateUrl: 'views/modal/assign-geofence.html', 250 controller: 'AssignGeofenceCtrl', 251 backdrop: 'static', 252 resolve: { 253 data: function () { 254 return data; 255 } 256 } 257 }); 258 }; 259 260 261 }) 262 .controller('addGeofenceCtrl', function ($scope, $rootScope, $uibModalInstance, data, GeofenceService, $timeout) { 263 $scope.geofenceList = data.geofenceList; 264 $scope.polyList = data.polyList; 265 var geofence = data.geofence; 266 $scope.newPoly = data.newPoly; 267 $scope.geofenceAdded = false; 268 269 $scope.isUpdating = false; 270 $scope.updateGMsg = ''; 271 $scope.updateGErr = false; 272 $scope.geofenceData = { "name": geofence.name, 'userId': $rootScope.user.id, "area": geofence.area, "description": geofence.description }; 273 274 $scope.addGeofence = function () { 275 $scope.isUpdating = true; 276 GeofenceService.addGeofence($scope.geofenceData) 277 .then(function successCallback(res) { 278 $scope.isUpdating = false; 279 if (res.status == 200) { 280 $scope.geofenceData.id = res.data.id; 281 geofence.id = res.data.id; 282 geofence.name = res.data.name; 283 geofence.area = res.data.area; 284 geofence.description = res.data.description; 285 $scope.geofenceList.push(geofence); 286 $scope.polyList.push($scope.newPoly); 287 $scope.updateGMsg = 'Geofence updated sucessfully!'; 288 $scope.geofenceAdded = true; 289 $timeout(function () { 290 clearGUMessage(); 291 $uibModalInstance.dismiss('cancel'); 292 }, 2000); 293 } 294 else { 295 $scope.updateGMsg = 'Error occured! please try again.'; 296 $scope.updateGErr = true; 297 $timeout(function () { 298 clearGUMessage(); 299 }, 5000); 300 } 301 }, function errorCallback(err) { 302 $scope.isUpdating = false; 303 $scope.updateGErr = true; 304 $scope.updateGMsg = 'Error occured! please try again.'; 305 $timeout(function () { 306 clearGUMessage(); 307 }, 5000); 308 }); 309 } 310 var clearGUMessage = function () { 311 $scope.updateGMsg = ''; 312 $scope.updateGErr = false; 313 } 314 315 $scope.cancel = function () { 316 if ($scope.newPoly) 317 $scope.newPoly.setMap(null); 318 $uibModalInstance.dismiss('cancel'); 319 }; 320 }) 321 .controller('AssignGeofenceCtrl', function ($scope, $rootScope, $uibModalInstance, GeofenceService, data) { 322 $scope.geofenceData = { selectedDevice: [], geofence: data }; 323 console.log($scope.geofenceData) 324 $scope.geofenceId = data.id; 325 $scope.updateGMsg = ''; 326 $scope.vehicleList1 = $rootScope.deviceList; 327 $scope.vehicleList = []; 328 $scope.cancel = function () { 329 $uibModalInstance.dismiss('cancel'); 330 } 331 332 var getAssignedVehicleList = function () { 333 var assignedVehicleList = []; 334 $scope.vehicleList.push(...$scope.vehicleList1); 335 console.log($scope.vehicleList); 336 $scope.assignedVehicleList = []; 337 338 GeofenceService.getAssignedVehicleList($scope.geofenceId) 339 .then(function successCallback(res) { 340 if (res.status == 200) { 341 assignedVehicleList = res.data; 342 if (assignedVehicleList) { 343 for (var i = 0; i < assignedVehicleList.length; i++) { 344 for (var j = 0; j < $scope.vehicleList.length; j++) { 345 if ($scope.vehicleList[j].id == assignedVehicleList[i]) { 346 $scope.assignedVehicleList.push($scope.vehicleList[j]); 347 $scope.vehicleList.splice(j, 1); 348 } 349 } 350 } 351 console.log($scope.vehicleList, $scope.assignedVehicleList); 352 } 353 } 354 if (res.status != 200) { 355 alert("Unable to get assigned vehicle list!"); 356 } 357 }, function errorCallback(err) { 358 alert("Unable to get assigned vehicle list!"); 359 }); 360 } 361 362 $scope.vehiclecustomTexts = { buttonDefaultText: 'Select Device' }; 363 364 // $scope.vehicleEvents = { 365 // onSelectionChanged: function () { 366 // $scope.geofenceData.selectedDevice.forEach((selectedData) => { 367 // console.log(selectedData) 368 // var data = $scope.vehicleList.find(function (item) { 369 // return item.id == selectedData.id; 370 // }); 371 // if (data != null) { 372 // angular.copy(data, selectedData); 373 // } 374 375 // }); 376 // } 377 // } 378 $scope.vehicleSettings = { 379 380 displayProp: 'name', 381 scrollableHeight: '150px', 382 scrollable: true, 383 selectedToTop: true, 384 checkBoxes: true 385 }; 386 387 $scope.assignVehicle = function () { 388 var deviceArr = []; 389 if ($scope.geofenceData.selectedDevice) { 390 for (var i = 0; i < $scope.geofenceData.selectedDevice.length; i++) { 391 deviceArr.push($scope.geofenceData.selectedDevice[i].id); 392 } 393 var deviceId = deviceArr.toString(); 394 } 395 396 if (confirm("Are you sure want to assign?")) { 397 GeofenceService.assignVehicle(deviceId, $scope.geofenceId) 398 .then(function successCallback(res) { 399 if (res.status == 200) { 400 $scope.vehicleList.splice(0, $scope.vehicleList.length); 401 $scope.geofenceData.selectedDevice = []; 402 getAssignedVehicleList(); 403 404 } 405 if (res.status != 200) { 406 alert("Unable to assign vehicle!"); 407 } 408 }, function errorCallback(err) { 409 alert("Unable to assign vehicle!"); 410 }); 411 } 412 } 413 414 $scope.deassignVehicle = function (index) { 415 var deviceId = $scope.assignedVehicleList[index].id; 416 if (confirm(`Are you sure want to deassign ${$scope.assignedVehicleList[index].name}?`)) { 417 GeofenceService.deassignVehicle(deviceId, $scope.geofenceId) 418 .then(function successCallback(res) { 419 if (res.status == 200) { 420 $scope.vehicleList.splice(0, $scope.vehicleList.length); 421 $scope.geofenceData.selectedDevice = []; 422 getAssignedVehicleList(); 423 424 } 425 if (res.status != 200) { 426 alert("Unable to De-assign vehicle!"); 427 } 428 }, function errorCallback(err) { 429 alert("Unable to De-assign vehicle!"); 430 }); 431 } 432 } 433 434 getAssignedVehicleList(); 435 436 437 }) 438 .controller('updateGeofenceCtrl', function ($scope, $rootScope, $uibModalInstance, data, GeofenceService, $timeout) { 439 440 $scope.isUpdating = false; 441 $scope.updateGMsg = ''; 442 $scope.updateGErr = false; 443 $scope.geofenceData = data; 444 $scope.name = $scope.geofenceData.name; 445 $scope.description = $scope.geofenceData.description 446 console.log($scope.geofenceData); 447 $scope.updateGeofence = function () { 448 $scope.geofenceData.name = $scope.name; 449 $scope.geofenceData.description = $scope.description; 450 $scope.isUpdating = false; 451 console.log($scope.geofenceData); 452 GeofenceService.updateGeofence($scope.geofenceData, $scope.geofenceData.id) 453 .then(function successCallback(res) { 454 $scope.isUpdating = false; 455 if (res.status == 200) { 456 $scope.updateGMsg = 'Geofence updated sucessfully!'; 457 $scope.geofenceAdded = true; 458 $timeout(function () { 459 clearGUMessage(); 460 $uibModalInstance.dismiss('cancel'); 461 }, 2000); 462 } 463 else { 464 $scope.updateGMsg = 'Error occured! please try again.'; 465 $scope.updateGErr = true; 466 $timeout(function () { 467 clearGUMessage(); 468 }, 5000); 469 } 470 }, function errorCallback(err) { 471 $scope.isUpdating = false; 472 $scope.updateGErr = true; 473 $scope.updateGMsg = 'Error occured! please try again.'; 474 $timeout(function () { 475 clearGUMessage(); 476 }, 5000); 477 }); 478 } 479 var clearGUMessage = function () { 480 $scope.updateGMsg = ''; 481 $scope.updateGErr = false; 482 } 483 484 $scope.cancel = function () { 485 if ($scope.newPoly) 486 $scope.newPoly.setMap(null); 487 $uibModalInstance.dismiss('cancel'); 488 }; 489 })
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.