# HG changeset patch # User Nattee Niparnan # Date 2016-12-26 05:09:45 # Node ID 3b5645cfc80e153ae59b5e80a2291a3ed7371011 # Parent 2101ac88fe70bb1380f12f2ee6032b7e84e1f70c fix compiler message add testing database diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'mysql2' +gem 'sqlite3' # Gems used only for assets and not required # in production environments by default. @@ -45,7 +46,7 @@ # jquery addition gem 'jquery-rails' -gem 'jquery-ui-sass-rails' +gem 'jquery-ui-rails' gem 'jquery-timepicker-addon-rails' gem 'jquery-tablesorter' gem 'jquery-countdown-rails' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,10 +103,6 @@ jquery-ui-rails (4.0.3) jquery-rails railties (>= 3.1.0) - jquery-ui-sass-rails (4.0.3.0) - jquery-rails - jquery-ui-rails (= 4.0.3) - railties (>= 3.1.0) json (1.8.3) loofah (2.0.3) nokogiri (>= 1.5.9) @@ -192,6 +188,7 @@ actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + sqlite3 (1.3.12) test-unit (3.2.3) power_assert thor (0.19.4) @@ -223,7 +220,7 @@ jquery-rails jquery-tablesorter jquery-timepicker-addon-rails - jquery-ui-sass-rails + jquery-ui-rails mail momentjs-rails mysql2 @@ -234,6 +231,7 @@ rspec-rails sass-rails select2-rails + sqlite3 test-unit uglifier verification! diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -1,6 +1,6 @@ class SubmissionsController < ApplicationController before_filter :authenticate - before_filter :submission_authorization, only: [:show, :direct_edit_submission] + before_filter :submission_authorization, only: [:show, :direct_edit_submission, :download] # GET /submissions # GET /submissions.json @@ -33,6 +33,18 @@ SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? end + def download + @submission = Submission.find(params[:id]) + send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'}) + end + + def compiler_msg + @submission = Submission.find(params[:id]) + respond_to do |format| + format.js + end + end + #on-site new submission on specific problem def direct_edit_problem @problem = Problem.find(params[:problem_id]) @@ -62,6 +74,7 @@ protected + def submission_authorization #admin always has privileged if @current_user.admin? diff --git a/app/views/application/_submission_short.html.haml b/app/views/application/_submission_short.html.haml --- a/app/views/application/_submission_short.html.haml +++ b/app/views/application/_submission_short.html.haml @@ -6,21 +6,21 @@ = t 'main.submitted_at' = format_short_time(submission.submitted_at.localtime) - else - = t 'main.graded_at' - = "#{format_short_time(submission.graded_at.localtime)}, " + %strong= t 'main.graded_at' + = "#{format_short_time(submission.graded_at.localtime)} " + %br - if GraderConfiguration['ui.show_score'] - = t 'main.score' + %strong=t 'main.score' = "#{(submission.points*100/submission.problem.full_score).to_i} " = " [" %tt = submission.grader_comment = "]" + %br + %strong View: - if GraderConfiguration.show_grading_result - = " | " = link_to '[detailed result]', :action => 'result', :id => submission.id - = " | " - = link_to("[#{t 'main.cmp_msg'}]", {:action => 'compiler_msg', :id => submission.id}, {:popup => true}) - = " | " - = link_to("[#{t 'main.src_link'}]",{:action => 'source', :id => submission.id}) - //= " | " - //= link_to "[#{t 'main.submissions_link'}]", main_submission_path(submission.problem.id) + = link_to "#{t 'main.cmp_msg'}", {:action => 'compiler_msg', :id => submission.id}, {popup: true,class: 'btn btn-xs btn-info'} + = link_to "#{t 'main.src_link'}", download_submission_path(submission.id), class: 'btn btn-xs btn-info' + = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info' + diff --git a/app/views/main/_submission_short.html.haml b/app/views/main/_submission_short.html.haml --- a/app/views/main/_submission_short.html.haml +++ b/app/views/main/_submission_short.html.haml @@ -20,7 +20,8 @@ %strong View: - if GraderConfiguration.show_grading_result = link_to '[detailed result]', :action => 'result', :id => submission.id - = link_to "#{t 'main.cmp_msg'}", {:action => 'compiler_msg', :id => submission.id}, {popup: true,class: 'btn btn-xs btn-info'} + /= link_to "#{t 'main.cmp_msg'}", {:action => 'compiler_msg', :id => submission.id}, {popup: true,class: 'btn btn-xs btn-info'} + = link_to "#{t 'main.cmp_msg'}", compiler_msg_submission_path(submission.id), {popup: true,remote: true,class: 'btn btn-xs btn-info'} = link_to "#{t 'main.src_link'}",{:action => 'source', :id => submission.id}, class: 'btn btn-xs btn-info' = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info' diff --git a/app/views/submissions/edit.html.haml b/app/views/submissions/edit.html.haml --- a/app/views/submissions/edit.html.haml +++ b/app/views/submissions/edit.html.haml @@ -28,10 +28,11 @@ .panel.panel-info .panel-heading Latest Submission Status + = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true .panel-body - if @submission = render :partial => 'submission_short', - :locals => {:submission => @submission, :problem_name => @problem.name } + :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id } .row .col-md-12 %h2 Console diff --git a/app/views/submissions/show.html.haml b/app/views/submissions/show.html.haml --- a/app/views/submissions/show.html.haml +++ b/app/views/submissions/show.html.haml @@ -85,19 +85,20 @@ %td %button.btn.btn-info.btn-xs{type: 'button', data: {toggle: 'modal', target: '#compiler'}} view - .modal.fade#compiler{tabindex: -1,role: 'dialog'} - .modal-dialog.modal-lg{role:'document'} - .modal-content - .modal-header - %button.close{type: 'button', data: {dismissed: :modal}, aria: {label: 'close'}} - %span{aria: {hidden: 'true'}, data: {dismiss: 'modal'}} × - %h4 Compiler message - .modal-body - %pre= @submission.compiler_message - .modal-footer - %button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}} Close - if session[:admin] %tr %td.text-right %strong IP %td #{@submission.ip_address} + +.modal.fade#compiler{tabindex: -1,role: 'dialog'} + .modal-dialog.modal-lg{role:'document'} + .modal-content + .modal-header + %button.close{type: 'button', data: {dismissed: :modal}, aria: {label: 'close'}} + %span{aria: {hidden: 'true'}, data: {dismiss: 'modal'}} × + %h4 Compiler message + .modal-body + %pre#compiler_msg= @submission.compiler_message + .modal-footer + %button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}} Close diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,10 @@ end resources :submissions do + member do + get 'download' + get 'compiler_msg' + end collection do get 'prob/:problem_id', to: 'submissions#index', as: 'problem' get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -9,112 +9,112 @@ # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # -# It's strongly recommended to check this file into your version control system. +# It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(:version => 20161031063337) do +ActiveRecord::Schema.define(version: 20161031063337) do - create_table "announcements", :force => true do |t| + create_table "announcements", force: :cascade do |t| t.string "author" t.text "body" t.boolean "published" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.boolean "frontpage", :default => false - t.boolean "contest_only", :default => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "frontpage", default: false + t.boolean "contest_only", default: false t.string "title" t.string "notes" end - create_table "contests", :force => true do |t| + create_table "contests", force: :cascade do |t| t.string "title" t.boolean "enabled" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "name" end - create_table "contests_problems", :id => false, :force => true do |t| + create_table "contests_problems", id: false, force: :cascade do |t| t.integer "contest_id" t.integer "problem_id" end - create_table "contests_users", :id => false, :force => true do |t| + create_table "contests_users", id: false, force: :cascade do |t| t.integer "contest_id" t.integer "user_id" end - create_table "countries", :force => true do |t| + create_table "countries", force: :cascade do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "descriptions", :force => true do |t| + create_table "descriptions", force: :cascade do |t| t.text "body" t.boolean "markdowned" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "grader_configurations", :force => true do |t| + create_table "grader_configurations", force: :cascade do |t| t.string "key" t.string "value_type" t.string "value" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.text "description" end - create_table "grader_processes", :force => true do |t| + create_table "grader_processes", force: :cascade do |t| t.string "host" t.integer "pid" t.string "mode" t.boolean "active" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "task_id" t.string "task_type" t.boolean "terminated" end - add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" + add_index "grader_processes", ["host", "pid"], name: "index_grader_processes_on_ip_and_pid" - create_table "heart_beats", :force => true do |t| + create_table "heart_beats", force: :cascade do |t| t.integer "user_id" t.string "ip_address" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "status" end - add_index "heart_beats", ["updated_at"], :name => "index_heart_beats_on_updated_at" + add_index "heart_beats", ["updated_at"], name: "index_heart_beats_on_updated_at" - create_table "languages", :force => true do |t| - t.string "name", :limit => 10 + create_table "languages", force: :cascade do |t| + t.string "name", limit: 10 t.string "pretty_name" - t.string "ext", :limit => 10 + t.string "ext", limit: 10 t.string "common_ext" end - create_table "logins", :force => true do |t| + create_table "logins", force: :cascade do |t| t.integer "user_id" t.string "ip_address" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "messages", :force => true do |t| + create_table "messages", force: :cascade do |t| t.integer "sender_id" t.integer "receiver_id" t.integer "replying_message_id" t.text "body" t.boolean "replied" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "problems", :force => true do |t| - t.string "name", :limit => 30 + create_table "problems", force: :cascade do |t| + t.string "name", limit: 30 t.string "full_name" t.integer "full_score" t.date "date_added" @@ -126,57 +126,57 @@ t.string "description_filename" end - create_table "rights", :force => true do |t| + create_table "rights", force: :cascade do |t| t.string "name" t.string "controller" t.string "action" end - create_table "rights_roles", :id => false, :force => true do |t| + create_table "rights_roles", id: false, force: :cascade do |t| t.integer "right_id" t.integer "role_id" end - add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" + add_index "rights_roles", ["role_id"], name: "index_rights_roles_on_role_id" - create_table "roles", :force => true do |t| + create_table "roles", force: :cascade do |t| t.string "name" end - create_table "roles_users", :id => false, :force => true do |t| + create_table "roles_users", id: false, force: :cascade do |t| t.integer "role_id" t.integer "user_id" end - add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" + add_index "roles_users", ["user_id"], name: "index_roles_users_on_user_id" - create_table "sessions", :force => true do |t| + create_table "sessions", force: :cascade do |t| t.string "session_id" t.text "data" t.datetime "updated_at" end - add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" - add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" + add_index "sessions", ["session_id"], name: "index_sessions_on_session_id" + add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at" - create_table "sites", :force => true do |t| + create_table "sites", force: :cascade do |t| t.string "name" t.boolean "started" t.datetime "start_time" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "country_id" t.string "password" end - create_table "submission_view_logs", :force => true do |t| + create_table "submission_view_logs", force: :cascade do |t| t.integer "user_id" t.integer "submission_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "submissions", :force => true do |t| + create_table "submissions", force: :cascade do |t| t.integer "user_id" t.integer "problem_id" t.integer "language_id" @@ -196,25 +196,25 @@ t.string "ip_address" end - add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true - add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" + add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true + add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id" - create_table "tasks", :force => true do |t| + create_table "tasks", force: :cascade do |t| t.integer "submission_id" t.datetime "created_at" t.integer "status" t.datetime "updated_at" end - create_table "test_pairs", :force => true do |t| + create_table "test_pairs", force: :cascade do |t| t.integer "problem_id" - t.text "input", :limit => 16777215 - t.text "solution", :limit => 16777215 - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.text "input", limit: 16777215 + t.text "solution", limit: 16777215 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "test_requests", :force => true do |t| + create_table "test_requests", force: :cascade do |t| t.integer "user_id" t.integer "problem_id" t.integer "submission_id" @@ -222,59 +222,59 @@ t.string "output_file_name" t.string "running_stat" t.integer "status" - t.datetime "updated_at", :null => false + t.datetime "updated_at", null: false t.datetime "submitted_at" t.datetime "compiled_at" t.text "compiler_message" t.datetime "graded_at" t.string "grader_comment" - t.datetime "created_at", :null => false + t.datetime "created_at", null: false t.float "running_time" t.string "exit_status" t.integer "memory_usage" end - add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" + add_index "test_requests", ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id" - create_table "testcases", :force => true do |t| + create_table "testcases", force: :cascade do |t| t.integer "problem_id" t.integer "num" t.integer "group" t.integer "score" t.text "input" t.text "sol" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "testcases", ["problem_id"], :name => "index_testcases_on_problem_id" + add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id" - create_table "user_contest_stats", :force => true do |t| + create_table "user_contest_stats", force: :cascade do |t| t.integer "user_id" t.datetime "started_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "forced_logout" end - create_table "users", :force => true do |t| - t.string "login", :limit => 50 + create_table "users", force: :cascade do |t| + t.string "login", limit: 50 t.string "full_name" t.string "hashed_password" - t.string "salt", :limit => 5 + t.string "salt", limit: 5 t.string "alias" t.string "email" t.integer "site_id" t.integer "country_id" - t.boolean "activated", :default => false + t.boolean "activated", default: false t.datetime "created_at" t.datetime "updated_at" - t.boolean "enabled", :default => true + t.boolean "enabled", default: true t.string "remark" t.string "last_ip" t.string "section" end - add_index "users", ["login"], :name => "index_users_on_login", :unique => true + add_index "users", ["login"], name: "index_users_on_login", unique: true end