diff options
| author | Kir | 2011-11-01 20:23:57 +0400 |
|---|---|---|
| committer | Kir | 2011-11-01 20:23:57 +0400 |
| commit | e855fb8574570934cde28cfb190cc3cba31fbec0 (patch) | |
| tree | 8cd131551d43b3aaa13d7d7e71517b1424271ff0 | |
| parent | 6477ad7cdba8a06fa00be6c374aaa1cad2d2f505 (diff) | |
| download | inboxes-e855fb8574570934cde28cfb190cc3cba31fbec0.tar.bz2 | |
New scope and templates
| -rw-r--r-- | app/controllers/speakers_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/discussion.rb | 16 | ||||
| -rw-r--r-- | app/views/discussions/_form.html.haml | 8 | ||||
| -rw-r--r-- | app/views/discussions/index.html.haml | 19 | ||||
| -rw-r--r-- | app/views/discussions/new.html.haml | 6 | ||||
| -rw-r--r-- | app/views/discussions/show.html.haml | 34 | ||||
| -rw-r--r-- | app/views/messages/_form.html.haml | 9 |
7 files changed, 62 insertions, 32 deletions
diff --git a/app/controllers/speakers_controller.rb b/app/controllers/speakers_controller.rb index 7fd5f1e..17cedb9 100644 --- a/app/controllers/speakers_controller.rb +++ b/app/controllers/speakers_controller.rb @@ -14,7 +14,7 @@ class SpeakersController < ApplicationController @speaker = Speaker.find(params[:id]) @speaker.destroy flash[:notice] = t("views.speakers.removed") - redirect_to @discussion.speakers.any? ? @discussion : discussions_url + redirect_to @discussion.speakers.any? && @discussion.can_participate?(current_user) ? @discussion : discussions_url end private diff --git a/app/models/discussion.rb b/app/models/discussion.rb index cc1da7a..ad53523 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -13,10 +13,12 @@ class Discussion < ActiveRecord::Base has_many :users, :through => :speakers # отметки о прочтении юзеров - # has_many :views, :dependent => :destroy, :class_name => "DiscussionView" - - # жутко неоптимизированная часть, возможны баги - # scope :unread_for, lambda { |user_or_user_id| joins(:views, :speakers).where("discussions.updated_at >= discussion_views.updated_at AND speakers.user_id = ?", user_or_user_id.is_a?(User) ? user_or_user_id.id : user_or_user_id ) } + has_many :views, :dependent => :destroy, :class_name => "DiscussionView" + + scope :unread_for, (lambda do |user_or_user_id| + user = user_or_user_id.is_a?(User) ? user_or_user_id.id : user_or_user_id + joins(:views, :speakers).where("discussions.updated_at >= discussion_views.updated_at AND speakers.user_id = ? AND discussion_views.user_id = ?", user, user) + end) accepts_nested_attributes_for :messages @@ -81,9 +83,9 @@ class Discussion < ActiveRecord::Base end # дата последнего сообщения в дискуссии - def last_message_at - self.messages.last ? self.messages.last.created_at : nil - end + # def last_message_at + # self.messages.last ? self.messages.last.created_at : nil + # end # проверка, является ли дискуссия непрочитанной для пользователя def unread_for?(user) diff --git a/app/views/discussions/_form.html.haml b/app/views/discussions/_form.html.haml index 7ceee2b..303f0bb 100644 --- a/app/views/discussions/_form.html.haml +++ b/app/views/discussions/_form.html.haml @@ -1,12 +1,12 @@ = form_for @discussion do |f| - %div + %p = f.label :recipient_tokens %br = select_tag "discussion[recipient_tokens]", options_from_collection_for_select(User.all, :id, Inboxes::config.user_name), :multiple => true, :size => "4" - %div + %p = f.fields_for :messages do |j| = j.label :body %br - = j.text_area :body, :label => "Сообщение" + = j.text_area :body - = f.submit 'Отправить'
\ No newline at end of file + %p= f.submit
\ No newline at end of file diff --git a/app/views/discussions/index.html.haml b/app/views/discussions/index.html.haml index 8f47198..8060254 100644 --- a/app/views/discussions/index.html.haml +++ b/app/views/discussions/index.html.haml @@ -1,7 +1,18 @@ -%h3 Discussions list -- @discussions.each do |discussion| - .discussion - = link_to "Discussion with #{discussion.users.collect{|u| u[Inboxes::config.user_name]}.join(', ')}", discussion +%h1 Discussions list + +%table + %tr + %th Last message + %th Members + %th Unread + - @discussions.each do |discussion| + %tr + %td + = discussion.updated_at + %td + = link_to discussion.users.collect{|u| u[Inboxes::config.user_name]}.join(', '), discussion + %td + = discussion.unread_for?(current_user) ? "Yes" : "No" %p = link_to "Create new", new_discussion_path
\ No newline at end of file diff --git a/app/views/discussions/new.html.haml b/app/views/discussions/new.html.haml index ac6665c..6bcf481 100644 --- a/app/views/discussions/new.html.haml +++ b/app/views/discussions/new.html.haml @@ -1,3 +1,5 @@ -%h3 New discussion +%h1 New discussion + = render "form" -= link_to "All discussions", discussions_path
\ No newline at end of file + +%p= link_to "All discussions", discussions_path
\ No newline at end of file diff --git a/app/views/discussions/show.html.haml b/app/views/discussions/show.html.haml index ecad61f..6672c54 100644 --- a/app/views/discussions/show.html.haml +++ b/app/views/discussions/show.html.haml @@ -1,5 +1,7 @@ -%h2 - Members: +%h1 Discussion + +%h3 + Members - @discussion.speakers.each do |speaker| %div = speaker.user[Inboxes::config.user_name] @@ -12,14 +14,26 @@ = f.collection_select :user_id, available_users, :id, :name = f.submit "Add" -%h2 Messages -- @discussion.messages.each do |message| - %div - = "[#{message.user[Inboxes::config.user_name]}]" - = message.body - = "@ #{l(message.created_at)}" + +%h3 Messages + +%table + %tr + %th User + %th Message + %th Posted at + - @discussion.messages.each do |message| + %tr + %td + = message.user[Inboxes::config.user_name] + %td + = message.body + %td + = l(message.created_at) -%h3 Add message +%h3 Add message = render "messages/form" -= link_to "All discussions", discussions_path
\ No newline at end of file +%p + = link_to "Выйти из переписки", leave_discussion_path(@discussion), :method => :post unless @discussion.private? + = link_to "All discussions", discussions_path
\ No newline at end of file diff --git a/app/views/messages/_form.html.haml b/app/views/messages/_form.html.haml index 78ccaa0..f85ed37 100644 --- a/app/views/messages/_form.html.haml +++ b/app/views/messages/_form.html.haml @@ -1,6 +1,7 @@ .message_form = form_for Message.new, :url => discussion_messages_path(@discussion.id), :method => :post do |f| - = f.text_area :body - = f.submit "Отправить" - -= link_to "Выйти из переписки", leave_discussion_path(@discussion), :method => :post unless @discussion.private?
\ No newline at end of file + %p + = f.label :body + %br + = f.text_area :body + %p= f.submit
\ No newline at end of file |
