diff --git a/Gemfile b/Gemfile index a31f62b19..83275fd5a 100644 --- a/Gemfile +++ b/Gemfile @@ -10,8 +10,6 @@ gem 'mini_racer', '~> 0.4' gem 'uglifier', '~> 2.7' gem 'sanitize', '~> 6.0' -gem 'mumuki-domain', github: 'mumuki/mumuki-domain', branch: 'feature-time-left-for-exam' - group :test do gem 'rspec-rails', '~> 3.6' gem 'factory_bot_rails', '~> 5.0' @@ -37,3 +35,7 @@ group :development, :test do gem 'pry-stack_explorer' gem 'binding_of_caller' end +# +gem 'mumuki-domain', github: 'mumuki/mumuki-domain', branch: 'feature-async-massive-notifications' +# +gem 'mumukit-nuntius', github: 'mumuki/mumukit-nuntius', branch: 'feature-async-massive-notifications' diff --git a/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss b/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss index ed152a17d..2c31750f9 100644 --- a/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss +++ b/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss @@ -30,3 +30,4 @@ @import "modules/upload"; @import "modules/user_menu"; @import "modules/user_profile"; +@import "modules/notifications"; diff --git a/app/assets/stylesheets/mumuki_laboratory/application/modules/_notifications.scss b/app/assets/stylesheets/mumuki_laboratory/application/modules/_notifications.scss new file mode 100644 index 000000000..543f93663 --- /dev/null +++ b/app/assets/stylesheets/mumuki_laboratory/application/modules/_notifications.scss @@ -0,0 +1,58 @@ +.notifications-dropdown { + min-width: 18rem; + + .mu-see-all-notifications { + text-align: center; + width: 100%; + + a { + text-decoration: none; + width: 100%; + } + } +} + +.mu-notifications-content { + position: relative; + + .mu-notifications-title { + font-weight: bold; + } + + .mu-notifications-body { + min-height: 2rem; + height: 2rem; + overflow: hidden; + } + + .mu-notifications-arrow { + position: absolute; + border: none; + background: none; + top: 5px; + right: 0; + i { + @extend .fa-angle-down; + } + } + + &.opened { + .mu-notifications-body { + height: auto; + overflow: hidden; + } + .mu-notifications-arrow { + i { + @extend .fa-angle-up; + } + } + } +} + +.mu-readable-item-icon { + width: 3.5em; + text-align: center; + a { + color: unset; + } +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 227ff00c8..517234a24 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,6 +37,7 @@ class ApplicationController < ActionController::Base :login_button, :notifications_count, :has_notifications?, + :has_many_notifications?, :user_notifications, :subject, :should_choose_organization?, diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e5b00bdcd..a02866fa0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -59,7 +59,7 @@ def permissible_params end def notifications - @notifications = @user.notifications_in_organization.order(created_at: :desc).page(params[:page]) + @notifications = @user.notifications_in_organization.order(:read, created_at: :desc).page(params[:page]).per(10) end def toggle_read diff --git a/app/helpers/user_discussions_helper.rb b/app/helpers/user_discussions_helper.rb deleted file mode 100644 index 07a395689..000000000 --- a/app/helpers/user_discussions_helper.rb +++ /dev/null @@ -1,38 +0,0 @@ -module UserDiscussionsHelper - def user_discussions_table_title(discussion, user, last_read) - <<~HTML.html_safe - - - - - #{discussion.read_by?(user) ? t(:discussions_read) : t(:discussions_unread)} - - - - HTML - end - - def user_discussions_table_header - <<~HTML.html_safe - - - #{t(:exercise)} - #{t(:discussion_created_by)} - #{t(:last_message)} - - HTML - end - - def user_discussions_table_item(discussion, user) - <<~HTML.html_safe - - - #{icon_for_read(discussion.read_by?(user))} - - #{link_to discussion.item.name, item_discussion_path(discussion)} - #{discussion_user_name discussion.initiator} - #{friendly_time(discussion.last_message_date, :time_since)} - - HTML - end -end diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb new file mode 100644 index 000000000..a0ea75591 --- /dev/null +++ b/app/helpers/user_notifications_helper.rb @@ -0,0 +1,23 @@ +module UserNotificationsHelper + def notification_toggle_read(notification) + link_to icon_for_read(notification.read?), + "notifications/#{notification.id}/toggle_read", + tooltip_options(:toggle_read).merge(method: :post, role: :button) + end + + def notification_content(notification) + <<~HTML.html_safe +
+ #{ render partial: "notifications/titles/#{notification.subject}", locals: { notification: notification } } +
+
+
+ #{ render partial: "notifications/#{notification.subject}", locals: { notification: notification } } +
+
+ + HTML + end +end diff --git a/app/helpers/user_readable_items_table_helper.rb b/app/helpers/user_readable_items_table_helper.rb new file mode 100644 index 000000000..4698f3288 --- /dev/null +++ b/app/helpers/user_readable_items_table_helper.rb @@ -0,0 +1,40 @@ +module UserReadableItemsTableHelper + + def user_notifications_table_header + <<~HTML.html_safe + + + #{ t :notification } + #{ t :created_at } + + HTML + end + + def user_notifications_table_item(notification) + <<~HTML.html_safe + + + #{ link_to icon_for_read(notification.read?), + "notifications/#{notification.id}/toggle_read", + tooltip_options(:toggle_read).merge(method: :post, role: :button) } + + +
+ #{ render partial: "notifications/titles/#{notification.subject}", locals: { notification: notification } } +
+
+
+ #{ render partial: "notifications/#{notification.subject}", locals: { notification: notification } } +
+
+ + + + #{ friendly_time(notification.created_at, :time_since) } + + + HTML + end +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 3b53e6324..35bb3fea4 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -6,7 +6,7 @@ class UserMailer < ApplicationMailer def welcome_email(user, organization) with_locale(user, organization) do organization_name = organization.display_name || t(:your_new_organization) - build_email t(:welcome, name: organization_name), { inline: organization.welcome_email_template }, from: organization.welcome_email_sender + build_email t(:welcome, name: organization_name), 'welcome', from: organization.welcome_email_sender end end diff --git a/app/views/layouts/_user_readable_table.html.erb b/app/views/layouts/_user_readable_table.html.erb new file mode 100644 index 000000000..8221c7481 --- /dev/null +++ b/app/views/layouts/_user_readable_table.html.erb @@ -0,0 +1,42 @@ +
+
+

