Add year to notifications page
This commit is contained in:
parent
3149ab7125
commit
9c22ed6aef
6 changed files with 67 additions and 12 deletions
|
|
@ -15,11 +15,26 @@
|
||||||
margin-bottom: 10px;
|
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 {
|
.day_group {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
border-bottom: 1px dashed $border-grey;
|
border-bottom: 1px dashed $border-grey;
|
||||||
&:last-child { border-bottom: none; }
|
|
||||||
.date {
|
.date {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: $light-grey;
|
color: $light-grey;
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class NotificationsController < ApplicationController
|
||||||
@notifications.each do |n|
|
@notifications.each do |n|
|
||||||
n.note_html = render_to_string( :partial => 'notify_popup_item', :locals => { :n => n } )
|
n.note_html = render_to_string( :partial => 'notify_popup_item', :locals => { :n => n } )
|
||||||
end
|
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
|
@unread_notification_count = current_user.unread_notifications.count
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,12 +55,27 @@ module NotificationsHelper
|
||||||
object_link(note, notification_people_link(note))
|
object_link(note, notification_people_link(note))
|
||||||
end
|
end
|
||||||
|
|
||||||
def the_day(i18n)
|
def the_day(date)
|
||||||
i18n[0].match(/\d/) ? i18n[0].gsub('.', '') : i18n[1].gsub('.', '')
|
date.split('-')[2].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def the_month(i18n)
|
def the_month(date)
|
||||||
i18n[0].match(/\d/) ? i18n[1] : i18n[0]
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,17 @@
|
||||||
-else
|
-else
|
||||||
= t('.mark_all_as_read')
|
= t('.mark_all_as_read')
|
||||||
- if @group_days.length > 0
|
- 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
|
.day_group.row-fluid
|
||||||
.date.span2
|
.date.span2
|
||||||
.day= the_day(day.split(' '))
|
.day= the_day(date)
|
||||||
.month= the_month(day.split(' '))
|
.month= the_month(date)
|
||||||
|
|
||||||
.notifications_for_day.span10
|
.notifications_for_day.span10
|
||||||
- notes.each do |note|
|
- notes.each do |note|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@
|
||||||
-else
|
-else
|
||||||
= link_to t('.mark_all_as_read'), read_all_notifications_path, :class => 'btn'
|
= link_to t('.mark_all_as_read'), read_all_notifications_path, :class => 'btn'
|
||||||
%ul.notifications
|
%ul.notifications
|
||||||
- @group_days.each do |day, notes|
|
- @group_days.each do |date, notes|
|
||||||
%li
|
%li
|
||||||
.notification_day_header
|
.notification_day_header
|
||||||
%span.label
|
%span.label
|
||||||
= day
|
= locale_date(date)
|
||||||
%ul.notifications_for_day
|
%ul.notifications_for_day
|
||||||
- notes.each do |note|
|
- notes.each do |note|
|
||||||
.stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : 'read'}"}
|
.stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : 'read'}"}
|
||||||
|
|
|
||||||
|
|
@ -93,4 +93,23 @@ describe NotificationsHelper, :type => :helper do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue