From a29ba926c0bd837ef0d803f936afd482066bcee0 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Mon, 18 Dec 2017 16:15:38 +0100 Subject: [PATCH] fix events/index order, frontend js code was conflicting with server-side behaviour --- .../javascripts/controllers/events.coffee.erb | 15 +++------------ app/assets/templates/events/index.html.erb | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/controllers/events.coffee.erb b/app/assets/javascripts/controllers/events.coffee.erb index 9dd525549..9f9b86b14 100644 --- a/app/assets/javascripts/controllers/events.coffee.erb +++ b/app/assets/javascripts/controllers/events.coffee.erb @@ -31,7 +31,7 @@ Application.Controllers.controller "EventsController", ["$scope", "$state", 'Eve theme_id: null age_range_id: null - + $scope.monthNames = [<%= t('date.month_names')[1..-1].map { |m| "\"#{m}\"" }.join(', ') %>] ## # Adds a resultset of events to the bottom of the page, grouped by month @@ -106,19 +106,10 @@ Application.Controllers.controller "EventsController", ["$scope", "$state", 'Eve groupEvents = (events) -> if events.length > 0 eventsGroupedByMonth = _.groupBy(events, (obj) -> - _.map ['month', 'year'], (key, value) -> obj[key] + _.map ['month_id', 'year'], (key, value) -> obj[key] ) $scope.eventsGroupByMonth = Object.assign($scope.eventsGroupByMonth, eventsGroupedByMonth) - - monthsOrder = _.sortBy _.keys($scope.eventsGroupByMonth), (k)-> - monthYearArray = k.split(',') - date = new Date() - date.setMonth(monthYearArray[0]) - date.setYear(monthYearArray[1]) - return -date.getTime() - - $scope.monthOrder = monthsOrder - + $scope.monthOrder = Object.keys($scope.eventsGroupByMonth) ## !!! MUST BE CALLED AT THE END of the controller diff --git a/app/assets/templates/events/index.html.erb b/app/assets/templates/events/index.html.erb index 341b53910..49b85f4a3 100644 --- a/app/assets/templates/events/index.html.erb +++ b/app/assets/templates/events/index.html.erb @@ -41,7 +41,7 @@
-

{{month.split(',')[0]}}, {{month.split(',')[1]}}

+

{{monthNames[month.split(',')[0] - 1]}}, {{month.split(',')[1]}}