Merge pull request #5676 from svbergerem/notifications-add-year

Add year to notifications page
This commit is contained in:
Jonne Haß 2015-02-16 18:43:59 +01:00
commit 278ca84ec2
7 changed files with 68 additions and 12 deletions

View file

@ -169,6 +169,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Show hovercard on mentions [#5652](https://github.com/diaspora/diaspora/pull/5652)
* Make help sections linkable [#5667](https://github.com/diaspora/diaspora/pull/5667)
* Add invitation link to contacts page [#5655](https://github.com/diaspora/diaspora/pull/5655)
* Add year to notifications page [#5676](https://github.com/diaspora/diaspora/pull/5676)
# 0.4.1.2

View file

@ -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;

View file

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

View file

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

View file

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

View file

@ -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'}"}

View file

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