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

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