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 +
@@ -9,13 +9,16
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
@@ -127,7 +130,45
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
@@ -3,15 +3,16
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>
You need to be logged in to leave comments. Login now