Description:
- fix pdf loading fail
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r634:56cf4357ce2a - - 4 files changed: 11 inserted, 4 deleted
@@ -1,288 +1,294 | |||||
|
1 | class ProblemsController < ApplicationController |
|
1 | class ProblemsController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_action :authenticate, :authorization |
|
3 | before_action :authenticate, :authorization |
|
4 | before_action :testcase_authorization, only: [:show_testcase] |
|
4 | before_action :testcase_authorization, only: [:show_testcase] |
|
5 |
|
5 | ||
|
6 | in_place_edit_for :problem, :name |
|
6 | in_place_edit_for :problem, :name |
|
7 | in_place_edit_for :problem, :full_name |
|
7 | in_place_edit_for :problem, :full_name |
|
8 | in_place_edit_for :problem, :full_score |
|
8 | in_place_edit_for :problem, :full_score |
|
9 |
|
9 | ||
|
10 | def index |
|
10 | def index |
|
11 | @problems = Problem.order(date_added: :desc) |
|
11 | @problems = Problem.order(date_added: :desc) |
|
12 | end |
|
12 | end |
|
13 |
|
13 | ||
|
14 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
14 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
15 | verify :method => :post, :only => [ :create, :quick_create, |
|
15 | verify :method => :post, :only => [ :create, :quick_create, |
|
16 | :do_manage, |
|
16 | :do_manage, |
|
17 | :do_import, |
|
17 | :do_import, |
|
18 | ], |
|
18 | ], |
|
19 | :redirect_to => { :action => :index } |
|
19 | :redirect_to => { :action => :index } |
|
20 |
|
20 | ||
|
21 | def show |
|
21 | def show |
|
22 | @problem = Problem.find(params[:id]) |
|
22 | @problem = Problem.find(params[:id]) |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | def new |
|
25 | def new |
|
26 | @problem = Problem.new |
|
26 | @problem = Problem.new |
|
27 | @description = nil |
|
27 | @description = nil |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def create |
|
30 | def create |
|
31 | @problem = Problem.new(params[:problem]) |
|
31 | @problem = Problem.new(params[:problem]) |
|
32 | @description = Description.new(params[:description]) |
|
32 | @description = Description.new(params[:description]) |
|
33 | if @description.body!='' |
|
33 | if @description.body!='' |
|
34 | if !@description.save |
|
34 | if !@description.save |
|
35 | render :action => new and return |
|
35 | render :action => new and return |
|
36 | end |
|
36 | end |
|
37 | else |
|
37 | else |
|
38 | @description = nil |
|
38 | @description = nil |
|
39 | end |
|
39 | end |
|
40 | @problem.description = @description |
|
40 | @problem.description = @description |
|
41 | if @problem.save |
|
41 | if @problem.save |
|
42 | flash[:notice] = 'Problem was successfully created.' |
|
42 | flash[:notice] = 'Problem was successfully created.' |
|
43 | redirect_to action: :index |
|
43 | redirect_to action: :index |
|
44 | else |
|
44 | else |
|
45 | render :action => 'new' |
|
45 | render :action => 'new' |
|
46 | end |
|
46 | end |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
49 | def quick_create |
|
49 | def quick_create |
|
50 | @problem = Problem.new(params[:problem]) |
|
50 | @problem = Problem.new(params[:problem]) |
|
51 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
51 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
52 | @problem.full_score = 100 |
|
52 | @problem.full_score = 100 |
|
53 | @problem.available = false |
|
53 | @problem.available = false |
|
54 | @problem.test_allowed = true |
|
54 | @problem.test_allowed = true |
|
55 | @problem.output_only = false |
|
55 | @problem.output_only = false |
|
56 | @problem.date_added = Time.new |
|
56 | @problem.date_added = Time.new |
|
57 | if @problem.save |
|
57 | if @problem.save |
|
58 | flash[:notice] = 'Problem was successfully created.' |
|
58 | flash[:notice] = 'Problem was successfully created.' |
|
59 | redirect_to action: :index |
|
59 | redirect_to action: :index |
|
60 | else |
|
60 | else |
|
61 | flash[:notice] = 'Error saving problem' |
|
61 | flash[:notice] = 'Error saving problem' |
|
62 | redirect_to action: :index |
|
62 | redirect_to action: :index |
|
63 | end |
|
63 | end |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | def edit |
|
66 | def edit |
|
67 | @problem = Problem.find(params[:id]) |
|
67 | @problem = Problem.find(params[:id]) |
|
68 | @description = @problem.description |
|
68 | @description = @problem.description |
|
69 | end |
|
69 | end |
|
70 |
|
70 | ||
|
71 | def update |
|
71 | def update |
|
72 | @problem = Problem.find(params[:id]) |
|
72 | @problem = Problem.find(params[:id]) |
|
73 | @description = @problem.description |
|
73 | @description = @problem.description |
|
74 | if @description.nil? and params[:description][:body]!='' |
|
74 | if @description.nil? and params[:description][:body]!='' |
|
75 | @description = Description.new(params[:description]) |
|
75 | @description = Description.new(params[:description]) |
|
76 | if !@description.save |
|
76 | if !@description.save |
|
77 | flash[:notice] = 'Error saving description' |
|
77 | flash[:notice] = 'Error saving description' |
|
78 | render :action => 'edit' and return |
|
78 | render :action => 'edit' and return |
|
79 | end |
|
79 | end |
|
80 | @problem.description = @description |
|
80 | @problem.description = @description |
|
81 | elsif @description |
|
81 | elsif @description |
|
82 | if !@description.update_attributes(params[:description]) |
|
82 | if !@description.update_attributes(params[:description]) |
|
83 | flash[:notice] = 'Error saving description' |
|
83 | flash[:notice] = 'Error saving description' |
|
84 | render :action => 'edit' and return |
|
84 | render :action => 'edit' and return |
|
85 | end |
|
85 | end |
|
86 | end |
|
86 | end |
|
87 | if params[:file] and params[:file].content_type != 'application/pdf' |
|
87 | if params[:file] and params[:file].content_type != 'application/pdf' |
|
88 | flash[:notice] = 'Error: Uploaded file is not PDF' |
|
88 | flash[:notice] = 'Error: Uploaded file is not PDF' |
|
89 | render :action => 'edit' and return |
|
89 | render :action => 'edit' and return |
|
90 | end |
|
90 | end |
|
91 |
- if @problem.update_attributes( |
|
91 | + if @problem.update_attributes(problem_params) |
|
92 | flash[:notice] = 'Problem was successfully updated.' |
|
92 | flash[:notice] = 'Problem was successfully updated.' |
|
93 | unless params[:file] == nil or params[:file] == '' |
|
93 | unless params[:file] == nil or params[:file] == '' |
|
94 | flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' |
|
94 | flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' |
|
95 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
95 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
96 | if not FileTest.exists? out_dirname |
|
96 | if not FileTest.exists? out_dirname |
|
97 | Dir.mkdir out_dirname |
|
97 | Dir.mkdir out_dirname |
|
98 | end |
|
98 | end |
|
99 |
|
99 | ||
|
100 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
100 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
101 | if FileTest.exists? out_filename |
|
101 | if FileTest.exists? out_filename |
|
102 | File.delete out_filename |
|
102 | File.delete out_filename |
|
103 | end |
|
103 | end |
|
104 |
|
104 | ||
|
105 | File.open(out_filename,"wb") do |file| |
|
105 | File.open(out_filename,"wb") do |file| |
|
106 | file.write(params[:file].read) |
|
106 | file.write(params[:file].read) |
|
107 | end |
|
107 | end |
|
108 | @problem.description_filename = "#{@problem.name}.pdf" |
|
108 | @problem.description_filename = "#{@problem.name}.pdf" |
|
109 | @problem.save |
|
109 | @problem.save |
|
110 | end |
|
110 | end |
|
111 | redirect_to :action => 'show', :id => @problem |
|
111 | redirect_to :action => 'show', :id => @problem |
|
112 | else |
|
112 | else |
|
113 | render :action => 'edit' |
|
113 | render :action => 'edit' |
|
114 | end |
|
114 | end |
|
115 | end |
|
115 | end |
|
116 |
|
116 | ||
|
117 | def destroy |
|
117 | def destroy |
|
118 | p = Problem.find(params[:id]).destroy |
|
118 | p = Problem.find(params[:id]).destroy |
|
119 | redirect_to action: :index |
|
119 | redirect_to action: :index |
|
120 | end |
|
120 | end |
|
121 |
|
121 | ||
|
122 | def toggle |
|
122 | def toggle |
|
123 | @problem = Problem.find(params[:id]) |
|
123 | @problem = Problem.find(params[:id]) |
|
124 | @problem.update_attributes(available: !(@problem.available) ) |
|
124 | @problem.update_attributes(available: !(@problem.available) ) |
|
125 | respond_to do |format| |
|
125 | respond_to do |format| |
|
126 | format.js { } |
|
126 | format.js { } |
|
127 | end |
|
127 | end |
|
128 | end |
|
128 | end |
|
129 |
|
129 | ||
|
130 | def toggle_test |
|
130 | def toggle_test |
|
131 | @problem = Problem.find(params[:id]) |
|
131 | @problem = Problem.find(params[:id]) |
|
132 | @problem.update_attributes(test_allowed: !(@problem.test_allowed?) ) |
|
132 | @problem.update_attributes(test_allowed: !(@problem.test_allowed?) ) |
|
133 | respond_to do |format| |
|
133 | respond_to do |format| |
|
134 | format.js { } |
|
134 | format.js { } |
|
135 | end |
|
135 | end |
|
136 | end |
|
136 | end |
|
137 |
|
137 | ||
|
138 | def toggle_view_testcase |
|
138 | def toggle_view_testcase |
|
139 | @problem = Problem.find(params[:id]) |
|
139 | @problem = Problem.find(params[:id]) |
|
140 | @problem.update_attributes(view_testcase: !(@problem.view_testcase?) ) |
|
140 | @problem.update_attributes(view_testcase: !(@problem.view_testcase?) ) |
|
141 | respond_to do |format| |
|
141 | respond_to do |format| |
|
142 | format.js { } |
|
142 | format.js { } |
|
143 | end |
|
143 | end |
|
144 | end |
|
144 | end |
|
145 |
|
145 | ||
|
146 | def turn_all_off |
|
146 | def turn_all_off |
|
147 | Problem.available.all.each do |problem| |
|
147 | Problem.available.all.each do |problem| |
|
148 | problem.available = false |
|
148 | problem.available = false |
|
149 | problem.save |
|
149 | problem.save |
|
150 | end |
|
150 | end |
|
151 | redirect_to action: :index |
|
151 | redirect_to action: :index |
|
152 | end |
|
152 | end |
|
153 |
|
153 | ||
|
154 | def turn_all_on |
|
154 | def turn_all_on |
|
155 | Problem.where.not(available: true).each do |problem| |
|
155 | Problem.where.not(available: true).each do |problem| |
|
156 | problem.available = true |
|
156 | problem.available = true |
|
157 | problem.save |
|
157 | problem.save |
|
158 | end |
|
158 | end |
|
159 | redirect_to action: :index |
|
159 | redirect_to action: :index |
|
160 | end |
|
160 | end |
|
161 |
|
161 | ||
|
162 | def stat |
|
162 | def stat |
|
163 | @problem = Problem.find(params[:id]) |
|
163 | @problem = Problem.find(params[:id]) |
|
164 | unless @problem.available or session[:admin] |
|
164 | unless @problem.available or session[:admin] |
|
165 | redirect_to :controller => 'main', :action => 'list' |
|
165 | redirect_to :controller => 'main', :action => 'list' |
|
166 | return |
|
166 | return |
|
167 | end |
|
167 | end |
|
168 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
168 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
169 |
|
169 | ||
|
170 | #stat summary |
|
170 | #stat summary |
|
171 | range =65 |
|
171 | range =65 |
|
172 | @histogram = { data: Array.new(range,0), summary: {} } |
|
172 | @histogram = { data: Array.new(range,0), summary: {} } |
|
173 | user = Hash.new(0) |
|
173 | user = Hash.new(0) |
|
174 | @submissions.find_each do |sub| |
|
174 | @submissions.find_each do |sub| |
|
175 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
175 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
176 | @histogram[:data][d.to_i] += 1 if d < range |
|
176 | @histogram[:data][d.to_i] += 1 if d < range |
|
177 | user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max |
|
177 | user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max |
|
178 | end |
|
178 | end |
|
179 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
179 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
180 |
|
180 | ||
|
181 | @summary = { attempt: user.count, solve: 0 } |
|
181 | @summary = { attempt: user.count, solve: 0 } |
|
182 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
182 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
183 | end |
|
183 | end |
|
184 |
|
184 | ||
|
185 | def manage |
|
185 | def manage |
|
186 | @problems = Problem.order(date_added: :desc) |
|
186 | @problems = Problem.order(date_added: :desc) |
|
187 | end |
|
187 | end |
|
188 |
|
188 | ||
|
189 | def do_manage |
|
189 | def do_manage |
|
190 | if params.has_key? 'change_date_added' |
|
190 | if params.has_key? 'change_date_added' |
|
191 | change_date_added |
|
191 | change_date_added |
|
192 | elsif params.has_key? 'add_to_contest' |
|
192 | elsif params.has_key? 'add_to_contest' |
|
193 | add_to_contest |
|
193 | add_to_contest |
|
194 | elsif params.has_key? 'enable_problem' |
|
194 | elsif params.has_key? 'enable_problem' |
|
195 | set_available(true) |
|
195 | set_available(true) |
|
196 | elsif params.has_key? 'disable_problem' |
|
196 | elsif params.has_key? 'disable_problem' |
|
197 | set_available(false) |
|
197 | set_available(false) |
|
198 | end |
|
198 | end |
|
199 | redirect_to :action => 'manage' |
|
199 | redirect_to :action => 'manage' |
|
200 | end |
|
200 | end |
|
201 |
|
201 | ||
|
202 | def import |
|
202 | def import |
|
203 | @allow_test_pair_import = allow_test_pair_import? |
|
203 | @allow_test_pair_import = allow_test_pair_import? |
|
204 | end |
|
204 | end |
|
205 |
|
205 | ||
|
206 | def do_import |
|
206 | def do_import |
|
207 | old_problem = Problem.find_by_name(params[:name]) |
|
207 | old_problem = Problem.find_by_name(params[:name]) |
|
208 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
208 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
209 | params.delete :import_to_db |
|
209 | params.delete :import_to_db |
|
210 | end |
|
210 | end |
|
211 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
211 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
212 | old_problem) |
|
212 | old_problem) |
|
213 |
|
213 | ||
|
214 | if !@problem.errors.empty? |
|
214 | if !@problem.errors.empty? |
|
215 | render :action => 'import' and return |
|
215 | render :action => 'import' and return |
|
216 | end |
|
216 | end |
|
217 |
|
217 | ||
|
218 | if old_problem!=nil |
|
218 | if old_problem!=nil |
|
219 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
219 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
220 | end |
|
220 | end |
|
221 | @log = import_log |
|
221 | @log = import_log |
|
222 | end |
|
222 | end |
|
223 |
|
223 | ||
|
224 | def remove_contest |
|
224 | def remove_contest |
|
225 | problem = Problem.find(params[:id]) |
|
225 | problem = Problem.find(params[:id]) |
|
226 | contest = Contest.find(params[:contest_id]) |
|
226 | contest = Contest.find(params[:contest_id]) |
|
227 | if problem!=nil and contest!=nil |
|
227 | if problem!=nil and contest!=nil |
|
228 | problem.contests.delete(contest) |
|
228 | problem.contests.delete(contest) |
|
229 | end |
|
229 | end |
|
230 | redirect_to :action => 'manage' |
|
230 | redirect_to :action => 'manage' |
|
231 | end |
|
231 | end |
|
232 |
|
232 | ||
|
233 | ################################## |
|
233 | ################################## |
|
234 | protected |
|
234 | protected |
|
235 |
|
235 | ||
|
236 | def allow_test_pair_import? |
|
236 | def allow_test_pair_import? |
|
237 | if defined? ALLOW_TEST_PAIR_IMPORT |
|
237 | if defined? ALLOW_TEST_PAIR_IMPORT |
|
238 | return ALLOW_TEST_PAIR_IMPORT |
|
238 | return ALLOW_TEST_PAIR_IMPORT |
|
239 | else |
|
239 | else |
|
240 | return false |
|
240 | return false |
|
241 | end |
|
241 | end |
|
242 | end |
|
242 | end |
|
243 |
|
243 | ||
|
244 | def change_date_added |
|
244 | def change_date_added |
|
245 | problems = get_problems_from_params |
|
245 | problems = get_problems_from_params |
|
246 | year = params[:date_added][:year].to_i |
|
246 | year = params[:date_added][:year].to_i |
|
247 | month = params[:date_added][:month].to_i |
|
247 | month = params[:date_added][:month].to_i |
|
248 | day = params[:date_added][:day].to_i |
|
248 | day = params[:date_added][:day].to_i |
|
249 | date = Date.new(year,month,day) |
|
249 | date = Date.new(year,month,day) |
|
250 | problems.each do |p| |
|
250 | problems.each do |p| |
|
251 | p.date_added = date |
|
251 | p.date_added = date |
|
252 | p.save |
|
252 | p.save |
|
253 | end |
|
253 | end |
|
254 | end |
|
254 | end |
|
255 |
|
255 | ||
|
256 | def add_to_contest |
|
256 | def add_to_contest |
|
257 | problems = get_problems_from_params |
|
257 | problems = get_problems_from_params |
|
258 | contest = Contest.find(params[:contest][:id]) |
|
258 | contest = Contest.find(params[:contest][:id]) |
|
259 | if contest!=nil and contest.enabled |
|
259 | if contest!=nil and contest.enabled |
|
260 | problems.each do |p| |
|
260 | problems.each do |p| |
|
261 | p.contests << contest |
|
261 | p.contests << contest |
|
262 | end |
|
262 | end |
|
263 | end |
|
263 | end |
|
264 | end |
|
264 | end |
|
265 |
|
265 | ||
|
266 | def set_available(avail) |
|
266 | def set_available(avail) |
|
267 | problems = get_problems_from_params |
|
267 | problems = get_problems_from_params |
|
268 | problems.each do |p| |
|
268 | problems.each do |p| |
|
269 | p.available = avail |
|
269 | p.available = avail |
|
270 | p.save |
|
270 | p.save |
|
271 | end |
|
271 | end |
|
272 | end |
|
272 | end |
|
273 |
|
273 | ||
|
274 | def get_problems_from_params |
|
274 | def get_problems_from_params |
|
275 | problems = [] |
|
275 | problems = [] |
|
276 | params.keys.each do |k| |
|
276 | params.keys.each do |k| |
|
277 | if k.index('prob-')==0 |
|
277 | if k.index('prob-')==0 |
|
278 | name, id, order = k.split('-') |
|
278 | name, id, order = k.split('-') |
|
279 | problems << Problem.find(id) |
|
279 | problems << Problem.find(id) |
|
280 | end |
|
280 | end |
|
281 | end |
|
281 | end |
|
282 | problems |
|
282 | problems |
|
283 | end |
|
283 | end |
|
284 |
|
284 | ||
|
285 | def get_problems_stat |
|
285 | def get_problems_stat |
|
286 | end |
|
286 | end |
|
287 |
|
287 | ||
|
|
288 | + private | ||
|
|
289 | + | ||
|
|
290 | + def problem_params | ||
|
|
291 | + params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description) | ||
|
288 | end |
|
292 | end |
|
|
293 | + | ||
|
|
294 | + end |
@@ -1,313 +1,313 | |||||
|
1 | require 'csv' |
|
1 | require 'csv' |
|
2 |
|
2 | ||
|
3 | class UserAdminController < ApplicationController |
|
3 | class UserAdminController < ApplicationController |
|
4 |
|
4 | ||
|
5 | include MailHelperMethods |
|
5 | include MailHelperMethods |
|
6 |
|
6 | ||
|
7 | before_filter :admin_authorization |
|
7 | before_filter :admin_authorization |
|
8 |
|
8 | ||
|
9 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
9 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
10 | verify :method => :post, :only => [ |
|
10 | verify :method => :post, :only => [ |
|
11 | :create, :create_from_list, |
|
11 | :create, :create_from_list, |
|
12 | :update, |
|
12 | :update, |
|
13 | :manage_contest, |
|
13 | :manage_contest, |
|
14 | :bulk_mail |
|
14 | :bulk_mail |
|
15 | ], |
|
15 | ], |
|
16 | :redirect_to => { :action => :list } |
|
16 | :redirect_to => { :action => :list } |
|
17 |
|
17 | ||
|
18 | def index |
|
18 | def index |
|
19 | @user_count = User.count |
|
19 | @user_count = User.count |
|
20 | if params[:page] == 'all' |
|
20 | if params[:page] == 'all' |
|
21 | @users = User.all |
|
21 | @users = User.all |
|
22 | @paginated = false |
|
22 | @paginated = false |
|
23 | else |
|
23 | else |
|
24 | @users = User.paginate :page => params[:page] |
|
24 | @users = User.paginate :page => params[:page] |
|
25 | @paginated = true |
|
25 | @paginated = true |
|
26 | end |
|
26 | end |
|
27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
28 | @contests = Contest.enabled |
|
28 | @contests = Contest.enabled |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | def active |
|
31 | def active |
|
32 | sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) |
|
32 | sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) |
|
33 | @users = [] |
|
33 | @users = [] |
|
34 | sessions.each do |session| |
|
34 | sessions.each do |session| |
|
35 | if session.data[:user_id] |
|
35 | if session.data[:user_id] |
|
36 | @users << User.find(session.data[:user_id]) |
|
36 | @users << User.find(session.data[:user_id]) |
|
37 | end |
|
37 | end |
|
38 | end |
|
38 | end |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
41 | def show |
|
41 | def show |
|
42 | @user = User.find(params[:id]) |
|
42 | @user = User.find(params[:id]) |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | def new |
|
45 | def new |
|
46 | @user = User.new |
|
46 | @user = User.new |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
49 | def create |
|
49 | def create |
|
50 | @user = User.new(params[:user]) |
|
50 | @user = User.new(params[:user]) |
|
51 | @user.activated = true |
|
51 | @user.activated = true |
|
52 | if @user.save |
|
52 | if @user.save |
|
53 | flash[:notice] = 'User was successfully created.' |
|
53 | flash[:notice] = 'User was successfully created.' |
|
54 | redirect_to :action => 'index' |
|
54 | redirect_to :action => 'index' |
|
55 | else |
|
55 | else |
|
56 | render :action => 'new' |
|
56 | render :action => 'new' |
|
57 | end |
|
57 | end |
|
58 | end |
|
58 | end |
|
59 |
|
59 | ||
|
60 | def clear_last_ip |
|
60 | def clear_last_ip |
|
61 | @user = User.find(params[:id]) |
|
61 | @user = User.find(params[:id]) |
|
62 | @user.last_ip = nil |
|
62 | @user.last_ip = nil |
|
63 | @user.save |
|
63 | @user.save |
|
64 | redirect_to action: 'index', page: params[:page] |
|
64 | redirect_to action: 'index', page: params[:page] |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | def create_from_list |
|
67 | def create_from_list |
|
68 | lines = params[:user_list] |
|
68 | lines = params[:user_list] |
|
69 |
|
69 | ||
|
70 | note = [] |
|
70 | note = [] |
|
71 |
|
71 | ||
|
72 | lines.split("\n").each do |line| |
|
72 | lines.split("\n").each do |line| |
|
73 | items = line.chomp.split(',') |
|
73 | items = line.chomp.split(',') |
|
74 | if items.length>=2 |
|
74 | if items.length>=2 |
|
75 | login = items[0] |
|
75 | login = items[0] |
|
76 | full_name = items[1] |
|
76 | full_name = items[1] |
|
77 | remark ='' |
|
77 | remark ='' |
|
78 | user_alias = '' |
|
78 | user_alias = '' |
|
79 |
|
79 | ||
|
80 | added_random_password = false |
|
80 | added_random_password = false |
|
81 | if items.length >= 3 and items[2].chomp(" ").length > 0; |
|
81 | if items.length >= 3 and items[2].chomp(" ").length > 0; |
|
82 | password = items[2].chomp(" ") |
|
82 | password = items[2].chomp(" ") |
|
83 | else |
|
83 | else |
|
84 | password = random_password |
|
84 | password = random_password |
|
85 | add_random_password=true; |
|
85 | add_random_password=true; |
|
86 | end |
|
86 | end |
|
87 |
|
87 | ||
|
88 | if items.length>= 4 and items[3].chomp(" ").length > 0; |
|
88 | if items.length>= 4 and items[3].chomp(" ").length > 0; |
|
89 | user_alias = items[3].chomp(" ") |
|
89 | user_alias = items[3].chomp(" ") |
|
90 | else |
|
90 | else |
|
91 | user_alias = login |
|
91 | user_alias = login |
|
92 | end |
|
92 | end |
|
93 |
|
93 | ||
|
94 | if items.length>=5 |
|
94 | if items.length>=5 |
|
95 | remark = items[4].strip; |
|
95 | remark = items[4].strip; |
|
96 | end |
|
96 | end |
|
97 |
|
97 | ||
|
98 | user = User.find_by_login(login) |
|
98 | user = User.find_by_login(login) |
|
99 | if (user) |
|
99 | if (user) |
|
100 | user.full_name = full_name |
|
100 | user.full_name = full_name |
|
101 | user.password = password |
|
101 | user.password = password |
|
102 | user.remark = remark |
|
102 | user.remark = remark |
|
103 | else |
|
103 | else |
|
104 | user = User.new({:login => login, |
|
104 | user = User.new({:login => login, |
|
105 | :full_name => full_name, |
|
105 | :full_name => full_name, |
|
106 | :password => password, |
|
106 | :password => password, |
|
107 | :password_confirmation => password, |
|
107 | :password_confirmation => password, |
|
108 | :alias => user_alias, |
|
108 | :alias => user_alias, |
|
109 | :remark => remark}) |
|
109 | :remark => remark}) |
|
110 | end |
|
110 | end |
|
111 | user.activated = true |
|
111 | user.activated = true |
|
112 | user.save |
|
112 | user.save |
|
113 |
|
113 | ||
|
114 | if added_random_password |
|
114 | if added_random_password |
|
115 | note << "'#{login}' (+)" |
|
115 | note << "'#{login}' (+)" |
|
116 | else |
|
116 | else |
|
117 | note << login |
|
117 | note << login |
|
118 | end |
|
118 | end |
|
119 | end |
|
119 | end |
|
120 | end |
|
120 | end |
|
121 |
- flash[: |
|
121 | + flash[:success] = 'User(s) ' + note.join(', ') + |
|
122 | ' were successfully created. ' + |
|
122 | ' were successfully created. ' + |
|
123 | '( (+) - created with random passwords.)' |
|
123 | '( (+) - created with random passwords.)' |
|
124 | redirect_to :action => 'index' |
|
124 | redirect_to :action => 'index' |
|
125 | end |
|
125 | end |
|
126 |
|
126 | ||
|
127 | def edit |
|
127 | def edit |
|
128 | @user = User.find(params[:id]) |
|
128 | @user = User.find(params[:id]) |
|
129 | end |
|
129 | end |
|
130 |
|
130 | ||
|
131 | def update |
|
131 | def update |
|
132 | @user = User.find(params[:id]) |
|
132 | @user = User.find(params[:id]) |
|
133 | if @user.update_attributes(user_params) |
|
133 | if @user.update_attributes(user_params) |
|
134 | flash[:notice] = 'User was successfully updated.' |
|
134 | flash[:notice] = 'User was successfully updated.' |
|
135 | redirect_to :action => 'show', :id => @user |
|
135 | redirect_to :action => 'show', :id => @user |
|
136 | else |
|
136 | else |
|
137 | render :action => 'edit' |
|
137 | render :action => 'edit' |
|
138 | end |
|
138 | end |
|
139 | end |
|
139 | end |
|
140 |
|
140 | ||
|
141 | def destroy |
|
141 | def destroy |
|
142 | User.find(params[:id]).destroy |
|
142 | User.find(params[:id]).destroy |
|
143 | redirect_to :action => 'index' |
|
143 | redirect_to :action => 'index' |
|
144 | end |
|
144 | end |
|
145 |
|
145 | ||
|
146 | def user_stat |
|
146 | def user_stat |
|
147 | if params[:commit] == 'download csv' |
|
147 | if params[:commit] == 'download csv' |
|
148 | @problems = Problem.all |
|
148 | @problems = Problem.all |
|
149 | else |
|
149 | else |
|
150 | @problems = Problem.available_problems |
|
150 | @problems = Problem.available_problems |
|
151 | end |
|
151 | end |
|
152 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
152 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
153 | @scorearray = Array.new |
|
153 | @scorearray = Array.new |
|
154 | @users.each do |u| |
|
154 | @users.each do |u| |
|
155 | ustat = Array.new |
|
155 | ustat = Array.new |
|
156 | ustat[0] = u |
|
156 | ustat[0] = u |
|
157 | @problems.each do |p| |
|
157 | @problems.each do |p| |
|
158 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
158 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
159 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
159 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
160 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
160 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
161 | else |
|
161 | else |
|
162 | ustat << [0,false] |
|
162 | ustat << [0,false] |
|
163 | end |
|
163 | end |
|
164 | end |
|
164 | end |
|
165 | @scorearray << ustat |
|
165 | @scorearray << ustat |
|
166 | end |
|
166 | end |
|
167 | if params[:commit] == 'download csv' then |
|
167 | if params[:commit] == 'download csv' then |
|
168 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
168 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
169 | send_data csv, filename: 'last_score.csv' |
|
169 | send_data csv, filename: 'last_score.csv' |
|
170 | else |
|
170 | else |
|
171 | render template: 'user_admin/user_stat' |
|
171 | render template: 'user_admin/user_stat' |
|
172 | end |
|
172 | end |
|
173 | end |
|
173 | end |
|
174 |
|
174 | ||
|
175 | def user_stat_max |
|
175 | def user_stat_max |
|
176 | if params[:commit] == 'download csv' |
|
176 | if params[:commit] == 'download csv' |
|
177 | @problems = Problem.all |
|
177 | @problems = Problem.all |
|
178 | else |
|
178 | else |
|
179 | @problems = Problem.available_problems |
|
179 | @problems = Problem.available_problems |
|
180 | end |
|
180 | end |
|
181 | @users = User.includes(:contests).includes(:contest_stat).all |
|
181 | @users = User.includes(:contests).includes(:contest_stat).all |
|
182 | @scorearray = Array.new |
|
182 | @scorearray = Array.new |
|
183 | #set up range from param |
|
183 | #set up range from param |
|
184 | since_id = params.fetch(:since_id, 0).to_i |
|
184 | since_id = params.fetch(:since_id, 0).to_i |
|
185 | until_id = params.fetch(:until_id, 0).to_i |
|
185 | until_id = params.fetch(:until_id, 0).to_i |
|
186 | @users.each do |u| |
|
186 | @users.each do |u| |
|
187 | ustat = Array.new |
|
187 | ustat = Array.new |
|
188 | ustat[0] = u |
|
188 | ustat[0] = u |
|
189 | @problems.each do |p| |
|
189 | @problems.each do |p| |
|
190 | max_points = 0 |
|
190 | max_points = 0 |
|
191 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
191 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
192 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
192 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
193 | end |
|
193 | end |
|
194 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
194 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
195 | end |
|
195 | end |
|
196 | @scorearray << ustat |
|
196 | @scorearray << ustat |
|
197 | end |
|
197 | end |
|
198 |
|
198 | ||
|
199 | if params[:commit] == 'download csv' then |
|
199 | if params[:commit] == 'download csv' then |
|
200 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
200 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
201 | send_data csv, filename: 'max_score.csv' |
|
201 | send_data csv, filename: 'max_score.csv' |
|
202 | else |
|
202 | else |
|
203 | render template: 'user_admin/user_stat' |
|
203 | render template: 'user_admin/user_stat' |
|
204 | end |
|
204 | end |
|
205 | end |
|
205 | end |
|
206 |
|
206 | ||
|
207 | def import |
|
207 | def import |
|
208 | if params[:file]=='' |
|
208 | if params[:file]=='' |
|
209 | flash[:notice] = 'Error importing no file' |
|
209 | flash[:notice] = 'Error importing no file' |
|
210 | redirect_to :action => 'index' and return |
|
210 | redirect_to :action => 'index' and return |
|
211 | end |
|
211 | end |
|
212 | import_from_file(params[:file]) |
|
212 | import_from_file(params[:file]) |
|
213 | end |
|
213 | end |
|
214 |
|
214 | ||
|
215 | def random_all_passwords |
|
215 | def random_all_passwords |
|
216 | users = User.all |
|
216 | users = User.all |
|
217 | @prefix = params[:prefix] || '' |
|
217 | @prefix = params[:prefix] || '' |
|
218 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
218 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
219 | @changed = false |
|
219 | @changed = false |
|
220 | if request.request_method == 'POST' |
|
220 | if request.request_method == 'POST' |
|
221 | @non_admin_users.each do |user| |
|
221 | @non_admin_users.each do |user| |
|
222 | password = random_password |
|
222 | password = random_password |
|
223 | user.password = password |
|
223 | user.password = password |
|
224 | user.password_confirmation = password |
|
224 | user.password_confirmation = password |
|
225 | user.save |
|
225 | user.save |
|
226 | end |
|
226 | end |
|
227 | @changed = true |
|
227 | @changed = true |
|
228 | end |
|
228 | end |
|
229 | end |
|
229 | end |
|
230 |
|
230 | ||
|
231 | # contest management |
|
231 | # contest management |
|
232 |
|
232 | ||
|
233 | def contests |
|
233 | def contests |
|
234 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
234 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
235 | @contests = Contest.enabled |
|
235 | @contests = Contest.enabled |
|
236 | end |
|
236 | end |
|
237 |
|
237 | ||
|
238 | def assign_from_list |
|
238 | def assign_from_list |
|
239 | contest_id = params[:users_contest_id] |
|
239 | contest_id = params[:users_contest_id] |
|
240 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
240 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
241 | contest = Contest.find(params[:new_contest][:id]) |
|
241 | contest = Contest.find(params[:new_contest][:id]) |
|
242 | if !contest |
|
242 | if !contest |
|
243 | flash[:notice] = 'Error: no contest' |
|
243 | flash[:notice] = 'Error: no contest' |
|
244 | redirect_to :action => 'contests', :id =>contest_id |
|
244 | redirect_to :action => 'contests', :id =>contest_id |
|
245 | end |
|
245 | end |
|
246 |
|
246 | ||
|
247 | note = [] |
|
247 | note = [] |
|
248 | users.each do |u| |
|
248 | users.each do |u| |
|
249 | u.contests = [contest] |
|
249 | u.contests = [contest] |
|
250 | note << u.login |
|
250 | note << u.login |
|
251 | end |
|
251 | end |
|
252 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
252 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
253 | " were successfully reassigned to #{contest.title}." |
|
253 | " were successfully reassigned to #{contest.title}." |
|
254 | redirect_to :action => 'contests', :id =>contest.id |
|
254 | redirect_to :action => 'contests', :id =>contest.id |
|
255 | end |
|
255 | end |
|
256 |
|
256 | ||
|
257 | def add_to_contest |
|
257 | def add_to_contest |
|
258 | user = User.find(params[:id]) |
|
258 | user = User.find(params[:id]) |
|
259 | contest = Contest.find(params[:contest_id]) |
|
259 | contest = Contest.find(params[:contest_id]) |
|
260 | if user and contest |
|
260 | if user and contest |
|
261 | user.contests << contest |
|
261 | user.contests << contest |
|
262 | end |
|
262 | end |
|
263 | redirect_to :action => 'index' |
|
263 | redirect_to :action => 'index' |
|
264 | end |
|
264 | end |
|
265 |
|
265 | ||
|
266 | def remove_from_contest |
|
266 | def remove_from_contest |
|
267 | user = User.find(params[:id]) |
|
267 | user = User.find(params[:id]) |
|
268 | contest = Contest.find(params[:contest_id]) |
|
268 | contest = Contest.find(params[:contest_id]) |
|
269 | if user and contest |
|
269 | if user and contest |
|
270 | user.contests.delete(contest) |
|
270 | user.contests.delete(contest) |
|
271 | end |
|
271 | end |
|
272 | redirect_to :action => 'index' |
|
272 | redirect_to :action => 'index' |
|
273 | end |
|
273 | end |
|
274 |
|
274 | ||
|
275 | def contest_management |
|
275 | def contest_management |
|
276 | end |
|
276 | end |
|
277 |
|
277 | ||
|
278 | def manage_contest |
|
278 | def manage_contest |
|
279 | contest = Contest.find(params[:contest][:id]) |
|
279 | contest = Contest.find(params[:contest][:id]) |
|
280 | if !contest |
|
280 | if !contest |
|
281 | flash[:notice] = 'You did not choose the contest.' |
|
281 | flash[:notice] = 'You did not choose the contest.' |
|
282 | redirect_to :action => 'contest_management' and return |
|
282 | redirect_to :action => 'contest_management' and return |
|
283 | end |
|
283 | end |
|
284 |
|
284 | ||
|
285 | operation = params[:operation] |
|
285 | operation = params[:operation] |
|
286 |
|
286 | ||
|
287 | if not ['add','remove','assign'].include? operation |
|
287 | if not ['add','remove','assign'].include? operation |
|
288 | flash[:notice] = 'You did not choose the operation to perform.' |
|
288 | flash[:notice] = 'You did not choose the operation to perform.' |
|
289 | redirect_to :action => 'contest_management' and return |
|
289 | redirect_to :action => 'contest_management' and return |
|
290 | end |
|
290 | end |
|
291 |
|
291 | ||
|
292 | lines = params[:login_list] |
|
292 | lines = params[:login_list] |
|
293 | if !lines or lines.blank? |
|
293 | if !lines or lines.blank? |
|
294 | flash[:notice] = 'You entered an empty list.' |
|
294 | flash[:notice] = 'You entered an empty list.' |
|
295 | redirect_to :action => 'contest_management' and return |
|
295 | redirect_to :action => 'contest_management' and return |
|
296 | end |
|
296 | end |
|
297 |
|
297 | ||
|
298 | note = [] |
|
298 | note = [] |
|
299 | users = [] |
|
299 | users = [] |
|
300 | lines.split("\n").each do |line| |
|
300 | lines.split("\n").each do |line| |
|
301 | user = User.find_by_login(line.chomp) |
|
301 | user = User.find_by_login(line.chomp) |
|
302 | if user |
|
302 | if user |
|
303 | if operation=='add' |
|
303 | if operation=='add' |
|
304 | if ! user.contests.include? contest |
|
304 | if ! user.contests.include? contest |
|
305 | user.contests << contest |
|
305 | user.contests << contest |
|
306 | end |
|
306 | end |
|
307 | elsif operation=='remove' |
|
307 | elsif operation=='remove' |
|
308 | user.contests.delete(contest) |
|
308 | user.contests.delete(contest) |
|
309 | else |
|
309 | else |
|
310 | user.contests = [contest] |
|
310 | user.contests = [contest] |
|
311 | end |
|
311 | end |
|
312 |
|
312 | ||
|
313 | if params[:reset_timer] |
|
313 | if params[:reset_timer] |
@@ -1,54 +1,55 | |||||
|
1 | <%= error_messages_for 'problem' %> |
|
1 | <%= error_messages_for 'problem' %> |
|
2 |
|
2 | ||
|
3 | <!--[form:problem]--> |
|
3 | <!--[form:problem]--> |
|
4 | <p><label for="problem_name">Name</label><br/> |
|
4 | <p><label for="problem_name">Name</label><br/> |
|
5 | - <%= text_field 'problem', 'name' %></p> |
|
5 | + <%= text_field 'problem', 'name' %> Do not directly edit the problem name, unless you know what you are doing. If you want to change the name, use the name change button in the problem management menu instead. |
|
|
6 | + </p> | ||
|
6 |
|
7 | ||
|
7 | <p><label for="problem_full_name">Full name</label><br/> |
|
8 | <p><label for="problem_full_name">Full name</label><br/> |
|
8 | <%= text_field 'problem', 'full_name' %></p> |
|
9 | <%= text_field 'problem', 'full_name' %></p> |
|
9 |
|
10 | ||
|
10 | <p><label for="problem_full_score">Full score</label><br/> |
|
11 | <p><label for="problem_full_score">Full score</label><br/> |
|
11 | <%= text_field 'problem', 'full_score' %></p> |
|
12 | <%= text_field 'problem', 'full_score' %></p> |
|
12 |
|
13 | ||
|
13 | <p><label for="problem_date_added">Date added</label><br/> |
|
14 | <p><label for="problem_date_added">Date added</label><br/> |
|
14 | <%= date_select 'problem', 'date_added' %></p> |
|
15 | <%= date_select 'problem', 'date_added' %></p> |
|
15 |
|
16 | ||
|
16 | <% |
|
17 | <% |
|
17 | # TODO: these should be put in model Problem, but I can't think of |
|
18 | # TODO: these should be put in model Problem, but I can't think of |
|
18 | # nice default values for them. These values look fine only |
|
19 | # nice default values for them. These values look fine only |
|
19 | # in this case (of lazily adding new problems). |
|
20 | # in this case (of lazily adding new problems). |
|
20 | @problem.available = true if @problem!=nil and @problem.available==nil |
|
21 | @problem.available = true if @problem!=nil and @problem.available==nil |
|
21 | @problem.test_allowed = true if @problem!=nil and @problem.test_allowed==nil |
|
22 | @problem.test_allowed = true if @problem!=nil and @problem.test_allowed==nil |
|
22 | @problem.output_only = false if @problem!=nil and @problem.output_only==nil |
|
23 | @problem.output_only = false if @problem!=nil and @problem.output_only==nil |
|
23 | %> |
|
24 | %> |
|
24 |
|
25 | ||
|
25 | <p> |
|
26 | <p> |
|
26 | <label for="problem_available">Available?</label> |
|
27 | <label for="problem_available">Available?</label> |
|
27 | <%= check_box :problem, :available %> |
|
28 | <%= check_box :problem, :available %> |
|
28 |
|
29 | ||
|
29 | <label for="problem_test_allowed">Test allowed?</label> |
|
30 | <label for="problem_test_allowed">Test allowed?</label> |
|
30 | <%= check_box :problem, :test_allowed %> |
|
31 | <%= check_box :problem, :test_allowed %> |
|
31 |
|
32 | ||
|
32 | <label for="problem_output_only">Output only?</label> |
|
33 | <label for="problem_output_only">Output only?</label> |
|
33 | <%= check_box :problem, :output_only %> |
|
34 | <%= check_box :problem, :output_only %> |
|
34 | </p> |
|
35 | </p> |
|
35 |
|
36 | ||
|
36 | <%= error_messages_for 'description' %> |
|
37 | <%= error_messages_for 'description' %> |
|
37 |
|
38 | ||
|
38 | <p><label for="description_body">Description</label><br/> |
|
39 | <p><label for="description_body">Description</label><br/> |
|
39 | <%= text_area :description, :body, :rows => 10, :cols => 80 %></p> |
|
40 | <%= text_area :description, :body, :rows => 10, :cols => 80 %></p> |
|
40 |
|
41 | ||
|
41 | <p><label for="description_markdowned">Markdowned?</label> |
|
42 | <p><label for="description_markdowned">Markdowned?</label> |
|
42 | <%= select "description", |
|
43 | <%= select "description", |
|
43 | "markdowned", |
|
44 | "markdowned", |
|
44 | [['True',true],['False',false]], |
|
45 | [['True',true],['False',false]], |
|
45 | {:selected => (@description) ? @description.markdowned : false } |
|
46 | {:selected => (@description) ? @description.markdowned : false } |
|
46 | %></p> |
|
47 | %></p> |
|
47 |
|
48 | ||
|
48 | <p><label for="problem_url">URL</label><br/> |
|
49 | <p><label for="problem_url">URL</label><br/> |
|
49 | <%= text_field 'problem', 'url' %></p> |
|
50 | <%= text_field 'problem', 'url' %></p> |
|
50 |
|
51 | ||
|
51 | <p>Task PDF <%= file_field_tag 'file' %></p> |
|
52 | <p>Task PDF <%= file_field_tag 'file' %></p> |
|
52 |
|
53 | ||
|
53 |
|
54 | ||
|
54 | <!--[eoform:problem]--> |
|
55 | <!--[eoform:problem]--> |
@@ -1,24 +1,24 | |||||
|
1 | <% for column in Problem.content_columns %> |
|
1 | <% for column in Problem.content_columns %> |
|
2 | <p> |
|
2 | <p> |
|
3 | <b><%= column.human_name %>:</b> |
|
3 | <b><%= column.human_name %>:</b> |
|
4 | <%=h @problem.send(column.name) %> |
|
4 | <%=h @problem.send(column.name) %> |
|
5 | </p> |
|
5 | </p> |
|
6 | <% end %> |
|
6 | <% end %> |
|
7 |
|
7 | ||
|
8 | <p> |
|
8 | <p> |
|
9 | <b>Description:</b><br/> |
|
9 | <b>Description:</b><br/> |
|
10 | <% if @problem.description!=nil %> |
|
10 | <% if @problem.description!=nil %> |
|
11 | <% if @problem.description.markdowned %> |
|
11 | <% if @problem.description.markdowned %> |
|
12 | <%= markdown(@problem.description.body) %> |
|
12 | <%= markdown(@problem.description.body) %> |
|
13 | <% else %> |
|
13 | <% else %> |
|
14 | <pre> |
|
14 | <pre> |
|
15 | <%= @problem.description.body %> |
|
15 | <%= @problem.description.body %> |
|
16 | </pre> |
|
16 | </pre> |
|
17 | <% end %> |
|
17 | <% end %> |
|
18 | <% else %> |
|
18 | <% else %> |
|
19 | (not available) |
|
19 | (not available) |
|
20 | <% end %> |
|
20 | <% end %> |
|
21 | </p> |
|
21 | </p> |
|
22 |
|
22 | ||
|
23 | <%= link_to 'Edit', :action => 'edit', :id => @problem %> | |
|
23 | <%= link_to 'Edit', :action => 'edit', :id => @problem %> | |
|
24 |
- <%= link_to 'Back', |
|
24 | + <%= link_to 'Back', problems_path %> |
You need to be logged in to leave comments.
Login now