Improve message threads (by @paroga)

This commit is contained in:
wvengen 2016-03-04 17:24:28 +01:00
parent 673448a5ac
commit 6b32d0c960
13 changed files with 89 additions and 27 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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