Skip to content
Extraits de code Groupes Projets
Valider 9c22ed6a rédigé par Steffen van Bergerem's avatar Steffen van Bergerem
Parcourir les fichiers

Add year to notifications page

parent 3149ab71
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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;
......
......@@ -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
......
......@@ -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
end
def display_year?(year, date)
unless year
Date.current.year != the_year(date)
else
year != the_year(date)
end
end
end
......@@ -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|
......
......@@ -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'}"}
......
......@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter