Description:
- add view testcase toggle for each problem - refactor: move view testcase to testcase_controller - change flash rendering
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r632:b4dd5e5f23ab - - 14 files changed: 130 inserted, 71 deleted

@@ -0,0 +1,2
1 + = render partial: 'toggle_button',
2 + locals: {button_id: "#problem-view-testcase-#{@problem.id}",button_on: @problem.view_testcase?}
@@ -0,0 +1,25
1 + %h1 Test cases
2 + %h2= @problem.long_name
3 +
4 + /navbar
5 + %ul.nav.nav-pills{role: :tablist}
6 + - @problem.testcases.each.with_index do |tc,id|
7 + %li{role: :presentation, class: ('active' if id == 0)}
8 + %a{href:"#tc#{tc.id}", role: 'tab', data: {toggle: 'tab'}}= tc.num
9 +
10 + /actual data
11 + .tab-content
12 + - @problem.testcases.each.with_index do |tc,id|
13 + .tab-pane{id: "tc#{tc.id}",class: ('active' if id == 0)}
14 + .row
15 + .col-md-6
16 + %h3 Input
17 + = link_to "Download",download_input_testcase_path(tc),class: 'btn btn-info btn-sm'
18 + .col-md-6
19 + %h3 Output
20 + = link_to "Download",download_sol_testcase_path(tc),class: 'btn btn-info btn-sm'
21 + .row
22 + .col-md-6
23 + %textarea{ rows: 25,readonly: true,style: "width:100%;resize=none;overflow-y: scroll;"}= tc.input
24 + .col-md-6
25 + %textarea{ rows: 25,readonly: true,style: "width:100%;resize=none;overflow-y: scroll;"}= tc.sol
@@ -0,0 +1,5
1 + class AddViewTestcaseToProblem < ActiveRecord::Migration
2 + def change
3 + add_column :problems, :view_testcase, :bool
4 + end
5 + end
@@ -39,11 +39,14
39
39
40 def testcase_authorization
40 def testcase_authorization
41 #admin always has privileged
41 #admin always has privileged
42 + puts "haha"
42 if @current_user.admin?
43 if @current_user.admin?
43 return true
44 return true
44 end
45 end
45
46
46 - unauthorized_redirect if GraderConfiguration["right.view_testcase"]
47 + puts "hehe"
48 + puts GraderConfiguration["right.view_testcase"]
49 + unauthorized_redirect unless GraderConfiguration["right.view_testcase"]
47 end
50 end
48
51
49 protected
52 protected
@@ -108,13 +111,15
108
111
109 def authorization
112 def authorization
110 return false unless authenticate
113 return false unless authenticate
114 + puts "haha 1"
111 user = User.find(session[:user_id])
115 user = User.find(session[:user_id])
112 unless user.roles.detect { |role|
116 unless user.roles.detect { |role|
113 - role.rights.detect{ |right|
117 + role.rights.detect{ |right|
114 - right.controller == self.class.controller_name and
118 + right.controller == self.class.controller_name and
115 - (right.action == 'all' or right.action == action_name)
119 + (right.action == 'all' or right.action == action_name)
116 - }
120 + }
117 }
121 }
122 + puts "haha 2"
118 flash[:notice] = 'You are not authorized to view the page you requested'
123 flash[:notice] = 'You are not authorized to view the page you requested'
119 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
124 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
120 redirect_to :controller => 'main', :action => 'login'
125 redirect_to :controller => 'main', :action => 'login'
@@ -135,6 +135,14
135 end
135 end
136 end
136 end
137
137
138 + def toggle_view_testcase
139 + @problem = Problem.find(params[:id])
140 + @problem.update_attributes(view_testcase: !(@problem.view_testcase?) )
141 + respond_to do |format|
142 + format.js { }
143 + end
144 + end
145 +
138 def turn_all_off
146 def turn_all_off
139 Problem.available.all.each do |problem|
147 Problem.available.all.each do |problem|
140 problem.available = false
148 problem.available = false
@@ -222,10 +230,6
222 redirect_to :action => 'manage'
230 redirect_to :action => 'manage'
223 end
231 end
224
232
225 - def show_testcase
226 - @problem = Problem.includes(:testcases).find(params[:id])
227 - end
228 -
229 ##################################
233 ##################################
230 protected
234 protected
231
235
@@ -10,6 +10,14
10 send_data @testcase.sol, type: 'text/plain', filename: "#{@testcase.problem.name}.#{@testcase.num}.sol"
10 send_data @testcase.sol, type: 'text/plain', filename: "#{@testcase.problem.name}.#{@testcase.num}.sol"
11 end
11 end
12
12
13 + def show_problem
14 + @problem = Problem.includes(:testcases).find(params[:problem_id])
15 + unless @current_user.admin? or @problem.view_testcase
16 + flash[:error] = 'You cannot view the testcase of this problem'
17 + redirect_to :controller => 'main', :action => 'list'
18 + end
19 + end
20 +
13
21
14 private
22 private
15 # Use callbacks to share common setup or constraints between actions.
23 # Use callbacks to share common setup or constraints between actions.
@@ -196,4 +196,27
196 markdown.to_html.html_safe
196 markdown.to_html.html_safe
197 end
197 end
198
198
199 +
200 + BOOTSTRAP_FLASH_MSG = {
201 + success: 'alert-success',
202 + error: 'alert-danger',
203 + alert: 'alert-block',
204 + notice: 'alert-info'
205 + }
206 +
207 + def bootstrap_class_for(flash_type)
208 + BOOTSTRAP_FLASH_MSG.fetch(flash_type.to_sym, flash_type.to_s)
209 + end
210 +
211 + def flash_messages
212 + puts "flahs size = #{flash.count}"
213 + flash.each do |msg_type, message|
214 + concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do
215 + concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' })
216 + concat message
217 + end)
218 + end
219 + nil
220 + end
221 +
199 end
222 end
@@ -11,5 +11,6
11 %body
11 %body
12 = render 'layouts/header'
12 = render 'layouts/header'
13
13
14 - = content_tag(:p,flash[:notice],class: 'alert alert-success') if flash[:notice]!=nil
14 + /= content_tag(:p,flash[:notice],class: 'alert alert-success') if flash[:notice]!=nil
15 + = flash_messages
15 = yield
16 = yield
@@ -6,9 +6,11
6 %br/
6 %br/
7 %br/
7 %br/
8
8
9 + - puts flash.inspect
9 - if flash[:notice]
10 - if flash[:notice]
10 %hr/
11 %hr/
11 %b= flash[:notice]
12 %b= flash[:notice]
13 + %b= haha
12 %hr/
14 %hr/
13
15
14 %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"}
16 %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"}
@@ -25,5 +25,5
25 = link_to "#{t 'main.src_link'}",{:action => 'source', :id => submission.id}, class: 'btn btn-xs btn-info'
25 = link_to "#{t 'main.src_link'}",{:action => 'source', :id => submission.id}, class: 'btn btn-xs btn-info'
26 = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info'
26 = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info'
27 - if GraderConfiguration.show_testcase
27 - if GraderConfiguration.show_testcase
28 - = link_to "testcases", show_testcase_problem_path(problem_id), class: 'btn btn-xs btn-info'
28 + = link_to "testcases", show_problem_testcases_path(problem_id), class: 'btn btn-xs btn-info'
29
29
@@ -26,6 +26,9
26 Avail?
26 Avail?
27 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user submits to this problem?' } [?]
27 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user submits to this problem?' } [?]
28 %th.text-center
28 %th.text-center
29 + View Data?
30 + %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user view the testcase of this problem?' } [?]
31 + %th.text-center
29 Test?
32 Test?
30 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user uses test interface on this problem?' } [?]
33 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user uses test interface on this problem?' } [?]
31 - if GraderConfiguration.multicontests?
34 - if GraderConfiguration.multicontests?
@@ -38,6 +41,7
38 %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1
41 %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1
39 %td= problem.date_added
42 %td= problem.date_added
40 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
43 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
44 + %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}")
41 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
45 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
42 - if GraderConfiguration.multicontests?
46 - if GraderConfiguration.multicontests?
43 %td
47 %td
@@ -20,8 +20,8
20 member do
20 member do
21 get 'toggle'
21 get 'toggle'
22 get 'toggle_test'
22 get 'toggle_test'
23 + get 'toggle_view_testcase'
23 get 'stat'
24 get 'stat'
24 - get 'show_testcase'
25 end
25 end
26 collection do
26 collection do
27 get 'turn_all_off'
27 get 'turn_all_off'
@@ -30,11 +30,15
30 get 'manage'
30 get 'manage'
31 end
31 end
32
32
33 - resources :testcases, only: [] do
33 + end
34 - member do
34 +
35 - get 'download_input'
35 + resources :testcases, only: [] do
36 - get 'download_sol'
36 + member do
37 - end
37 + get 'download_input'
38 + get 'download_sol'
39 + end
40 + collection do
41 + get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
38 end
42 end
39 end
43 end
40
44
@@ -11,16 +11,16
11 #
11 #
12 # It's strongly recommended that you check this file into your version control system.
12 # It's strongly recommended that you check this file into your version control system.
13
13
14 - ActiveRecord::Schema.define(version: 20170123162543) do
14 + ActiveRecord::Schema.define(version: 20170124024527) do
15
15
16 create_table "announcements", force: :cascade do |t|
16 create_table "announcements", force: :cascade do |t|
17 t.string "author", limit: 255
17 t.string "author", limit: 255
18 - t.text "body", limit: 16777215
18 + t.text "body", limit: 65535
19 t.boolean "published"
19 t.boolean "published"
20 - t.datetime "created_at", null: false
20 + t.datetime "created_at", null: false
21 - t.datetime "updated_at", null: false
21 + t.datetime "updated_at", null: false
22 - t.boolean "frontpage", default: false
22 + t.boolean "frontpage", default: false
23 - t.boolean "contest_only", default: false
23 + t.boolean "contest_only", default: false
24 t.string "title", limit: 255
24 t.string "title", limit: 255
25 t.string "notes", limit: 255
25 t.string "notes", limit: 255
26 end
26 end
@@ -50,19 +50,19
50 end
50 end
51
51
52 create_table "descriptions", force: :cascade do |t|
52 create_table "descriptions", force: :cascade do |t|
53 - t.text "body", limit: 16777215
53 + t.text "body", limit: 65535
54 t.boolean "markdowned"
54 t.boolean "markdowned"
55 - t.datetime "created_at", null: false
55 + t.datetime "created_at", null: false
56 - t.datetime "updated_at", null: false
56 + t.datetime "updated_at", null: false
57 end
57 end
58
58
59 create_table "grader_configurations", force: :cascade do |t|
59 create_table "grader_configurations", force: :cascade do |t|
60 t.string "key", limit: 255
60 t.string "key", limit: 255
61 t.string "value_type", limit: 255
61 t.string "value_type", limit: 255
62 t.string "value", limit: 255
62 t.string "value", limit: 255
63 - t.datetime "created_at", null: false
63 + t.datetime "created_at", null: false
64 - t.datetime "updated_at", null: false
64 + t.datetime "updated_at", null: false
65 - t.text "description", limit: 16777215
65 + t.text "description", limit: 65535
66 end
66 end
67
67
68 create_table "grader_processes", force: :cascade do |t|
68 create_table "grader_processes", force: :cascade do |t|
@@ -107,10 +107,10
107 t.integer "sender_id", limit: 4
107 t.integer "sender_id", limit: 4
108 t.integer "receiver_id", limit: 4
108 t.integer "receiver_id", limit: 4
109 t.integer "replying_message_id", limit: 4
109 t.integer "replying_message_id", limit: 4
110 - t.text "body", limit: 16777215
110 + t.text "body", limit: 65535
111 t.boolean "replied"
111 t.boolean "replied"
112 - t.datetime "created_at", null: false
112 + t.datetime "created_at", null: false
113 - t.datetime "updated_at", null: false
113 + t.datetime "updated_at", null: false
114 end
114 end
115
115
116 create_table "problems", force: :cascade do |t|
116 create_table "problems", force: :cascade do |t|
@@ -124,6 +124,7
124 t.boolean "test_allowed"
124 t.boolean "test_allowed"
125 t.boolean "output_only"
125 t.boolean "output_only"
126 t.string "description_filename", limit: 255
126 t.string "description_filename", limit: 255
127 + t.boolean "view_testcase"
127 end
128 end
128
129
129 create_table "rights", force: :cascade do |t|
130 create_table "rights", force: :cascade do |t|
@@ -152,7 +153,7
152
153
153 create_table "sessions", force: :cascade do |t|
154 create_table "sessions", force: :cascade do |t|
154 t.string "session_id", limit: 255
155 t.string "session_id", limit: 255
155 - t.text "data", limit: 16777215
156 + t.text "data", limit: 65535
156 t.datetime "updated_at"
157 t.datetime "updated_at"
157 end
158 end
158
159
@@ -180,14 +181,14
180 t.integer "user_id", limit: 4
181 t.integer "user_id", limit: 4
181 t.integer "problem_id", limit: 4
182 t.integer "problem_id", limit: 4
182 t.integer "language_id", limit: 4
183 t.integer "language_id", limit: 4
183 - t.text "source", limit: 16777215
184 + t.text "source", limit: 65535
184 t.binary "binary", limit: 65535
185 t.binary "binary", limit: 65535
185 t.datetime "submitted_at"
186 t.datetime "submitted_at"
186 t.datetime "compiled_at"
187 t.datetime "compiled_at"
187 - t.text "compiler_message", limit: 16777215
188 + t.text "compiler_message", limit: 65535
188 t.datetime "graded_at"
189 t.datetime "graded_at"
189 t.integer "points", limit: 4
190 t.integer "points", limit: 4
190 - t.text "grader_comment", limit: 16777215
191 + t.text "grader_comment", limit: 65535
191 t.integer "number", limit: 4
192 t.integer "number", limit: 4
192 t.string "source_filename", limit: 255
193 t.string "source_filename", limit: 255
193 t.float "max_runtime", limit: 24
194 t.float "max_runtime", limit: 24
@@ -208,10 +209,10
208
209
209 create_table "test_pairs", force: :cascade do |t|
210 create_table "test_pairs", force: :cascade do |t|
210 t.integer "problem_id", limit: 4
211 t.integer "problem_id", limit: 4
211 - t.text "input", limit: 4294967295
212 + t.text "input", limit: 16777215
212 - t.text "solution", limit: 4294967295
213 + t.text "solution", limit: 16777215
213 - t.datetime "created_at", null: false
214 + t.datetime "created_at", null: false
214 - t.datetime "updated_at", null: false
215 + t.datetime "updated_at", null: false
215 end
216 end
216
217
217 create_table "test_requests", force: :cascade do |t|
218 create_table "test_requests", force: :cascade do |t|
@@ -222,13 +223,13
222 t.string "output_file_name", limit: 255
223 t.string "output_file_name", limit: 255
223 t.string "running_stat", limit: 255
224 t.string "running_stat", limit: 255
224 t.integer "status", limit: 4
225 t.integer "status", limit: 4
225 - t.datetime "updated_at", null: false
226 + t.datetime "updated_at", null: false
226 t.datetime "submitted_at"
227 t.datetime "submitted_at"
227 t.datetime "compiled_at"
228 t.datetime "compiled_at"
228 - t.text "compiler_message", limit: 16777215
229 + t.text "compiler_message", limit: 65535
229 t.datetime "graded_at"
230 t.datetime "graded_at"
230 t.string "grader_comment", limit: 255
231 t.string "grader_comment", limit: 255
231 - t.datetime "created_at", null: false
232 + t.datetime "created_at", null: false
232 t.float "running_time", limit: 24
233 t.float "running_time", limit: 24
233 t.string "exit_status", limit: 255
234 t.string "exit_status", limit: 255
234 t.integer "memory_usage", limit: 4
235 t.integer "memory_usage", limit: 4
@@ -243,8 +244,8
243 t.integer "score", limit: 4
244 t.integer "score", limit: 4
244 t.text "input", limit: 4294967295
245 t.text "input", limit: 4294967295
245 t.text "sol", limit: 4294967295
246 t.text "sol", limit: 4294967295
246 - t.datetime "created_at", null: false
247 + t.datetime "created_at"
247 - t.datetime "updated_at", null: false
248 + t.datetime "updated_at"
248 end
249 end
249
250
250 add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id", using: :btree
251 add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id", using: :btree
@@ -269,10 +270,10
269 t.boolean "activated", default: false
270 t.boolean "activated", default: false
270 t.datetime "created_at"
271 t.datetime "created_at"
271 t.datetime "updated_at"
272 t.datetime "updated_at"
272 - t.string "section", limit: 255
273 t.boolean "enabled", default: true
273 t.boolean "enabled", default: true
274 t.string "remark", limit: 255
274 t.string "remark", limit: 255
275 t.string "last_ip", limit: 255
275 t.string "last_ip", limit: 255
276 + t.string "section", limit: 255
276 end
277 end
277
278
278 add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree
279 add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree
deleted file
You need to be logged in to leave comments. Login now