diff --git a/app/assets/stylesheets/notifications.css.scss b/app/assets/stylesheets/notifications.css.scss index ac3f05519..3e4cd7533 100644 --- a/app/assets/stylesheets/notifications.css.scss +++ b/app/assets/stylesheets/notifications.css.scss @@ -15,11 +15,26 @@ margin-bottom: 10px; } + .year_container { margin-top: 75px; } + .header + .year_container { margin-top: 50px; } + .year { + background-color: $white; + color: $light-grey; + font-size: 20px; + line-height: 20px; + margin-bottom: -20px; + text-align: center; + } + + .year_container + .day_group { + border-top: 1px solid $border-grey; + padding-top: 10px; + } + .day_group { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px dashed $border-grey; - &:last-child { border-bottom: none; } .date { text-align: center; color: $light-grey; diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 2f5a92191..c364d50c3 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -44,7 +44,7 @@ class NotificationsController < ApplicationController @notifications.each do |n| n.note_html = render_to_string( :partial => 'notify_popup_item', :locals => { :n => n } ) end - @group_days = @notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) } + @group_days = @notifications.group_by{|note| note.created_at.strftime('%Y-%m-%d')} @unread_notification_count = current_user.unread_notifications.count diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 6db4e46e4..af9578f62 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -55,12 +55,27 @@ module NotificationsHelper object_link(note, notification_people_link(note)) end - def the_day(i18n) - i18n[0].match(/\d/) ? i18n[0].gsub('.', '') : i18n[1].gsub('.', '') + def the_day(date) + date.split('-')[2].to_i end - def the_month(i18n) - i18n[0].match(/\d/) ? i18n[1] : i18n[0] + def the_month(date) + I18n.l(Date.strptime(date, '%Y-%m-%d'), :format => '%B') + end + + def the_year(date) + date.split('-')[0].to_i + end + + def locale_date(date) + I18n.l(Date.strptime(date, '%Y-%m-%d'), :format => I18n.t('date.formats.fullmonth_day')) + end + + def display_year?(year, date) + unless year + Date.current.year != the_year(date) + else + year != the_year(date) + end end end - diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 564017900..dfd0bd946 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -43,11 +43,17 @@ -else = t('.mark_all_as_read') - if @group_days.length > 0 - - @group_days.each do |day, notes| + - year = nil + - @group_days.each do |date, notes| + - if display_year?(year, date) + - year = the_year(date) + .row-fluid.year_container + .span2.offset5.year= year + .day_group.row-fluid .date.span2 - .day= the_day(day.split(' ')) - .month= the_month(day.split(' ')) + .day= the_day(date) + .month= the_month(date) .notifications_for_day.span10 - notes.each do |note| diff --git a/app/views/notifications/index.mobile.haml b/app/views/notifications/index.mobile.haml index 498ee29a4..7258fc418 100644 --- a/app/views/notifications/index.mobile.haml +++ b/app/views/notifications/index.mobile.haml @@ -7,11 +7,11 @@ -else = link_to t('.mark_all_as_read'), read_all_notifications_path, :class => 'btn' %ul.notifications - - @group_days.each do |day, notes| + - @group_days.each do |date, notes| %li .notification_day_header %span.label - = day + = locale_date(date) %ul.notifications_for_day - notes.each do |note| .stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : 'read'}"} diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb index 2e30be976..3b9cefb1e 100644 --- a/spec/helpers/notifications_helper_spec.rb +++ b/spec/helpers/notifications_helper_spec.rb @@ -93,4 +93,23 @@ describe NotificationsHelper, :type => :helper do end end end + + describe '#display_year?' do + it 'returns false if year is nil and the date includes the current year' do + expect(display_year?(nil,Date.current.strftime('%Y-%m-%d'))).to be_falsey + end + + it 'returns true if year is nil and the date does not include the current year' do + expect(display_year?(nil,'1900-12-31')).to be_truthy + end + + it 'returns false if the date includes the given year' do + expect(display_year?(2015,'2015-12-31')).to be_falsey + end + + it 'returns true if the date does not include the given year' do + expect(display_year?(2015,'2014-12-31')).to be_truthy + expect(display_year?(2015,'2016-12-31')).to be_truthy + end + end end