Description:
add rejudge button
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r645:a2d233431d60 - - 8 files changed: 50 inserted, 18 deleted

@@ -0,0 +1,2
1 + :plain
2 + $("body").prepend("<div class=\"alert alert-info\"> Submission #{@submission.id}'s task status has been chaned to \"#{@task.status_str}\" </div>")
@@ -0,0 +1,5
1 + class AddIndexToTask < ActiveRecord::Migration
2 + def change
3 + add_index :tasks, :submission_id
4 + end
5 + end
@@ -1,15 +1,16
1 1 class SubmissionsController < ApplicationController
2 - before_filter :authenticate
3 - before_filter :submission_authorization, only: [:show, :direct_edit_submission, :download, :edit]
2 + before_action :authenticate
3 + before_action :submission_authorization, only: [:show, :direct_edit_submission, :download, :edit]
4 + before_action :admin_authorization, only: [:rejudge]
4 5
5 6 # GET /submissions
6 7 # GET /submissions.json
7 8 # Show problem selection and user's submission of that problem
8 9 def index
9 10 @user = @current_user
10 11 @problems = @user.available_problems
11 12
12 13 if params[:problem_id]==nil
13 14 @problem = nil
14 15 @submissions = nil
15 16 else
@@ -22,24 +23,26
22 23 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id).order(id: :desc)
23 24 end
24 25 end
25 26
26 27 # GET /submissions/1
27 28 # GET /submissions/1.json
28 29 def show
29 30 @submission = Submission.find(params[:id])
30 31
31 32 #log the viewing
32 33 user = User.find(session[:user_id])
33 34 SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin?
35 +
36 + @task = @submission.task
34 37 end
35 38
36 39 def download
37 40 @submission = Submission.find(params[:id])
38 41 send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'})
39 42 end
40 43
41 44 def compiler_msg
42 45 @submission = Submission.find(params[:id])
43 46 respond_to do |format|
44 47 format.js
45 48 end
@@ -63,24 +66,34
63 66
64 67 def get_latest_submission_status
65 68 @problem = Problem.find(params[:pid])
66 69 @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid])
67 70 puts User.find(params[:uid]).login
68 71 puts Problem.find(params[:pid]).name
69 72 puts 'nil' unless @submission
70 73 respond_to do |format|
71 74 format.js
72 75 end
73 76 end
74 77
78 + # GET /submissions/:id/rejudge
79 + def rejudge
80 + @submission = Submission.find(params[:id])
81 + @task = @submission.task
82 + @task.status_inqueue! if @task
83 + respond_to do |format|
84 + format.js
85 + end
86 + end
87 +
75 88
76 89 protected
77 90
78 91 def submission_authorization
79 92 #admin always has privileged
80 93 if @current_user.admin?
81 94 return true
82 95 end
83 96
84 97 sub = Submission.find(params[:id])
85 98 if sub.problem.available?
86 99 puts "sub = #{sub.user.id}, current = #{@current_user.id}"
@@ -200,23 +200,22
200 200 BOOTSTRAP_FLASH_MSG = {
201 201 success: 'alert-success',
202 202 error: 'alert-danger',
203 203 alert: 'alert-block',
204 204 notice: 'alert-info'
205 205 }
206 206
207 207 def bootstrap_class_for(flash_type)
208 208 BOOTSTRAP_FLASH_MSG.fetch(flash_type.to_sym, flash_type.to_s)
209 209 end
210 210
211 211 def flash_messages
212 - puts "flahs size = #{flash.count}"
213 212 flash.each do |msg_type, message|
214 213 concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do
215 214 concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' })
216 215 concat message
217 216 end)
218 217 end
219 218 nil
220 219 end
221 220
222 221 end
@@ -4,24 +4,26
4 4 belongs_to :problem
5 5 belongs_to :user
6 6
7 7 before_validation :assign_problem
8 8 before_validation :assign_language
9 9
10 10 validates_presence_of :source
11 11 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
12 12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
13 13 validate :must_have_valid_problem
14 14 validate :must_specify_language
15 15
16 + has_one :task
17 +
16 18 before_save :assign_latest_number_if_new_recond
17 19
18 20 def self.find_last_by_user_and_problem(user_id, problem_id)
19 21 where("user_id = ? AND problem_id = ?",user_id,problem_id).last
20 22 end
21 23
22 24 def self.find_all_last_by_problem(problem_id)
23 25 # need to put in SQL command, maybe there's a better way
24 26 Submission.includes(:user).find_by_sql("SELECT * FROM submissions " +
25 27 "WHERE id = " +
26 28 "(SELECT MAX(id) FROM submissions AS subs " +
27 29 "WHERE subs.user_id = submissions.user_id AND " +
@@ -81,24 +81,32
81 81 %td #{@submission.peak_memory}
82 82 %tr
83 83 %td.text-right
84 84 %strong Compiler result
85 85 %td
86 86 %button.btn.btn-info.btn-xs{type: 'button', data: {toggle: 'modal', target: '#compiler'}}
87 87 view
88 88 - if session[:admin]
89 89 %tr
90 90 %td.text-right
91 91 %strong IP
92 92 %td #{@submission.ip_address}
93 + %tr
94 + %td.text-right
95 + %strong Grading Task Status
96 + %td
97 + = @task.status_str if @task
98 + - if session[:admin]
99 + = link_to "rejudge", rejudge_submission_path, data: {remote: true}, class: 'btn btn-info btn-xs'
100 +
93 101
94 102 .modal.fade#compiler{tabindex: -1,role: 'dialog'}
95 103 .modal-dialog.modal-lg{role:'document'}
96 104 .modal-content
97 105 .modal-header
98 106 %button.close{type: 'button', data: {dismissed: :modal}, aria: {label: 'close'}}
99 107 %span{aria: {hidden: 'true'}, data: {dismiss: 'modal'}} &times;
100 108 %h4 Compiler message
101 109 .modal-body
102 110 %pre#compiler_msg= @submission.compiler_message
103 111 .modal-footer
104 112 %button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}} Close
@@ -46,24 +46,25
46 46
47 47 resources :users do
48 48 member do
49 49 get 'toggle_activate', 'toggle_enable'
50 50 get 'stat'
51 51 end
52 52 end
53 53
54 54 resources :submissions do
55 55 member do
56 56 get 'download'
57 57 get 'compiler_msg'
58 + get 'rejudge'
58 59 end
59 60 collection do
60 61 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
61 62 get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
62 63 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
63 64 end
64 65 end
65 66
66 67
67 68
68 69 #main
69 70 get "main/list"
@@ -2,29 +2,29
2 2 # This file is auto-generated from the current state of the database. Instead
3 3 # of editing this file, please use the migrations feature of Active Record to
4 4 # incrementally modify your database, and then regenerate this schema definition.
5 5 #
6 6 # Note that this schema.rb definition is the authoritative source for your
7 7 # database schema. If you need to create the application database on another
8 8 # system, you should be using db:schema:load, not running all the migrations
9 9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13
14 - ActiveRecord::Schema.define(version: 20170124024527) do
14 + ActiveRecord::Schema.define(version: 20170310110146) do
15 15
16 16 create_table "announcements", force: :cascade do |t|
17 17 t.string "author", limit: 255
18 - t.text "body", limit: 16777215
18 + t.text "body", limit: 65535
19 19 t.boolean "published"
20 20 t.datetime "created_at", null: false
21 21 t.datetime "updated_at", null: false
22 22 t.boolean "frontpage", default: false
23 23 t.boolean "contest_only", default: false
24 24 t.string "title", limit: 255
25 25 t.string "notes", limit: 255
26 26 end
27 27
28 28 create_table "contests", force: :cascade do |t|
29 29 t.string "title", limit: 255
30 30 t.boolean "enabled"
@@ -41,37 +41,37
41 41 create_table "contests_users", id: false, force: :cascade do |t|
42 42 t.integer "contest_id", limit: 4
43 43 t.integer "user_id", limit: 4
44 44 end
45 45
46 46 create_table "countries", force: :cascade do |t|
47 47 t.string "name", limit: 255
48 48 t.datetime "created_at", null: false
49 49 t.datetime "updated_at", null: false
50 50 end
51 51
52 52 create_table "descriptions", force: :cascade do |t|
53 - t.text "body", limit: 16777215
53 + t.text "body", limit: 65535
54 54 t.boolean "markdowned"
55 55 t.datetime "created_at", null: false
56 56 t.datetime "updated_at", null: false
57 57 end
58 58
59 59 create_table "grader_configurations", force: :cascade do |t|
60 60 t.string "key", limit: 255
61 61 t.string "value_type", limit: 255
62 62 t.string "value", limit: 255
63 63 t.datetime "created_at", null: false
64 64 t.datetime "updated_at", null: false
65 - t.text "description", limit: 16777215
65 + t.text "description", limit: 65535
66 66 end
67 67
68 68 create_table "grader_processes", force: :cascade do |t|
69 69 t.string "host", limit: 255
70 70 t.integer "pid", limit: 4
71 71 t.string "mode", limit: 255
72 72 t.boolean "active"
73 73 t.datetime "created_at", null: false
74 74 t.datetime "updated_at", null: false
75 75 t.integer "task_id", limit: 4
76 76 t.string "task_type", limit: 255
77 77 t.boolean "terminated"
@@ -98,25 +98,25
98 98
99 99 create_table "logins", force: :cascade do |t|
100 100 t.integer "user_id", limit: 4
101 101 t.string "ip_address", limit: 255
102 102 t.datetime "created_at", null: false
103 103 t.datetime "updated_at", null: false
104 104 end
105 105
106 106 create_table "messages", force: :cascade do |t|
107 107 t.integer "sender_id", limit: 4
108 108 t.integer "receiver_id", limit: 4
109 109 t.integer "replying_message_id", limit: 4
110 - t.text "body", limit: 16777215
110 + t.text "body", limit: 65535
111 111 t.boolean "replied"
112 112 t.datetime "created_at", null: false
113 113 t.datetime "updated_at", null: false
114 114 end
115 115
116 116 create_table "problems", force: :cascade do |t|
117 117 t.string "name", limit: 30
118 118 t.string "full_name", limit: 255
119 119 t.integer "full_score", limit: 4
120 120 t.date "date_added"
121 121 t.boolean "available"
122 122 t.string "url", limit: 255
@@ -144,25 +144,25
144 144 t.string "name", limit: 255
145 145 end
146 146
147 147 create_table "roles_users", id: false, force: :cascade do |t|
148 148 t.integer "role_id", limit: 4
149 149 t.integer "user_id", limit: 4
150 150 end
151 151
152 152 add_index "roles_users", ["user_id"], name: "index_roles_users_on_user_id", using: :btree
153 153
154 154 create_table "sessions", force: :cascade do |t|
155 155 t.string "session_id", limit: 255
156 - t.text "data", limit: 16777215
156 + t.text "data", limit: 65535
157 157 t.datetime "updated_at"
158 158 end
159 159
160 160 add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
161 161 add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
162 162
163 163 create_table "sites", force: :cascade do |t|
164 164 t.string "name", limit: 255
165 165 t.boolean "started"
166 166 t.datetime "start_time"
167 167 t.datetime "created_at", null: false
168 168 t.datetime "updated_at", null: false
@@ -172,110 +172,112
172 172
173 173 create_table "submission_view_logs", force: :cascade do |t|
174 174 t.integer "user_id", limit: 4
175 175 t.integer "submission_id", limit: 4
176 176 t.datetime "created_at", null: false
177 177 t.datetime "updated_at", null: false
178 178 end
179 179
180 180 create_table "submissions", force: :cascade do |t|
181 181 t.integer "user_id", limit: 4
182 182 t.integer "problem_id", limit: 4
183 183 t.integer "language_id", limit: 4
184 - t.text "source", limit: 16777215
184 + t.text "source", limit: 65535
185 185 t.binary "binary", limit: 65535
186 186 t.datetime "submitted_at"
187 187 t.datetime "compiled_at"
188 - t.text "compiler_message", limit: 16777215
188 + t.text "compiler_message", limit: 65535
189 189 t.datetime "graded_at"
190 190 t.integer "points", limit: 4
191 - t.text "grader_comment", limit: 16777215
191 + t.text "grader_comment", limit: 65535
192 192 t.integer "number", limit: 4
193 193 t.string "source_filename", limit: 255
194 194 t.float "max_runtime", limit: 24
195 195 t.integer "peak_memory", limit: 4
196 196 t.integer "effective_code_length", limit: 4
197 197 t.string "ip_address", limit: 255
198 198 end
199 199
200 200 add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree
201 201 add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree
202 202
203 203 create_table "tasks", force: :cascade do |t|
204 204 t.integer "submission_id", limit: 4
205 205 t.datetime "created_at"
206 206 t.integer "status", limit: 4
207 207 t.datetime "updated_at"
208 208 end
209 209
210 + add_index "tasks", ["submission_id"], name: "index_tasks_on_submission_id", using: :btree
211 +
210 212 create_table "test_pairs", force: :cascade do |t|
211 213 t.integer "problem_id", limit: 4
212 - t.text "input", limit: 4294967295
213 - t.text "solution", limit: 4294967295
214 + t.text "input", limit: 16777215
215 + t.text "solution", limit: 16777215
214 216 t.datetime "created_at", null: false
215 217 t.datetime "updated_at", null: false
216 218 end
217 219
218 220 create_table "test_requests", force: :cascade do |t|
219 221 t.integer "user_id", limit: 4
220 222 t.integer "problem_id", limit: 4
221 223 t.integer "submission_id", limit: 4
222 224 t.string "input_file_name", limit: 255
223 225 t.string "output_file_name", limit: 255
224 226 t.string "running_stat", limit: 255
225 227 t.integer "status", limit: 4
226 228 t.datetime "updated_at", null: false
227 229 t.datetime "submitted_at"
228 230 t.datetime "compiled_at"
229 - t.text "compiler_message", limit: 16777215
231 + t.text "compiler_message", limit: 65535
230 232 t.datetime "graded_at"
231 233 t.string "grader_comment", limit: 255
232 234 t.datetime "created_at", null: false
233 235 t.float "running_time", limit: 24
234 236 t.string "exit_status", limit: 255
235 237 t.integer "memory_usage", limit: 4
236 238 end
237 239
238 240 add_index "test_requests", ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id", using: :btree
239 241
240 242 create_table "testcases", force: :cascade do |t|
241 243 t.integer "problem_id", limit: 4
242 244 t.integer "num", limit: 4
243 245 t.integer "group", limit: 4
244 246 t.integer "score", limit: 4
245 247 t.text "input", limit: 4294967295
246 248 t.text "sol", limit: 4294967295
247 - t.datetime "created_at", null: false
248 - t.datetime "updated_at", null: false
249 + t.datetime "created_at"
250 + t.datetime "updated_at"
249 251 end
250 252
251 253 add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id", using: :btree
252 254
253 255 create_table "user_contest_stats", force: :cascade do |t|
254 256 t.integer "user_id", limit: 4
255 257 t.datetime "started_at"
256 258 t.datetime "created_at", null: false
257 259 t.datetime "updated_at", null: false
258 260 t.boolean "forced_logout"
259 261 end
260 262
261 263 create_table "users", force: :cascade do |t|
262 264 t.string "login", limit: 50
263 265 t.string "full_name", limit: 255
264 266 t.string "hashed_password", limit: 255
265 267 t.string "salt", limit: 5
266 268 t.string "alias", limit: 255
267 269 t.string "email", limit: 255
268 270 t.integer "site_id", limit: 4
269 271 t.integer "country_id", limit: 4
270 272 t.boolean "activated", default: false
271 273 t.datetime "created_at"
272 274 t.datetime "updated_at"
273 - t.string "section", limit: 255
274 275 t.boolean "enabled", default: true
275 276 t.string "remark", limit: 255
276 277 t.string "last_ip", limit: 255
278 + t.string "section", limit: 255
277 279 end
278 280
279 281 add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree
280 282
281 283 end
You need to be logged in to leave comments. Login now