Show More
Commit Description:
prob manage
Commit Description:
prob manage
File last commit:
Show/Diff file:
Action:
app/controllers/problems_controller.rb | 285 lines | 7.3 KiB | text/x-ruby | RubyLexer |
pramook
initial commit...
r0 class ProblemsController < ApplicationController
modernize problem
r876 include ActiveStorage::SetCurrent
allow ta to view problem stat
r803 before_action :admin_authorization, except: [:stat]
modernize problem
r876 before_action :set_problem, only: [:show, :edit, :update, :destroy, :get_statement, :toggle, :toggle_test, :toggle_view_testcase, :stat]
allow ta to view problem stat
r803 before_action only: [:stat] do
authorization_by_roles(['admin','ta'])
end
more test and clean up authorization
r756
modernize problem
r876
pramook
initial commit...
r0 def index
change find(:xxx) to correct syntax for rails 4
r619 @problems = Problem.order(date_added: :desc)
pramook
initial commit...
r0 end
def show
modernize problem
r876 end
#get statement download link
def get_statement
unless @current_user.can_view_problem? @problem
redirect_to list_main_path, error: 'You are not authorized to access this file'
return
end
if params[:ext]=='pdf'
content_type = 'application/pdf'
else
content_type = 'application/octet-stream'
end
filename = @problem.statement.filename.to_s
data =@problem.statement.download
send_data data, stream: false, disposition: 'inline', filename: filename, type: content_type
pramook
initial commit...
r0 end
def new
@problem = Problem.new
end
def create
NEED TESTING...
r637 @problem = Problem.new(problem_params)
pramook
initial commit...
r0 if @problem.save
modernize problem
r876 redirect_to action: :index, notice: 'Problem was successfully created.'
pramook
initial commit...
r0 else
render :action => 'new'
end
end
jittat
added quick new problem...
r171 def quick_create
NEED TESTING...
r637 @problem = Problem.new(problem_params)
jittat
added quick new problem...
r171 @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.'
problem toggle on/off
r558 redirect_to action: :index
jittat
added quick new problem...
r171 else
flash[:notice] = 'Error saving problem'
problem toggle on/off
r558 redirect_to action: :index
jittat
added quick new problem...
r171 end
end
pramook
initial commit...
r0 def edit
jittat
[web] refactor problem description, some styling...
r92 @description = @problem.description
pramook
initial commit...
r0 end
def update
modernize problem
r876 if problem_params[:statement] && problem_params[:statement].content_type != 'application/pdf'
flash[:error] = 'Error: Uploaded file is not PDF'
render :action => 'edit'
return
add option to update PDF file of a problem in /problem/edit/:id
r453 end
wip
r869 if @problem.update(problem_params)
modernize problem
r876 flash[:notice] = 'Problem was successfully updated. '
flash[:notice] += 'A new statement PDF is uploaded' if problem_params[:statement]
@problem.save
redirect_to edit_problem_path(@problem)
pramook
initial commit...
r0 else
render :action => 'edit'
end
end
def destroy
modernize problem
r876 @problem.destroy
fix destroy for user and problem
r605 redirect_to action: :index
pramook
initial commit...
r0 end
jittat
change problem toggle to ajax...
r147 def toggle
wip
r869 @problem.update(available: !(@problem.available) )
problem toggle on/off
r558 respond_to do |format|
* DRY the toggle button via application_helper.rb#toggle_button and _toggle_button.js.haml...
r562 format.js { }
problem toggle on/off
r558 end
pramook
initial commit...
r0 end
- add problem manage toggle test interface...
r569 def toggle_test
wip
r869 @problem.update(test_allowed: !(@problem.test_allowed?) )
- add problem manage toggle test interface...
r569 respond_to do |format|
format.js { }
end
end
- add view testcase toggle for each problem...
r632 def toggle_view_testcase
wip
r869 @problem.update(view_testcase: !(@problem.view_testcase?) )
- add view testcase toggle for each problem...
r632 respond_to do |format|
format.js { }
end
end
jittat
[web] in problems, added turn_all_off, and improved ui...
r56 def turn_all_off
change find(:xxx) to correct syntax for rails 4
r619 Problem.available.all.each do |problem|
jittat
[web] in problems, added turn_all_off, and improved ui...
r56 problem.available = false
problem.save
end
problem toggle on/off
r558 redirect_to action: :index
jittat
[web] in problems, added turn_all_off, and improved ui...
r56 end
jittat
[web] fixed test page crashes when problem is deleted...
r101 def turn_all_on
change find(:xxx) to correct syntax for rails 4
r619 Problem.where.not(available: true).each do |problem|
jittat
[web] fixed test page crashes when problem is deleted...
r101 problem.available = true
problem.save
end
problem toggle on/off
r558 redirect_to action: :index
jittat
[web] fixed test page crashes when problem is deleted...
r101 end
pramook
initial commit...
r0 def stat
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 language
r697 @submissions = Submission.includes(:user).includes(:language).where(problem_id: params[:id]).order(:user_id,:id)
add more problem stat
r457
#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
* multiple ip login fix...
r531 user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @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 }
wip
r880
#for new graph
@chart_dataset = @problem.get_jschart_history.to_json.html_safe
pramook
initial commit...
r0 end
jittat
added problem date_added bulk update...
r201
def manage
prob manage
r882 @problems = Problem.order(date_added: :desc).includes(:tags)
jittat
added problem date_added bulk update...
r201 end
def do_manage
prob manage
r882 change_date_added if params[:change_date_added] == '1' && params[:date_added].strip.empty? == false
add_to_contest if params.has_key? 'add_to_contest'
set_available(params[:enable] == 'yes') if params[:change_enable] == '1'
if params[:add_group] == '1'
add problem group
r672 group = Group.find(params[:group_id])
make group_user and group_problem unique
r678 ok = []
failed = []
add problem group
r672 get_problems_from_params.each do |p|
make group_user and group_problem unique
r678 begin
group.problems << p
ok << p.full_name
rescue => e
failed << p.full_name
end
add problem group
r672 end
make group_user and group_problem unique
r678 flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0
flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0
prob manage
r882 end
if params[:add_tags] == '1'
get_problems_from_params.each { |p| p.tag_ids += params[:tag_ids] }
jittat
added problem date_added bulk update...
r201 end
make group_user and group_problem unique
r678
jittat
added problem date_added bulk update...
r201 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
change datetime picker widget
r692 date = Date.parse(params[:date_added])
jittat
added problem date_added bulk update...
r201 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
- fix pdf loading fail
r634 private
modernize problem
r876 def set_problem
@problem = Problem.find(params[:id])
end
- fix pdf loading fail
r634 def problem_params
modernize problem
r876 params.require(:problem).permit(:name, :full_name, :full_score, :change_date_added, :date_added, :available,
:test_allowed, :output_only, :url, :description, :statement, :description, tag_ids:[])
- fix pdf loading fail
r634 end
still upgrading
r753 def description_params
merge algo-bm to master
r778 params.require(:description).permit(:body, :markdowned)
still upgrading
r753 end
pramook
initial commit...
r0 end