Skip to content

Commit 3bb3aeb

Browse files
authored
rr/view/location (#11)
* rr/main-controller (pull request #2) rr/main-controller * fix gulp indexHTML task * removing unecessary elements * main-controller base Approved-by: Roberto Robson Soares Nogueira <[email protected]> * Merged in rr/navigation-bar (pull request #3) rr/navigation-bar * navigation-bar directive * add navigation-bar app.js dependency. set tiny md override md-button-icon Approved-by: Roberto Robson Soares Nogueira <[email protected]> * rr/side-menu (pull request #4) rr/side-menu Approved-by: Roberto Robson Soares Nogueira <[email protected]> * rr/ng-route (pull request #5) rr/ng-route * rr/fix/ng-view (pull request #6) rr/fix/ng-view Approved-by: Roberto Robson Soares Nogueira <[email protected]> * rr/view/home (pull request #7) rr/view/home Approved-by: Roberto Robson Soares Nogueira <[email protected]> * rr/fix/issues/#1-#2 (pull request #8) rr/fix/issues/#1-#2 * view home, set navigation bar title * main-controller set view attribute when current path get changed Approved-by: Roberto Robson Soares Nogueira <[email protected]> * Merged in rr/view/location (pull request #9) rr/view/location * view location init * google maps, services maps, freegeoip location, display locations on the map Approved-by: Roberto Robson Soares Nogueira <[email protected]>
1 parent 5e12516 commit 3bb3aeb

File tree

14 files changed

+505
-5
lines changed

14 files changed

+505
-5
lines changed

config.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
var config = {
55
timestamp: Date.now(),
6+
googleMapsKey: 'AIzaSyCRXrHeiZf654pjQGDSuKuWesgEMB73g3Q',
67

78
dev: true,
89

gulp-tasks/indexhtml.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ module.exports = function(gulp, modules){
2525
};
2626

2727
return gulp.src(globMatchFiles)
28-
.pipe(modules.handlebars(data))
28+
.pipe(modules.handlebars(data, {
29+
ignorePartials: true
30+
}))
2931
.pipe(gulp.dest(modules.config.getDirDest()));
3032
};
3133
};

src/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
'directives.side-menu',
2424

2525
// views
26-
'views.home'
26+
'views.home',
27+
'views.location'
2728

2829
])
2930

src/config/urls.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
(function(){
4+
5+
angular.module('uiChallengeApp')
6+
7+
.value('URLs', {
8+
9+
freegeoip: 'http://www.freegeoip.net/json/'
10+
11+
});
12+
13+
})();

src/directives/navigation-bar/navigation-bar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
aria-label="Menu"
88
md-ripple-size="auto"
99
class="md-icon-button"
10-
hide-gt-md
10+
hide-gt-sm
1111
>
1212
<md-icon md-svg-icon="assets/icons/menu.svg"></md-icon>
1313
</md-button>

src/directives/side-menu/side-menu.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<md-sidenav
33
side-menu
44
md-component-id="{{componentId}}"
5-
md-is-locked-open="$mdMedia('gt-md')"
5+
md-is-locked-open="$mdMedia('gt-sm')"
66
class="md-sidenav-left"
77
md-whiteframe="4"
88
layout="column"
@@ -11,7 +11,7 @@
1111
<md-content flex layout="column">
1212

1313
<md-button
14-
hide-gt-md
14+
hide-gt-sm
1515
class="close-side-menu md-icon-button"
1616
aria-label="Close side menu"
1717
ng-click="closeSideMenu()"

src/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
<main-controller layout="column" flex></main-controller>
1717

18+
<script src="http://maps.google.com/maps/api/js?key={{config.googleMapsKey}}"></script>
19+
1820
<script src="js/libs.min.js?t={{config.timestamp}}"></script>
1921
<script src="js/app.min.js?t={{config.timestamp}}"></script>
2022
<script src="js/templates.min.js?t={{config.timestamp}}"></script>

src/services/freegeoip/freegeoip.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
'use strict';
3+
4+
(function(){
5+
6+
angular.module('services.freegeoip', [])
7+
8+
.factory('freegeoipService', function(
9+
$http,
10+
URLs
11+
){
12+
13+
var get = function(attr){
14+
15+
$http({
16+
method: 'get',
17+
url: URLs.freegeoip + attr.model.url
18+
}).then(
19+
attr.success,
20+
attr.error
21+
);
22+
23+
};
24+
25+
var factory = {
26+
get: get
27+
};
28+
29+
return factory;
30+
31+
});
32+
33+
})();

