# HG changeset patch # User Nattee Niparnan # Date 2015-02-19 15:28:54 # Node ID dd2e569af6cbe8818122485f9b11708f29ac195e # Parent 5a22064770a986677df32c1a93fc153080c55eaa # Parent c902838c1d8522087a9fc99fce8fb17a676aaa7d modernize java-bm, merge with algo-bm,master diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rails', '3.2.19' +gem 'rails', '3.2.21' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' @@ -10,13 +10,13 @@ # Gems used only for assets and not required # in production environments by default. group :assets do - gem 'sass-rails', '~> 3.2.3' - gem 'coffee-rails', '~> 3.2.1' + gem 'sass-rails', '~> 3.2.6' + gem 'coffee-rails', '~> 3.2.2' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby - gem 'uglifier', '>= 1.0.3' + gem 'uglifier' end gem 'prototype-rails' @@ -37,6 +37,9 @@ # gem 'debugger' # +#in-place editor +gem 'best_in_place', '~> 3.0.1' + # jquery addition gem 'jquery-rails' gem 'jquery-ui-sass-rails' @@ -46,15 +49,15 @@ #syntax highlighter gem 'rouge' -gem "haml" -gem "mail" -gem "rdiscount" -gem "test-unit" -gem 'will_paginate', '~> 3.0.0' +gem 'haml' +gem 'mail' +gem 'rdiscount' +gem 'test-unit' +gem 'will_paginate', '~> 3.0.7' gem 'dynamic_form' gem 'in_place_editing' -gem 'verification', :git => 'git://github.com/sikachu/verification.git' +gem 'verification', :git => 'https://github.com/sikachu/verification.git' group :test, :development do - gem "rspec-rails", "~> 2.0" + gem 'rspec-rails', '~> 2.99.0' end diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GIT - remote: git://github.com/sikachu/verification.git + remote: https://github.com/sikachu/verification.git revision: 76eaf51b13276ecae54bd9cd115832595d2ff56d specs: verification (1.0.3) @@ -9,12 +9,12 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.19) - actionpack (= 3.2.19) + actionmailer (3.2.21) + actionpack (= 3.2.21) mail (~> 2.5.4) - actionpack (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) + actionpack (3.2.21) + activemodel (= 3.2.21) + activesupport (= 3.2.21) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -22,21 +22,24 @@ rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.19) - activesupport (= 3.2.19) + activemodel (3.2.21) + activesupport (= 3.2.21) builder (~> 3.0.0) - activerecord (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) + activerecord (3.2.21) + activemodel (= 3.2.21) + activesupport (= 3.2.21) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) - activesupport (3.2.19) + activeresource (3.2.21) + activemodel (= 3.2.21) + activesupport (= 3.2.21) + activesupport (3.2.21) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) arel (3.0.3) + best_in_place (3.0.3) + actionpack (>= 3.2) + railties (>= 3.2) builder (3.0.4) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -44,21 +47,21 @@ coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.7.1) + coffee-script-source (1.9.0) diff-lcs (1.2.5) dynamic_form (1.1.4) erubis (2.7.0) - execjs (2.2.1) - haml (4.0.5) + execjs (2.3.0) + haml (4.0.6) tilt hike (1.2.3) - i18n (0.6.11) + i18n (0.7.0) in_place_editing (1.2.0) journey (1.0.4) - jquery-rails (3.1.1) + jquery-rails (3.1.2) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - jquery-tablesorter (1.12.7) + jquery-tablesorter (1.13.4) railties (>= 3.1, < 5) jquery-timepicker-addon-rails (1.4.1) railties (>= 3.1) @@ -69,15 +72,15 @@ jquery-rails jquery-ui-rails (= 4.0.3) railties (>= 3.1.0) - json (1.8.1) + json (1.8.2) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) multi_json (1.10.1) - mysql2 (0.3.16) + mysql2 (0.3.17) polyglot (0.3.5) - power_assert (0.1.3) + power_assert (0.2.2) prototype-rails (3.2.1) rails (~> 3.2) rack (1.4.5) @@ -85,34 +88,34 @@ rack (>= 0.4) rack-ssl (1.3.4) rack - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) - rails (3.2.19) - actionmailer (= 3.2.19) - actionpack (= 3.2.19) - activerecord (= 3.2.19) - activeresource (= 3.2.19) - activesupport (= 3.2.19) + rails (3.2.21) + actionmailer (= 3.2.21) + actionpack (= 3.2.21) + activerecord (= 3.2.21) + activeresource (= 3.2.21) + activesupport (= 3.2.21) bundler (~> 1.0) - railties (= 3.2.19) - railties (3.2.19) - actionpack (= 3.2.19) - activesupport (= 3.2.19) + railties (= 3.2.21) + railties (3.2.21) + actionpack (= 3.2.21) + activesupport (= 3.2.21) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.3.2) - rdiscount (2.1.7.1) + rake (10.4.2) + rdiscount (2.1.8) rdoc (3.12.2) json (~> 1.4) - rouge (1.6.2) - rspec-collection_matchers (1.0.0) + rouge (1.8.0) + rspec-collection_matchers (1.1.2) rspec-expectations (>= 2.99.0.beta1) rspec-core (2.99.2) rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.2) + rspec-mocks (2.99.3) rspec-rails (2.99.0) actionpack (>= 3.0) activemodel (>= 3.0) @@ -122,25 +125,25 @@ rspec-core (~> 2.99.0) rspec-expectations (~> 2.99.0) rspec-mocks (~> 2.99.0) - sass (3.4.1) + sass (3.4.11) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - sprockets (2.2.2) + sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - test-unit (3.0.1) + test-unit (3.0.9) power_assert thor (0.19.1) tilt (1.4.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.41) - uglifier (2.5.3) + tzinfo (0.3.43) + uglifier (2.7.0) execjs (>= 0.3.0) json (>= 1.8.0) will_paginate (3.0.7) @@ -149,7 +152,8 @@ ruby DEPENDENCIES - coffee-rails (~> 3.2.1) + best_in_place (~> 3.0.1) + coffee-rails (~> 3.2.2) dynamic_form haml in_place_editing @@ -160,12 +164,12 @@ mail mysql2 prototype-rails - rails (= 3.2.19) + rails (= 3.2.21) rdiscount rouge - rspec-rails (~> 2.0) - sass-rails (~> 3.2.3) + rspec-rails (~> 2.99.0) + sass-rails (~> 3.2.6) test-unit - uglifier (>= 1.0.3) + uglifier verification! - will_paginate (~> 3.0.0) + will_paginate (~> 3.0.7) diff --git a/README b/README --- a/README +++ b/README @@ -1,182 +1,10 @@ -== Welcome to Rails - -Rails is a web-application and persistence framework that includes everything -needed to create database-backed web-applications according to the -Model-View-Control pattern of separation. This pattern splits the view (also -called the presentation) into "dumb" templates that are primarily responsible -for inserting pre-built data in between HTML tags. The model contains the -"smart" domain objects (such as Account, Product, Person, Post) that holds all -the business logic and knows how to persist themselves to a database. The -controller handles the incoming requests (such as Save New Account, Update -Product, Show Post) by manipulating the model and directing data to the view. - -In Rails, the model is handled by what's called an object-relational mapping -layer entitled Active Record. This layer allows you to present the data from -database rows as objects and embellish these data objects with business logic -methods. You can read more about Active Record in -link:files/vendor/rails/activerecord/README.html. - -The controller and view are handled by the Action Pack, which handles both -layers by its two parts: Action View and Action Controller. These two layers -are bundled in a single package due to their heavy interdependence. This is -unlike the relationship between the Active Record and Action Pack that is much -more separate. Each of these packages can be used independently outside of -Rails. You can read more about Action Pack in -link:files/vendor/rails/actionpack/README.html. - - -== Getting started - -1. At the command prompt, start a new rails application using the rails command - and your application name. Ex: rails myapp - (If you've downloaded rails in a complete tgz or zip, this step is already done) -2. Change directory into myapp and start the web server: script/server (run with --help for options) -3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!" -4. Follow the guidelines to start developing your application - - -== Web Servers - -By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise -Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server, -Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures -that you can always get up and running quickly. +== cafe grader -Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is -suitable for development and deployment of Rails applications. If you have Ruby Gems installed, -getting up and running with mongrel is as easy as: gem install mongrel. -More info at: http://mongrel.rubyforge.org - -If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than -Mongrel and WEBrick and also suited for production use, but requires additional -installation and currently only works well on OS X/Unix (Windows users are encouraged -to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from -http://www.lighttpd.net. - -And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby -web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not -for production. - -But of course its also possible to run Rails on any platform that supports FCGI. -Apache, LiteSpeed, IIS are just a few. For more information on FCGI, -please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI - - -== Debugging Rails - -Have "tail -f" commands running on the server.log and development.log. Rails will -automatically display debugging and runtime information to these files. Debugging -info will also be shown in the browser on requests from 127.0.0.1. - - -== Breakpoints - -Breakpoint support is available through the script/breakpointer client. This -means that you can break out of execution at any point in the code, investigate -and change the model, AND then resume execution! Example: - - class WeblogController < ActionController::Base - def index - @posts = Post.find(:all) - breakpoint "Breaking out from the list" - end - end - -So the controller will accept the action, run the first line, then present you -with a IRB prompt in the breakpointer window. Here you can do things like: - -Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint' +cafe grader is a programming contest platform used in Thailand IOI training. +The package includes 2 repositories, jittat/cafe-grader-web and jittat/cafe-grader-judge-scripts. - >> @posts.inspect - => "[#nil, \"body\"=>nil, \"id\"=>\"1\"}>, - #\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]" - >> @posts.first.title = "hello from a breakpoint" - => "hello from a breakpoint" - -...and even better is that you can examine how your runtime objects actually work: - - >> f = @posts.first - => #nil, "body"=>nil, "id"=>"1"}> - >> f. - Display all 152 possibilities? (y or n) - -Finally, when you're ready to resume execution, you press CTRL-D - - -== Console - -You can interact with the domain model by starting the console through script/console. -Here you'll have all parts of the application configured, just like it is when the -application is running. You can inspect domain models, change values, and save to the -database. Starting the script without arguments will launch it in the development environment. -Passing an argument will specify a different environment, like script/console production. - -To reload your controllers and models after launching the console run reload! - -To reload your controllers and models after launching the console run reload! - - - -== Description of contents - -app - Holds all the code that's specific to this particular application. - -app/controllers - Holds controllers that should be named like weblogs_controller.rb for - automated URL mapping. All controllers should descend from ApplicationController - which itself descends from ActionController::Base. - -app/models - Holds models that should be named like post.rb. - Most models will descend from ActiveRecord::Base. +=== Installation -app/views - Holds the template files for the view that should be named like - weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby - syntax. - -app/views/layouts - Holds the template files for layouts to be used with views. This models the common - header/footer method of wrapping views. In your views, define a layout using the - layout :default and create a file named default.rhtml. Inside default.rhtml, - call <% yield %> to render the view using this layout. - -app/helpers - Holds view helpers that should be named like weblogs_helper.rb. These are generated - for you automatically when using script/generate for controllers. Helpers can be used to - wrap functionality for your views into methods. - -config - Configuration files for the Rails environment, the routing map, the database, and other dependencies. - -components - Self-contained mini-applications that can bundle together controllers, models, and views. +The system is tested on ubuntu 14.04 LTS. Use the installation script in +cafe-grader-judge-scripts/installer/install.sh . See http://theory.cpe.ku.ac.th/wiki/index.php/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87_Cafe_grader for the detail. -db - Contains the database schema in schema.rb. db/migrate contains all - the sequence of Migrations for your schema. - -doc - This directory is where your application documentation will be stored when generated - using rake doc:app - -lib - Application specific libraries. Basically, any kind of custom code that doesn't - belong under controllers, models, or helpers. This directory is in the load path. - -public - The directory available for the web server. Contains subdirectories for images, stylesheets, - and javascripts. Also contains the dispatchers and the default HTML files. This should be - set as the DOCUMENT_ROOT of your web server. - -script - Helper scripts for automation and generation. - -test - Unit and functional tests along with fixtures. When using the script/generate scripts, template - test files will be generated for you and placed in this directory. - -vendor - External libraries that the application depends on. Also includes the plugins subdirectory. - This directory is in the load path. diff --git a/app/assets/javascripts/local_jquery.js b/app/assets/javascripts/local_jquery.js --- a/app/assets/javascripts/local_jquery.js +++ b/app/assets/javascripts/local_jquery.js @@ -5,3 +5,10 @@ //= require jquery.ui.slider //= require jquery-ui-timepicker-addon //= require jquery-tablesorter +//= require best_in_place +//= require best_in_place.jquery-ui + +$(document).ready(function() { + /* Activating Best In Place */ + jQuery(".best_in_place").best_in_place(); +}); diff --git a/app/controllers/configurations_controller.rb b/app/controllers/configurations_controller.rb --- a/app/controllers/configurations_controller.rb +++ b/app/controllers/configurations_controller.rb @@ -3,9 +3,6 @@ before_filter :authenticate before_filter { |controller| controller.authorization_by_roles(['admin'])} - in_place_edit_for :grader_configuration, :key - in_place_edit_for :grader_configuration, :type - in_place_edit_for :grader_configuration, :value def index @configurations = GraderConfiguration.find(:all, @@ -17,4 +14,15 @@ redirect_to :action => 'index' end + def update + @config = GraderConfiguration.find(params[:id]) + respond_to do |format| + if @config.update_attributes(params[:grader_configuration]) + format.json { head :ok } + else + format.json { respond_with_bip(@config) } + end + end + end + end diff --git a/app/controllers/contest_management_controller.rb b/app/controllers/contest_management_controller.rb --- a/app/controllers/contest_management_controller.rb +++ b/app/controllers/contest_management_controller.rb @@ -37,7 +37,7 @@ end def change_contest_mode - if ['standard', 'contest', 'indv-contest'].include? params[:id] + if ['standard', 'contest', 'indv-contest', 'analysis'].include? params[:id] config = GraderConfiguration.find_by_key('system.mode') config.value = params[:id] config.save diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -71,7 +71,7 @@ @submission.ip_address = request.remote_ip if GraderConfiguration.time_limit_mode? and user.contest_finished? - @submission.errors.add_to_base "The contest is over." + @submission.errors.add(:base,"The contest is over.") prepare_list_information render :action => 'list' and return end @@ -194,7 +194,7 @@ def confirm_contest_start user = User.find(session[:user_id]) - if request.method == :post + if request.method == 'POST' user.update_start_time redirect_to :action => 'list' else diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -31,20 +31,21 @@ user = User.find(session[:user_id]) @message = Message.new(params[:message]) @message.sender = user - if !@message.save - render :action => 'list' and return + if @message.body == '' or !@message.save + flash[:notice] = 'An error occurred' else flash[:notice] = 'New message posted' - redirect_to :action => 'list' end + redirect_to :action => 'list' end def reply user = User.find(session[:user_id]) @message = Message.new(params[:r_message]) @message.sender = user - if !@message.save - render :action => 'show' and return + if @message.body == '' or !@message.save + flash[:notice] = 'An error occurred' + redirect_to :action => 'show', :id => @message.replying_message_id else flash[:notice] = 'Message replied' rep_msg = @message.replying_message @@ -58,7 +59,7 @@ message = Message.find(params[:id]) message.replied = true message.save - flash[:notice] = 'Message hided (just marked replied)' + flash[:notice] = 'Message hidden (just marked replied)' redirect_to :action => 'console' end diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -1,6 +1,6 @@ class ReportController < ApplicationController - before_filter :admin_authorization, only: [:login_stat,:submission_stat] + before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck] before_filter(only: [:problem_hof]) { |c| return false unless authenticate @@ -118,6 +118,7 @@ d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 @histogram[:data][d.to_i] += 1 if d < range + next unless sub.points @summary[:count] += 1 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max @@ -196,7 +197,7 @@ @struggle = Array.new record = {} Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub| - next unless sub.user and sub.problem + next unless sub.problem and sub.user if user != sub.user_id or problem != sub.problem_id @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve record = {user: sub.user, problem: sub.problem} diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -26,7 +26,7 @@ if GraderConfiguration.time_limit_mode? if @user.contest_finished? - @submitted_test_request.errors.add_to_base('Contest is over.') + @submitted_test_request.errors.add(:base,'Contest is over.') prepare_index_information render :action => 'index' and return end diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -2,7 +2,6 @@ class UserAdminController < ApplicationController - include MailHelperMethods before_filter :admin_authorization @@ -85,7 +84,8 @@ end user = User.find_by_login(login) - if user + if (user) + user.full_name = full_name user.password = password else user = User.new({:login => login, @@ -150,7 +150,6 @@ end @scorearray << ustat end - if params[:commit] == 'download csv' then csv = gen_csv_from_scorearray(@scorearray,@problems) send_data csv, filename: 'last_score.csv' diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -63,7 +63,7 @@ render :action => 'email_error', :layout => 'empty' end else - @user.errors.add_to_base("Email cannot be blank") if @user.email=='' + @user.errors.add(:base,"Email cannot be blank") if @user.email=='' render :action => 'new', :layout => 'empty' end end @@ -154,7 +154,7 @@ :login => user.login, :password => user.password, :activation_url => activation_url, - :admin_email => admin_email + :admin_email => GraderConfiguration['system.admin_email'] }) logger.info mail_body @@ -170,7 +170,7 @@ :contest_name => contest_name, :login => user.login, :password => user.password, - :admin_email => admin_email + :admin_email => GraderConfiguration['system.admin_email'] }) logger.info mail_body diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -118,7 +118,7 @@ #{user.full_name}
-#{t 'title_bar.current_time'} #{format_short_time(Time.new)} +#{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} #{time_left}
diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -45,7 +45,7 @@ import_params[:memory_limit], import_params[:checker_name], import_to_db) - problem.errors.add_to_base('Import error.') + problem.errors.add(:base,'Import error.') end return problem, importer.log_msg @@ -85,17 +85,17 @@ DEFAULT_MEMORY_LIMIT) if time_limit<=0 or time_limit >60 - problem.errors.add_to_base('Time limit out of range.') + problem.errors.add(:base,'Time limit out of range.') end if memory_limit==0 and params[:memory_limit]!='0' - problem.errors.add_to_base('Memory limit format errors.') + problem.errors.add(:base,'Memory limit format errors.') elsif memory_limit<=0 or memory_limit >512 - problem.errors.add_to_base('Memory limit out of range.') + problem.errors.add(:base,'Memory limit out of range.') end if params[:file]==nil or params[:file]=='' - problem.errors.add_to_base('No testdata file.') + problem.errors.add(:base,'No testdata file.') end checker_name = 'text' diff --git a/app/models/test_request.rb b/app/models/test_request.rb --- a/app/models/test_request.rb +++ b/app/models/test_request.rb @@ -70,12 +70,12 @@ # checks if the user submits any input file if params[:input_file]==nil or params[:input_file]=="" - test_request.errors.add_to_base("No input submitted.") + test_request.errors.add(:base,"No input submitted.") test_request.input_file_name = nil else test_request.input_file_name = save_input_file(params[:input_file], user, problem) if test_request.input_file_name == nil - test_request.errors.add_to_base("No input submitted.") + test_request.errors.adds(:base,"No input submitted.") end if params[:additional_file]!=nil and params[:additional_file]!="" save_additional_file(params[:additional_file], diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,11 +67,11 @@ user = find_by_login(login) if user return user if user.authenticated?(password) -# if user.authenticated_by_cucas?(password) or user.authenticated_by_pop3?(password) -# user.password = password -# user.save -# return user -# end + if user.authenticated_by_cucas?(password) or user.authenticated_by_pop3?(password) + user.password = password + user.save + return user + end end end @@ -351,7 +351,7 @@ def uniqueness_of_email_from_activated_users user = User.activated_users.find_by_email(self.email) if user and (user.login != self.login) - self.errors.add_to_base("Email has already been taken") + self.errors.add(:base,"Email has already been taken") end end @@ -362,7 +362,7 @@ :order => 'created_at DESC') if open_user and open_user.created_at and (open_user.created_at > Time.now.gmtime - 5.minutes) - self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") + self.errors.add(:base,"There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") end end diff --git a/app/views/configurations/index.html.haml b/app/views/configurations/index.html.haml --- a/app/views/configurations/index.html.haml +++ b/app/views/configurations/index.html.haml @@ -1,3 +1,6 @@ +- content_for :header do + = javascript_include_tag 'local_jquery' + %h1 System configuration %table.info @@ -14,7 +17,7 @@ %td = in_place_editor_field :grader_configuration, :value_type, {}, :rows=>1 %td - = in_place_editor_field :grader_configuration, :value, {}, :rows=>1 + = best_in_place @grader_configuration, :value, ok_button: "ok", cancel_button: "cancel" %td= conf.description - if GraderConfiguration.config_cached? diff --git a/app/views/contest_management/index.html.haml b/app/views/contest_management/index.html.haml --- a/app/views/contest_management/index.html.haml +++ b/app/views/contest_management/index.html.haml @@ -11,18 +11,21 @@ .infobox %b Web interface mode: - - if (not GraderConfiguration.contest_mode?) and (not GraderConfiguration.indv_contest_mode?) - standard mode + - if GraderConfiguration.analysis_mode? + Analysis Mode + - elsif (not GraderConfiguration.contest_mode?) and (not GraderConfiguration.indv_contest_mode?) + Standard Mode - elsif GraderConfiguration.contest_mode? - normal contest mode. + Normal Contest Mode - else - individual contest mode. + Individual Contest Mode %br/ Change mode to: - =raw "[#{link_to 'standard', :action => 'change_contest_mode', :id => 'standard'}]" - =raw "[#{link_to 'contest', :action => 'change_contest_mode', :id => 'contest'}]" - =raw "[#{link_to 'individual contest', :action => 'change_contest_mode', :id => 'indv-contest'}]" + =raw "[#{link_to 'Standard', :action => 'change_contest_mode', :id => 'standard'}]" + =raw "[#{link_to 'Contest', :action => 'change_contest_mode', :id => 'contest'}]" + =raw "[#{link_to 'Individual Contest', :action => 'change_contest_mode', :id => 'indv-contest'}]" + =raw "[#{link_to 'Analysis', :action => 'change_contest_mode', :id => 'analysis'}]" - if GraderConfiguration.indv_contest_mode? = render :partial => 'indv_contest_mode_index' diff --git a/app/views/graders/list.html.haml b/app/views/graders/list.html.haml --- a/app/views/graders/list.html.haml +++ b/app/views/graders/list.html.haml @@ -1,5 +1,6 @@ - content_for :head do = stylesheet_link_tag 'graders' + = javascript_include_tag 'local_jquery' %h1 Grader information @@ -66,7 +67,7 @@ %td= sub.try(:user).try(:full_name) %td= sub.try(:problem).try(:full_name) %td= "#{time_ago_in_words(sub.submitted_at)} ago" - %td= "#{sub.graded_at ? time_ago_in_words(sub.graded_at) : ''} ago" + %td= sub.graded_at ? "#{time_ago_in_words(sub.graded_at)} ago" : " " %td= sub.grader_comment diff --git a/app/views/graders/test_request.html.haml b/app/views/graders/test_request.html.haml --- a/app/views/graders/test_request.html.haml +++ b/app/views/graders/test_request.html.haml @@ -25,7 +25,7 @@ - if @test_request.compiler_message!=nil and @test_request.compiler_message!='' %b Compiler Message %div{:style => "border: 1px solid black; background: lightgrey"} - = simple_format(truncate((@test_request.compiler_message or ''),200)) + = simple_format(truncate((@test_request.compiler_message or ''), :length => 200)) %b Input (first 2kb) %div{:style => "border: 1px solid black; background: lightgrey"} diff --git a/app/views/main/_compiler_message.html.erb b/app/views/main/_compiler_message.html.erb --- a/app/views/main/_compiler_message.html.erb +++ b/app/views/main/_compiler_message.html.erb @@ -1,5 +1,5 @@ -<% if compiler_message==nil or compiler_message=='' %> +<% if compiler_message == nil or compiler_message.chomp == '' %> No message <% else %>
"center"} + = submission.source_filename + = " (#{submission.language.pretty_name}) " = link_to('[load]',{:action => 'source', :id => submission.id}) %td.info - if submission.graded_at!=nil diff --git a/app/views/main/compiler_msg.html.haml b/app/views/main/compiler_msg.html.haml --- a/app/views/main/compiler_msg.html.haml +++ b/app/views/main/compiler_msg.html.haml @@ -1,6 +1,6 @@ %h2= "Compiler message for submission \##{@submission.number}, task: #{@submission.problem.name}" %p - - if @submission.compiler_message.chomp == '' - no message + - if @submission.compiler_message == nil or @submission.compiler_message.chomp == '' + No message - else = simple_format(@submission.compiler_message) diff --git a/app/views/main/confirm_contest_start.html.haml b/app/views/main/confirm_contest_start.html.haml --- a/app/views/main/confirm_contest_start.html.haml +++ b/app/views/main/confirm_contest_start.html.haml @@ -12,5 +12,5 @@ =t 'main.confirm_contest_start.timer_starts_after_click' - = form_tag :action => 'confirm_contest_start', :method => 'post' do + = form_tag :action => 'confirm_contest_start' do = submit_tag t('main.confirm_contest_start.start_button'), :confirm => t('main.confirm_contest_start.start_button_confirm') diff --git a/app/views/problems/do_import.html.haml b/app/views/problems/do_import.html.haml --- a/app/views/problems/do_import.html.haml +++ b/app/views/problems/do_import.html.haml @@ -7,8 +7,7 @@ %b Problem: = "#{@problem.full_name} (#{@problem.name})" %br/ - Note that the full score has be assigned to the default value, 100. - You should change it to the correct full score. + = "Note that the full score has been set to #{@problem.full_score}." %p = link_to '[Back to problem list]', :action => 'list' diff --git a/app/views/report/_task_hof.html.haml b/app/views/report/_task_hof.html.haml --- a/app/views/report/_task_hof.html.haml +++ b/app/views/report/_task_hof.html.haml @@ -9,7 +9,6 @@ $("#mem_remark_box").hide(); }); }); - alert("hahaha"); :css .hof_user { color: orangered; font-style: italic; } .hof_language { color: green; font-style: italic; } diff --git a/app/views/user_admin/_form.html.erb b/app/views/user_admin/_form.html.erb --- a/app/views/user_admin/_form.html.erb +++ b/app/views/user_admin/_form.html.erb @@ -14,9 +14,12 @@ <%= password_field 'user', 'password_confirmation' %>


