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,63 +1,66
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
40 end
43 end
41 @problem.description = @description
44 @problem.description = @description
42 if @problem.save
45 if @problem.save
43 flash[:notice] = 'Problem was successfully created.'
46 flash[:notice] = 'Problem was successfully created.'
44 redirect_to :action => 'list'
47 redirect_to :action => 'list'
45 else
48 else
46 render :action => 'new'
49 render :action => 'new'
47 end
50 end
48 end
51 end
49
52
50 def quick_create
53 def quick_create
51 @problem = Problem.new(params[:problem])
54 @problem = Problem.new(params[:problem])
52 @problem.full_name = @problem.name if @problem.full_name == ''
55 @problem.full_name = @problem.name if @problem.full_name == ''
53 @problem.full_score = 100
56 @problem.full_score = 100
54 @problem.available = false
57 @problem.available = false
55 @problem.test_allowed = true
58 @problem.test_allowed = true
56 @problem.output_only = false
59 @problem.output_only = false
57 @problem.date_added = Time.new
60 @problem.date_added = Time.new
58 if @problem.save
61 if @problem.save
59 flash[:notice] = 'Problem was successfully created.'
62 flash[:notice] = 'Problem was successfully created.'
60 redirect_to :action => 'list'
63 redirect_to :action => 'list'
61 else
64 else
62 flash[:notice] = 'Error saving problem'
65 flash[:notice] = 'Error saving problem'
63 redirect_to :action => 'list'
66 redirect_to :action => 'list'
@@ -85,49 +88,87
85 render :action => 'edit' and return
88 render :action => 'edit' and return
86 end
89 end
87 end
90 end
88 if @problem.update_attributes(params[:problem])
91 if @problem.update_attributes(params[:problem])
89 flash[:notice] = 'Problem was successfully updated.'
92 flash[:notice] = 'Problem was successfully updated.'
90 redirect_to :action => 'show', :id => @problem
93 redirect_to :action => 'show', :id => @problem
91 else
94 else
92 render :action => 'edit'
95 render :action => 'edit'
93 end
96 end
94 end
97 end
95
98
96 def destroy
99 def destroy
97 Problem.find(params[:id]).destroy
100 Problem.find(params[:id]).destroy
98 redirect_to :action => 'list'
101 redirect_to :action => 'list'
99 end
102 end
100
103
101 def toggle
104 def toggle
102 @problem = Problem.find(params[:id])
105 @problem = Problem.find(params[:id])
103 @problem.available = !(@problem.available)
106 @problem.available = !(@problem.available)
104 @problem.save
107 @problem.save
105 end
108 end
106
109
107 def turn_all_off
110 def turn_all_off
108 Problem.find(:all,
111 Problem.find(:all,
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,56 +1,57
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 %>
36 <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>">
37 <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>">
37 <% @problem=problem %>
38 <% @problem=problem %>
38 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
39 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
39 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
40 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
40 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
41 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
41 <td><%= problem.date_added %></td>
42 <td><%= problem.date_added %></td>
42 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
43 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
43 <td><%= problem.test_allowed %></td>
44 <td><%= problem.test_allowed %></td>
44
45
45 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
46 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
46 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
47 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
47 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
48 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
48 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
49 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
49 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
50 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
50 </tr>
51 </tr>
51 <% end %>
52 <% end %>
52 </table>
53 </table>
53
54
54 <br />
55 <br />
55
56
56 <%= link_to 'New problem', :action => 'new' %>
57 <%= link_to 'New problem', :action => 'new' %>
You need to be logged in to leave comments. Login now