src/services/location/location.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
'use strict';
3+
4+
(function(){
5+
6+
angular.module('services.location', [])
7+
8+
.factory('locationService', function(){
9+
10+
var requestLocation = function(attrs){
11+
12+
if(navigator.geolocation){
13+
navigator.geolocation.getCurrentPosition(
14+
attrs.success,
15+
attrs.error
16+
);
17+
} else {
18+
attrs.error();
19+
}
20+
21+
};
22+
23+
var factory = {
24+
25+
getLocation: function(attrs){
26+
requestLocation(attrs);
27+
}
28+
29+
};
30+
31+
return factory;
32+
33+
});
34+
35+
})();

src/services/maps/maps.js

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* globals google */
2+
3+
'use strict';
4+
5+
(function(){
6+
7+
angular.module('services.maps', [])
8+
9+
.factory('mapsService', function(
10+
$document,
11+
$timeout
12+
){
13+
14+
var getObj = function(id){
15+
return {
16+
ready: false,
17+
loading: false,
18+
error: false,
19+
position: {
20+
lat: 0,
21+
lng: 0
22+
},
23+
id: id,
24+
mapObj: null,
25+
marker: null
26+
};
27+
};
28+
29+
var setObjLocationPosition = function(obj,coords){
30+
obj.position = {
31+
lat: coords.latitude,
32+
lng: coords.longitude
33+
};
34+
};
35+
36+
var setStatus = function(obj, status){
37+
angular.extend(obj, status);
38+
};
39+
40+
var initGoogleMaps = function(obj){
41+
42+
if(!obj.mapObj){
43+
obj.mapObj = new google.maps.Map(
44+
$document[0].querySelector('#' + obj.id),
45+
{
46+
zoom: 16
47+
}
48+
);
49+
}
50+
51+
obj.mapObj.setCenter(obj.position);
52+
};
53+
54+
var setMarker = function(obj){
55+
if(!obj.marker){
56+
obj.marker = new google.maps.Marker({
57+
position: obj.position,
58+
map: obj.mapObj
59+
});
60+
}else{
61+
obj.marker.setPosition(obj.position);
62+
}
63+
};
64+
65+
var showLocationOnMap = function(obj, data){
66+
67+
setStatus(
68+
obj,
69+
{
70+
ready: true,
71+
loading: false,
72+
error: false
73+
}
74+
);
75+
76+
$timeout(function(){
77+
78+
setObjLocationPosition(
79+
obj,
80+
{
81+
latitude: data.coords.latitude,
82+
longitude: data.coords.longitude
83+
}
84+
);
85+
86+
initGoogleMaps(obj);
87+
88+
setMarker(obj);
89+
90+
},0);
91+
92+
};
93+
94+
var getLocationError = function(obj){
95+
96+
$timeout(function(){
97+
setStatus(
98+
obj,
99+
{
100+
ready: false,
101+
loading: false,
102+
error: true
103+
}
104+
);
105+
},0);
106+
107+
};
108+
109+
var factory = {
110+
getObj: getObj,
111+
setStatus: setStatus,
112+
showLocationOnMap: showLocationOnMap,
113+
getLocationError: getLocationError
114+
};
115+
116+
return factory;
117+
118+
});
119+
120+
})();

src/views/location/location.config.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
'use strict';
3+
4+
(function(){
5+
6+
// properties
7+
8+
var view = 'location';
9+
var controller = 'ViewLocationController';
10+
11+
var route = {
12+
templateUrl: view + '/' + view + '.html',
13+
controller: controller,
14+
};
15+
16+
var configPath = {
17+
path: '/location/',
18+
label: 'Get location',
19+
icon: 'location.svg',
20+
sideMenu: true
21+
};
22+
23+
// config
24+
25+
angular.module('views.' + view)
26+
27+
.config(function(
28+
$routeProvider,
29+
$locationProvider,
30+
pathProvider
31+
){
32+
33+
var pathObj = pathProvider.addPath(
34+
view,
35+
configPath
36+
);
37+
38+
$routeProvider
39+
40+
.when(
41+
pathObj.path,
42+
route
43+
)
44+
45+
;
46+
47+
});
48+
49+
})();

0 commit comments

Comments
 (0)