From 6b32d0c960ef92ca989f2f26d1eb386d41fe644e Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 4 Mar 2016 17:24:28 +0100 Subject: [PATCH] Improve message threads (by @paroga) --- .../controllers/message_threads_controller.rb | 5 +++-- .../app/controllers/messages_controller.rb | 4 ++++ ...est_public_messages_index.html.haml.deface | 5 ++++- .../_groupmessage_threads.html.haml | 11 +++++++++++ .../_message_threads.html.haml | 16 ++++++++++++---- .../app/views/message_threads/index.html.haml | 7 +++++-- .../app/views/message_threads/show.haml | 19 +++++-------------- .../{index.js.haml => show.js.haml} | 0 .../messages/app/views/messages/thread.haml | 17 +++++++++++++++++ plugins/messages/config/locales/de.yml | 18 ++++++++++++++++-- plugins/messages/config/locales/en.yml | 6 ++++++ plugins/messages/config/routes.rb | 6 +++++- .../messages/lib/foodsoft_messages/engine.rb | 2 +- 13 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 plugins/messages/app/views/message_threads/_groupmessage_threads.html.haml rename plugins/messages/app/views/message_threads/{index.js.haml => show.js.haml} (100%) create mode 100644 plugins/messages/app/views/messages/thread.haml diff --git a/plugins/messages/app/controllers/message_threads_controller.rb b/plugins/messages/app/controllers/message_threads_controller.rb index 7794ce45..43756fa0 100644 --- a/plugins/messages/app/controllers/message_threads_controller.rb +++ b/plugins/messages/app/controllers/message_threads_controller.rb @@ -3,10 +3,11 @@ class MessageThreadsController < ApplicationController before_filter -> { require_plugin_enabled FoodsoftMessages } def index - @message_threads = Message.pub.threads.page(params[:page]).per(@per_page).order(created_at: :desc).includes(:sender) + @groups = Group.order(:name) end def show - @messages = Message.thread(params[:id]).order(:created_at) + @group = Group.find_by_id(params[:id]) + @message_threads = Message.pub.threads.where(group: @group).page(params[:page]).per(@per_page).order(created_at: :desc) end end diff --git a/plugins/messages/app/controllers/messages_controller.rb b/plugins/messages/app/controllers/messages_controller.rb index 5cb7e11d..f05c4335 100644 --- a/plugins/messages/app/controllers/messages_controller.rb +++ b/plugins/messages/app/controllers/messages_controller.rb @@ -47,4 +47,8 @@ class MessagesController < ApplicationController redirect_to messages_url, alert: 'Nachricht ist privat!' end end + + def thread + @messages = Message.thread(params[:id]).order(:created_at) + end end diff --git a/plugins/messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface b/plugins/messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface index 73eb416d..d984b61c 100644 --- a/plugins/messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface +++ b/plugins/messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface @@ -4,4 +4,7 @@ %section#messages %h2= t '.messages.title' = render 'messages/messages', messages: Message.pub.order('created_at DESC').limit(5), pagination: false - %p= link_to t('.messages.view_all'), messages_path + %p + = link_to t('.messages.view_all'), messages_path + != ' | ' + = link_to t('.message_threads.view_all'), message_threads_path diff --git a/plugins/messages/app/views/message_threads/_groupmessage_threads.html.haml b/plugins/messages/app/views/message_threads/_groupmessage_threads.html.haml new file mode 100644 index 00000000..443fc1d8 --- /dev/null +++ b/plugins/messages/app/views/message_threads/_groupmessage_threads.html.haml @@ -0,0 +1,11 @@ +- message_threads = Message.pub.threads.where(group: group).order(created_at: :desc).limit(5) +- unless message_threads.empty? + %section + %h3 + = name + %small + = link_to message_thread_path(id) do + = t '.show_message_threads' + %i.icon.icon-chevron-right + = render 'message_threads', message_threads: message_threads, pagination: false + = link_to_top diff --git a/plugins/messages/app/views/message_threads/_message_threads.html.haml b/plugins/messages/app/views/message_threads/_message_threads.html.haml index ef3109f5..9be5779d 100644 --- a/plugins/messages/app/views/message_threads/_message_threads.html.haml +++ b/plugins/messages/app/views/message_threads/_message_threads.html.haml @@ -5,15 +5,23 @@ - unless message_threads.empty? %table.table.table-striped + %thead + %tr + %th= heading_helper Message, :subject + %th= t '.started_at' + %th= t '.started_by' + %th= t '.last_reply_at' + %th= t '.last_reply_by' %tbody - for message in message_threads %tr %td - %b= link_to message.subject, message_thread_path(message) - %td= h(message.sender_name) + %b= link_to message.subject, thread_message_path(message) + %td= format_time message.created_at + %td= show_user message.sender - if message.last_reply - %td= format_time(message.last_reply.created_at) - %td= h(message.last_reply.sender_name) + %td= format_time message.last_reply.created_at + %td= show_user message.last_reply.sender - else %td{:colspan => "2"} // %td= link_to t('.reply'), new_message_path(:message => {:reply_to => message.id}), class: 'btn' diff --git a/plugins/messages/app/views/message_threads/index.html.haml b/plugins/messages/app/views/message_threads/index.html.haml index 3511aa80..ff275ae1 100644 --- a/plugins/messages/app/views/message_threads/index.html.haml +++ b/plugins/messages/app/views/message_threads/index.html.haml @@ -3,5 +3,8 @@ - content_for :actionbar do = link_to t('.messages'), messages_path, class: 'btn' = link_to t('.new'), new_message_path, class: 'btn btn-primary' -#message_threads - = render 'message_threads', message_threads: @message_threads, pagination: true + += render 'groupmessage_threads', group: nil, name: t('.other'), id: 0 + +- for group in @groups + = render 'groupmessage_threads', group: group, name: group.name, id: group.id diff --git a/plugins/messages/app/views/message_threads/show.haml b/plugins/messages/app/views/message_threads/show.haml index efb1cf5c..bc1eb84c 100644 --- a/plugins/messages/app/views/message_threads/show.haml +++ b/plugins/messages/app/views/message_threads/show.haml @@ -1,16 +1,7 @@ -- if @messages.first.group - - title @messages.first.subject + ' (' + @messages.first.group.name + ')' +- if @group.nil? + - title t '.other' - else - - title @messages.first.subject + - title @group.name -- for message in @messages - .panel.panel-default{:style => "width:40em"} - .panel-heading - %b= h(message.sender_name) - = format_time(message.created_at) - .panel-body= simple_format(h(message.body)) - -%p - = link_to t('.reply'), new_message_path(:message => {:reply_to => @messages.first.id}), class: 'btn' - | - = link_to t('.all_message_threads'), message_threads_path +#message_threads + = render 'message_threads', message_threads: @message_threads, pagination: true diff --git a/plugins/messages/app/views/message_threads/index.js.haml b/plugins/messages/app/views/message_threads/show.js.haml similarity index 100% rename from plugins/messages/app/views/message_threads/index.js.haml rename to plugins/messages/app/views/message_threads/show.js.haml diff --git a/plugins/messages/app/views/messages/thread.haml b/plugins/messages/app/views/messages/thread.haml new file mode 100644 index 00000000..4bc36bcb --- /dev/null +++ b/plugins/messages/app/views/messages/thread.haml @@ -0,0 +1,17 @@ +- thread_message = @messages.first +- if thread_message.group + - title thread_message.subject + ' (' + thread_message.group.name + ')' +- else + - title thread_message.subject + +- for message in @messages + .panel.panel-default{:style => "width:40em"} + .panel-heading + %b= h(message.sender_name) + = format_time(message.created_at) + .panel-body= simple_format(h(message.body)) + +%p + = link_to t('.reply'), new_message_path(:message => {:reply_to => thread_message.id}), class: 'btn' + | + = link_to t('.all_message_threads'), message_threads_path diff --git a/plugins/messages/config/locales/de.yml b/plugins/messages/config/locales/de.yml index 14dee615..08584d44 100644 --- a/plugins/messages/config/locales/de.yml +++ b/plugins/messages/config/locales/de.yml @@ -29,6 +29,10 @@ de: messagegroups: members: Mitglieder name: Name + home: + index: + message_threads: + view_all: Alle Nachrichteverläufe anzeigen messagegroups: index: body: Du kannst jede der Nachrichtengruppen beitreten oder sie wieder verlassen. @@ -45,14 +49,24 @@ de: messages: index: message_threads: Nachrichtenverläufe + thread: + all_message_threads: Alle Nachrichtenverläufe + reply: Antworten message_threads: + groupmessage_threads: + show_message_threads: Alle Nachrichtenverläufe anzeigen index: messages: Nachrichten new: Neue Nachricht + other: Allgemeine Nachrichten title: Nachrichtenverläufe + message_threads: + last_reply_at: Letze Antwort am + last_reply_by: Letze Antwort von + started_at: Gestartet am + started_by: Gestartet von show: - all_message_threads: Alle Nachrichtenverläufe - reply: Antworten + other: Allgemeine Nachrichten navigation: admin: messagegroups: Nachrichtengruppen diff --git a/plugins/messages/config/locales/en.yml b/plugins/messages/config/locales/en.yml index 212d1e67..9c1bb67f 100644 --- a/plugins/messages/config/locales/en.yml +++ b/plugins/messages/config/locales/en.yml @@ -75,13 +75,19 @@ en: sent_on: ! 'Sent:' subject: ! 'Subject:' title: Show message + thread: + all_message_threads: All message threads message_threads: + groupmessage_threads: + show_message_threads: show all index: messages: View as messages new: New message + other: General title: Message threads show: all_message_threads: All message threads + other: General reply: Reply messages_mailer: foodsoft_message: diff --git a/plugins/messages/config/routes.rb b/plugins/messages/config/routes.rb index 478d8e8a..2b681fe5 100644 --- a/plugins/messages/config/routes.rb +++ b/plugins/messages/config/routes.rb @@ -1,6 +1,10 @@ Rails.application.routes.draw do scope '/:foodcoop' do - resources :messages, :only => [:index, :show, :new, :create] + resources :messages, :only => [:index, :show, :new, :create] do + member do + get :thread + end + end resources :message_threads, :only => [:index, :show] diff --git a/plugins/messages/lib/foodsoft_messages/engine.rb b/plugins/messages/lib/foodsoft_messages/engine.rb index 81b063bb..527b5603 100644 --- a/plugins/messages/lib/foodsoft_messages/engine.rb +++ b/plugins/messages/lib/foodsoft_messages/engine.rb @@ -5,7 +5,7 @@ module FoodsoftMessages return if primary[:foodcoop].nil? sub_nav = primary[:foodcoop].sub_navigation sub_nav.items << - SimpleNavigation::Item.new(primary, :messages, I18n.t('navigation.messages'), context.messages_path) + SimpleNavigation::Item.new(primary, :message_threads, I18n.t('navigation.messages'), context.message_threads_path) # move to right before tasks item if i = sub_nav.items.index(sub_nav[:tasks]) sub_nav.items.insert(i, sub_nav.items.delete_at(-1))