Skip to content

Commit

Permalink
add weather box svg icons + controller + style
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Jan 29, 2017
1 parent eca654e commit da9d21b
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 1 deletion.
Binary file added assets/img/landscape-gladys-weather.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions assets/img/weather-icon/cloud.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/img/weather-icon/rain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/img/weather-icon/snow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions assets/img/weather-icon/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions assets/img/weather-icon/white/cloud.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions assets/img/weather-icon/white/rain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions assets/img/weather-icon/white/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion assets/js/app/translate/translate.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ var translationsEN = {
EVENT: {
CREATED_SUCCESS_NOTIFICATION: 'Event created with success : ',
CREATED_FAIL_NOTIFICATION: 'Failed to create event : '
},
WEATHER: {
day: 'Day',
night: 'Night',
HUMIDITY: 'Humidity'
}
};

Expand All @@ -37,7 +42,12 @@ var translationsFR = {
EVENT: {
CREATED_SUCCESS_NOTIFICATION: 'Event créé avec succès : ',
CREATED_FAIL_NOTIFICATION: 'Erreur lors de la création de l\'event : '
}
},
WEATHER: {
day: 'Jour',
night: 'Nuit',
HUMIDITY: 'Humidité'
}
};


Expand Down
107 changes: 107 additions & 0 deletions assets/js/app/weather/weather.controller.js
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;
});
}

}
})();
31 changes: 31 additions & 0 deletions assets/js/app/weather/weather.service.js
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 });
}
}
})();
3 changes: 3 additions & 0 deletions assets/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.box-full-width .box-body{
padding: 0;
}
Loading

0 comments on commit da9d21b

Please sign in to comment.