Show More
Commit Description:
added quick new problem...
Commit Description:
added quick new problem git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@369 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/controllers/problems_controller.rb | 133 lines | 3.4 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)
verify :method => :post, :only => [ :destroy, :create, :update ],
: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
pramook
initial commit...
r0 if @problem.update_attributes(params[:problem])
flash[:notice] = 'Problem was successfully updated.'
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])
jittat
[web] uploading output-only submission...
r100 if !@problem.available
redirect_to :controller => 'main', :action => 'list'
else
@submissions = Submission.find_all_last_by_problem(params[:id])
end
pramook
initial commit...
r0 end
end