Skip to content

Commit ae61681

Browse files
authored
Registration address (#441)
* refactor(search): Add geocoder component Move address search to own geocoder component * feat(Registration): Add address search to registration Use own geocoder component to search for addresses during registration fix #320
1 parent 36427f5 commit ae61681

File tree

7 files changed

+310
-136
lines changed

7 files changed

+310
-136
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ module.exports = function (grunt) {
231231
"<%= yeoman.app %>/components/loader.directive.js",
232232
"<%= yeoman.app %>/components/clipboard.directive.js",
233233
"<%= yeoman.app %>/components/announcement.directive.js",
234+
"<%= yeoman.app %>/components/geocoder.directive.js",
234235
],
235236
tasks: [
236237
// 'newer:copy:api',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div class="ng-cloak input-group xxxl" style="display: table; padding: 0px 12px; z-index: 2000;">
2+
<input id="searchField" type="text" style="border-radius: 4px;" class="form-control" ng-model="geocoder.searchString"
3+
ng-change="geocoder.searchStringChanged()" ng-model-options="geocoder.modelOptions"
4+
placeholder="{{ 'SEARCH' | translate }}"
5+
uib-typeahead="address.display_name for address in geocoder.getLocations($viewValue)"
6+
typeahead-on-select="geocoder.selectResult($item)" typeahead-loading="geocoder.loadingLocations"
7+
typeahead-no-results="geocoder.noResults" typeahead-popup-template-url="/views/search.html"
8+
typeahead-template-url="views/search.item.html" typeahead-min-length="3" />
9+
<div id="reset_search" ng-show="geocoder.showClearSearch" ng-cloak>
10+
<span class="helper"></span>
11+
<i class="fa fa-times fa-lg" aria-hidden="true" ng-click="geocoder.clearSearch()"></i>
12+
</div>
13+
</div>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
(function () {
2+
'use strict';
3+
4+
angular
5+
.module('openSenseMapApp')
6+
.directive('osemGeocoder', osemGeocoder);
7+
8+
osemGeocoder.$inject = [];
9+
10+
function osemGeocoder () {
11+
var directive = {
12+
templateUrl: 'components/geocoder.directive.html',
13+
link: link,
14+
// eslint-disable-next-line angular/directive-restrict
15+
restrict: 'E',
16+
transclude: true,
17+
controller: GeocoderController,
18+
controllerAs: 'geocoder',
19+
bindToController: true, // because the scope is isolated
20+
scope: {
21+
selectBox: '='
22+
},
23+
};
24+
25+
return directive;
26+
27+
////
28+
29+
function link (scope, element, attrs) {}
30+
}
31+
32+
GeocoderController.$inject = ['$scope', '$http'];
33+
34+
function GeocoderController ($scope, $http) {
35+
var vm = this;
36+
37+
vm.$onInit = onInit;
38+
vm.$onDestroy = onDestroy;
39+
40+
vm.searchString = '';
41+
vm.showClearSearch = false;
42+
vm.modelOptions = {
43+
debounce: {
44+
default: 300,
45+
blur: 250,
46+
},
47+
getterSetter: true,
48+
};
49+
50+
vm.searchStringChanged = searchStringChanged;
51+
vm.getLocations = getLocations;
52+
vm.selectResult = selectResult;
53+
vm.clearSearch = clearSearch;
54+
55+
////
56+
57+
function onInit () {
58+
activate();
59+
}
60+
61+
function onDestroy () {}
62+
63+
function activate () {}
64+
65+
function searchStringChanged () {
66+
if (vm.searchString !== '') {
67+
vm.showClearSearch = true;
68+
} else {
69+
vm.showClearSearch = false;
70+
}
71+
}
72+
73+
function getLocations (searchstring) {
74+
var results = [];
75+
76+
return $http
77+
.get('//locationiq.org/v1/search.php', {
78+
params: {
79+
format: 'json',
80+
key: '23e12b10d8c3aad04e8e',
81+
addressdetails: 1,
82+
limit: 4,
83+
q: searchstring,
84+
},
85+
})
86+
.then(function (response) {
87+
return results.concat(response.data);
88+
})
89+
.catch(function () {
90+
return results;
91+
});
92+
}
93+
94+
function selectResult (item) {
95+
$scope.geocoder.selectBox(item);
96+
}
97+
98+
function clearSearch () {
99+
vm.searchString = '';
100+
vm.searchStringChanged();
101+
}
102+
103+
////
104+
}
105+
})();

app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@
386386
<script src="scripts/models/box.js"></script>
387387
<script src="scripts/models/sensor.js"></script>
388388
<script src="components/announcement.directive.js"></script>
389+
<script src="components/geocoder.directive.js"></script>
389390
<script src="components/calendar.directive.js"></script>
390391
<script src="components/leaflet.directive.js"></script>
391392
<script src="components/leaflet.service.js"></script>

app/scripts/controllers/header.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@
207207
});
208208

209209
$rootScope.$on('osemAnnouncementClosed', function () {
210-
console.log('header closed');
211210
vm.showAnnouncment = false;
212211
});
213212
}

0 commit comments

Comments
 (0)