# HG changeset patch # User Nattee Niparnan # Date 2018-03-10 07:07:14 # Node ID 757ebc0ccd63c64ecdfd3e322949693ba8ef8984 # Parent dd5555537101f6636c238457fcd736d988f260ef add tags diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -209,6 +209,10 @@ end flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0 flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0 + elsif params.has_key? 'add_tags' + get_problems_from_params.each do |p| + p.tag_ids += params[:tag_ids] + end end redirect_to :action => 'manage' @@ -300,7 +304,7 @@ private def problem_params - params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description) + params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description, tag_ids:[]) end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -41,6 +41,8 @@ # DELETE /tags/1 def destroy + #remove any association + ProblemTag.where(tag_id: @tag.id).destroy_all @tag.destroy redirect_to tags_url, notice: 'Tag was successfully destroyed.' end diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -46,6 +46,7 @@ %ul.dropdown-menu = add_menu( 'Announcements', 'announcements', 'index') = add_menu( 'Problems', 'problems', 'index') + = add_menu( 'Tags', 'tags', 'index') = add_menu( 'Users', 'user_admin', 'index') = add_menu( 'User Groups', 'groups', 'index') = add_menu( 'Graders', 'graders', 'list') diff --git a/app/views/problems/_form.html.haml b/app/views/problems/_form.html.haml --- a/app/views/problems/_form.html.haml +++ b/app/views/problems/_form.html.haml @@ -12,6 +12,9 @@ %label{:for => "problem_full_score"} Full score = text_field 'problem', 'full_score', class: 'form-control' .form-group + %label{:for => "problem_full_score"} Tags + = collection_select(:problem, :tag_ids, Tag.all, :id, :name, {}, {multiple: true, class: 'form-control select2'}) +.form-group %label{:for => "problem_date_added"} Date added = date_select 'problem', 'date_added', class: 'form-control' - # TODO: these should be put in model Problem, but I can't think of diff --git a/app/views/problems/index.html.haml b/app/views/problems/index.html.haml --- a/app/views/problems/index.html.haml +++ b/app/views/problems/index.html.haml @@ -21,6 +21,7 @@ %th Name %th Full name %th.text-right Full score + %th Tags %th Submit %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Admin can always submit to any problem' } [?] @@ -44,6 +45,10 @@ = problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1 = link_to_description_if_any "[#{t 'main.problem_desc'}] ".html_safe, problem %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1 + %td + - problem.tags.each do |t| + - #%button.btn.btn-default.btn-xs= t.name + %span.label.label-default= t.name %td= link_to "Submit", direct_edit_problem_submissions_path(problem,@current_user.id), class: 'btn btn-xs btn-primary' %td= problem.date_added %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}") diff --git a/app/views/problems/manage.html.haml b/app/views/problems/manage.html.haml --- a/app/views/problems/manage.html.haml +++ b/app/views/problems/manage.html.haml @@ -49,7 +49,7 @@ (You can shift-click to select a range of problems) %ul.form-inline %li - Change date added to + Change "Date added" to .input-group.date = text_field_tag :date_added, class: 'form-control' %span.input-group-addon @@ -58,44 +58,53 @@     = submit_tag 'Change', :name => 'change_date_added', class: 'btn btn-primary btn-sm' %li - Set available to + Set "Available" to = submit_tag 'True', :name => 'enable_problem', class: 'btn btn-primary btn-sm' = submit_tag 'False', :name => 'disable_problem', class: 'btn btn-primary btn-sm' - if GraderConfiguration.multicontests? %li - Add to + Add selected problems to contest = select("contest","id",Contest.all.collect {|c| [c.title, c.id]}) = submit_tag 'Add', :name => 'add_to_contest', class: 'btn btn-primary btn-sm' %li - Add problems to group + Add selected problems to user group = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2' - = submit_tag 'Add', name: 'add_group', class: 'btn btn-default' - + = submit_tag 'Add', name: 'add_group', class: 'btn btn-primary' + %li + Add the following tags to the selected problems + = select_tag "tag_ids", options_from_collection_for_select( Tag.all, 'id','name'), id: 'tags_name',class: 'select2', multiple: true, data: {placeholder: 'Select tags by clicking', width: "200px"} + = submit_tag 'Add', name: 'add_tags', class: 'btn btn-primary' - %table.table.table-hover - %tr{style: "text-align: left;"} - %th= check_box_tag 'select_all' - %th Name - %th Full name - %th Available - %th Date added - - if GraderConfiguration.multicontests? - %th Contests + %table.table.table-hover.datatable + %thead + %tr{style: "text-align: left;"} + %th= check_box_tag 'select_all' + %th Name + %th Full name + %th Tags + %th Available + %th Date added + - if GraderConfiguration.multicontests? + %th Contests - - num = 0 - - for problem in @problems - - num += 1 - %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"} - %td= check_box_tag "prob-#{problem.id}-#{num}" - %td= problem.name - %td= problem.full_name - %td= problem.available - %td= problem.date_added - - if GraderConfiguration.multicontests? + %tbody + - num = 0 + - for problem in @problems + - num += 1 + %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"} + %td= check_box_tag "prob-#{problem.id}-#{num}" + %td= problem.name + %td= problem.full_name %td - - problem.contests.each do |contest| - = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])" + - problem.tags.each do |t| + %span.label.label-default= t.name + %td= problem.available + %td= problem.date_added + - if GraderConfiguration.multicontests? + %td + - problem.contests.each do |contest| + = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])" :javascript $('.input-group.date').datetimepicker({ @@ -104,4 +113,6 @@ widgetPositioning: {horizontal: 'auto', vertical: 'bottom'}, }); - + $('.datatable').DataTable({ + paging: false + }); diff --git a/app/views/sites/edit.html.haml b/app/views/sites/edit.html.haml --- a/app/views/sites/edit.html.haml +++ b/app/views/sites/edit.html.haml @@ -31,5 +31,6 @@ :javascript $('.input-group.date').datetimepicker({ format: 'DD/MMM/YYYY HH:mm', + showTodayButton: true, });