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 }}

- -
- -
- - -
-
- -
-
-
-
-

{{event.title}}

-
-
- {{event.category.name}} -
-
-

- -
-
-
- -
{{ 'app.public.home.from_date_to_date' | translate:{START:(event.start_date | amDateFormat:'L'), END:(event.end_date | amDateFormat:'L')} }}
-
{{ 'app.public.home.on_the_date' | translate:{DATE:(event.start_date | amDateFormat:'L')} }}
-
-
- -
- {{ 'app.public.home.all_day' }} - {{ 'app.public.home.from_time_to_time' | translate:{START:(event.start_date | amDateFormat:'LT'), END:(event.end_date | amDateFormat:'LT')} }} -
-
-
- -
-
- -
- {{ 'app.public.home.still_available' | translate }} {{event.nb_free_places}} - {{ 'app.public.home.free_entry' }} - {{ 'app.public.home.event_full' }} -
-
-
- -
- {{ 'app.public.home.free_admission' }} - {{ 'app.public.home.full_price' | translate }} {{event.amount | currency}} -
-
-
- -
-
{{ 'app.shared.buttons.consult' }}
-
-
-
-
-
-
- + + +
+
+ +
diff --git a/app/assets/templates/home/events.html b/app/assets/templates/home/events.html new file mode 100644 index 000000000..4f315be44 --- /dev/null +++ b/app/assets/templates/home/events.html @@ -0,0 +1,65 @@ +
+

{{ 'app.public.home.fablab_s_next_events' | translate }} {{ 'app.public.home.every_events' | translate }}

+ +
+ +
+ + +
+
+ +
+
+
+
+

{{event.title}}

+
+
+ {{event.category.name}} +
+
+

+ +
+
+
+ +
{{ 'app.public.home.from_date_to_date' | translate:{START:(event.start_date | amDateFormat:'L'), END:(event.end_date | amDateFormat:'L')} }}
+
{{ 'app.public.home.on_the_date' | translate:{DATE:(event.start_date | amDateFormat:'L')} }}
+
+
+ +
+ {{ 'app.public.home.all_day' }} + {{ 'app.public.home.from_time_to_time' | translate:{START:(event.start_date | amDateFormat:'LT'), END:(event.end_date | amDateFormat:'LT')} }} +
+
+
+ +
+
+ +
+ {{ 'app.public.home.still_available' | translate }} {{event.nb_free_places}} + {{ 'app.public.home.free_entry' }} + {{ 'app.public.home.event_full' }} +
+
+
+ +
+ {{ 'app.public.home.free_admission' }} + {{ 'app.public.home.full_price' | translate }} {{event.amount | currency}} +
+
+
+ +
+
{{ 'app.shared.buttons.consult' }}
+
+
+
+
+
+
diff --git a/app/assets/templates/home/twitter.html.erb b/app/assets/templates/home/twitter.html similarity index 100% rename from app/assets/templates/home/twitter.html.erb rename to app/assets/templates/home/twitter.html diff --git a/db/seeds.rb b/db/seeds.rb index 93dce5e8b..3a129b72f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -667,7 +667,9 @@ unless Setting.find_by(name: 'home_content').try(:value)
-
#{I18n.t('app.admin.settings.item_events')}
+
+
#{I18n.t('app.admin.settings.item_events')}
+
HTML setting.save