Description:
added problem date_added bulk update git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@432 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r201:ac6aa35270da - - 3 files changed: 78 inserted, 4 deleted

@@ -0,0 +1,32
1 + - content_for :head do
2 + = stylesheet_link_tag 'problems'
3 + = javascript_include_tag :defaults
4 +
5 + %h1 Manage problems
6 +
7 + %p= link_to '[Back to problem list]', :action => 'list'
8 +
9 + - form_tag :action=>'do_manage' do
10 + .submitbox
11 + What do you want to do?
12 + %br/
13 + %ul
14 + %li
15 + Change date added to
16 + = select_date Date.current, :prefix => 'date_added'
17 +    
18 + = submit_tag 'Change', :name => 'change_date_added'
19 + %table
20 + %tr
21 + %th/
22 + %th Name
23 + %th Full name
24 + %th Date added
25 +
26 + - for problem in @problems
27 + %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
28 + %td= check_box_tag "prob-#{problem.id}"
29 + %td= problem.name
30 + %td= problem.full_name
31 + %td= problem.date_added
32 +
@@ -1,39 +1,42
1 class ProblemsController < ApplicationController
1 class ProblemsController < ApplicationController
2
2
3 before_filter :authenticate, :authorization
3 before_filter :authenticate, :authorization
4
4
5 in_place_edit_for :problem, :name
5 in_place_edit_for :problem, :name
6 in_place_edit_for :problem, :full_name
6 in_place_edit_for :problem, :full_name
7 in_place_edit_for :problem, :full_score
7 in_place_edit_for :problem, :full_score
8
8
9 def index
9 def index
10 list
10 list
11 render :action => 'list'
11 render :action => 'list'
12 end
12 end
13
13
14 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
14 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15 - verify :method => :post, :only => [ :destroy, :create, :update ],
15 + verify :method => :post, :only => [ :destroy,
16 + :create, :quick_create,
17 + :do_manage,
18 + :update ],
16 :redirect_to => { :action => :list }
19 :redirect_to => { :action => :list }
17
20
18 def list
21 def list
19 @problems = Problem.find(:all, :order => 'date_added DESC')
22 @problems = Problem.find(:all, :order => 'date_added DESC')
20 end
23 end
21
24
22 def show
25 def show
23 @problem = Problem.find(params[:id])
26 @problem = Problem.find(params[:id])
24 end
27 end
25
28
26 def new
29 def new
27 @problem = Problem.new
30 @problem = Problem.new
28 @description = nil
31 @description = nil
29 end
32 end
30
33
31 def create
34 def create
32 @problem = Problem.new(params[:problem])
35 @problem = Problem.new(params[:problem])
33 @description = Description.new(params[:description])
36 @description = Description.new(params[:description])
34 if @description.body!=''
37 if @description.body!=''
35 if !@description.save
38 if !@description.save
36 render :action => new and return
39 render :action => new and return
37 end
40 end
38 else
41 else
39 @description = nil
42 @description = nil
@@ -109,25 +112,63
109 :conditions => "available = 1").each do |problem|
112 :conditions => "available = 1").each do |problem|
110 problem.available = false
113 problem.available = false
111 problem.save
114 problem.save
112 end
115 end
113 redirect_to :action => 'list'
116 redirect_to :action => 'list'
114 end
117 end
115
118
116 def turn_all_on
119 def turn_all_on
117 Problem.find(:all,
120 Problem.find(:all,
118 :conditions => "available = 0").each do |problem|
121 :conditions => "available = 0").each do |problem|
119 problem.available = true
122 problem.available = true
120 problem.save
123 problem.save
121 end
124 end
122 redirect_to :action => 'list'
125 redirect_to :action => 'list'
123 end
126 end
124
127
125 def stat
128 def stat
126 @problem = Problem.find(params[:id])
129 @problem = Problem.find(params[:id])
127 if !@problem.available
130 if !@problem.available
128 redirect_to :controller => 'main', :action => 'list'
131 redirect_to :controller => 'main', :action => 'list'
129 else
132 else
130 @submissions = Submission.find_all_last_by_problem(params[:id])
133 @submissions = Submission.find_all_last_by_problem(params[:id])
131 end
134 end
132 end
135 end
136 +
137 + def manage
138 + @problems = Problem.find(:all, :order => 'date_added DESC')
139 + end
140 +
141 + def do_manage
142 + if params.has_key? 'change_date_added'
143 + change_date_added
144 + end
145 + redirect_to :action => 'manage'
146 + end
147 +
148 + ##################################
149 + protected
150 +
151 + def change_date_added
152 + problems = get_problems_from_params
153 + year = params[:date_added][:year].to_i
154 + month = params[:date_added][:month].to_i
155 + day = params[:date_added][:day].to_i
156 + date = Date.new(year,month,day)
157 + problems.each do |p|
158 + p.date_added = date
159 + p.save
160 + end
161 + end
162 +
163 + def get_problems_from_params
164 + problems = []
165 + params.keys.each do |k|
166 + if k.index('prob-')==0
167 + name, id = k.split('-')
168 + problems << Problem.find(id)
169 + end
170 + end
171 + problems
172 + end
173 +
133 end
174 end
@@ -1,35 +1,36
1 <% content_for :head do %>
1 <% content_for :head do %>
2 <%= stylesheet_link_tag 'problems' %>
2 <%= stylesheet_link_tag 'problems' %>
3 <%= javascript_include_tag :defaults %>
3 <%= javascript_include_tag :defaults %>
4 <% end %>
4 <% end %>
5
5
6 <h1>Listing problems</h1>
6 <h1>Listing problems</h1>
7
7
8 <p>
8 <p>
9 - <%= link_to 'New problem', :action => 'new' %>
9 + <%= link_to '[New problem]', :action => 'new' %>
10 - <%= link_to 'Turn off all problems', :action => 'turn_all_off' %>
10 + <%= link_to '[Manage problems]', :action => 'manage' %>
11 - <%= link_to 'Turn on all problems', :action => 'turn_all_on' %>
11 + <%= link_to '[Turn off all problems]', :action => 'turn_all_off' %>
12 + <%= link_to '[Turn on all problems]', :action => 'turn_all_on' %>
12 </p>
13 </p>
13
14
14 <div class="submitbox">
15 <div class="submitbox">
15 <% form_tag :action => 'quick_create' do %>
16 <% form_tag :action => 'quick_create' do %>
16 <b>Quick New:</b>
17 <b>Quick New:</b>
17 <label for="problem_name">Name</label>
18 <label for="problem_name">Name</label>
18 <%= text_field 'problem', 'name' %> |
19 <%= text_field 'problem', 'name' %> |
19 <label for="problem_full_name">Full name</label>
20 <label for="problem_full_name">Full name</label>
20 <%= text_field 'problem', 'full_name' %>
21 <%= text_field 'problem', 'full_name' %>
21 <%= submit_tag "Create" %>
22 <%= submit_tag "Create" %>
22 <% end %>
23 <% end %>
23 </div>
24 </div>
24
25
25 <table>
26 <table>
26 <tr>
27 <tr>
27 <th>Name</th>
28 <th>Name</th>
28 <th>Full name</th>
29 <th>Full name</th>
29 <th>Full score</th>
30 <th>Full score</th>
30 <th>Date added</th>
31 <th>Date added</th>
31 <th>Avail?</th>
32 <th>Avail?</th>
32 <th>Test?</th>
33 <th>Test?</th>
33 </tr>
34 </tr>
34
35
35 <% for problem in @problems %>
36 <% for problem in @problems %>
You need to be logged in to leave comments. Login now