Show More
Commit Description:
associate logins with users
Commit Description:
associate logins with users
References:
File last commit:
Show/Diff file:
Action:
app/controllers/problems_controller.rb | 277 lines | 7.3 KiB | text/x-ruby | RubyLexer |
pramook
initial commit...
r0 class ProblemsController < ApplicationController
before_filter :authenticate, :authorization
jittat
+in_place_editing for problems...
r21 in_place_edit_for :problem, :name
in_place_edit_for :problem, :full_name
in_place_edit_for :problem, :full_score
pramook
initial commit...
r0 def index
list
render :action => 'list'
end
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
jittat
added problem date_added bulk update...
r201 verify :method => :post, :only => [ :destroy,
:create, :quick_create,
:do_manage,
jittat
added problem import...
r204 :do_import,
jittat
added problem date_added bulk update...
r201 :update ],
pramook
initial commit...
r0 :redirect_to => { :action => :list }
def list
jittat
moved to ror 2.0.2, add user rel to model submission...
r1 @problems = Problem.find(:all, :order => 'date_added DESC')
pramook
initial commit...
r0 end
def show
@problem = Problem.find(params[:id])
end
def new
@problem = Problem.new
jittat
[web] refactor problem description, some styling...
r92 @description = nil
pramook
initial commit...
r0 end
def create
@problem = Problem.new(params[:problem])
jittat
[web] refactor problem description, some styling...
r92 @description = Description.new(params[:description])
if @description.body!=''
if !@description.save
render :action => new and return
end
else
@description = nil
end
@problem.description = @description
pramook
initial commit...
r0 if @problem.save
flash[:notice] = 'Problem was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
jittat
added quick new problem...
r171 def quick_create
@problem = Problem.new(params[:problem])
@problem.full_name = @problem.name if @problem.full_name == ''
@problem.full_score = 100
@problem.available = false
@problem.test_allowed = true
@problem.output_only = false
@problem.date_added = Time.new
if @problem.save
flash[:notice] = 'Problem was successfully created.'
redirect_to :action => 'list'
else
flash[:notice] = 'Error saving problem'
redirect_to :action => 'list'
end
end
pramook
initial commit...
r0 def edit
@problem = Problem.find(params[:id])
jittat
[web] refactor problem description, some styling...
r92 @description = @problem.description
pramook
initial commit...
r0 end
def update
@problem = Problem.find(params[:id])
jittat
[web] refactor problem description, some styling...
r92 @description = @problem.description
if @description == nil and params[:description][:body]!=''
@description = Description.new(params[:description])
if !@description.save
flash[:notice] = 'Error saving description'
render :action => 'edit' and return
end
@problem.description = @description
elsif @description!=nil
if !@description.update_attributes(params[:description])
flash[:notice] = 'Error saving description'
render :action => 'edit' and return
end
end
add option to update PDF file of a problem in /problem/edit/:id
r453 if params[:file] and params[:file].content_type != 'application/pdf'
flash[:notice] = 'Error: Uploaded file is not PDF'
render :action => 'edit' and return
end
pramook
initial commit...
r0 if @problem.update_attributes(params[:problem])
flash[:notice] = 'Problem was successfully updated.'
add option to update PDF file of a problem in /problem/edit/:id
r453 unless params[:file] == nil or params[:file] == ''
flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.'
out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
if not FileTest.exists? out_dirname
Dir.mkdir out_dirname
end
out_filename = "#{out_dirname}/#{@problem.name}.pdf"
if FileTest.exists? out_filename
File.delete out_filename
end
File.open(out_filename,"wb") do |file|
file.write(params[:file].read)
end
@problem.description_filename = "#{@problem.name}.pdf"
@problem.save
end
pramook
initial commit...
r0 redirect_to :action => 'show', :id => @problem
else
render :action => 'edit'
end
end
def destroy
Problem.find(params[:id]).destroy
redirect_to :action => 'list'
end
jittat
change problem toggle to ajax...
r147 def toggle
jittat
forgot to change prob controller back before commit last change...
r149 @problem = Problem.find(params[:id])
@problem.available = !(@problem.available)
@problem.save
pramook
initial commit...
r0 end
jittat
[web] in problems, added turn_all_off, and improved ui...
r56 def turn_all_off
Problem.find(:all,
:conditions => "available = 1").each do |problem|
problem.available = false
problem.save
end
redirect_to :action => 'list'
end
jittat
[web] fixed test page crashes when problem is deleted...
r101 def turn_all_on
Problem.find(:all,
:conditions => "available = 0").each do |problem|
problem.available = true
problem.save
end
redirect_to :action => 'list'
end
pramook
initial commit...
r0 def stat
@problem = Problem.find(params[:id])
add more problem stat
r457 unless @problem.available or session[:admin]
jittat
[web] uploading output-only submission...
r100 redirect_to :controller => 'main', :action => 'list'
add more problem stat
r457 return
jittat
[web] uploading output-only submission...
r100 end
add more problem stat
r457 @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id)
#stat summary
range =65
@histogram = { data: Array.new(range,0), summary: {} }
user = Hash.new(0)
@submissions.find_each do |sub|
d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
@histogram[:data][d.to_i] += 1 if d < range
fix very little typo
r503 user[sub.user_id] = [user[sub.user_id], (sub.try(:points) >= @problem.full_score) ? 1 : 0].max
add more problem stat
r457 end
@histogram[:summary][:max] = [@histogram[:data].max,1].max
@summary = { attempt: user.count, solve: 0 }
user.each_value { |v| @summary[:solve] += 1 if v == 1 }
pramook
initial commit...
r0 end
jittat
added problem date_added bulk update...
r201
def manage
@problems = Problem.find(:all, :order => 'date_added DESC')
end
def do_manage
if params.has_key? 'change_date_added'
change_date_added
add jquery to manage problem, now we can select a range of problem
r456 elsif params.has_key? 'add_to_contest'
Jittat Fakcharoenphol
manages problems in contests
r279 add_to_contest
add jquery to manage problem, now we can select a range of problem
r456 elsif params.has_key? 'enable_problem'
set_available(true)
elsif params.has_key? 'disable_problem'
set_available(false)
jittat
added problem date_added bulk update...
r201 end
redirect_to :action => 'manage'
end
jittat
added problem import...
r204 def import
Jittat Fakcharoenphol
added options to enable test-pair import
r212 @allow_test_pair_import = allow_test_pair_import?
jittat
added problem import...
r204 end
def do_import
Jittat Fakcharoenphol
imports test pairs
r210 old_problem = Problem.find_by_name(params[:name])
Jittat Fakcharoenphol
added options to enable test-pair import
r212 if !allow_test_pair_import? and params.has_key? :import_to_db
params.delete :import_to_db
end
Jittat Fakcharoenphol
imports test pairs
r210 @problem, import_log = Problem.create_from_import_form_params(params,
old_problem)
jittat
added problem import...
r204
Jittat Fakcharoenphol
uses empty? instead of length to check model validation errors when importing problems
r338 if !@problem.errors.empty?
jittat
added problem import...
r204 render :action => 'import' and return
end
jittat
import problem replaced old one, fixed small problems...
r205 if old_problem!=nil
flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
end
jittat
added problem import...
r204 @log = import_log
end
Jittat Fakcharoenphol
manages problems in contests
r279 def remove_contest
problem = Problem.find(params[:id])
contest = Contest.find(params[:contest_id])
if problem!=nil and contest!=nil
problem.contests.delete(contest)
end
redirect_to :action => 'manage'
end
jittat
added problem date_added bulk update...
r201 ##################################
protected
Jittat Fakcharoenphol
added options to enable test-pair import
r212 def allow_test_pair_import?
if defined? ALLOW_TEST_PAIR_IMPORT
return ALLOW_TEST_PAIR_IMPORT
else
return false
end
end
jittat
added problem date_added bulk update...
r201 def change_date_added
problems = get_problems_from_params
year = params[:date_added][:year].to_i
month = params[:date_added][:month].to_i
day = params[:date_added][:day].to_i
date = Date.new(year,month,day)
problems.each do |p|
p.date_added = date
p.save
end
end
Jittat Fakcharoenphol
manages problems in contests
r279 def add_to_contest
problems = get_problems_from_params
contest = Contest.find(params[:contest][:id])
if contest!=nil and contest.enabled
problems.each do |p|
p.contests << contest
end
end
end
add jquery to manage problem, now we can select a range of problem
r456 def set_available(avail)
problems = get_problems_from_params
problems.each do |p|
p.available = avail
p.save
end
end
jittat
added problem date_added bulk update...
r201 def get_problems_from_params
problems = []
params.keys.each do |k|
if k.index('prob-')==0
add jquery to manage problem, now we can select a range of problem
r456 name, id, order = k.split('-')
jittat
added problem date_added bulk update...
r201 problems << Problem.find(id)
end
end
problems
end
add more problem stat
r457 def get_problems_stat
end
pramook
initial commit...
r0 end