Description:
update message console
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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,57 +1,53 | |||
|
1 | 1 | class MessagesController < ApplicationController |
|
2 | 2 | |
|
3 |
- before_action : |
|
|
3 | + before_action :check_valid_login | |
|
4 | 4 | |
|
5 | + before_action :set_message, only: ['show', 'reply'] | |
|
5 | 6 | |
|
6 |
- before_ |
|
|
7 | + before_action :admin_authorization, :only => ['console','show', | |
|
7 | 8 | 'reply','hide','list_all'] |
|
8 | 9 | |
|
9 |
- def |
|
|
10 | - @user = User.find(session[:user_id]) | |
|
11 | - @messages = Message.find_all_sent_by_user(@user) | |
|
10 | + def index | |
|
11 | + @messages = Message.find_all_sent_by_user(@current_user) | |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | def console |
|
15 | - @user = User.find(session[:user_id]) | |
|
16 | 15 | @messages = Message.find_all_system_unreplied_messages |
|
17 | 16 | end |
|
18 | 17 | |
|
19 | 18 | def show |
|
20 | - @message = Message.find(params[:id]) | |
|
21 | 19 | end |
|
22 | 20 | |
|
23 | 21 | def list_all |
|
24 | - @user = User.find(session[:user_id]) | |
|
25 | 22 | @messages = Message.where(receiver_id: nil).order(:created_at) |
|
26 | 23 | end |
|
27 | 24 | |
|
28 | 25 | def create |
|
29 | - user = User.find(session[:user_id]) | |
|
30 | - @message = Message.new(params[:message]) | |
|
31 | - @message.sender = user | |
|
26 | + @message = Message.new(message_params) | |
|
27 | + @message.sender = @current_user | |
|
32 | 28 | if @message.body == '' or !@message.save |
|
33 | 29 | flash[:notice] = 'An error occurred' |
|
34 | 30 | else |
|
35 | 31 | flash[:notice] = 'New message posted' |
|
36 | 32 | end |
|
37 |
- redirect_to |
|
|
33 | + redirect_to action: 'index' | |
|
38 | 34 | end |
|
39 | 35 | |
|
40 | 36 | def reply |
|
41 | - user = User.find(session[:user_id]) | |
|
42 | - @message = Message.new(params[:r_message]) | |
|
43 | - @message.sender = user | |
|
37 | + @r_message = Message.new(message_params) | |
|
38 | + @r_message.receiver = @message.sender | |
|
39 | + @r_message.sender = @current_user | |
|
44 | 40 | if @message.body == '' or !@message.save |
|
45 | 41 | flash[:notice] = 'An error occurred' |
|
46 | 42 | redirect_to :action => 'show', :id => @message.replying_message_id |
|
47 | 43 | else |
|
48 | 44 | flash[:notice] = 'Message replied' |
|
49 |
- |
|
|
50 | - rep_msg.replied = true | |
|
51 |
- |
|
|
45 | + @message.replied = true | |
|
46 | + @message.replying_message = @r_message | |
|
47 | + @message.save | |
|
52 | 48 | redirect_to :action => 'console' |
|
53 | 49 | end |
|
54 | 50 | end |
|
55 | 51 | |
|
56 | 52 | def hide |
|
57 | 53 | message = Message.find(params[:id]) |
@@ -59,26 +55,34 | |||
|
59 | 55 | message.save |
|
60 | 56 | flash[:notice] = 'Message hidden (just marked replied)' |
|
61 | 57 | redirect_to :action => 'console' |
|
62 | 58 | end |
|
63 | 59 | |
|
64 | 60 | protected |
|
65 | - def build_replying_message_hierarchy(user) | |
|
66 | - @all_messages = {} | |
|
61 | + def build_replying_message_hierarchy(user) | |
|
62 | + @all_messages = {} | |
|
67 | 63 | |
|
68 | 64 | |
|
69 | - # manually build replies hierarchy (to improve efficiency) | |
|
70 | - [@messages, @replied_messages].each do |collection| | |
|
71 | - collection.each do |m| | |
|
72 | - @all_messages[m.id] = {:msg => m, :replies => []} | |
|
65 | + # manually build replies hierarchy (to improve efficiency) | |
|
66 | + [@messages, @replied_messages].each do |collection| | |
|
67 | + collection.each do |m| | |
|
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 | 77 | end |
|
74 | 78 | end |
|
75 | 79 | |
|
76 | - @all_messages.each do |m| | |
|
77 | - rep_id = m.replying_message_id | |
|
78 | - if @all_messages[rep_id]!=nil | |
|
79 | - @all_messages[rep_id][:replies] << m | |
|
80 | - end | |
|
80 | + def set_message | |
|
81 | + @message = Message.find(params[:id]) | |
|
81 | 82 | end |
|
82 | - end | |
|
83 | + | |
|
84 | + def message_params | |
|
85 | + params.require(:message).permit(:body) | |
|
86 | + end | |
|
83 | 87 | |
|
84 | 88 | end |
@@ -1,7 +1,6 | |||
|
1 | - = user_title_bar(@user) | |
|
2 | 1 |
|
|
3 | 2 | %h1 Console: active messages |
|
4 | 3 | |
|
5 | 4 | = link_to '[all messages]', :action => 'list_all' |
|
6 | 5 | |
|
7 | 6 | %table |
@@ -1,8 +1,6 | |||
|
1 | - = user_title_bar(@user) | |
|
2 | - | |
|
3 | 1 |
|
|
4 | 2 | |
|
5 | 3 | = link_to '[active messages]', :action => 'list_all' |
|
6 | 4 | |
|
7 | 5 | %table |
|
8 | 6 | %tr |
@@ -3,16 +3,16 | |||
|
3 | 3 | .message |
|
4 | 4 | .stat |
|
5 | 5 | = "#{@message.sender.full_name} at #{@message.created_at}" |
|
6 | 6 | .body= simple_format(@message.body) |
|
7 | 7 | |
|
8 | 8 | %h3 Your reply: |
|
9 |
- = form_for ' |
|
|
9 | + = form_for 'message', url: reply_message_path(@message) do |f| | |
|
10 | 10 | = f.text_area :body, :rows => 5, :cols => 100 |
|
11 | - = f.hidden_field :receiver_id, {:value => @message.sender_id } | |
|
12 | - = f.hidden_field :replying_message_id, {:value => @message.id } | |
|
11 | + -#= f.hidden_field :receiver_id, {:value => @message.sender_id } | |
|
12 | + -#= f.hidden_field :replying_message_id, {:value => @message.id } | |
|
13 | 13 | = submit_tag "Post" |
|
14 | 14 | |
|
15 | 15 | %p |
|
16 | 16 | If you do not want to reply, but want to hide this message from |
|
17 | 17 | console, you can |
|
18 | 18 | = link_to "[hide]", :action => 'hide', :id => @message.id |
@@ -9,14 +9,19 | |||
|
9 | 9 | |
|
10 | 10 | resources :contests |
|
11 | 11 | resources :sites |
|
12 | 12 | resources :test |
|
13 | 13 | |
|
14 | 14 | resources :messages do |
|
15 | + member do | |
|
16 | + get 'hide' | |
|
17 | + post 'reply' | |
|
18 | + end | |
|
15 | 19 | collection do |
|
16 | 20 | get 'console' |
|
21 | + get 'list_all' | |
|
17 | 22 | end |
|
18 | 23 | end |
|
19 | 24 | |
|
20 | 25 | resources :announcements do |
|
21 | 26 | member do |
|
22 | 27 | get 'toggle','toggle_front' |
deleted file |
You need to be logged in to leave comments.
Login now