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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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,133 +1,174 | |||
|
1 | 1 | class ProblemsController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :authorization |
|
4 | 4 | |
|
5 | 5 | in_place_edit_for :problem, :name |
|
6 | 6 | in_place_edit_for :problem, :full_name |
|
7 | 7 | in_place_edit_for :problem, :full_score |
|
8 | 8 | |
|
9 | 9 | def index |
|
10 | 10 | list |
|
11 | 11 | render :action => 'list' |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
15 |
- verify :method => :post, :only => [ :destroy, |
|
|
15 | + verify :method => :post, :only => [ :destroy, | |
|
16 | + :create, :quick_create, | |
|
17 | + :do_manage, | |
|
18 | + :update ], | |
|
16 | 19 | :redirect_to => { :action => :list } |
|
17 | 20 | |
|
18 | 21 | def list |
|
19 | 22 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
20 | 23 | end |
|
21 | 24 | |
|
22 | 25 | def show |
|
23 | 26 | @problem = Problem.find(params[:id]) |
|
24 | 27 | end |
|
25 | 28 | |
|
26 | 29 | def new |
|
27 | 30 | @problem = Problem.new |
|
28 | 31 | @description = nil |
|
29 | 32 | end |
|
30 | 33 | |
|
31 | 34 | def create |
|
32 | 35 | @problem = Problem.new(params[:problem]) |
|
33 | 36 | @description = Description.new(params[:description]) |
|
34 | 37 | if @description.body!='' |
|
35 | 38 | if !@description.save |
|
36 | 39 | render :action => new and return |
|
37 | 40 | end |
|
38 | 41 | else |
|
39 | 42 | @description = nil |
|
40 | 43 | end |
|
41 | 44 | @problem.description = @description |
|
42 | 45 | if @problem.save |
|
43 | 46 | flash[:notice] = 'Problem was successfully created.' |
|
44 | 47 | redirect_to :action => 'list' |
|
45 | 48 | else |
|
46 | 49 | render :action => 'new' |
|
47 | 50 | end |
|
48 | 51 | end |
|
49 | 52 | |
|
50 | 53 | def quick_create |
|
51 | 54 | @problem = Problem.new(params[:problem]) |
|
52 | 55 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
53 | 56 | @problem.full_score = 100 |
|
54 | 57 | @problem.available = false |
|
55 | 58 | @problem.test_allowed = true |
|
56 | 59 | @problem.output_only = false |
|
57 | 60 | @problem.date_added = Time.new |
|
58 | 61 | if @problem.save |
|
59 | 62 | flash[:notice] = 'Problem was successfully created.' |
|
60 | 63 | redirect_to :action => 'list' |
|
61 | 64 | else |
|
62 | 65 | flash[:notice] = 'Error saving problem' |
|
63 | 66 | redirect_to :action => 'list' |
|
64 | 67 | end |
|
65 | 68 | end |
|
66 | 69 | |
|
67 | 70 | def edit |
|
68 | 71 | @problem = Problem.find(params[:id]) |
|
69 | 72 | @description = @problem.description |
|
70 | 73 | end |
|
71 | 74 | |
|
72 | 75 | def update |
|
73 | 76 | @problem = Problem.find(params[:id]) |
|
74 | 77 | @description = @problem.description |
|
75 | 78 | if @description == nil and params[:description][:body]!='' |
|
76 | 79 | @description = Description.new(params[:description]) |
|
77 | 80 | if !@description.save |
|
78 | 81 | flash[:notice] = 'Error saving description' |
|
79 | 82 | render :action => 'edit' and return |
|
80 | 83 | end |
|
81 | 84 | @problem.description = @description |
|
82 | 85 | elsif @description!=nil |
|
83 | 86 | if !@description.update_attributes(params[:description]) |
|
84 | 87 | flash[:notice] = 'Error saving description' |
|
85 | 88 | render :action => 'edit' and return |
|
86 | 89 | end |
|
87 | 90 | end |
|
88 | 91 | if @problem.update_attributes(params[:problem]) |
|
89 | 92 | flash[:notice] = 'Problem was successfully updated.' |
|
90 | 93 | redirect_to :action => 'show', :id => @problem |
|
91 | 94 | else |
|
92 | 95 | render :action => 'edit' |
|
93 | 96 | end |
|
94 | 97 | end |
|
95 | 98 | |
|
96 | 99 | def destroy |
|
97 | 100 | Problem.find(params[:id]).destroy |
|
98 | 101 | redirect_to :action => 'list' |
|
99 | 102 | end |
|
100 | 103 | |
|
101 | 104 | def toggle |
|
102 | 105 | @problem = Problem.find(params[:id]) |
|
103 | 106 | @problem.available = !(@problem.available) |
|
104 | 107 | @problem.save |
|
105 | 108 | end |
|
106 | 109 | |
|
107 | 110 | def turn_all_off |
|
108 | 111 | Problem.find(:all, |
|
109 | 112 | :conditions => "available = 1").each do |problem| |
|
110 | 113 | problem.available = false |
|
111 | 114 | problem.save |
|
112 | 115 | end |
|
113 | 116 | redirect_to :action => 'list' |
|
114 | 117 | end |
|
115 | 118 | |
|
116 | 119 | def turn_all_on |
|
117 | 120 | Problem.find(:all, |
|
118 | 121 | :conditions => "available = 0").each do |problem| |
|
119 | 122 | problem.available = true |
|
120 | 123 | problem.save |
|
121 | 124 | end |
|
122 | 125 | redirect_to :action => 'list' |
|
123 | 126 | end |
|
124 | 127 | |
|
125 | 128 | def stat |
|
126 | 129 | @problem = Problem.find(params[:id]) |
|
127 | 130 | if !@problem.available |
|
128 | 131 | redirect_to :controller => 'main', :action => 'list' |
|
129 | 132 | else |
|
130 | 133 | @submissions = Submission.find_all_last_by_problem(params[:id]) |
|
131 | 134 | end |
|
132 | 135 | end |
|
136 | + | |
|
137 | + def manage | |
|
138 | + @problems = Problem.find(:all, :order => 'date_added DESC') | |
|
133 | 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 | + | |
|
174 | + end |
@@ -1,56 +1,57 | |||
|
1 | 1 | <% content_for :head do %> |
|
2 | 2 | <%= stylesheet_link_tag 'problems' %> |
|
3 | 3 | <%= javascript_include_tag :defaults %> |
|
4 | 4 | <% end %> |
|
5 | 5 | |
|
6 | 6 | <h1>Listing problems</h1> |
|
7 | 7 | |
|
8 | 8 | <p> |
|
9 | - <%= link_to 'New problem', :action => 'new' %> | |
|
10 |
- <%= link_to ' |
|
|
11 |
- <%= link_to 'Turn o |
|
|
9 | + <%= link_to '[New problem]', :action => 'new' %> | |
|
10 | + <%= link_to '[Manage problems]', :action => 'manage' %> | |
|
11 | + <%= link_to '[Turn off all problems]', :action => 'turn_all_off' %> | |
|
12 | + <%= link_to '[Turn on all problems]', :action => 'turn_all_on' %> | |
|
12 | 13 | </p> |
|
13 | 14 | |
|
14 | 15 | <div class="submitbox"> |
|
15 | 16 | <% form_tag :action => 'quick_create' do %> |
|
16 | 17 | <b>Quick New:</b> |
|
17 | 18 | <label for="problem_name">Name</label> |
|
18 | 19 | <%= text_field 'problem', 'name' %> | |
|
19 | 20 | <label for="problem_full_name">Full name</label> |
|
20 | 21 | <%= text_field 'problem', 'full_name' %> |
|
21 | 22 | <%= submit_tag "Create" %> |
|
22 | 23 | <% end %> |
|
23 | 24 | </div> |
|
24 | 25 | |
|
25 | 26 | <table> |
|
26 | 27 | <tr> |
|
27 | 28 | <th>Name</th> |
|
28 | 29 | <th>Full name</th> |
|
29 | 30 | <th>Full score</th> |
|
30 | 31 | <th>Date added</th> |
|
31 | 32 | <th>Avail?</th> |
|
32 | 33 | <th>Test?</th> |
|
33 | 34 | </tr> |
|
34 | 35 | |
|
35 | 36 | <% for problem in @problems %> |
|
36 | 37 | <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>"> |
|
37 | 38 | <% @problem=problem %> |
|
38 | 39 | <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td> |
|
39 | 40 | <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td> |
|
40 | 41 | <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td> |
|
41 | 42 | <td><%= problem.date_added %></td> |
|
42 | 43 | <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td> |
|
43 | 44 | <td><%= problem.test_allowed %></td> |
|
44 | 45 | |
|
45 | 46 | <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td> |
|
46 | 47 | <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td> |
|
47 | 48 | <td><%= link_to '[Show]', :action => 'show', :id => problem %></td> |
|
48 | 49 | <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td> |
|
49 | 50 | <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td> |
|
50 | 51 | </tr> |
|
51 | 52 | <% end %> |
|
52 | 53 | </table> |
|
53 | 54 | |
|
54 | 55 | <br /> |
|
55 | 56 | |
|
56 | 57 | <%= link_to 'New problem', :action => 'new' %> |
You need to be logged in to leave comments.
Login now