Description:
added announcement refresh, more styling, prep for announcement hiding
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@412 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
r192:f7680fc5e3dd - - 7 files changed: 102 inserted, 10 deleted
@@ -0,0 +1,33 | |||
|
1 | + | |
|
2 | + var Announcement = { | |
|
3 | + | |
|
4 | + mostRecentId: 0, | |
|
5 | + | |
|
6 | + setMostRecentId: function(id) { | |
|
7 | + Announcement.mostRecentId = id; | |
|
8 | + }, | |
|
9 | + | |
|
10 | + updateRecentId: function(id) { | |
|
11 | + if(Announcement.mostRecentId < id) | |
|
12 | + Announcement.mostRecentId = id; | |
|
13 | + }, | |
|
14 | + | |
|
15 | + refreshAnnouncement: function() { | |
|
16 | + var url = '/main/announcements'; | |
|
17 | + new Ajax.Request(url, { | |
|
18 | + method: 'get', | |
|
19 | + parameters: { recent: Announcement.mostRecentId }, | |
|
20 | + onSuccess: function(transport) { | |
|
21 | + var announcementBody = $("announcementbox-body"); | |
|
22 | + announcementBody.insert({ top: transport.responseText }); | |
|
23 | + } | |
|
24 | + }); | |
|
25 | + Announcement.registerRefreshEventTimer(); | |
|
26 | + }, | |
|
27 | + | |
|
28 | + registerRefreshEventTimer: function() { | |
|
29 | + setTimeout(function () { | |
|
30 | + Announcement.refreshAnnouncement(); | |
|
31 | + }, 30000); | |
|
32 | + } | |
|
33 | + }; No newline at end of file |
@@ -118,114 +118,136 | |||
|
118 | 118 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
119 | 119 | end |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def result |
|
123 | 123 | if !Configuration.show_grading_result |
|
124 | 124 | redirect_to :action => 'list' and return |
|
125 | 125 | end |
|
126 | 126 | @user = User.find(session[:user_id]) |
|
127 | 127 | @submission = Submission.find(params[:id]) |
|
128 | 128 | if @submission.user!=@user |
|
129 | 129 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
130 | 130 | redirect_to :action => 'list' and return |
|
131 | 131 | end |
|
132 | 132 | prepare_grading_result(@submission) |
|
133 | 133 | end |
|
134 | 134 | |
|
135 | 135 | def load_output |
|
136 | 136 | if !Configuration.show_grading_result or params[:num]==nil |
|
137 | 137 | redirect_to :action => 'list' and return |
|
138 | 138 | end |
|
139 | 139 | @user = User.find(session[:user_id]) |
|
140 | 140 | @submission = Submission.find(params[:id]) |
|
141 | 141 | if @submission.user!=@user |
|
142 | 142 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
143 | 143 | redirect_to :action => 'list' and return |
|
144 | 144 | end |
|
145 | 145 | case_num = params[:num].to_i |
|
146 | 146 | out_filename = output_filename(@user.login, |
|
147 | 147 | @submission.problem.name, |
|
148 | 148 | @submission.id, |
|
149 | 149 | case_num) |
|
150 | 150 | if !FileTest.exists?(out_filename) |
|
151 | 151 | flash[:notice] = 'Output not found.' |
|
152 | 152 | redirect_to :action => 'list' and return |
|
153 | 153 | end |
|
154 | 154 | |
|
155 | 155 | response.headers['Content-Type'] = "application/force-download" |
|
156 | 156 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
157 | 157 | response.headers["X-Sendfile"] = out_filename |
|
158 | 158 | response.headers['Content-length'] = File.size(out_filename) |
|
159 | 159 | render :nothing => true |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def error |
|
163 | 163 | @user = User.find(session[:user_id]) |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | + # announcement refreshing and hiding methods | |
|
167 | + | |
|
168 | + def announcements | |
|
169 | + if params.has_key? 'recent' | |
|
170 | + prepare_announcements(params[:recent]) | |
|
171 | + else | |
|
172 | + prepare_announcements | |
|
173 | + end | |
|
174 | + render(:partial => 'announcement', | |
|
175 | + :collection => @announcements, | |
|
176 | + :locals => {:announcement_effect => true}) | |
|
177 | + end | |
|
178 | + | |
|
166 | 179 | protected |
|
180 | + | |
|
181 | + def prepare_announcements(recent=nil) | |
|
182 | + if Configuration.show_tasks_to?(@user) | |
|
183 | + @announcements = Announcement.find_published(true) | |
|
184 | + else | |
|
185 | + @announcements = Announcement.find_published | |
|
186 | + end | |
|
187 | + if recent!=nil | |
|
188 | + recent_id = recent.to_i | |
|
189 | + @announcements = @announcements.find_all { |a| a.id > recent_id } | |
|
190 | + end | |
|
191 | + end | |
|
192 | + | |
|
167 | 193 | def prepare_list_information |
|
168 | 194 | @problems = Problem.find_available_problems |
|
169 | 195 | @prob_submissions = Array.new |
|
170 | 196 | @user = User.find(session[:user_id]) |
|
171 | 197 | @problems.each do |p| |
|
172 | 198 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
173 | 199 | if sub!=nil |
|
174 | 200 | @prob_submissions << { :count => sub.number, :submission => sub } |
|
175 | 201 | else |
|
176 | 202 | @prob_submissions << { :count => 0, :submission => nil } |
|
177 | 203 | end |
|
178 | 204 | end |
|
179 | - if Configuration.show_tasks_to?(@user) | |
|
180 | - @announcements = Announcement.find_published(true) | |
|
181 | - else | |
|
182 | - @announcements = Announcement.find_published | |
|
183 | - end | |
|
205 | + prepare_announcements | |
|
184 | 206 | end |
|
185 | 207 | |
|
186 | 208 | def check_viewability |
|
187 | 209 | @user = User.find(session[:user_id]) |
|
188 | 210 | if (!Configuration.show_tasks_to?(@user)) and |
|
189 | 211 | ((action_name=='submission') or (action_name=='submit')) |
|
190 | 212 | redirect_to :action => 'list' and return |
|
191 | 213 | end |
|
192 | 214 | end |
|
193 | 215 | |
|
194 | 216 | def prepare_grading_result(submission) |
|
195 | 217 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
196 | 218 | @test_runs = [] |
|
197 | 219 | if grading_info['testruns'].is_a? Integer |
|
198 | 220 | trun_count = grading_info['testruns'] |
|
199 | 221 | trun_count.times do |i| |
|
200 | 222 | @test_runs << [ read_grading_result(@user.login, |
|
201 | 223 | submission.problem.name, |
|
202 | 224 | submission.id, |
|
203 | 225 | i+1) ] |
|
204 | 226 | end |
|
205 | 227 | else |
|
206 | 228 | grading_info['testruns'].keys.sort.each do |num| |
|
207 | 229 | run = [] |
|
208 | 230 | testrun = grading_info['testruns'][num] |
|
209 | 231 | testrun.each do |c| |
|
210 | 232 | run << read_grading_result(@user.login, |
|
211 | 233 | submission.problem.name, |
|
212 | 234 | submission.id, |
|
213 | 235 | c) |
|
214 | 236 | end |
|
215 | 237 | @test_runs << run |
|
216 | 238 | end |
|
217 | 239 | end |
|
218 | 240 | end |
|
219 | 241 | |
|
220 | 242 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
221 | 243 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
222 | 244 | end |
|
223 | 245 | |
|
224 | 246 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
225 | 247 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
226 | 248 | return "#{dir}/output.txt" |
|
227 | 249 | end |
|
228 | 250 | |
|
229 | 251 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
230 | 252 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
231 | 253 | result_file_name = "#{dir}/result" |
@@ -1,4 +1,17 | |||
|
1 | - .announcement | |
|
1 | + .announcement{:id => "announcement-#{announcement.id}", :style => "#{'opacity: 0;' if (defined? announcement_effect) and announcement_effect }"} | |
|
2 | + -# .announcement-title | |
|
3 | + -# .toggles | |
|
4 | + -# %a{:href => '#', :onclick => "$(\"announcement-body-#{announcement.id}\").hide(); return false;"} | |
|
5 | + -# [hide] | |
|
6 | + -# %a{:href => '#', :onclick => "$(\"announcement-body-#{announcement.id}\").show(); return false;"} | |
|
7 | + -# [show] | |
|
8 | + -# Announcement Title | |
|
9 | + .announcement-body{:id => "announcement-body-#{announcement.id}"} | |
|
2 | 10 | = markdown(announcement.body) |
|
3 | 11 | -#.pub-info |
|
4 | 12 | -# %p= "#{announcement.author}, #{announcement.created_at}" |
|
13 | + :javascript | |
|
14 | + Announcement.updateRecentId(#{announcement.id}); | |
|
15 | + - if (defined? announcement_effect) and announcement_effect | |
|
16 | + :javascript | |
|
17 | + $("announcement-#{announcement.id}").appear(); |
@@ -1,30 +1,39 | |||
|
1 | + - content_for :head do | |
|
2 | + = javascript_include_tag :defaults | |
|
3 | + %script{:type => 'text/javascript', :src => '/javascripts/announcement_refresh.js'} | |
|
4 | + | |
|
1 | 5 | = user_title_bar(@user) |
|
2 | 6 | |
|
3 | 7 | - if @announcements.length!=0 |
|
4 | 8 | .announcementbox |
|
5 | 9 | %span{:class => 'title'} |
|
6 | 10 | Announcements |
|
11 | + #announcementbox-body | |
|
7 | 12 | = render :partial => 'announcement', :collection => @announcements |
|
8 | 13 | |
|
9 | 14 | - if Configuration.show_submitbox_to?(@user) |
|
10 | 15 | .submitbox |
|
11 | 16 | = error_messages_for 'submission' |
|
12 | 17 | = render :partial => 'submission_box' |
|
13 | 18 | |
|
14 | 19 | |
|
15 | 20 | %hr/ |
|
16 | 21 | |
|
17 |
- - if (Configuration.contest_mode) and (@user.site!=nil) |
|
|
22 | + - if (Configuration.contest_mode) and (@user.site!=nil) | | |
|
23 | + and (@user.site.started!=true) | |
|
18 | 24 | %p=t 'main.start_soon' |
|
19 | 25 | |
|
20 | 26 | - if Configuration.show_tasks_to?(@user) |
|
21 | 27 | %table.info |
|
22 | 28 | %tr.info-head |
|
23 | 29 | %th |
|
24 | 30 | %th Tasks |
|
25 | 31 | %th # of sub(s) |
|
26 | 32 | %th Results |
|
27 | 33 | = render :partial => 'problem', :collection => @problems |
|
28 | 34 | |
|
29 | 35 | %hr/ |
|
30 | 36 | |
|
37 | + :javascript | |
|
38 | + Announcement.registerRefreshEventTimer(); | |
|
39 | + |
@@ -192,108 +192,121 | |||
|
192 | 192 | font-size: 13px; |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | table.taskdesc tr.name { |
|
196 | 196 | border: 2px solid #dddddd; |
|
197 | 197 | background: #dddddd; |
|
198 | 198 | color: #333333; |
|
199 | 199 | font-weight: bold; |
|
200 | 200 | font-size: 14px; |
|
201 | 201 | line-height: 1.5em; |
|
202 | 202 | text-align: center; |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | table.taskdesc td.desc-odd { |
|
206 | 206 | padding: 5px; |
|
207 | 207 | padding-left: 20px; |
|
208 | 208 | background: #fefeee; |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | table.taskdesc td.desc-even { |
|
212 | 212 | padding: 5px; |
|
213 | 213 | padding-left: 20px; |
|
214 | 214 | background: #feeefe; |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | /********************** |
|
218 | 218 | Announcement |
|
219 | 219 | ***********************/ |
|
220 | 220 | |
|
221 | 221 | div.announcementbox { |
|
222 | 222 | margin: 10px 0px; |
|
223 | 223 | background: #bbddee; |
|
224 | 224 | padding: 1px; |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | div.announcementbox span.title { |
|
228 | 228 | font-weight: bold; |
|
229 | 229 | color: #224455; |
|
230 | 230 | padding-left: 10px; |
|
231 | 231 | line-height: 1.6em; |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | div.announcement { |
|
235 | 235 | margin: 2px; |
|
236 | 236 | background: white; |
|
237 | 237 | padding: 1px; |
|
238 | 238 | padding-left: 10px; |
|
239 | 239 | padding-right: 10px; |
|
240 | + padding-top: 5px; | |
|
241 | + padding-bottom: 5px; | |
|
240 | 242 | } |
|
241 | 243 | |
|
242 |
- |
|
|
244 | + .announcement p { | |
|
243 | 245 | font-size: 12px; |
|
246 | + margin: 2px; | |
|
244 | 247 | } |
|
245 | 248 | |
|
246 | 249 | div.pub-info, div.pub-info p { |
|
247 | 250 | text-align: right; |
|
248 | 251 | font-style: italic; |
|
249 | 252 | font-size: 9px; |
|
250 | 253 | } |
|
251 | 254 | |
|
255 | + .announcement .toggles { | |
|
256 | + font-weight: normal; | |
|
257 | + float: right; | |
|
258 | + font-size: 80%; | |
|
259 | + } | |
|
260 | + | |
|
261 | + .announcement .announcement-title { | |
|
262 | + font-weight: bold; | |
|
263 | + } | |
|
264 | + | |
|
252 | 265 | /****************** |
|
253 | 266 | Messages |
|
254 | 267 | ******************/ |
|
255 | 268 | |
|
256 | 269 | div.message { |
|
257 | 270 | margin: 10px 0 0; |
|
258 | 271 | } |
|
259 | 272 | |
|
260 | 273 | div.message div.message { |
|
261 | 274 | margin: 0 0 0 30px; |
|
262 | 275 | } |
|
263 | 276 | |
|
264 | 277 | div.message div.body { |
|
265 | 278 | border: 2px solid #dddddd; |
|
266 | 279 | background: #fff8f8; |
|
267 | 280 | padding-left: 5px; |
|
268 | 281 | } |
|
269 | 282 | |
|
270 | 283 | div.message div.reply-body { |
|
271 | 284 | border: 2px solid #bbbbbb; |
|
272 | 285 | background: #fffff8; |
|
273 | 286 | padding-left: 5px; |
|
274 | 287 | } |
|
275 | 288 | |
|
276 | 289 | div.message div.stat { |
|
277 | 290 | font-size: 10px; |
|
278 | 291 | line-height: 1.75em; |
|
279 | 292 | padding: 0 5px; |
|
280 | 293 | color: #333333; |
|
281 | 294 | background: #dddddd; |
|
282 | 295 | font-weight: bold; |
|
283 | 296 | } |
|
284 | 297 | |
|
285 | 298 | div.message div.message div.stat { |
|
286 | 299 | font-size: 10px; |
|
287 | 300 | line-height: 1.75em; |
|
288 | 301 | padding: 0 5px; |
|
289 | 302 | color: #444444; |
|
290 | 303 | background: #bbbbbb; |
|
291 | 304 | font-weight: bold; |
|
292 | 305 | } |
|
293 | 306 | |
|
294 | 307 | /******************** |
|
295 | 308 | Registration |
|
296 | 309 | ********************/ |
|
297 | 310 | div.contest-title { |
|
298 | 311 | color: white; |
|
299 | 312 | text-align: center; |
You need to be logged in to leave comments.
Login now