Description:
* add forgotten toggle file
* main/submission changed to bootstrap
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r559:2e5e11be6cae - - 9 files changed: 91 inserted, 9 deleted
@@ -0,0 +1,6 | |||
|
1 | + $ -> | |
|
2 | + $("#submission_problem_go").on 'click', (event) -> | |
|
3 | + url = $("#submission_problem_id").val() | |
|
4 | + if (url) | |
|
5 | + window.location = url | |
|
6 | + |
@@ -0,0 +1,46 | |||
|
1 | + - content_for :head do | |
|
2 | + = stylesheet_link_tag 'problems' | |
|
3 | + %h1 Listing problems | |
|
4 | + %p | |
|
5 | + = link_to 'New problem', new_problem_path, class: 'btn btn-default btn-sm' | |
|
6 | + = link_to 'Manage problems', { action: 'manage'}, class: 'btn btn-default btn-sm' | |
|
7 | + = link_to 'Import problems', {:action => 'import'}, class: 'btn btn-default btn-sm' | |
|
8 | + = link_to 'Turn off all problems', {:action => 'turn_all_off'}, class: 'btn btn-default btn-sm' | |
|
9 | + = link_to 'Turn on all problems', {:action => 'turn_all_on'}, class: 'btn btn-default btn-sm' | |
|
10 | + .submitbox | |
|
11 | + = form_tag :action => 'quick_create' do | |
|
12 | + %b Quick New: | |
|
13 | + %label{:for => "problem_name"} Name | |
|
14 | + = text_field 'problem', 'name' | |
|
15 | + | | |
|
16 | + %label{:for => "problem_full_name"} Full name | |
|
17 | + = text_field 'problem', 'full_name' | |
|
18 | + = submit_tag "Create" | |
|
19 | + %table.table.table-condensed.table-hover | |
|
20 | + %thead | |
|
21 | + %th Name | |
|
22 | + %th Full name | |
|
23 | + %th Full score | |
|
24 | + %th Date added | |
|
25 | + %th Avail? | |
|
26 | + %th Test? | |
|
27 | + - if GraderConfiguration.multicontests? | |
|
28 | + %th Contests | |
|
29 | + - for problem in @problems | |
|
30 | + %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"} | |
|
31 | + - @problem=problem | |
|
32 | + %td= in_place_editor_field :problem, :name, {}, :rows=>1 | |
|
33 | + %td= in_place_editor_field :problem, :full_name, {}, :rows=>1 | |
|
34 | + %td= in_place_editor_field :problem, :full_score, {}, :rows=>1 | |
|
35 | + %td= problem.date_added | |
|
36 | + %td{}= link_to (@problem.available? ? "Yes" : "No"), url_for(controller: :problems, action: :toggle, id: @problem), { class: "btn btn-block btn-sm btn-#{(@problem.available? ? 'success' : 'default')} ajax-toggle", id: "prob-#{@problem.id}-avail", data: {remote: true, method: 'post' } } | |
|
37 | + %td= problem.test_allowed | |
|
38 | + - if GraderConfiguration.multicontests? | |
|
39 | + %td | |
|
40 | + = problem.contests.collect { |c| c.name }.join(', ') | |
|
41 | + %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn-primary btn-sm' | |
|
42 | + %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn-primary btn-sm' | |
|
43 | + %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn-primary btn-sm' | |
|
44 | + %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post, class: 'btn btn-danger btn-sm' | |
|
45 | + %br/ | |
|
46 | + = link_to '[New problem]', :action => 'new' |
@@ -0,0 +1,12 | |||
|
1 | + :plain | |
|
2 | + b = $("#prob-#{@problem.id}-avail"); | |
|
3 | + b.removeClass('btn-default'); | |
|
4 | + b.removeClass('btn-success'); | |
|
5 | + b.removeClass('btn-warning'); | |
|
6 | + b.addClass("btn-#{@problem.available? ? 'success' : 'default'}"); | |
|
7 | + b.text("#{@problem.available? ? 'Yes' : 'No'}"); | |
|
8 | + r = $("#prob-#{@problem.id}"); | |
|
9 | + r.removeClass('success'); | |
|
10 | + r.removeClass('danger'); | |
|
11 | + r.addClass("#{@problem.available? ? 'success' : 'danger'}"); | |
|
12 | + |
@@ -1,15 +1,14 | |||
|
1 | 1 | #js for announcement |
|
2 | 2 | $ -> |
|
3 | 3 | $('.ajax-toggle').on 'click', (event) -> |
|
4 | - console.log event.target.id | |
|
5 | 4 | target = $(event.target) |
|
6 | 5 | target.removeClass 'btn-default' |
|
7 | 6 | target.removeClass 'btn-success' |
|
8 | 7 | target.addClass 'btn-warning' |
|
9 | 8 | target.text '...' |
|
10 | 9 | return |
|
11 | 10 | |
|
12 | 11 | $(document).ajaxError (event, jqxhr, settings, exception) -> |
|
13 | 12 | if jqxhr.status |
|
14 | 13 | alert 'We\'re sorry, but something went wrong (' + jqxhr.status + ')' |
|
15 | 14 | return |
@@ -1,319 +1,319 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :except => [:index, :login] |
|
4 | 4 | before_filter :check_viewability, :except => [:index, :login] |
|
5 | 5 | |
|
6 | 6 | append_before_filter :confirm_and_update_start_time, |
|
7 | 7 | :except => [:index, |
|
8 | 8 | :login, |
|
9 | 9 | :confirm_contest_start] |
|
10 | 10 | |
|
11 | 11 | # to prevent log in box to be shown when user logged out of the |
|
12 | 12 | # system only in some tab |
|
13 | 13 | prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
14 | 14 | :only => [:announcements] |
|
15 | 15 | |
|
16 | 16 | before_filter :authenticate_by_ip_address, :only => [:list] |
|
17 | 17 | |
|
18 | 18 | # COMMENTED OUT: filter in each action instead |
|
19 | 19 | # before_filter :verify_time_limit, :only => [:submit] |
|
20 | 20 | |
|
21 | 21 | verify :method => :post, :only => [:submit], |
|
22 | 22 | :redirect_to => { :action => :index } |
|
23 | 23 | |
|
24 | 24 | # COMMENT OUT: only need when having high load |
|
25 | 25 | # caches_action :index, :login |
|
26 | 26 | |
|
27 | 27 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
28 | 28 | # assigned action login as a default action. |
|
29 | 29 | def index |
|
30 | 30 | redirect_to :action => 'login' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def login |
|
34 | 34 | saved_notice = flash[:notice] |
|
35 | 35 | reset_session |
|
36 | 36 | flash.now[:notice] = saved_notice |
|
37 | 37 | |
|
38 | 38 | # EXPERIMENT: |
|
39 | 39 | # Hide login if in single user mode and the url does not |
|
40 | 40 | # explicitly specify /login |
|
41 | 41 | # |
|
42 | 42 | # logger.info "PATH: #{request.path}" |
|
43 | 43 | # if GraderConfiguration['system.single_user_mode'] and |
|
44 | 44 | # request.path!='/main/login' |
|
45 | 45 | # @hidelogin = true |
|
46 | 46 | # end |
|
47 | 47 | |
|
48 | 48 | @announcements = Announcement.find_for_frontpage |
|
49 | 49 | render :action => 'login', :layout => 'empty' |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def list |
|
53 | 53 | prepare_list_information |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def help |
|
57 | 57 | @user = User.find(session[:user_id]) |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def submit |
|
61 | 61 | user = User.find(session[:user_id]) |
|
62 | 62 | |
|
63 | 63 | @submission = Submission.new |
|
64 | 64 | @submission.problem_id = params[:submission][:problem_id] |
|
65 | 65 | @submission.user = user |
|
66 | 66 | @submission.language_id = 0 |
|
67 | 67 | if (params['file']) and (params['file']!='') |
|
68 | 68 | @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) |
|
69 | 69 | @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
70 | 70 | @submission.source_filename = params['file'].original_filename |
|
71 | 71 | end |
|
72 | 72 | @submission.submitted_at = Time.new.gmtime |
|
73 | 73 | @submission.ip_address = request.remote_ip |
|
74 | 74 | |
|
75 | 75 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
76 | 76 | @submission.errors.add(:base,"The contest is over.") |
|
77 | 77 | prepare_list_information |
|
78 | 78 | render :action => 'list' and return |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | if @submission.valid? |
|
82 | 82 | if @submission.save == false |
|
83 | 83 | flash[:notice] = 'Error saving your submission' |
|
84 | 84 | elsif Task.create(:submission_id => @submission.id, |
|
85 | 85 | :status => Task::STATUS_INQUEUE) == false |
|
86 | 86 | flash[:notice] = 'Error adding your submission to task queue' |
|
87 | 87 | end |
|
88 | 88 | else |
|
89 | 89 | prepare_list_information |
|
90 | 90 | render :action => 'list' and return |
|
91 | 91 | end |
|
92 | 92 | redirect_to :action => 'list' |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def source |
|
96 | 96 | submission = Submission.find(params[:id]) |
|
97 | 97 | if ((submission.user_id == session[:user_id]) and |
|
98 | 98 | (submission.problem != nil) and |
|
99 | 99 | (submission.problem.available)) |
|
100 | 100 | send_data(submission.source, |
|
101 | 101 | {:filename => submission.download_filename, |
|
102 | 102 | :type => 'text/plain'}) |
|
103 | 103 | else |
|
104 | 104 | flash[:notice] = 'Error viewing source' |
|
105 | 105 | redirect_to :action => 'list' |
|
106 | 106 | end |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def compiler_msg |
|
110 | 110 | @submission = Submission.find(params[:id]) |
|
111 | 111 | if @submission.user_id == session[:user_id] |
|
112 | 112 | render :action => 'compiler_msg', :layout => 'empty' |
|
113 | 113 | else |
|
114 | 114 | flash[:notice] = 'Error viewing source' |
|
115 | 115 | redirect_to :action => 'list' |
|
116 | 116 | end |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def submission |
|
120 | 120 | @user = User.find(session[:user_id]) |
|
121 | 121 | @problems = @user.available_problems |
|
122 | 122 | if params[:id]==nil |
|
123 | 123 | @problem = nil |
|
124 | 124 | @submissions = nil |
|
125 | 125 | else |
|
126 |
- @problem = Problem.find_by_ |
|
|
127 | - if not @problem.available | |
|
126 | + @problem = Problem.find_by_id(params[:id]) | |
|
127 | + if (@problem == nil) or (not @problem.available) | |
|
128 | 128 | redirect_to :action => 'list' |
|
129 | 129 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
130 | 130 | return |
|
131 | 131 | end |
|
132 | 132 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
133 | 133 | end |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | def result |
|
137 | 137 | if !GraderConfiguration.show_grading_result |
|
138 | 138 | redirect_to :action => 'list' and return |
|
139 | 139 | end |
|
140 | 140 | @user = User.find(session[:user_id]) |
|
141 | 141 | @submission = Submission.find(params[:id]) |
|
142 | 142 | if @submission.user!=@user |
|
143 | 143 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
144 | 144 | redirect_to :action => 'list' and return |
|
145 | 145 | end |
|
146 | 146 | prepare_grading_result(@submission) |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | def load_output |
|
150 | 150 | if !GraderConfiguration.show_grading_result or params[:num]==nil |
|
151 | 151 | redirect_to :action => 'list' and return |
|
152 | 152 | end |
|
153 | 153 | @user = User.find(session[:user_id]) |
|
154 | 154 | @submission = Submission.find(params[:id]) |
|
155 | 155 | if @submission.user!=@user |
|
156 | 156 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
157 | 157 | redirect_to :action => 'list' and return |
|
158 | 158 | end |
|
159 | 159 | case_num = params[:num].to_i |
|
160 | 160 | out_filename = output_filename(@user.login, |
|
161 | 161 | @submission.problem.name, |
|
162 | 162 | @submission.id, |
|
163 | 163 | case_num) |
|
164 | 164 | if !FileTest.exists?(out_filename) |
|
165 | 165 | flash[:notice] = 'Output not found.' |
|
166 | 166 | redirect_to :action => 'list' and return |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
170 | 170 | response.headers['Content-Type'] = "application/force-download" |
|
171 | 171 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
172 | 172 | response.headers["X-Sendfile"] = out_filename |
|
173 | 173 | response.headers['Content-length'] = File.size(out_filename) |
|
174 | 174 | render :nothing => true |
|
175 | 175 | else |
|
176 | 176 | send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain" |
|
177 | 177 | end |
|
178 | 178 | end |
|
179 | 179 | |
|
180 | 180 | def error |
|
181 | 181 | @user = User.find(session[:user_id]) |
|
182 | 182 | end |
|
183 | 183 | |
|
184 | 184 | # announcement refreshing and hiding methods |
|
185 | 185 | |
|
186 | 186 | def announcements |
|
187 | 187 | if params.has_key? 'recent' |
|
188 | 188 | prepare_announcements(params[:recent]) |
|
189 | 189 | else |
|
190 | 190 | prepare_announcements |
|
191 | 191 | end |
|
192 | 192 | render(:partial => 'announcement', |
|
193 | 193 | :collection => @announcements, |
|
194 | 194 | :locals => {:announcement_effect => true}) |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def confirm_contest_start |
|
198 | 198 | user = User.find(session[:user_id]) |
|
199 | 199 | if request.method == 'POST' |
|
200 | 200 | user.update_start_time |
|
201 | 201 | redirect_to :action => 'list' |
|
202 | 202 | else |
|
203 | 203 | @contests = user.contests |
|
204 | 204 | @user = user |
|
205 | 205 | end |
|
206 | 206 | end |
|
207 | 207 | |
|
208 | 208 | protected |
|
209 | 209 | |
|
210 | 210 | def prepare_announcements(recent=nil) |
|
211 | 211 | if GraderConfiguration.show_tasks_to?(@user) |
|
212 | 212 | @announcements = Announcement.find_published(true) |
|
213 | 213 | else |
|
214 | 214 | @announcements = Announcement.find_published |
|
215 | 215 | end |
|
216 | 216 | if recent!=nil |
|
217 | 217 | recent_id = recent.to_i |
|
218 | 218 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
219 | 219 | end |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def prepare_list_information |
|
223 | 223 | @user = User.find(session[:user_id]) |
|
224 | 224 | if not GraderConfiguration.multicontests? |
|
225 | 225 | @problems = @user.available_problems |
|
226 | 226 | else |
|
227 | 227 | @contest_problems = @user.available_problems_group_by_contests |
|
228 | 228 | @problems = @user.available_problems |
|
229 | 229 | end |
|
230 | 230 | @prob_submissions = {} |
|
231 | 231 | @problems.each do |p| |
|
232 | 232 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
233 | 233 | if sub!=nil |
|
234 | 234 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
235 | 235 | else |
|
236 | 236 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
237 | 237 | end |
|
238 | 238 | end |
|
239 | 239 | prepare_announcements |
|
240 | 240 | end |
|
241 | 241 | |
|
242 | 242 | def check_viewability |
|
243 | 243 | @user = User.find(session[:user_id]) |
|
244 | 244 | if (!GraderConfiguration.show_tasks_to?(@user)) and |
|
245 | 245 | ((action_name=='submission') or (action_name=='submit')) |
|
246 | 246 | redirect_to :action => 'list' and return |
|
247 | 247 | end |
|
248 | 248 | end |
|
249 | 249 | |
|
250 | 250 | def prepare_grading_result(submission) |
|
251 | 251 | if GraderConfiguration.task_grading_info.has_key? submission.problem.name |
|
252 | 252 | grading_info = GraderConfiguration.task_grading_info[submission.problem.name] |
|
253 | 253 | else |
|
254 | 254 | # guess task info from problem.full_score |
|
255 | 255 | cases = submission.problem.full_score / 10 |
|
256 | 256 | grading_info = { |
|
257 | 257 | 'testruns' => cases, |
|
258 | 258 | 'testcases' => cases |
|
259 | 259 | } |
|
260 | 260 | end |
|
261 | 261 | @test_runs = [] |
|
262 | 262 | if grading_info['testruns'].is_a? Integer |
|
263 | 263 | trun_count = grading_info['testruns'] |
|
264 | 264 | trun_count.times do |i| |
|
265 | 265 | @test_runs << [ read_grading_result(@user.login, |
|
266 | 266 | submission.problem.name, |
|
267 | 267 | submission.id, |
|
268 | 268 | i+1) ] |
|
269 | 269 | end |
|
270 | 270 | else |
|
271 | 271 | grading_info['testruns'].keys.sort.each do |num| |
|
272 | 272 | run = [] |
|
273 | 273 | testrun = grading_info['testruns'][num] |
|
274 | 274 | testrun.each do |c| |
|
275 | 275 | run << read_grading_result(@user.login, |
|
276 | 276 | submission.problem.name, |
|
277 | 277 | submission.id, |
|
278 | 278 | c) |
|
279 | 279 | end |
|
280 | 280 | @test_runs << run |
|
281 | 281 | end |
|
282 | 282 | end |
|
283 | 283 | end |
|
284 | 284 | |
|
285 | 285 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
286 | 286 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
287 | 287 | end |
|
288 | 288 | |
|
289 | 289 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
290 | 290 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
291 | 291 | return "#{dir}/output.txt" |
|
292 | 292 | end |
|
293 | 293 | |
|
294 | 294 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
295 | 295 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
296 | 296 | result_file_name = "#{dir}/result" |
|
297 | 297 | if !FileTest.exists?(result_file_name) |
|
298 | 298 | return {:num => case_num, :msg => 'program did not run'} |
|
299 | 299 | else |
|
300 | 300 | results = File.open(result_file_name).readlines |
|
301 | 301 | run_stat = extract_running_stat(results) |
|
302 | 302 | output_filename = "#{dir}/output.txt" |
|
303 | 303 | if FileTest.exists?(output_filename) |
|
304 | 304 | output_file = true |
|
305 | 305 | output_size = File.size(output_filename) |
|
306 | 306 | else |
|
307 | 307 | output_file = false |
|
308 | 308 | output_size = 0 |
|
309 | 309 | end |
|
310 | 310 | |
|
311 | 311 | return { |
|
312 | 312 | :num => case_num, |
|
313 | 313 | :msg => results[0], |
|
314 | 314 | :run_stat => run_stat, |
|
315 | 315 | :output => output_file, |
|
316 | 316 | :output_size => output_size |
|
317 | 317 | } |
|
318 | 318 | end |
|
319 | 319 | end |
@@ -1,170 +1,182 | |||
|
1 | 1 | # Methods added to this helper will be available to all templates in the application. |
|
2 | 2 | module ApplicationHelper |
|
3 | 3 | |
|
4 | 4 | def navbar_user_header |
|
5 | 5 | left_menu = '' |
|
6 | 6 | right_menu = '' |
|
7 | 7 | user = User.find(session[:user_id]) |
|
8 | 8 | |
|
9 | 9 | if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) |
|
10 | 10 | left_menu << add_menu("#{I18n.t 'menu.tasks'}", 'tasks', 'list') |
|
11 | 11 | left_menu << add_menu("#{I18n.t 'menu.submissions'}", 'main', 'submission') |
|
12 | 12 | left_menu << add_menu("#{I18n.t 'menu.test'}", 'test', 'index') |
|
13 | 13 | end |
|
14 | 14 | |
|
15 | 15 | if GraderConfiguration['right.user_hall_of_fame'] |
|
16 | 16 | left_menu << add_menu("#{I18n.t 'menu.hall_of_fame'}", 'report', 'problem_hof') |
|
17 | 17 | end |
|
18 | 18 | |
|
19 | 19 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') |
|
20 | 20 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'list', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) |
|
21 | 21 | if GraderConfiguration['system.user_setting_enabled'] |
|
22 | 22 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', 'index', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) |
|
23 | 23 | end |
|
24 | 24 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | result = content_tag(:ul,left_menu.html_safe,class: 'nav navbar-nav') + content_tag(:ul,right_menu.html_safe,class: 'nav navbar-nav navbar-right') |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def add_menu(title, controller, action,html_option = {}) |
|
31 | 31 | link_option = {controller: controller, action: action} |
|
32 | 32 | html_option[:class] = (html_option[:class] || '') + " active" if current_page?(link_option) |
|
33 | 33 | content_tag(:li, link_to(title,link_option),html_option) |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def user_header |
|
37 | 37 | menu_items = '' |
|
38 | 38 | user = User.find(session[:user_id]) |
|
39 | 39 | |
|
40 | 40 | if (user!=nil) and (session[:admin]) |
|
41 | 41 | # admin menu |
|
42 | 42 | menu_items << "<b>Administrative task:</b> " |
|
43 | 43 | append_to menu_items, '[Announcements]', 'announcements', 'index' |
|
44 | 44 | append_to menu_items, '[Msg console]', 'messages', 'console' |
|
45 | 45 | append_to menu_items, '[Problems]', 'problems', 'index' |
|
46 | 46 | append_to menu_items, '[Users]', 'user_admin', 'index' |
|
47 | 47 | append_to menu_items, '[Results]', 'user_admin', 'user_stat' |
|
48 | 48 | append_to menu_items, '[Report]', 'report', 'multiple_login' |
|
49 | 49 | append_to menu_items, '[Graders]', 'graders', 'list' |
|
50 | 50 | append_to menu_items, '[Contests]', 'contest_management', 'index' |
|
51 | 51 | append_to menu_items, '[Sites]', 'sites', 'index' |
|
52 | 52 | append_to menu_items, '[System config]', 'configurations', 'index' |
|
53 | 53 | menu_items << "<br/>" |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | # main page |
|
57 | 57 | append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list' |
|
58 | 58 | append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list' |
|
59 | 59 | |
|
60 | 60 | if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) |
|
61 | 61 | append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list' |
|
62 | 62 | append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission' |
|
63 | 63 | append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index' |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | if GraderConfiguration['right.user_hall_of_fame'] |
|
67 | 67 | append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof' |
|
68 | 68 | end |
|
69 | 69 | append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' |
|
70 | 70 | |
|
71 | 71 | if GraderConfiguration['system.user_setting_enabled'] |
|
72 | 72 | append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index' |
|
73 | 73 | end |
|
74 | 74 | append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login' |
|
75 | 75 | |
|
76 | 76 | menu_items.html_safe |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | def append_to(option,label, controller, action) |
|
80 | 80 | option << ' ' if option!='' |
|
81 | 81 | option << link_to_unless_current(label, |
|
82 | 82 | :controller => controller, |
|
83 | 83 | :action => action) |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | def format_short_time(time) |
|
87 | 87 | now = Time.now.gmtime |
|
88 | 88 | st = '' |
|
89 | 89 | if (time.yday != now.yday) or |
|
90 | 90 | (time.year != now.year) |
|
91 | 91 | st = time.strftime("%x ") |
|
92 | 92 | end |
|
93 | 93 | st + time.strftime("%X") |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def format_short_duration(duration) |
|
97 | 97 | return '' if duration==nil |
|
98 | 98 | d = duration.to_f |
|
99 | 99 | return Time.at(d).gmtime.strftime("%X") |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def read_textfile(fname,max_size=2048) |
|
103 | 103 | begin |
|
104 | 104 | File.open(fname).read(max_size) |
|
105 | 105 | rescue |
|
106 | 106 | nil |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | + def problem_select(problems, options = {}) | |
|
111 | + prefix = options[:with_specific_in_header] ? [[(t 'main.specified_in_header'),'-1']] : [] | |
|
112 | + selected = options[:selected] || (options[:with_specific_in_header] ? -1 : nil) | |
|
113 | + puts "selected = #{selected} hehe" | |
|
114 | + html_options = {class: 'select2 form-control'} | |
|
115 | + html_options[:id] = options[:id]if options[:id] | |
|
116 | + select 'submission', | |
|
117 | + 'problem_id', prefix + problems.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}, | |
|
118 | + (selected ? { selected: "#{selected}"} : {} ), | |
|
119 | + html_options | |
|
120 | + end | |
|
121 | + | |
|
110 | 122 | def user_title_bar(user) |
|
111 | 123 | header = '' |
|
112 | 124 | time_left = '' |
|
113 | 125 | |
|
114 | 126 | # |
|
115 | 127 | # if the contest is over |
|
116 | 128 | if GraderConfiguration.time_limit_mode? |
|
117 | 129 | if user.contest_finished? |
|
118 | 130 | header = <<CONTEST_OVER |
|
119 | 131 | <tr><td colspan="2" align="center"> |
|
120 | 132 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
121 | 133 | </td></tr> |
|
122 | 134 | CONTEST_OVER |
|
123 | 135 | end |
|
124 | 136 | if !user.contest_started? |
|
125 | 137 | time_left = " " + (t 'title_bar.contest_not_started') |
|
126 | 138 | else |
|
127 | 139 | time_left = " " + (t 'title_bar.remaining_time') + |
|
128 | 140 | " #{format_short_duration(user.contest_time_left)}" |
|
129 | 141 | end |
|
130 | 142 | end |
|
131 | 143 | |
|
132 | 144 | # |
|
133 | 145 | # if the contest is in the anaysis mode |
|
134 | 146 | if GraderConfiguration.analysis_mode? |
|
135 | 147 | header = <<ANALYSISMODE |
|
136 | 148 | <tr><td colspan="2" align="center"> |
|
137 | 149 | <span class="contest-over-msg">ANALYSIS MODE</span> |
|
138 | 150 | </td></tr> |
|
139 | 151 | ANALYSISMODE |
|
140 | 152 | end |
|
141 | 153 | |
|
142 | 154 | contest_name = GraderConfiguration['contest.name'] |
|
143 | 155 | |
|
144 | 156 | # |
|
145 | 157 | # build real title bar |
|
146 | 158 | result = <<TITLEBAR |
|
147 | 159 | <div class="title"> |
|
148 | 160 | <table> |
|
149 | 161 | #{header} |
|
150 | 162 | <tr> |
|
151 | 163 | <td class="left-col"> |
|
152 | 164 | #{user.full_name}<br/> |
|
153 | 165 | #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} |
|
154 | 166 | #{time_left} |
|
155 | 167 | <br/> |
|
156 | 168 | </td> |
|
157 | 169 | <td class="right-col">#{contest_name}</td> |
|
158 | 170 | </tr> |
|
159 | 171 | </table> |
|
160 | 172 | </div> |
|
161 | 173 | TITLEBAR |
|
162 | 174 | result.html_safe |
|
163 | 175 | end |
|
164 | 176 | |
|
165 | 177 | def markdown(text) |
|
166 | 178 | markdown = RDiscount.new(text) |
|
167 | 179 | markdown.to_html.html_safe |
|
168 | 180 | end |
|
169 | 181 | |
|
170 | 182 | end |
@@ -1,20 +1,20 | |||
|
1 | 1 | = form_tag({:action => 'submit'}, :multipart => true, class: 'form-inline') do |
|
2 | 2 | - if @submission and @submission.errors.any? |
|
3 | 3 | #error_explanation |
|
4 | 4 | .alert.alert-danger |
|
5 | 5 | %h3= "#{pluralize(@submission.errors.count, "error")} prohibited this user from being saved:" |
|
6 | 6 | %ul |
|
7 | 7 | - @submission.errors.full_messages.each do |msg| |
|
8 | 8 | %li= msg |
|
9 | 9 | .form-group |
|
10 | 10 | = label_tag :submission, 'Problem:' |
|
11 | - = select 'submission', 'problem_id', [[(t 'main.specified_in_header'),'-1']] + @problems.collect {|p| [p.full_name, p.id]}, {:selected => '-1'}, { class: 'select2 form-control' } | |
|
11 | + = select 'submission', 'problem_id', [[(t 'main.specified_in_header'),'-1']] + @problems.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}, {:selected => '-1'}, { class: 'select2 form-control' } | |
|
12 | 12 | .form-group |
|
13 | 13 | = label_tag :file, 'File:' |
|
14 | 14 | .input-group |
|
15 | 15 | %span.input-group-btn |
|
16 | 16 | %span.btn.btn-default.btn-file |
|
17 | 17 | Browse |
|
18 | 18 | = file_field_tag 'file' |
|
19 | 19 | = text_field_tag '' , nil, {readonly: true, class: 'form-control'} |
|
20 | 20 | = submit_tag 'Submit', class: 'btn btn-default' |
@@ -1,25 +1,31 | |||
|
1 | 1 | = user_title_bar(@user) |
|
2 | 2 | |
|
3 | - .task-menu | |
|
4 | - Task List | |
|
5 | - %br/ | |
|
6 | - - @problems.each do |problem| | |
|
7 | - = link_to problem.name, :action => 'submission', :id => problem.name | |
|
3 | + .panel.panel-info | |
|
4 | + .panel-heading | |
|
5 | + Select Problems | |
|
6 | + .panel-body | |
|
7 | + .form-inline | |
|
8 | + = select 'submission', | |
|
9 | + 'problem_id', | |
|
10 | + @problems.collect {|p| ["[#{p.name}] #{p.full_name}", main_submission_url(p.id)]}, | |
|
11 | + {:selected => '-1'}, | |
|
12 | + { class: 'select2 form-control' } | |
|
13 | + %button.btn.btn-primary.btn-sm#submission_problem_go Go | |
|
8 | 14 | |
|
9 | 15 | - if @problem!=nil |
|
10 | 16 | %h2= "Task: #{@problem.full_name} (#{@problem.name})" |
|
11 | 17 | |
|
12 | 18 | - if @submissions!=nil |
|
13 | 19 | - if @submissions.length>0 |
|
14 | 20 | %table.info |
|
15 | 21 | %tr.info-head |
|
16 | 22 | %th.info No. |
|
17 | 23 | %th.info # |
|
18 | 24 | %th.info At |
|
19 | 25 | %th.info Source |
|
20 | 26 | %th.info Result |
|
21 | 27 | %th.info{:width => "300px"} |
|
22 | 28 | Compiler message |
|
23 | 29 | = render :partial => 'submission', :collection => @submissions |
|
24 | 30 | - else |
|
25 | 31 | No submission |
@@ -1,29 +1,30 | |||
|
1 | 1 | CafeGrader::Application.routes.draw do |
|
2 | 2 | root :to => 'main#login' |
|
3 | 3 | |
|
4 | 4 | get "report/login" |
|
5 | 5 | |
|
6 | 6 | resources :contests |
|
7 | 7 | |
|
8 | 8 | resources :announcements |
|
9 | 9 | match 'announcements/toggle/:id' => 'announcements#toggle' |
|
10 | 10 | |
|
11 | 11 | resources :sites |
|
12 | 12 | |
|
13 | 13 | resources :problem |
|
14 | 14 | |
|
15 | 15 | resources :grader_configuration, controller: 'configurations' |
|
16 | 16 | |
|
17 | 17 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
18 | 18 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
19 | 19 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
20 | 20 | |
|
21 | 21 | #main |
|
22 | 22 | get "main/list" |
|
23 | + get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' | |
|
23 | 24 | |
|
24 | 25 | # See how all your routes lay out with "rake routes" |
|
25 | 26 | |
|
26 | 27 | # This is a legacy wild controller route that's not recommended for RESTful applications. |
|
27 | 28 | # Note: This route will make all actions in every controller accessible via GET requests. |
|
28 | 29 | match ':controller(/:action(/:id))(.:format)' |
|
29 | 30 | end |
You need to be logged in to leave comments.
Login now