<%= title %>

+
+ <% if readable_items.empty? %> +
+ <%= empty_legend %> +
+ <% else %> +
+ + <% readable_items.group_by(&group_by).each_with_index do |(is_read, grouped_readable_items), index| %> + + + + + + + + <% table.keys.each do |header| %> + + <% end %> + + <% grouped_readable_items.each_with_index do |it| %> + + <% table.values.each do |transformation| %> + + <% end %> + + <% end %> + <% end %> +
+ <%= is_read ? t(:discussions_read) : t(:discussions_unread) %> +
<%= header %>
<%= transformation[:proc].call it %>
+
+ +
+ <%= paginate readable_items, nav_class: 'pagination' %> +
+ + <% end %> +
diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index 69285e39e..7959e496d 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -13,480 +13,7 @@ - - + <%= yield %> diff --git a/app/views/notifications/_custom_notification.html.erb b/app/views/notifications/_custom_notification.html.erb new file mode 100644 index 000000000..3c17a3483 --- /dev/null +++ b/app/views/notifications/_custom_notification.html.erb @@ -0,0 +1 @@ +<%= notification.target.body_html.html_safe %> diff --git a/app/views/notifications/_dropdown.html.erb b/app/views/notifications/_dropdown.html.erb index 8a3f2fb4c..9e6c2cd9d 100644 --- a/app/views/notifications/_dropdown.html.erb +++ b/app/views/notifications/_dropdown.html.erb @@ -3,10 +3,17 @@ <%= notifications_count %> -