Description:
[web] fixed test page crashes when problem is deleted git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@193 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

r101:4a05c0a30468 - - 5 files changed: 28 inserted, 8 deleted

@@ -52,57 +52,66
52 @description = @problem.description
52 @description = @problem.description
53 end
53 end
54
54
55 def update
55 def update
56 @problem = Problem.find(params[:id])
56 @problem = Problem.find(params[:id])
57 @description = @problem.description
57 @description = @problem.description
58 if @description == nil and params[:description][:body]!=''
58 if @description == nil and params[:description][:body]!=''
59 @description = Description.new(params[:description])
59 @description = Description.new(params[:description])
60 if !@description.save
60 if !@description.save
61 flash[:notice] = 'Error saving description'
61 flash[:notice] = 'Error saving description'
62 render :action => 'edit' and return
62 render :action => 'edit' and return
63 end
63 end
64 @problem.description = @description
64 @problem.description = @description
65 elsif @description!=nil
65 elsif @description!=nil
66 if !@description.update_attributes(params[:description])
66 if !@description.update_attributes(params[:description])
67 flash[:notice] = 'Error saving description'
67 flash[:notice] = 'Error saving description'
68 render :action => 'edit' and return
68 render :action => 'edit' and return
69 end
69 end
70 end
70 end
71 if @problem.update_attributes(params[:problem])
71 if @problem.update_attributes(params[:problem])
72 flash[:notice] = 'Problem was successfully updated.'
72 flash[:notice] = 'Problem was successfully updated.'
73 redirect_to :action => 'show', :id => @problem
73 redirect_to :action => 'show', :id => @problem
74 else
74 else
75 render :action => 'edit'
75 render :action => 'edit'
76 end
76 end
77 end
77 end
78
78
79 def destroy
79 def destroy
80 Problem.find(params[:id]).destroy
80 Problem.find(params[:id]).destroy
81 redirect_to :action => 'list'
81 redirect_to :action => 'list'
82 end
82 end
83
83
84 def toggle_avail
84 def toggle_avail
85 problem = Problem.find(params[:id])
85 problem = Problem.find(params[:id])
86 problem.available = !(problem.available)
86 problem.available = !(problem.available)
87 problem.save
87 problem.save
88 redirect_to :action => 'list'
88 redirect_to :action => 'list'
89 end
89 end
90
90
91 def turn_all_off
91 def turn_all_off
92 Problem.find(:all,
92 Problem.find(:all,
93 :conditions => "available = 1").each do |problem|
93 :conditions => "available = 1").each do |problem|
94 problem.available = false
94 problem.available = false
95 problem.save
95 problem.save
96 end
96 end
97 redirect_to :action => 'list'
97 redirect_to :action => 'list'
98 end
98 end
99
99
100 + def turn_all_on
101 + Problem.find(:all,
102 + :conditions => "available = 0").each do |problem|
103 + problem.available = true
104 + problem.save
105 + end
106 + redirect_to :action => 'list'
107 + end
108 +
100 def stat
109 def stat
101 @problem = Problem.find(params[:id])
110 @problem = Problem.find(params[:id])
102 if !@problem.available
111 if !@problem.available
103 redirect_to :controller => 'main', :action => 'list'
112 redirect_to :controller => 'main', :action => 'list'
104 else
113 else
105 @submissions = Submission.find_all_last_by_problem(params[:id])
114 @submissions = Submission.find_all_last_by_problem(params[:id])
106 end
115 end
107 end
116 end
108 end
117 end
@@ -1,44 +1,47
1 <% content_for :head do %>
1 <% content_for :head do %>
2 <%= stylesheet_link_tag 'scaffold' %>
2 <%= stylesheet_link_tag 'scaffold' %>
3 <%= stylesheet_link_tag 'problems' %>
3 <%= stylesheet_link_tag 'problems' %>
4 <%= javascript_include_tag :defaults %>
4 <%= javascript_include_tag :defaults %>
5 <% end %>
5 <% end %>
6
6
7 <h1>Listing problems</h1>
7 <h1>Listing problems</h1>
8
8
9 + <p>
9 <%= link_to 'New problem', :action => 'new' %>
10 <%= link_to 'New problem', :action => 'new' %>
10 - <%= link_to 'Turn off all problems', :action => 'turn_all_off' %><br/>
11 + <%= link_to 'Turn off all problems', :action => 'turn_all_off' %>
12 + <%= link_to 'Turn on all problems', :action => 'turn_all_on' %>
13 + </p>
11
14
12 <table>
15 <table>
13 <tr>
16 <tr>
14 <th>Name</th>
17 <th>Name</th>
15 <th>Full name</th>
18 <th>Full name</th>
16 <th>Full score</th>
19 <th>Full score</th>
17 <th>Date added</th>
20 <th>Date added</th>
18 <th>Avail?</th>
21 <th>Avail?</th>
19 <th>Test?</th>
22 <th>Test?</th>
20 </tr>
23 </tr>
21
24
22 <% for problem in @problems %>
25 <% for problem in @problems %>
23 <tr class="<%= (problem.available) ? "available" : "not-available" %>">
26 <tr class="<%= (problem.available) ? "available" : "not-available" %>">
24 <% @problem=problem %>
27 <% @problem=problem %>
25 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
28 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
26 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
29 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
27 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
30 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
28 <td><%= problem.date_added %></td>
31 <td><%= problem.date_added %></td>
29 <td><%= problem.available %></td>
32 <td><%= problem.available %></td>
30 <td><%= problem.test_allowed %></td>
33 <td><%= problem.test_allowed %></td>
31
34
32 <td><%= link_to '[Toggle]', :action => 'toggle_avail', :id => problem.id %></td>
35 <td><%= link_to '[Toggle]', :action => 'toggle_avail', :id => problem.id %></td>
33 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
36 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
34 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
37 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
35 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
38 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
36 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
39 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
37 </tr>
40 </tr>
38 <% end %>
41 <% end %>
39 </table>
42 </table>
40
43
41
44
42 <br />
45 <br />
43
46
44 <%= link_to 'New problem', :action => 'new' %>
47 <%= link_to 'New problem', :action => 'new' %>
@@ -1,18 +1,22
1 %tr{:class => (test_request_counter%2==0) ? "info-even" : "info-odd"}
1 %tr{:class => (test_request_counter%2==0) ? "info-even" : "info-odd"}
2 %td{:align => "center"}
2 %td{:align => "center"}
3 = format_short_time(test_request.submitted_at)
3 = format_short_time(test_request.submitted_at)
4 - %td= test_request.problem.full_name
4 + %td
5 + - if test_request.problem!=nil
6 + = test_request.problem.full_name
7 + - else
8 + (n/a)
5 %td{:align => "center"}
9 %td{:align => "center"}
6 = test_request.submission.number
10 = test_request.submission.number
7 %td{:align => "center"}
11 %td{:align => "center"}
8 = test_request.status_str
12 = test_request.status_str
9 %td{:align => "center"}
13 %td{:align => "center"}
10 - if test_request.output_file_name!=nil
14 - if test_request.output_file_name!=nil
11 = link_to '[download]', :action => 'read', :id => test_request.id
15 = link_to '[download]', :action => 'read', :id => test_request.id
12 %td{:align => "center"}
16 %td{:align => "center"}
13 - if test_request.compiler_message!=nil and test_request.compiler_message!=''
17 - if test_request.compiler_message!=nil and test_request.compiler_message!=''
14 = "yes"
18 = "yes"
15 - else
19 - else
16 = "no"
20 = "no"
17 %td{:align => "center"}
21 %td{:align => "center"}
18 = link_to '[view]', :action => 'result', :id => test_request.id
22 = link_to '[view]', :action => 'result', :id => test_request.id
@@ -1,32 +1,36
1 = user_title_bar(@user)
1 = user_title_bar(@user)
2
2
3 %div{:style => "text-align: center; font-size: 12px"}
3 %div{:style => "text-align: center; font-size: 12px"}
4 - = "Problem: #{@test_request.problem.full_name}"
4 + Problem:
5 + - if @test_request.problem!=nil
6 + = "#{@test_request.problem.full_name}"
7 + - else
8 + = "(n/a)"
5 %br/
9 %br/
6 = "Submission: #{@test_request.submission.number}"
10 = "Submission: #{@test_request.submission.number}"
7 %br/
11 %br/
8 = "Test submitted at: #{format_short_time(@test_request.submitted_at)}"
12 = "Test submitted at: #{format_short_time(@test_request.submitted_at)}"
9 %br/
13 %br/
10 = "Execution time: #{@test_request.running_time} s."
14 = "Execution time: #{@test_request.running_time} s."
11 %br/
15 %br/
12 = "Memory usage: #{@test_request.memory_usage}kb"
16 = "Memory usage: #{@test_request.memory_usage}kb"
13 %br/
17 %br/
14 %b= @test_request.exit_status
18 %b= @test_request.exit_status
15 %br/
19 %br/
16
20
17 - if @test_request.compiler_message!=nil and @test_request.compiler_message!=''
21 - if @test_request.compiler_message!=nil and @test_request.compiler_message!=''
18 %b Compiler Message
22 %b Compiler Message
19 %div{:style => "border: 1px solid black; background: lightgrey"}
23 %div{:style => "border: 1px solid black; background: lightgrey"}
20 = simple_format((@test_request.compiler_message or ''))
24 = simple_format((@test_request.compiler_message or ''))
21
25
22 %b Input (first 2kb)
26 %b Input (first 2kb)
23 %div{:style => "border: 1px solid black; background: lightgrey"}
27 %div{:style => "border: 1px solid black; background: lightgrey"}
24 - if @test_request.input_file_name!=nil
28 - if @test_request.input_file_name!=nil
25 = simple_format(read_textfile(@test_request.input_file_name,2048))
29 = simple_format(read_textfile(@test_request.input_file_name,2048))
26
30
27 %b Output (first 2kb)
31 %b Output (first 2kb)
28 %div{:style => "border: 1px solid black; background: lightgrey"}
32 %div{:style => "border: 1px solid black; background: lightgrey"}
29 - if @test_request.output_file_name!=nil
33 - if @test_request.output_file_name!=nil
30 = simple_format(read_textfile(@test_request.output_file_name,2048))
34 = simple_format(read_textfile(@test_request.output_file_name,2048))
31 - else
35 - else
32 (no output)
36 (no output)
@@ -120,74 +120,74
120 border-bottom: 1px solid black;
120 border-bottom: 1px solid black;
121 margin-top: 2px;
121 margin-top: 2px;
122 margin-bottom: 4px;
122 margin-bottom: 4px;
123 }
123 }
124
124
125 /*******************************
125 /*******************************
126 [Submission]
126 [Submission]
127 ********************************/
127 ********************************/
128 table.taskdesc {
128 table.taskdesc {
129 border: 1px solid black;
129 border: 1px solid black;
130 border-collapse: collapse;
130 border-collapse: collapse;
131 width: 95%;
131 width: 95%;
132 font-size: 13px;
132 font-size: 13px;
133 }
133 }
134
134
135 table.taskdesc p {
135 table.taskdesc p {
136 font-size: 13px;
136 font-size: 13px;
137 }
137 }
138
138
139 table.taskdesc tr.name {
139 table.taskdesc tr.name {
140 border: 1px solid black;
140 border: 1px solid black;
141 background: #aaaaaa;
141 background: #aaaaaa;
142 color: white;
142 color: white;
143 font-weight: bold;
143 font-weight: bold;
144 font-size: 14px;
144 font-size: 14px;
145 text-align: center;
145 text-align: center;
146 }
146 }
147
147
148 table.taskdesc td.desc-odd {
148 table.taskdesc td.desc-odd {
149 padding: 5px;
149 padding: 5px;
150 padding-left: 20px;
150 padding-left: 20px;
151 background: #fefeee;
151 background: #fefeee;
152 }
152 }
153
153
154 table.taskdesc td.desc-even {
154 table.taskdesc td.desc-even {
155 padding: 5px;
155 padding: 5px;
156 padding-left: 20px;
156 padding-left: 20px;
157 background: #feeefe;
157 background: #feeefe;
158 }
158 }
159
159
160 /**********************
160 /**********************
161 [Announcement]
161 [Announcement]
162 ***********************/
162 ***********************/
163
163
164 div.announcementbox {
164 div.announcementbox {
165 margin-top: 10px;
165 margin-top: 10px;
166 margin-bottom: 10px;
166 margin-bottom: 10px;
167 background: green;
167 background: green;
168 - padding: 2px;
168 + padding: 1px;
169 }
169 }
170
170
171 div.announcementbox span.title {
171 div.announcementbox span.title {
172 font-weight: bold;
172 font-weight: bold;
173 color: white;
173 color: white;
174 padding-left: 10px;
174 padding-left: 10px;
175 }
175 }
176
176
177 div.announcement {
177 div.announcement {
178 margin: 2px;
178 margin: 2px;
179 background: white;
179 background: white;
180 - padding: 2px;
180 + padding: 1px;
181 padding-left: 10px;
181 padding-left: 10px;
182 padding-right: 10px;
182 padding-right: 10px;
183 }
183 }
184
184
185 div.announcement p {
185 div.announcement p {
186 - font-size: 13px;
186 + font-size: 12px;
187 }
187 }
188
188
189 div.pub-info, div.pub-info p {
189 div.pub-info, div.pub-info p {
190 text-align: right;
190 text-align: right;
191 font-style: italic;
191 font-style: italic;
192 - font-size: 10px;
192 + font-size: 9px;
193 - } No newline at end of file
193 + }
You need to be logged in to leave comments. Login now