Description:
added announcement to frontpage
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@290 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
r151:2e9ddcc1b233 - - 7 files changed: 38 inserted, 5 deleted
@@ -1,93 +1,94 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
4 | 4 | |
|
5 | 5 | before_filter :authenticate, :except => [:index, :login] |
|
6 | 6 | before_filter :check_viewability, :except => [:index, :login] |
|
7 | 7 | |
|
8 | 8 | # |
|
9 | 9 | # COMMENT OUT: filter in each action instead |
|
10 | 10 | # |
|
11 | 11 | # before_filter :verify_time_limit, :only => [:submit] |
|
12 | 12 | |
|
13 | 13 | verify :method => :post, :only => [:submit], |
|
14 | 14 | :redirect_to => { :action => :index } |
|
15 | 15 | |
|
16 | 16 | # COMMENT OUT, only need when having high load |
|
17 | 17 | # caches_action :index, :login |
|
18 | 18 | |
|
19 | 19 | def index |
|
20 | 20 | redirect_to :action => 'login' |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | 23 | def login |
|
24 | 24 | saved_notice = flash[:notice] |
|
25 | 25 | reset_session |
|
26 | 26 | flash[:notice] = saved_notice |
|
27 | 27 | |
|
28 | 28 | # |
|
29 | 29 | # These are for site administrator login |
|
30 | 30 | # |
|
31 | 31 | @countries = Country.find(:all, :include => :sites) |
|
32 | 32 | @country_select = @countries.collect { |c| [c.name, c.id] } |
|
33 | 33 | |
|
34 | 34 | @country_select_with_all = [['Any',0]] |
|
35 | 35 | @countries.each do |country| |
|
36 | 36 | @country_select_with_all << [country.name, country.id] |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | @site_select = [] |
|
40 | 40 | @countries.each do |country| |
|
41 | 41 | country.sites.each do |site| |
|
42 | 42 | @site_select << ["#{site.name}, #{country.name}", site.id] |
|
43 | 43 | end |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | + @announcements = Announcement.find_for_frontpage | |
|
46 | 47 | render :action => 'login', :layout => 'empty' |
|
47 | 48 | end |
|
48 | 49 | |
|
49 | 50 | def list |
|
50 | 51 | prepare_list_information |
|
51 | 52 | end |
|
52 | 53 | |
|
53 | 54 | def help |
|
54 | 55 | @user = User.find(session[:user_id]) |
|
55 | 56 | end |
|
56 | 57 | |
|
57 | 58 | def submit |
|
58 | 59 | user = User.find(session[:user_id]) |
|
59 | 60 | |
|
60 | 61 | @submission = Submission.new(params[:submission]) |
|
61 | 62 | @submission.user = user |
|
62 | 63 | @submission.language_id = 0 |
|
63 | 64 | if params['file']!='' |
|
64 | 65 | @submission.source = params['file'].read |
|
65 | 66 | @submission.source_filename = params['file'].original_filename |
|
66 | 67 | end |
|
67 | 68 | @submission.submitted_at = Time.new.gmtime |
|
68 | 69 | |
|
69 | 70 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and |
|
70 | 71 | user.site!=nil and user.site.finished? |
|
71 | 72 | @submission.errors.add_to_base "The contest is over." |
|
72 | 73 | prepare_list_information |
|
73 | 74 | render :action => 'list' and return |
|
74 | 75 | end |
|
75 | 76 | |
|
76 | 77 | if @submission.valid? |
|
77 | 78 | if @submission.save == false |
|
78 | 79 | flash[:notice] = 'Error saving your submission' |
|
79 | 80 | elsif Task.create(:submission_id => @submission.id, |
|
80 | 81 | :status => Task::STATUS_INQUEUE) == false |
|
81 | 82 | flash[:notice] = 'Error adding your submission to task queue' |
|
82 | 83 | end |
|
83 | 84 | else |
|
84 | 85 | prepare_list_information |
|
85 | 86 | render :action => 'list' and return |
|
86 | 87 | end |
|
87 | 88 | redirect_to :action => 'list' |
|
88 | 89 | end |
|
89 | 90 | |
|
90 | 91 | def source |
|
91 | 92 | submission = Submission.find(params[:id]) |
|
92 | 93 | if submission.user_id == session[:user_id] |
|
93 | 94 | if submission.problem.output_only |
@@ -138,100 +139,97 | |||
|
138 | 139 | end |
|
139 | 140 | prepare_grading_result(@submission) |
|
140 | 141 | end |
|
141 | 142 | |
|
142 | 143 | def load_output |
|
143 | 144 | if !Configuration.show_grading_result or params[:num]==nil |
|
144 | 145 | redirect_to :action => 'list' and return |
|
145 | 146 | end |
|
146 | 147 | @user = User.find(session[:user_id]) |
|
147 | 148 | @submission = Submission.find(params[:id]) |
|
148 | 149 | if @submission.user!=@user |
|
149 | 150 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
150 | 151 | redirect_to :action => 'list' and return |
|
151 | 152 | end |
|
152 | 153 | case_num = params[:num].to_i |
|
153 | 154 | out_filename = output_filename(@user.login, |
|
154 | 155 | @submission.problem.name, |
|
155 | 156 | @submission.id, |
|
156 | 157 | case_num) |
|
157 | 158 | if !FileTest.exists?(out_filename) |
|
158 | 159 | flash[:notice] = 'Output not found.' |
|
159 | 160 | redirect_to :action => 'list' and return |
|
160 | 161 | end |
|
161 | 162 | |
|
162 | 163 | response.headers['Content-Type'] = "application/force-download" |
|
163 | 164 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
164 | 165 | response.headers["X-Sendfile"] = out_filename |
|
165 | 166 | response.headers['Content-length'] = File.size(out_filename) |
|
166 | 167 | render :nothing => true |
|
167 | 168 | end |
|
168 | 169 | |
|
169 | 170 | def error |
|
170 | 171 | @user = User.find(session[:user_id]) |
|
171 | 172 | end |
|
172 | 173 | |
|
173 | 174 | protected |
|
174 | 175 | def prepare_list_information |
|
175 | 176 | @problems = Problem.find_available_problems |
|
176 | 177 | @prob_submissions = Array.new |
|
177 | 178 | @user = User.find(session[:user_id]) |
|
178 | 179 | @problems.each do |p| |
|
179 | 180 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
180 | 181 | if sub!=nil |
|
181 | 182 | @prob_submissions << { :count => sub.number, :submission => sub } |
|
182 | 183 | else |
|
183 | 184 | @prob_submissions << { :count => 0, :submission => nil } |
|
184 | 185 | end |
|
185 | 186 | end |
|
186 | - | |
|
187 | - @announcements = Announcement.find(:all, | |
|
188 | - :conditions => "published = 1", | |
|
189 | - :order => "created_at DESC") | |
|
187 | + @announcements = Announcement.find_published | |
|
190 | 188 | end |
|
191 | 189 | |
|
192 | 190 | def check_viewability |
|
193 | 191 | @user = User.find(session[:user_id]) |
|
194 | 192 | if (!Configuration.show_tasks_to?(@user)) and |
|
195 | 193 | ((action_name=='submission') or (action_name=='submit')) |
|
196 | 194 | redirect_to :action => 'list' and return |
|
197 | 195 | end |
|
198 | 196 | end |
|
199 | 197 | |
|
200 | 198 | def prepare_grading_result(submission) |
|
201 | 199 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
202 | 200 | @test_runs = [] |
|
203 | 201 | if grading_info['testruns'].is_a? Integer |
|
204 | 202 | trun_count = grading_info['testruns'] |
|
205 | 203 | trun_count.times do |i| |
|
206 | 204 | @test_runs << [ read_grading_result(@user.login, |
|
207 | 205 | submission.problem.name, |
|
208 | 206 | submission.id, |
|
209 | 207 | i+1) ] |
|
210 | 208 | end |
|
211 | 209 | else |
|
212 | 210 | grading_info['testruns'].keys.sort.each do |num| |
|
213 | 211 | run = [] |
|
214 | 212 | testrun = grading_info['testruns'][num] |
|
215 | 213 | testrun.each do |c| |
|
216 | 214 | run << read_grading_result(@user.login, |
|
217 | 215 | submission.problem.name, |
|
218 | 216 | submission.id, |
|
219 | 217 | c) |
|
220 | 218 | end |
|
221 | 219 | @test_runs << run |
|
222 | 220 | end |
|
223 | 221 | end |
|
224 | 222 | end |
|
225 | 223 | |
|
226 | 224 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
227 | 225 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
228 | 226 | end |
|
229 | 227 | |
|
230 | 228 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
231 | 229 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
232 | 230 | return "#{dir}/output.txt" |
|
233 | 231 | end |
|
234 | 232 | |
|
235 | 233 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
236 | 234 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
237 | 235 | result_file_name = "#{dir}/result" |
@@ -1,2 +1,15 | |||
|
1 | 1 | class Announcement < ActiveRecord::Base |
|
2 | + | |
|
3 | + def self.find_published | |
|
4 | + Announcement.find(:all, | |
|
5 | + :conditions => "(published = 1) AND (frontpage = 0)", | |
|
6 | + :order => "created_at DESC") | |
|
2 | 7 | end |
|
8 | + | |
|
9 | + def self.find_for_frontpage | |
|
10 | + Announcement.find(:all, | |
|
11 | + :conditions => "(published = 1) AND (frontpage = 1)", | |
|
12 | + :order => "created_at DESC") | |
|
13 | + end | |
|
14 | + | |
|
15 | + end |
@@ -1,27 +1,32 | |||
|
1 | 1 | <h1>Editing announcement</h1> |
|
2 | 2 | |
|
3 | 3 | <%= error_messages_for :announcement %> |
|
4 | 4 | |
|
5 | 5 | <% form_for(@announcement) do |f| %> |
|
6 | 6 | <p> |
|
7 | 7 | <b>Body</b><br /> |
|
8 | 8 | <%= f.text_area :body %> |
|
9 | 9 | </p> |
|
10 | 10 | |
|
11 | 11 | <p> |
|
12 | 12 | <b>Author</b><br /> |
|
13 | 13 | <%= f.text_field :author %> |
|
14 | 14 | </p> |
|
15 | 15 | |
|
16 | 16 | <p> |
|
17 | 17 | <b>Published</b><br /> |
|
18 | 18 | <%= f.check_box :published %> |
|
19 | 19 | </p> |
|
20 | 20 | |
|
21 | 21 | <p> |
|
22 | + <b>Show on front page?</b><br /> | |
|
23 | + <%= f.check_box :frontpage %> | |
|
24 | + </p> | |
|
25 | + | |
|
26 | + <p> | |
|
22 | 27 | <%= f.submit "Update" %> |
|
23 | 28 | </p> |
|
24 | 29 | <% end %> |
|
25 | 30 | |
|
26 | 31 | <%= link_to 'Show', @announcement %> | |
|
27 | 32 | <%= link_to 'Back', announcements_path %> |
@@ -1,26 +1,31 | |||
|
1 | 1 | <h1>New announcement</h1> |
|
2 | 2 | |
|
3 | 3 | <%= error_messages_for :announcement %> |
|
4 | 4 | |
|
5 | 5 | <% form_for(@announcement) do |f| %> |
|
6 | 6 | <p> |
|
7 | 7 | <b>Body</b><br /> |
|
8 | 8 | <%= f.text_area :body %> |
|
9 | 9 | </p> |
|
10 | 10 | |
|
11 | 11 | <p> |
|
12 | 12 | <b>Author</b><br /> |
|
13 | 13 | <%= f.text_field :author %> |
|
14 | 14 | </p> |
|
15 | 15 | |
|
16 | 16 | <p> |
|
17 | 17 | <b>Published</b><br /> |
|
18 | 18 | <%= f.check_box :published %> |
|
19 | 19 | </p> |
|
20 | 20 | |
|
21 | 21 | <p> |
|
22 | + <b>Show on front page?</b><br /> | |
|
23 | + <%= f.check_box :frontpage %> | |
|
24 | + </p> | |
|
25 | + | |
|
26 | + <p> | |
|
22 | 27 | <%= f.submit "Create" %> |
|
23 | 28 | </p> |
|
24 | 29 | <% end %> |
|
25 | 30 | |
|
26 | 31 | <%= link_to 'Back', announcements_path %> |
@@ -1,18 +1,23 | |||
|
1 | 1 | <p> |
|
2 | 2 | <b>Author:</b> |
|
3 | 3 | <%=h @announcement.author %> |
|
4 | 4 | </p> |
|
5 | 5 | |
|
6 | 6 | <p> |
|
7 | 7 | <b>Body:</b> |
|
8 | 8 | <%=h @announcement.body %> |
|
9 | 9 | </p> |
|
10 | 10 | |
|
11 | 11 | <p> |
|
12 | 12 | <b>Published:</b> |
|
13 | 13 | <%=h @announcement.published %> |
|
14 | 14 | </p> |
|
15 | 15 | |
|
16 | + <p> | |
|
17 | + <b>Show on front page:</b> | |
|
18 | + <%=h @announcement.frontpage %> | |
|
19 | + </p> | |
|
20 | + | |
|
16 | 21 | |
|
17 | 22 | <%= link_to 'Edit', edit_announcement_path(@announcement) %> | |
|
18 | 23 | <%= link_to 'Back', announcements_path %> |
@@ -1,50 +1,56 | |||
|
1 | 1 | %h1= Configuration['ui.front.title'] |
|
2 | 2 | |
|
3 | + - if @announcements.length!=0 | |
|
4 | + .announcementbox | |
|
5 | + %span{:class => 'title'} | |
|
6 | + Announcements | |
|
7 | + = render :partial => 'announcement', :collection => @announcements | |
|
8 | + | |
|
3 | 9 | %b= Configuration['ui.front.welcome_message'] |
|
4 | 10 | %br/ |
|
5 | 11 | Please login to see the problem list. |
|
6 | 12 | %br/ |
|
7 | 13 | %br/ |
|
8 | 14 | |
|
9 | 15 | - if flash[:notice] |
|
10 | 16 | %hr/ |
|
11 | 17 | %b= flash[:notice] |
|
12 | 18 | %hr/ |
|
13 | 19 | |
|
14 | 20 | %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} |
|
15 | 21 | - form_tag :controller => 'login', :action => 'login' do |
|
16 | 22 | %table |
|
17 | 23 | %tr |
|
18 | 24 | %td{:align => "right"} Login: |
|
19 | 25 | %td= text_field_tag 'login' |
|
20 | 26 | %tr |
|
21 | 27 | %td{:align => "right"} Password: |
|
22 | 28 | %td= password_field_tag |
|
23 | 29 | = submit_tag 'Login' |
|
24 | 30 | |
|
25 | 31 | %br/ |
|
26 | 32 | |
|
27 | 33 | - if Configuration['system.mode']=='contest' |
|
28 | 34 | %script{:type => 'text/javascript'} |
|
29 | 35 | var siteList = new Array(); |
|
30 | 36 | - @countries.each do |country| |
|
31 | 37 | = "siteList[#{country.id}] = new Array();" |
|
32 | 38 | - country.sites.each do |site| |
|
33 | 39 | = "siteList[#{country.id}][#{site.id}] = \"#{site.name}\";" |
|
34 | 40 | |
|
35 | 41 | var allSiteList = new Array(); |
|
36 | 42 | - @site_select.each do |sel| |
|
37 | 43 | = "allSiteList[#{sel[1]}]=\"#{sel[0]}\";" |
|
38 | 44 | |
|
39 | 45 | %script{:type => 'text/javascript', :src => '/javascripts/site_update.js'} |
|
40 | 46 | |
|
41 | 47 | %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} |
|
42 | 48 | %b For Site Administrator. |
|
43 | 49 | %br/ |
|
44 | 50 | Please select your country and site and login. |
|
45 | 51 | - form_for :login, nil, :url => {:controller => 'login', :action => 'site_login'} do |f| |
|
46 | 52 | Country: |
|
47 | 53 | = select :site_country, :id, @country_select_with_all, {}, {:onchange => "updateSiteList();", :onclick => "updateSiteList();" } |
|
48 | 54 | Site: |
|
49 | 55 | = select :login, :site_id, @site_select |
|
50 | 56 | %br/ |
@@ -1,67 +1,68 | |||
|
1 | 1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
2 | 2 | # please use the migrations feature of Active Record to incrementally modify your database, and |
|
3 | 3 | # then regenerate this schema definition. |
|
4 | 4 | # |
|
5 | 5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
6 | 6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | 7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | 8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
9 | 9 | # |
|
10 | 10 | # It's strongly recommended to check this file into your version control system. |
|
11 | 11 | |
|
12 |
- ActiveRecord::Schema.define(:version => 20081 |
|
|
12 | + ActiveRecord::Schema.define(:version => 20081107145815) do | |
|
13 | 13 | |
|
14 | 14 | create_table "announcements", :force => true do |t| |
|
15 | 15 | t.string "author" |
|
16 | 16 | t.text "body" |
|
17 | 17 | t.boolean "published" |
|
18 | 18 | t.datetime "created_at" |
|
19 | 19 | t.datetime "updated_at" |
|
20 | + t.boolean "frontpage", :default => false | |
|
20 | 21 | end |
|
21 | 22 | |
|
22 | 23 | create_table "configurations", :force => true do |t| |
|
23 | 24 | t.string "key" |
|
24 | 25 | t.string "value_type" |
|
25 | 26 | t.string "value" |
|
26 | 27 | t.datetime "created_at" |
|
27 | 28 | t.datetime "updated_at" |
|
28 | 29 | end |
|
29 | 30 | |
|
30 | 31 | create_table "countries", :force => true do |t| |
|
31 | 32 | t.string "name" |
|
32 | 33 | t.datetime "created_at" |
|
33 | 34 | t.datetime "updated_at" |
|
34 | 35 | end |
|
35 | 36 | |
|
36 | 37 | create_table "descriptions", :force => true do |t| |
|
37 | 38 | t.text "body" |
|
38 | 39 | t.boolean "markdowned" |
|
39 | 40 | t.datetime "created_at" |
|
40 | 41 | t.datetime "updated_at" |
|
41 | 42 | end |
|
42 | 43 | |
|
43 | 44 | create_table "grader_processes", :force => true do |t| |
|
44 | 45 | t.string "host", :limit => 20 |
|
45 | 46 | t.integer "pid" |
|
46 | 47 | t.string "mode" |
|
47 | 48 | t.boolean "active" |
|
48 | 49 | t.datetime "created_at" |
|
49 | 50 | t.datetime "updated_at" |
|
50 | 51 | t.integer "task_id" |
|
51 | 52 | t.string "task_type" |
|
52 | 53 | end |
|
53 | 54 | |
|
54 | 55 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
55 | 56 | |
|
56 | 57 | create_table "languages", :force => true do |t| |
|
57 | 58 | t.string "name", :limit => 10 |
|
58 | 59 | t.string "pretty_name" |
|
59 | 60 | t.string "ext", :limit => 10 |
|
60 | 61 | end |
|
61 | 62 | |
|
62 | 63 | create_table "messages", :force => true do |t| |
|
63 | 64 | t.integer "sender_id" |
|
64 | 65 | t.integer "receiver_id" |
|
65 | 66 | t.integer "replying_message_id" |
|
66 | 67 | t.text "body" |
|
67 | 68 | t.boolean "replied" |
You need to be logged in to leave comments.
Login now