diff --git a/app/assets/javascripts/controllers/home.js b/app/assets/javascripts/controllers/home.js
index a5e72d987..96fd68e66 100644
--- a/app/assets/javascripts/controllers/home.js
+++ b/app/assets/javascripts/controllers/home.js
@@ -1,18 +1,11 @@
'use strict';
-Application.Controllers.controller('HomeController', ['$scope', '$stateParams', 'upcomingEventsPromise',
- function ($scope, $stateParams, upcomingEventsPromise) {
+Application.Controllers.controller('HomeController', ['$scope', '$stateParams', 'homeContentPromise',
+ function ($scope, $stateParams, homeContentPromise) {
/* PUBLIC SCOPE */
- // The closest upcoming events
- $scope.upcomingEvents = upcomingEventsPromise;
-
- /**
- * Test if the provided event run on a single day or not
- * @param event {Object} single event from the $scope.upcomingEvents array
- * @returns {boolean} false if the event runs on more that 1 day
- */
- $scope.isOneDayEvent = event => moment(event.start_date).isSame(event.end_date, 'day');
+ // Home page HTML content
+ $scope.homeContent = homeContentPromise;
/* PRIVATE SCOPE */
diff --git a/app/assets/javascripts/directives/events.js.erb b/app/assets/javascripts/directives/events.js.erb
new file mode 100644
index 000000000..aca43325a
--- /dev/null
+++ b/app/assets/javascripts/directives/events.js.erb
@@ -0,0 +1,31 @@
+Application.Directives.directive('events', [ 'Event',
+ function (Event) {
+ return ({
+ restrict: 'E',
+ templateUrl: '<%= asset_path "home/events.html" %>',
+ link ($scope, element, attributes) {
+ // The closest upcoming events
+ $scope.upcomingEvents = null;
+
+ /**
+ * Test if the provided event run on a single day or not
+ * @param event {Object} single event from the $scope.upcomingEvents array
+ * @returns {boolean} false if the event runs on more that 1 day
+ */
+ $scope.isOneDayEvent = function(event) {
+ return moment(event.start_date).isSame(event.end_date, 'day');
+ }
+
+ // constructor
+ const initialize = function () {
+ Event.upcoming({ limit: 3 }, function (data) {
+ $scope.upcomingEvents = data;
+ })
+ };
+
+ // !!! MUST BE CALLED AT THE END of the directive
+ return initialize();
+ }
+ });
+ }
+]);
diff --git a/app/assets/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb
index 80ff57918..017524a33 100644
--- a/app/assets/javascripts/router.js.erb
+++ b/app/assets/javascripts/router.js.erb
@@ -98,7 +98,7 @@ angular.module('application.router', ['ui.router'])
}
},
resolve: {
- upcomingEventsPromise: ['Event', function (Event) { return Event.upcoming({ limit: 3 }).$promise; }]
+ homeContentPromise: ['Setting', function (Setting) { return Setting.get({ name: 'home_content' }).$promise; }]
}
})
.state('app.public.privacy', {
diff --git a/app/assets/templates/home.html.erb b/app/assets/templates/home.html.erb
index bac59eb8f..95da106d9 100644
--- a/app/assets/templates/home.html.erb
+++ b/app/assets/templates/home.html.erb
@@ -13,71 +13,10 @@
{{ 'app.public.home.fablab_s_next_events' | translate }} {{ 'app.public.home.every_events' | translate }}
-
-