-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add weather box svg icons + controller + style
- Loading branch information
1 parent
eca654e
commit da9d21b
Showing
14 changed files
with
447 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Gladys Project | ||
* http://gladysproject.com | ||
* Software under licence Creative Commons 3.0 France | ||
* http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ | ||
* You may not use this software for commercial purposes. | ||
* @author :: Pierre-Gilles Leymarie | ||
*/ | ||
|
||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('gladys') | ||
.controller('WeatherCtrl', WeatherCtrl); | ||
|
||
WeatherCtrl.$inject = ['weatherService', 'geoLocationService', 'cacheService', '$timeout']; | ||
|
||
function WeatherCtrl(weatherService, geoLocationService, cacheService, $timeout) { | ||
|
||
/* jshint validthis: true */ | ||
var vm = this; | ||
vm.weather = []; | ||
var EXPIRATION = 30*60*60*1000; | ||
|
||
activate(); | ||
|
||
function activate() { | ||
refresh(); | ||
|
||
// Start the timer | ||
$timeout(tick, 1000); | ||
return ; | ||
} | ||
|
||
function tick () { | ||
vm.currentTime = Date.now(); | ||
$timeout(tick, 1000); | ||
} | ||
|
||
function refresh() { | ||
|
||
// first get GEOLOCATION from cache if exist | ||
var coords = cacheService.get('GEOLOCATION_USER'); | ||
|
||
// if geoloc exist in cache | ||
if(coords) { | ||
return getWeather(coords); | ||
} | ||
// if not, get geoloc from browser | ||
else { | ||
return geoLocationService.getCurrentPosition() | ||
.then(function(data) { | ||
|
||
if(data.coords && data.coords.latitude && data.coords.longitude) { | ||
|
||
var geoloc = { | ||
latitude: data.coords.latitude, | ||
longitude: data.coords.longitude, | ||
accuracy: data.coords.accuracy | ||
}; | ||
|
||
// save geoloc in cache | ||
cacheService.set('GEOLOCATION_USER', geoloc, EXPIRATION); | ||
return getWeather(geoloc); | ||
} else { | ||
|
||
return null; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function getWeather(coords) { | ||
|
||
var latitude = coords.latitude; | ||
var longitude = coords.longitude; | ||
|
||
return weatherService.get({latitude: latitude, longitude: longitude}) | ||
.then(function(data) { | ||
vm.weather[0] = data.data; | ||
|
||
// get weather in | ||
return weatherService.get({latitude: latitude, longitude: longitude, offset: 24}); | ||
}) | ||
.then(function(data) { | ||
|
||
vm.weather[1] = data.data; | ||
|
||
// get weather in 48h | ||
return weatherService.get({latitude: latitude, longitude: longitude, offset: 48}); | ||
}) | ||
.then(function(data) { | ||
|
||
vm.weather[2] = data.data; | ||
|
||
// get weather in 72h | ||
return weatherService.get({latitude: latitude, longitude: longitude, offset: 72}); | ||
}) | ||
.then(function(data) { | ||
|
||
vm.weather[3] = data.data; | ||
}); | ||
} | ||
|
||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Gladys Project | ||
* http://gladysproject.com | ||
* Software under licence Creative Commons 3.0 France | ||
* http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ | ||
* You may not use this software for commercial purposes. | ||
* @author :: Pierre-Gilles Leymarie | ||
*/ | ||
|
||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('gladys') | ||
.factory('weatherService', weatherService); | ||
|
||
weatherService.$inject = ['$http']; | ||
|
||
function weatherService($http) { | ||
|
||
var service = { | ||
get: get | ||
}; | ||
|
||
return service; | ||
|
||
function get(options) { | ||
return $http({method: 'GET', url: '/weather', params: options }); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.box-full-width .box-body{ | ||
padding: 0; | ||
} |
Oops, something went wrong.