# HG changeset patch # User Nattee Niparnan # Date 2016-06-28 02:55:05 # Node ID 2e5e11be6caed4f9f065d2440c80d1fcdcdd1e2a # Parent 9fc5999b7c8e8e8921cf8708c3da77e9f660b9ce * add forgotten toggle file * main/submission changed to bootstrap diff --git a/app/assets/javascripts/announcements.js.coffee b/app/assets/javascripts/announcements.js.coffee --- a/app/assets/javascripts/announcements.js.coffee +++ b/app/assets/javascripts/announcements.js.coffee @@ -1,7 +1,6 @@ #js for announcement $ -> $('.ajax-toggle').on 'click', (event) -> - console.log event.target.id target = $(event.target) target.removeClass 'btn-default' target.removeClass 'btn-success' diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee new file mode 100644 --- /dev/null +++ b/app/assets/javascripts/main.js.coffee @@ -0,0 +1,6 @@ +$ -> + $("#submission_problem_go").on 'click', (event) -> + url = $("#submission_problem_id").val() + if (url) + window.location = url + 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 @@ -123,8 +123,8 @@ @problem = nil @submissions = nil else - @problem = Problem.find_by_name(params[:id]) - if not @problem.available + @problem = Problem.find_by_id(params[:id]) + if (@problem == nil) or (not @problem.available) redirect_to :action => 'list' flash[:notice] = 'Error: submissions for that problem are not viewable.' return 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 @@ -107,6 +107,18 @@ end end + def problem_select(problems, options = {}) + prefix = options[:with_specific_in_header] ? [[(t 'main.specified_in_header'),'-1']] : [] + selected = options[:selected] || (options[:with_specific_in_header] ? -1 : nil) + puts "selected = #{selected} hehe" + html_options = {class: 'select2 form-control'} + html_options[:id] = options[:id]if options[:id] + select 'submission', + 'problem_id', prefix + problems.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}, + (selected ? { selected: "#{selected}"} : {} ), + html_options + end + def user_title_bar(user) header = '' time_left = '' diff --git a/app/views/main/_submission_box.html.haml b/app/views/main/_submission_box.html.haml --- a/app/views/main/_submission_box.html.haml +++ b/app/views/main/_submission_box.html.haml @@ -8,7 +8,7 @@ %li= msg .form-group = label_tag :submission, 'Problem:' - = select 'submission', 'problem_id', [[(t 'main.specified_in_header'),'-1']] + @problems.collect {|p| [p.full_name, p.id]}, {:selected => '-1'}, { class: 'select2 form-control' } + = select 'submission', 'problem_id', [[(t 'main.specified_in_header'),'-1']] + @problems.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}, {:selected => '-1'}, { class: 'select2 form-control' } .form-group = label_tag :file, 'File:' .input-group diff --git a/app/views/main/submission.html.haml b/app/views/main/submission.html.haml --- a/app/views/main/submission.html.haml +++ b/app/views/main/submission.html.haml @@ -1,10 +1,16 @@ = user_title_bar(@user) -.task-menu - Task List - %br/ - - @problems.each do |problem| - = link_to problem.name, :action => 'submission', :id => problem.name +.panel.panel-info + .panel-heading + Select Problems + .panel-body + .form-inline + = select 'submission', + 'problem_id', + @problems.collect {|p| ["[#{p.name}] #{p.full_name}", main_submission_url(p.id)]}, + {:selected => '-1'}, + { class: 'select2 form-control' } + %button.btn.btn-primary.btn-sm#submission_problem_go Go - if @problem!=nil %h2= "Task: #{@problem.full_name} (#{@problem.name})" diff --git a/app/views/problems/index.html.haml b/app/views/problems/index.html.haml new file mode 100644 --- /dev/null +++ b/app/views/problems/index.html.haml @@ -0,0 +1,46 @@ +- content_for :head do + = stylesheet_link_tag 'problems' +%h1 Listing problems +%p + = link_to 'New problem', new_problem_path, class: 'btn btn-default btn-sm' + = link_to 'Manage problems', { action: 'manage'}, class: 'btn btn-default btn-sm' + = link_to 'Import problems', {:action => 'import'}, class: 'btn btn-default btn-sm' + = link_to 'Turn off all problems', {:action => 'turn_all_off'}, class: 'btn btn-default btn-sm' + = link_to 'Turn on all problems', {:action => 'turn_all_on'}, class: 'btn btn-default btn-sm' +.submitbox + = form_tag :action => 'quick_create' do + %b Quick New: + %label{:for => "problem_name"} Name + = text_field 'problem', 'name' + | + %label{:for => "problem_full_name"} Full name + = text_field 'problem', 'full_name' + = submit_tag "Create" +%table.table.table-condensed.table-hover + %thead + %th Name + %th Full name + %th Full score + %th Date added + %th Avail? + %th Test? + - if GraderConfiguration.multicontests? + %th Contests + - for problem in @problems + %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"} + - @problem=problem + %td= in_place_editor_field :problem, :name, {}, :rows=>1 + %td= in_place_editor_field :problem, :full_name, {}, :rows=>1 + %td= in_place_editor_field :problem, :full_score, {}, :rows=>1 + %td= problem.date_added + %td{}= link_to (@problem.available? ? "Yes" : "No"), url_for(controller: :problems, action: :toggle, id: @problem), { class: "btn btn-block btn-sm btn-#{(@problem.available? ? 'success' : 'default')} ajax-toggle", id: "prob-#{@problem.id}-avail", data: {remote: true, method: 'post' } } + %td= problem.test_allowed + - if GraderConfiguration.multicontests? + %td + = problem.contests.collect { |c| c.name }.join(', ') + %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn-primary btn-sm' + %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn-primary btn-sm' + %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn-primary btn-sm' + %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post, class: 'btn btn-danger btn-sm' +%br/ += link_to '[New problem]', :action => 'new' diff --git a/app/views/problems/toggle.js.haml b/app/views/problems/toggle.js.haml new file mode 100644 --- /dev/null +++ b/app/views/problems/toggle.js.haml @@ -0,0 +1,12 @@ +:plain + b = $("#prob-#{@problem.id}-avail"); + b.removeClass('btn-default'); + b.removeClass('btn-success'); + b.removeClass('btn-warning'); + b.addClass("btn-#{@problem.available? ? 'success' : 'default'}"); + b.text("#{@problem.available? ? 'Yes' : 'No'}"); + r = $("#prob-#{@problem.id}"); + r.removeClass('success'); + r.removeClass('danger'); + r.addClass("#{@problem.available? ? 'success' : 'danger'}"); + diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ #main get "main/list" + get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' # See how all your routes lay out with "rake routes"