Description:
update message console
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r766:4b83dfaa53e2 - - 7 files changed: 66 inserted, 62 deleted

@@ -0,0 +1,24
1 + .announcementbox
2 + %span{:class => 'title'}
3 + How to submit clarification requests
4 + .announcement
5 + %p
6 + :markdown
7 + The clarification requests should be phrased as yes/no questions.
8 + The answers will be one of the following:
9 + (1) **YES**,
10 + (2) <b>NO</b>,
11 + (3) **ANSWERED IN TASK DESCRIPTION (EXPLICITLY OR IMPLICITLY)**,
12 + (4) **INVALID QUESTION**, and
13 + (5) **NO COMMENT**.
14 +
15 + = form_for 'message', :url => { :action => 'create'} do |f|
16 + %p
17 + %b New clarification request
18 + = submit_tag "Post"
19 + %br/
20 + = f.text_area :body, :rows => 5, :cols => 100
21 +
22 + %hr/
23 +
24 + = render :partial => 'message', :collection => @messages, :locals => {:reply => false}
@@ -1,84 +1,88
1 class MessagesController < ApplicationController
1 class MessagesController < ApplicationController
2
2
3 - before_action :authenticate
3 + before_action :check_valid_login
4
4
5 + before_action :set_message, only: ['show', 'reply']
5
6
6 - before_filter :admin_authorization, :only => ['console','show',
7 + before_action :admin_authorization, :only => ['console','show',
7 'reply','hide','list_all']
8 'reply','hide','list_all']
8
9
9 - def list
10 + def index
10 - @user = User.find(session[:user_id])
11 + @messages = Message.find_all_sent_by_user(@current_user)
11 - @messages = Message.find_all_sent_by_user(@user)
12 end
12 end
13
13
14 def console
14 def console
15 - @user = User.find(session[:user_id])
16 @messages = Message.find_all_system_unreplied_messages
15 @messages = Message.find_all_system_unreplied_messages
17 end
16 end
18
17
19 def show
18 def show
20 - @message = Message.find(params[:id])
21 end
19 end
22
20
23 def list_all
21 def list_all
24 - @user = User.find(session[:user_id])
25 @messages = Message.where(receiver_id: nil).order(:created_at)
22 @messages = Message.where(receiver_id: nil).order(:created_at)
26 end
23 end
27
24
28 def create
25 def create
29 - user = User.find(session[:user_id])
26 + @message = Message.new(message_params)
30 - @message = Message.new(params[:message])
27 + @message.sender = @current_user
31 - @message.sender = user
32 if @message.body == '' or !@message.save
28 if @message.body == '' or !@message.save
33 flash[:notice] = 'An error occurred'
29 flash[:notice] = 'An error occurred'
34 else
30 else
35 flash[:notice] = 'New message posted'
31 flash[:notice] = 'New message posted'
36 end
32 end
37 - redirect_to :action => 'list'
33 + redirect_to action: 'index'
38 end
34 end
39
35
40 def reply
36 def reply
41 - user = User.find(session[:user_id])
37 + @r_message = Message.new(message_params)
42 - @message = Message.new(params[:r_message])
38 + @r_message.receiver = @message.sender
43 - @message.sender = user
39 + @r_message.sender = @current_user
44 if @message.body == '' or !@message.save
40 if @message.body == '' or !@message.save
45 flash[:notice] = 'An error occurred'
41 flash[:notice] = 'An error occurred'
46 redirect_to :action => 'show', :id => @message.replying_message_id
42 redirect_to :action => 'show', :id => @message.replying_message_id
47 else
43 else
48 flash[:notice] = 'Message replied'
44 flash[:notice] = 'Message replied'
49 - rep_msg = @message.replying_message
45 + @message.replied = true
50 - rep_msg.replied = true
46 + @message.replying_message = @r_message
51 - rep_msg.save
47 + @message.save
52 redirect_to :action => 'console'
48 redirect_to :action => 'console'
53 end
49 end
54 end
50 end
55
51
56 def hide
52 def hide
57 message = Message.find(params[:id])
53 message = Message.find(params[:id])
58 message.replied = true
54 message.replied = true
59 message.save
55 message.save
60 flash[:notice] = 'Message hidden (just marked replied)'
56 flash[:notice] = 'Message hidden (just marked replied)'
61 redirect_to :action => 'console'
57 redirect_to :action => 'console'
62 end
58 end
63
59
64 protected
60 protected
65 - def build_replying_message_hierarchy(user)
61 + def build_replying_message_hierarchy(user)
66 - @all_messages = {}
62 + @all_messages = {}
67
63
68
64
69 - # manually build replies hierarchy (to improve efficiency)
65 + # manually build replies hierarchy (to improve efficiency)
70 - [@messages, @replied_messages].each do |collection|
66 + [@messages, @replied_messages].each do |collection|
71 - collection.each do |m|
67 + collection.each do |m|
72 - @all_messages[m.id] = {:msg => m, :replies => []}
68 + @all_messages[m.id] = {:msg => m, :replies => []}
69 + end
70 + end
71 +
72 + @all_messages.each do |m|
73 + rep_id = m.replying_message_id
74 + if @all_messages[rep_id]!=nil
75 + @all_messages[rep_id][:replies] << m
76 + end
73 end
77 end
74 end
78 end
75
79
76 - @all_messages.each do |m|
80 + def set_message
77 - rep_id = m.replying_message_id
81 + @message = Message.find(params[:id])
78 - if @all_messages[rep_id]!=nil
79 - @all_messages[rep_id][:replies] << m
80 - end
81 end
82 end
82 - end
83 +
84 + def message_params
85 + params.require(:message).permit(:body)
86 + end
83
87
84 end
88 end
@@ -1,13 +1,12
1 - = user_title_bar(@user)
2
1
3 %h1 Console: active messages
2 %h1 Console: active messages
4
3
5 = link_to '[all messages]', :action => 'list_all'
4 = link_to '[all messages]', :action => 'list_all'
6
5
7 %table
6 %table
8 %tr
7 %tr
9 %th From
8 %th From
10 %th When
9 %th When
11 %th Message
10 %th Message
12 %th
11 %th
13 = render :partial => "short_message", :collection => @messages
12 = render :partial => "short_message", :collection => @messages
@@ -1,13 +1,11
1 - = user_title_bar(@user)
2 -
3 %h1 Console: all messages
1 %h1 Console: all messages
4
2
5 = link_to '[active messages]', :action => 'list_all'
3 = link_to '[active messages]', :action => 'list_all'
6
4
7 %table
5 %table
8 %tr
6 %tr
9 %th From
7 %th From
10 %th When
8 %th When
11 %th Message
9 %th Message
12 %th
10 %th
13 = render :partial => "short_message", :collection => @messages
11 = render :partial => "short_message", :collection => @messages
@@ -1,20 +1,20
1 %h3 Message
1 %h3 Message
2
2
3 .message
3 .message
4 .stat
4 .stat
5 = "#{@message.sender.full_name} at #{@message.created_at}"
5 = "#{@message.sender.full_name} at #{@message.created_at}"
6 .body= simple_format(@message.body)
6 .body= simple_format(@message.body)
7
7
8 %h3 Your reply:
8 %h3 Your reply:
9 - = form_for 'r_message', :url => { :action => 'reply'} do |f|
9 + = form_for 'message', url: reply_message_path(@message) do |f|
10 = f.text_area :body, :rows => 5, :cols => 100
10 = f.text_area :body, :rows => 5, :cols => 100
11 - = f.hidden_field :receiver_id, {:value => @message.sender_id }
11 + -#= f.hidden_field :receiver_id, {:value => @message.sender_id }
12 - = f.hidden_field :replying_message_id, {:value => @message.id }
12 + -#= f.hidden_field :replying_message_id, {:value => @message.id }
13 = submit_tag "Post"
13 = submit_tag "Post"
14
14
15 %p
15 %p
16 If you do not want to reply, but want to hide this message from
16 If you do not want to reply, but want to hide this message from
17 console, you can
17 console, you can
18 = link_to "[hide]", :action => 'hide', :id => @message.id
18 = link_to "[hide]", :action => 'hide', :id => @message.id
19 this message. (This message will be marked as replied.)
19 this message. (This message will be marked as replied.)
20
20
@@ -3,26 +3,31
3 get "sources/direct_edit"
3 get "sources/direct_edit"
4
4
5 root :to => 'main#login'
5 root :to => 'main#login'
6
6
7 #logins
7 #logins
8 match 'login/login', to: 'login#login', via: [:get,:post]
8 match 'login/login', to: 'login#login', via: [:get,:post]
9
9
10 resources :contests
10 resources :contests
11 resources :sites
11 resources :sites
12 resources :test
12 resources :test
13
13
14 resources :messages do
14 resources :messages do
15 + member do
16 + get 'hide'
17 + post 'reply'
18 + end
15 collection do
19 collection do
16 get 'console'
20 get 'console'
21 + get 'list_all'
17 end
22 end
18 end
23 end
19
24
20 resources :announcements do
25 resources :announcements do
21 member do
26 member do
22 get 'toggle','toggle_front'
27 get 'toggle','toggle_front'
23 end
28 end
24 end
29 end
25
30
26 resources :problems do
31 resources :problems do
27 member do
32 member do
28 get 'toggle'
33 get 'toggle'
deleted file
You need to be logged in to leave comments. Login now