diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -57,9 +57,13 @@ gem 'bootstrap-toggle-rails' gem 'autoprefixer-rails' +#bootstrap sortable +gem 'momentjs-rails' +gem 'rails_bootstrap_sortable' + +#ace editor gem 'ace-rails-ap' - gem 'haml' gem 'haml-rails' gem 'mail' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,8 @@ mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) + momentjs-rails (2.11.1) + railties (>= 3.1) multi_json (1.10.1) mysql2 (0.3.20) polyglot (0.3.5) @@ -111,6 +113,8 @@ activesupport (= 3.2.21) bundler (~> 1.0) railties (= 3.2.21) + rails_bootstrap_sortable (2.0.0) + momentjs-rails (~> 2, >= 2.8.3) railties (3.2.21) actionpack (= 3.2.21) activesupport (= 3.2.21) @@ -183,9 +187,11 @@ jquery-timepicker-addon-rails jquery-ui-sass-rails mail + momentjs-rails mysql2 prototype-rails rails (= 3.2.21) + rails_bootstrap_sortable rdiscount rouge rspec-rails (~> 2.99.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,8 +14,8 @@ //= require jquery_ujs //= require jquery.ui.all //= require bootstrap-sprockets -//x= require bootstrap-switch -//= require bootstrap-toggle +//= require moment +//= require bootstrap-sortable //= require select2 //= require custom //= require ace-rails-ap diff --git a/app/assets/javascripts/custom.js.coffee b/app/assets/javascripts/custom.js.coffee --- a/app/assets/javascripts/custom.js.coffee +++ b/app/assets/javascripts/custom.js.coffee @@ -37,7 +37,7 @@ target.addClass 'btn-warning' target.text '...' return - + #ace editor e = ace.edit("editor") e.setTheme('ace/theme/merbivore') diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -32,6 +32,7 @@ @import select2-bootstrap //@import bootstrap3-switch @import bootstrap-toggle +@import bootstrap-sortable //bootstrap navbar color (from) $bgDefault : #19197b @@ -105,6 +106,8 @@ .secondnavbar top: 50px + +// --------------- bootstrap file upload ---------------------- .btn-file position: relative overflow: hidden @@ -130,8 +133,18 @@ //font-family: Tahoma, "sans-serif" margin: 10px padding: 10px - padding-top: 40px + padding-top: 60px +// ------------------ bootstrap sortable -------------------- +table.sortable th + padding-right: 20px !important + span.sign + right: -15px !important + &.text-right + padding-left: 20px !important + padding-right: 8px !important + &:after, span.sign + left: -15px !important input font-family: Tahoma, "sans-serif" 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 @@ -12,6 +12,36 @@ admin_authorization } + def score + if params[:commit] == 'download csv' + @problems = Problem.all + else + @problems = Problem.find_available_problems + end + @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) + @scorearray = Array.new + @users.each do |u| + ustat = Array.new + ustat[0] = u + @problems.each do |p| + sub = Submission.find_last_by_user_and_problem(u.id,p.id) + if (sub!=nil) and (sub.points!=nil) and p and p.full_score + ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] + else + ustat << [0,false] + end + end + @scorearray << ustat + end + if params[:commit] == 'download csv' then + csv = gen_csv_from_scorearray(@scorearray,@problems) + send_data csv, filename: 'last_score.csv' + else + render template: 'user_admin/user_stat' + end + + end + def login_stat @logins = Array.new @@ -73,12 +103,7 @@ Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| if @submissions[s.user_id] if not @submissions[s.user_id][:sub].has_key?(s.problem_id) - a = nil - begin - a = Problem.find(s.problem_id) - rescue - a = nil - end + a = Problem.find_by_id(s.problem_id) @submissions[s.user_id][:sub][s.problem_id] = { prob_name: (a ? a.full_name : '(NULL)'), sub_ids: [s.id] } diff --git a/app/views/problems/toggle_test.js.haml b/app/views/problems/toggle_test.js.haml new file mode 100644 --- /dev/null +++ b/app/views/problems/toggle_test.js.haml @@ -0,0 +1,2 @@ += render partial: 'toggle_button', + locals: {button_id: "#problem-test-#{@problem.id}",button_on: @problem.test_allowed?} 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 @@ -1,12 +1,12 @@ -- content_for :header do - = javascript_include_tag 'local_jquery' - = stylesheet_link_tag 'tablesorter-theme.cafe' +/- content_for :header do +/ = javascript_include_tag 'local_jquery' +/ = stylesheet_link_tag 'tablesorter-theme.cafe' %script{:type=>"text/javascript"} $(function () { $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); - $('#my_table').tablesorter({widgets: ['zebra']}); + /$('#my_table').tablesorter({widgets: ['zebra']}); }); %h1 User grading results @@ -26,22 +26,22 @@ = link_to '[Show only latest submissions]', controller: :user_admin, action: :user_stat = link_to '[download csv with all problems]', controller: :user_admin, action: :user_stat_max, commit: 'download csv' -%table.tablesorter-cafe#my_table +%table.table.sortable.table-striped.table-bordered %thead %tr - %th User + %th Login %th Name %th Activated? - %th Logged in + %th Logged_in %th Contest(s) %th Remark - @problems.each do |p| - %th= p.name - %th Total - %th Passed + %th.text-right= p.name + %th.text-right Total + %th.text-right Passed %tbody - @scorearray.each do |sc| - %tr{class: cycle('info-even','info-odd')} + %tr - total,num_passed = 0,0 - sc.each_index do |i| - if i == 0 @@ -52,8 +52,10 @@ %td= sc[i].contests.collect {|c| c.name}.join(', ') %td= sc[i].remark - else - %td= sc[i][0] + %td.text-right= sc[i][0] - total += sc[i][0] - num_passed += 1 if sc[i][1] - %td= total - %td= num_passed + %td.text-right= total + %td.text-right= num_passed +:javascript + $.bootstrapSortable(true,'reversed')