Description:
fix change date not working in problem bulk manage
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r739:dd100c4f33f7 - - 1 file changed: 1 inserted, 1 deleted
@@ -115,196 +115,196 | |||
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def destroy |
|
118 | 118 | p = Problem.find(params[:id]).destroy |
|
119 | 119 | redirect_to action: :index |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def toggle |
|
123 | 123 | @problem = Problem.find(params[:id]) |
|
124 | 124 | @problem.update_attributes(available: !(@problem.available) ) |
|
125 | 125 | respond_to do |format| |
|
126 | 126 | format.js { } |
|
127 | 127 | end |
|
128 | 128 | end |
|
129 | 129 | |
|
130 | 130 | def toggle_test |
|
131 | 131 | @problem = Problem.find(params[:id]) |
|
132 | 132 | @problem.update_attributes(test_allowed: !(@problem.test_allowed?) ) |
|
133 | 133 | respond_to do |format| |
|
134 | 134 | format.js { } |
|
135 | 135 | end |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def toggle_view_testcase |
|
139 | 139 | @problem = Problem.find(params[:id]) |
|
140 | 140 | @problem.update_attributes(view_testcase: !(@problem.view_testcase?) ) |
|
141 | 141 | respond_to do |format| |
|
142 | 142 | format.js { } |
|
143 | 143 | end |
|
144 | 144 | end |
|
145 | 145 | |
|
146 | 146 | def turn_all_off |
|
147 | 147 | Problem.available.all.each do |problem| |
|
148 | 148 | problem.available = false |
|
149 | 149 | problem.save |
|
150 | 150 | end |
|
151 | 151 | redirect_to action: :index |
|
152 | 152 | end |
|
153 | 153 | |
|
154 | 154 | def turn_all_on |
|
155 | 155 | Problem.where.not(available: true).each do |problem| |
|
156 | 156 | problem.available = true |
|
157 | 157 | problem.save |
|
158 | 158 | end |
|
159 | 159 | redirect_to action: :index |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def stat |
|
163 | 163 | @problem = Problem.find(params[:id]) |
|
164 | 164 | unless @problem.available or session[:admin] |
|
165 | 165 | redirect_to :controller => 'main', :action => 'list' |
|
166 | 166 | return |
|
167 | 167 | end |
|
168 | 168 | @submissions = Submission.includes(:user).includes(:language).where(problem_id: params[:id]).order(:user_id,:id) |
|
169 | 169 | |
|
170 | 170 | #stat summary |
|
171 | 171 | range =65 |
|
172 | 172 | @histogram = { data: Array.new(range,0), summary: {} } |
|
173 | 173 | user = Hash.new(0) |
|
174 | 174 | @submissions.find_each do |sub| |
|
175 | 175 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
176 | 176 | @histogram[:data][d.to_i] += 1 if d < range |
|
177 | 177 | user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max |
|
178 | 178 | end |
|
179 | 179 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
180 | 180 | |
|
181 | 181 | @summary = { attempt: user.count, solve: 0 } |
|
182 | 182 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | def manage |
|
186 | 186 | @problems = Problem.order(date_added: :desc) |
|
187 | 187 | end |
|
188 | 188 | |
|
189 | 189 | def do_manage |
|
190 | 190 | if params.has_key? 'change_date_added' and params[:date_added].strip.empty? == false |
|
191 | 191 | change_date_added |
|
192 | 192 | elsif params.has_key? 'add_to_contest' |
|
193 | 193 | add_to_contest |
|
194 | 194 | elsif params.has_key? 'enable_problem' |
|
195 | 195 | set_available(true) |
|
196 | 196 | elsif params.has_key? 'disable_problem' |
|
197 | 197 | set_available(false) |
|
198 | 198 | elsif params.has_key? 'add_group' |
|
199 | 199 | group = Group.find(params[:group_id]) |
|
200 | 200 | ok = [] |
|
201 | 201 | failed = [] |
|
202 | 202 | get_problems_from_params.each do |p| |
|
203 | 203 | begin |
|
204 | 204 | group.problems << p |
|
205 | 205 | ok << p.full_name |
|
206 | 206 | rescue => e |
|
207 | 207 | failed << p.full_name |
|
208 | 208 | end |
|
209 | 209 | end |
|
210 | 210 | flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0 |
|
211 | 211 | flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0 |
|
212 | 212 | elsif params.has_key? 'add_tags' |
|
213 | 213 | get_problems_from_params.each do |p| |
|
214 | 214 | p.tag_ids += params[:tag_ids] |
|
215 | 215 | end |
|
216 | 216 | end |
|
217 | 217 | |
|
218 | 218 | redirect_to :action => 'manage' |
|
219 | 219 | end |
|
220 | 220 | |
|
221 | 221 | def import |
|
222 | 222 | @allow_test_pair_import = allow_test_pair_import? |
|
223 | 223 | end |
|
224 | 224 | |
|
225 | 225 | def do_import |
|
226 | 226 | old_problem = Problem.find_by_name(params[:name]) |
|
227 | 227 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
228 | 228 | params.delete :import_to_db |
|
229 | 229 | end |
|
230 | 230 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
231 | 231 | old_problem) |
|
232 | 232 | |
|
233 | 233 | if !@problem.errors.empty? |
|
234 | 234 | render :action => 'import' and return |
|
235 | 235 | end |
|
236 | 236 | |
|
237 | 237 | if old_problem!=nil |
|
238 | 238 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
239 | 239 | end |
|
240 | 240 | @log = import_log |
|
241 | 241 | end |
|
242 | 242 | |
|
243 | 243 | def remove_contest |
|
244 | 244 | problem = Problem.find(params[:id]) |
|
245 | 245 | contest = Contest.find(params[:contest_id]) |
|
246 | 246 | if problem!=nil and contest!=nil |
|
247 | 247 | problem.contests.delete(contest) |
|
248 | 248 | end |
|
249 | 249 | redirect_to :action => 'manage' |
|
250 | 250 | end |
|
251 | 251 | |
|
252 | 252 | ################################## |
|
253 | 253 | protected |
|
254 | 254 | |
|
255 | 255 | def allow_test_pair_import? |
|
256 | 256 | if defined? ALLOW_TEST_PAIR_IMPORT |
|
257 | 257 | return ALLOW_TEST_PAIR_IMPORT |
|
258 | 258 | else |
|
259 | 259 | return false |
|
260 | 260 | end |
|
261 | 261 | end |
|
262 | 262 | |
|
263 | 263 | def change_date_added |
|
264 | 264 | problems = get_problems_from_params |
|
265 | 265 | date = Date.parse(params[:date_added]) |
|
266 | 266 | problems.each do |p| |
|
267 | 267 | p.date_added = date |
|
268 | 268 | p.save |
|
269 | 269 | end |
|
270 | 270 | end |
|
271 | 271 | |
|
272 | 272 | def add_to_contest |
|
273 | 273 | problems = get_problems_from_params |
|
274 | 274 | contest = Contest.find(params[:contest][:id]) |
|
275 | 275 | if contest!=nil and contest.enabled |
|
276 | 276 | problems.each do |p| |
|
277 | 277 | p.contests << contest |
|
278 | 278 | end |
|
279 | 279 | end |
|
280 | 280 | end |
|
281 | 281 | |
|
282 | 282 | def set_available(avail) |
|
283 | 283 | problems = get_problems_from_params |
|
284 | 284 | problems.each do |p| |
|
285 | 285 | p.available = avail |
|
286 | 286 | p.save |
|
287 | 287 | end |
|
288 | 288 | end |
|
289 | 289 | |
|
290 | 290 | def get_problems_from_params |
|
291 | 291 | problems = [] |
|
292 | 292 | params.keys.each do |k| |
|
293 | 293 | if k.index('prob-')==0 |
|
294 | 294 | name, id, order = k.split('-') |
|
295 | 295 | problems << Problem.find(id) |
|
296 | 296 | end |
|
297 | 297 | end |
|
298 | 298 | problems |
|
299 | 299 | end |
|
300 | 300 | |
|
301 | 301 | def get_problems_stat |
|
302 | 302 | end |
|
303 | 303 | |
|
304 | 304 | private |
|
305 | 305 | |
|
306 | 306 | def problem_params |
|
307 | - params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description, tag_ids:[]) | |
|
307 | + params.require(:problem).permit(:name, :full_name, :full_score, :change_date_added, :date_added, :available, :test_allowed,:output_only, :url, :description, tag_ids:[]) | |
|
308 | 308 | end |
|
309 | 309 | |
|
310 | 310 | end |
You need to be logged in to leave comments.
Login now