diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -12,7 +12,10 @@ end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) - verify :method => :post, :only => [ :destroy, :create, :update ], + verify :method => :post, :only => [ :destroy, + :create, :quick_create, + :do_manage, + :update ], :redirect_to => { :action => :list } def list @@ -130,4 +133,42 @@ @submissions = Submission.find_all_last_by_problem(params[:id]) end end + + def manage + @problems = Problem.find(:all, :order => 'date_added DESC') + end + + def do_manage + if params.has_key? 'change_date_added' + change_date_added + end + redirect_to :action => 'manage' + end + + ################################## + protected + + 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 + + def get_problems_from_params + problems = [] + params.keys.each do |k| + if k.index('prob-')==0 + name, id = k.split('-') + problems << Problem.find(id) + end + end + problems + end + end diff --git a/app/views/problems/list.rhtml b/app/views/problems/list.rhtml --- a/app/views/problems/list.rhtml +++ b/app/views/problems/list.rhtml @@ -6,9 +6,10 @@

Listing problems

-<%= link_to 'New problem', :action => 'new' %> -<%= link_to 'Turn off all problems', :action => 'turn_all_off' %> -<%= link_to 'Turn on all problems', :action => 'turn_all_on' %> +<%= link_to '[New problem]', :action => 'new' %> +<%= link_to '[Manage problems]', :action => 'manage' %> +<%= link_to '[Turn off all problems]', :action => 'turn_all_off' %> +<%= link_to '[Turn on all problems]', :action => 'turn_all_on' %>

diff --git a/app/views/problems/manage.html.haml b/app/views/problems/manage.html.haml new file mode 100644 --- /dev/null +++ b/app/views/problems/manage.html.haml @@ -0,0 +1,32 @@ +- content_for :head do + = stylesheet_link_tag 'problems' + = javascript_include_tag :defaults + +%h1 Manage problems + +%p= link_to '[Back to problem list]', :action => 'list' + +- form_tag :action=>'do_manage' do + .submitbox + What do you want to do? + %br/ + %ul + %li + Change date added to + = select_date Date.current, :prefix => 'date_added' +     + = submit_tag 'Change', :name => 'change_date_added' + %table + %tr + %th/ + %th Name + %th Full name + %th Date added + + - for problem in @problems + %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"} + %td= check_box_tag "prob-#{problem.id}" + %td= problem.name + %td= problem.full_name + %td= problem.date_added +