From 3312f9798138f220461dfeffbe5b2df29271903e Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 23 Nov 2014 13:34:34 +0100 Subject: [PATCH] Fix timeago for notifications, add 'no notifications yet' message --- app/assets/javascripts/app/helpers/timeago.js | 9 +++++++ .../app/views/conversations_view.js | 8 +------ .../app/views/notifications_view.js | 1 + .../widgets/notifications-badge.js | 3 ++- app/assets/stylesheets/header.css.scss | 1 + app/assets/stylesheets/notifications.css.scss | 2 ++ app/views/conversations/show.js.erb | 13 +--------- app/views/notifications/index.html.haml | 24 ++++++++++++------- config/locales/diaspora/en.yml | 1 + spec/javascripts/app/helpers/timeago_spec.js | 20 ++++++++++++++++ 10 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 app/assets/javascripts/app/helpers/timeago.js create mode 100644 spec/javascripts/app/helpers/timeago_spec.js diff --git a/app/assets/javascripts/app/helpers/timeago.js b/app/assets/javascripts/app/helpers/timeago.js new file mode 100644 index 000000000..ddea02057 --- /dev/null +++ b/app/assets/javascripts/app/helpers/timeago.js @@ -0,0 +1,9 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later +(function(){ + app.helpers.timeago = function(el) { + el.find('time.timeago').each(function(i,e) { + $(e).attr('title', new Date($(e).attr('datetime')).toLocaleString()); + }).timeago().tooltip(); + }; +})(); +// @license-end diff --git a/app/assets/javascripts/app/views/conversations_view.js b/app/assets/javascripts/app/views/conversations_view.js index c30f87fdf..c5f75ce4a 100644 --- a/app/assets/javascripts/app/views/conversations_view.js +++ b/app/assets/javascripts/app/views/conversations_view.js @@ -17,13 +17,7 @@ app.views.Conversations = Backbone.View.extend({ } new app.views.ConversationsForm({contacts: gon.contacts}); - - $('.timeago').each(function(i,e) { - var jqe = $(e); - jqe.attr('title', new Date(jqe.attr('datetime')).toLocaleString()); - }) - .timeago() - .tooltip(); + app.helpers.timeago($(this.el)); }, hideParticipants: function(e){ diff --git a/app/assets/javascripts/app/views/notifications_view.js b/app/assets/javascripts/app/views/notifications_view.js index bffd22c09..330022198 100644 --- a/app/assets/javascripts/app/views/notifications_view.js +++ b/app/assets/javascripts/app/views/notifications_view.js @@ -9,6 +9,7 @@ app.views.Notifications = Backbone.View.extend({ initialize: function() { Diaspora.page.header.notifications.setUpNotificationPage(this); $(".unread-toggle .entypo").tooltip(); + app.helpers.timeago($(document)); }, toggleUnread: function(evt) { diff --git a/app/assets/javascripts/widgets/notifications-badge.js b/app/assets/javascripts/widgets/notifications-badge.js index fc1b3d30b..06ea7bf48 100644 --- a/app/assets/javascripts/widgets/notifications-badge.js +++ b/app/assets/javascripts/widgets/notifications-badge.js @@ -83,7 +83,8 @@ self.dropdownNotifications.append(notification.note_html); }); }); - self.dropdownNotifications.find("time.timeago").timeago(); + + app.helpers.timeago(self.dropdownNotifications); self.dropdownNotifications.find('.unread').each(function() { Diaspora.page.header.notifications.setUpUnread( $(this) ); diff --git a/app/assets/stylesheets/header.css.scss b/app/assets/stylesheets/header.css.scss index f443faa66..7cbea8601 100644 --- a/app/assets/stylesheets/header.css.scss +++ b/app/assets/stylesheets/header.css.scss @@ -174,6 +174,7 @@ body > header { .notification_message { margin-left: 40px; + .tooltip { position: fixed; } } .unread-toggle { diff --git a/app/assets/stylesheets/notifications.css.scss b/app/assets/stylesheets/notifications.css.scss index 8e93fdedd..ac3f05519 100644 --- a/app/assets/stylesheets/notifications.css.scss +++ b/app/assets/stylesheets/notifications.css.scss @@ -78,5 +78,7 @@ } .pagination { text-align: center; } + + .no_notifications { text-align: center; } } } diff --git a/app/views/conversations/show.js.erb b/app/views/conversations/show.js.erb index 660f21abb..13cba6f5e 100644 --- a/app/views/conversations/show.js.erb +++ b/app/views/conversations/show.js.erb @@ -10,19 +10,8 @@ $(".stream_element", "#conversation_inbox").removeClass('selected'); $(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").addClass('selected'); $(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").find(".unread_message_count").remove() -$('time.timeago').each(function(i,e) { - var jqe = $(e); - jqe.attr('data-original-title', new Date(jqe.attr('datetime')).toLocaleString()); -}); +app.helpers.timeago($(document)); if ($('#first_unread') > 0) { $("html").scrollTop($('#first_unread').offset().top-50); } - -$(".timeago").tooltip(); -$("time.timeago").timeago(); - -$('time.timeago').each(function(i,e) { - var jqe = $(e); - jqe.attr('title', ''); -}); diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 541d030aa..564017900 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -42,17 +42,23 @@ = t('.mark_all_shown_as_read') -else = t('.mark_all_as_read') - - @group_days.each do |day, notes| - .day_group.row-fluid - .date.span2 - .day= the_day(day.split(' ')) - .month= the_month(day.split(' ')) + - if @group_days.length > 0 + - @group_days.each do |day, notes| + .day_group.row-fluid + .date.span2 + .day= the_day(day.split(' ')) + .month= the_month(day.split(' ')) - .notifications_for_day.span10 - - notes.each do |note| - = render :partial => 'notifications/notification', :locals => { :note => note } + .notifications_for_day.span10 + - notes.each do |note| + = render :partial => 'notifications/notification', :locals => { :note => note } - = will_paginate @notifications, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer + = will_paginate @notifications, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer + + - else + .no_notifications.well + %h4 + = t('.no_notifications') :javascript $(document).ready(function(){ diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 4d950bae5..c7229f5f3 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -722,6 +722,7 @@ en: mentioned: "Mentioned" reshared: "Reshared" started_sharing: "Started sharing" + no_notifications: "You don't have any notifications yet." and_others: zero: "and nobody else" one: "and one more" diff --git a/spec/javascripts/app/helpers/timeago_spec.js b/spec/javascripts/app/helpers/timeago_spec.js new file mode 100644 index 000000000..6884bbc78 --- /dev/null +++ b/spec/javascripts/app/helpers/timeago_spec.js @@ -0,0 +1,20 @@ +describe("app.helpers.timeago", function() { + beforeEach(function(){ + this.date = '2015-02-08T13:37:42.000Z'; + this.datestring = new Date(this.date).toLocaleString(); + var html = ''; + this.content = spec.content().html(html); + }); + + it("converts the date into a locale string for the tooltip", function() { + var timeago = this.content.find('time.timeago'); + expect(timeago.attr('datetime')).toEqual(this.date); + expect(timeago.data('original-title')).toEqual(undefined); + + app.helpers.timeago(this.content); + + timeago = this.content.find('time.timeago'); + expect(timeago.attr('datetime')).toEqual(this.date); + expect(timeago.data('original-title')).toEqual(this.datestring); + }); +});