-<%= text_field 'user', 'email' %>

+<%= email_field 'user', 'email' %>


<%= text_field 'user', 'alias' %>

+ +


+<%= text_field 'user', 'remark' %>

diff --git a/app/views/user_admin/edit.html.erb b/app/views/user_admin/edit.html.erb deleted file mode 100644 --- a/app/views/user_admin/edit.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

Editing user

- -<%= form_tag :action => 'update', :id => @user do %> - <%= render :partial => 'form' %> - <%= submit_tag 'Edit' %> -<% end %> - -<%= link_to 'Show', :action => 'show', :id => @user %> | -<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/user_admin/edit.html.haml b/app/views/user_admin/edit.html.haml new file mode 100644 --- /dev/null +++ b/app/views/user_admin/edit.html.haml @@ -0,0 +1,11 @@ +%h1 Editing user + += form_tag :action => 'update', :id => @user do + = error_messages_for 'user' + = render partial: "form" + = submit_tag "Edit" + + += link_to 'Show', :action => 'show', :id => @user +| += link_to 'Back', :action => 'list' diff --git a/app/views/user_admin/list.html.erb b/app/views/user_admin/list.html.erb --- a/app/views/user_admin/list.html.erb +++ b/app/views/user_admin/list.html.erb @@ -16,7 +16,7 @@ <%= text_field 'user', 'full_name', :size => 30 %> <%= password_field 'user', 'password', :size => 10 %> <%= password_field 'user', 'password_confirmation', :size => 10 %> - <%= text_field 'user', 'email', :size => 15 %> + <%= email_field 'user', 'email', :size => 15 %> <%= submit_tag "Create" %> diff --git a/app/views/user_admin/user_stat.html.haml b/app/views/user_admin/user_stat.html.haml --- a/app/views/user_admin/user_stat.html.haml +++ b/app/views/user_admin/user_stat.html.haml @@ -34,7 +34,7 @@ %th Activated? %th Logged in %th Contest(s) - %th Section + %th Remark - @problems.each do |p| %th= p.name %th Total @@ -50,7 +50,7 @@ %td= sc[i].activated %td= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no' %td= sc[i].contests.collect {|c| c.name}.join(', ') - %td= sc[i].section + %td= sc[i].remark - else %td= sc[i][0] - total += sc[i][0] diff --git a/app/views/users/forget.html.haml b/app/views/users/forget.html.haml --- a/app/views/users/forget.html.haml +++ b/app/views/users/forget.html.haml @@ -11,7 +11,8 @@ = form_tag :action => 'retrieve_password' do =t 'registration.password_retrieval.instructions' - = text_field 'email', nil, :size => 20 + %br/ + = email_field 'email', nil, :size => 20 %br/ = submit_tag(t 'registration.password_retrieval.button_label') diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml --- a/app/views/users/new.html.haml +++ b/app/views/users/new.html.haml @@ -25,12 +25,12 @@ %tr %td{:align => "right"} = "#{t 'email_label'}:" - %td= f.text_field :email + %td= f.email_field :email %tr %td %td %small - =t 'registration.email_guide' + =t('registration.email_guide').html_safe %tr %td/ %td diff --git a/config/environments/development.rb b/config/environments/development.rb --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -34,4 +34,7 @@ # Expands the lines which load the assets config.assets.debug = true + + # Prevents assets from rendering twice + config.serve_static_assets = false end diff --git a/config/locales/en.yml b/config/locales/en.yml --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,8 +9,8 @@ email_label: 'E-mail' password_label: 'Password' - go_ahead_to: "Go ahead to" - go_back_to: "Go back to" + go_ahead_to: "Go ahead to " + go_back_to: "Go back to " login_page: "login page" home_page: "home page" diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,8 @@ resources :announcements resources :sites + resources :grader_configuration, controller: 'configurations' + # The priority is based upon order of creation: # first created -> highest priority. diff --git a/db/migrate/20150203153534_add_more_to_users.rb b/db/migrate/20150203153534_add_more_to_users.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20150203153534_add_more_to_users.rb @@ -0,0 +1,6 @@ +class AddMoreToUsers < ActiveRecord::Migration + def change + add_column :users, :enabled, :boolean, default: 1 + add_column :users, :remark, :string + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140917150629) do +ActiveRecord::Schema.define(:version => 20150203153534) do create_table "announcements", :force => true do |t| t.string "author" @@ -239,7 +239,8 @@ t.boolean "activated", :default => false t.datetime "created_at" t.datetime "updated_at" - t.string "section" + t.boolean "enabled", :default => true + t.string "remark" end add_index "users", ["login"], :name => "index_users_on_login", :unique => true diff --git a/db/seeds.rb b/db/seeds.rb --- a/db/seeds.rb +++ b/db/seeds.rb @@ -100,7 +100,7 @@ :value_type => 'boolean', :default_value => 'true', :description => 'If this option is true, users can change their settings' - } + }, # If Configuration['contest.test_request.early_timeout'] is true # the user will not be able to use test request at 30 minutes diff --git a/lib/mail_helper_methods.rb b/lib/mail_helper_methods.rb --- a/lib/mail_helper_methods.rb +++ b/lib/mail_helper_methods.rb @@ -22,7 +22,18 @@ body mail_body end - mail.delivery_settings = { :address => smtp_server } + mail_option = { + :address => smtp_server, +# :domain => nil, +# :port => 25, +# :user_name => nil, +# :password => nil, +# :authentication=>'plain', +# :enable_starttls_auto => true + } + + mail.delivery_method :smtp, mail_option + mail.deliver end