Description:
add tags
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r700:757ebc0ccd63 - - 7 files changed: 56 inserted, 29 deleted

@@ -200,24 +200,28
200 200 ok = []
201 201 failed = []
202 202 get_problems_from_params.each do |p|
203 203 begin
204 204 group.problems << p
205 205 ok << p.full_name
206 206 rescue => e
207 207 failed << p.full_name
208 208 end
209 209 end
210 210 flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0
211 211 flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0
212 + elsif params.has_key? 'add_tags'
213 + get_problems_from_params.each do |p|
214 + p.tag_ids += params[:tag_ids]
215 + end
212 216 end
213 217
214 218 redirect_to :action => 'manage'
215 219 end
216 220
217 221 def import
218 222 @allow_test_pair_import = allow_test_pair_import?
219 223 end
220 224
221 225 def do_import
222 226 old_problem = Problem.find_by_name(params[:name])
223 227 if !allow_test_pair_import? and params.has_key? :import_to_db
@@ -291,16 +295,16
291 295 problems << Problem.find(id)
292 296 end
293 297 end
294 298 problems
295 299 end
296 300
297 301 def get_problems_stat
298 302 end
299 303
300 304 private
301 305
302 306 def problem_params
303 - params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description)
307 + params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description, tag_ids:[])
304 308 end
305 309
306 310 end
@@ -32,24 +32,26
32 32
33 33 # PATCH/PUT /tags/1
34 34 def update
35 35 if @tag.update(tag_params)
36 36 redirect_to @tag, notice: 'Tag was successfully updated.'
37 37 else
38 38 render :edit
39 39 end
40 40 end
41 41
42 42 # DELETE /tags/1
43 43 def destroy
44 + #remove any association
45 + ProblemTag.where(tag_id: @tag.id).destroy_all
44 46 @tag.destroy
45 47 redirect_to tags_url, notice: 'Tag was successfully destroyed.'
46 48 end
47 49
48 50 private
49 51 # Use callbacks to share common setup or constraints between actions.
50 52 def set_tag
51 53 @tag = Tag.find(params[:id])
52 54 end
53 55
54 56 # Only allow a trusted parameter "white list" through.
55 57 def tag_params
@@ -37,24 +37,25
37 37 :javascript
38 38 $("#countdown").countdown({until: "+#{@current_user.contest_time_left.to_i}s", layout: 'Time left: {hnn}:{mnn}:{snn}'});
39 39 / admin section
40 40 - if (@current_user!=nil) and (session[:admin])
41 41 / management
42 42 %li.dropdown
43 43 %a.dropdown-toggle{href: '#', data: {toggle:'dropdown'}, aria: {haspopup:"true", expanded:"false"}, role: "button"}
44 44 Manage
45 45 %span.caret
46 46 %ul.dropdown-menu
47 47 = add_menu( 'Announcements', 'announcements', 'index')
48 48 = add_menu( 'Problems', 'problems', 'index')
49 + = add_menu( 'Tags', 'tags', 'index')
49 50 = add_menu( 'Users', 'user_admin', 'index')
50 51 = add_menu( 'User Groups', 'groups', 'index')
51 52 = add_menu( 'Graders', 'graders', 'list')
52 53 = add_menu( 'Message ', 'messages', 'console')
53 54 %li.divider{role: 'separator'}
54 55 = add_menu( 'System config', 'configurations', 'index')
55 56 %li.divider{role: 'separator'}
56 57 = add_menu( 'Sites', 'sites', 'index')
57 58 = add_menu( 'Contests', 'contest_management', 'index')
58 59 / report
59 60 %li.dropdown
60 61 %a.dropdown-toggle{href: '#', data: {toggle:'dropdown'}, aria: {haspopup:"true", expanded:"false"}, role: "button"}
@@ -3,24 +3,27
3 3 .form-group
4 4 %label{:for => "problem_name"} Name
5 5 = text_field 'problem', 'name', class: 'form-control'
6 6 %small
7 7 Do not directly edit the problem name, unless you know what you are doing. If you want to change the name, use the name change button in the problem management menu instead.
8 8 .form-group
9 9 %label{:for => "problem_full_name"} Full name
10 10 = text_field 'problem', 'full_name', class: 'form-control'
11 11 .form-group
12 12 %label{:for => "problem_full_score"} Full score
13 13 = text_field 'problem', 'full_score', class: 'form-control'
14 14 .form-group
15 + %label{:for => "problem_full_score"} Tags
16 + = collection_select(:problem, :tag_ids, Tag.all, :id, :name, {}, {multiple: true, class: 'form-control select2'})
17 + .form-group
15 18 %label{:for => "problem_date_added"} Date added
16 19 = date_select 'problem', 'date_added', class: 'form-control'
17 20 - # TODO: these should be put in model Problem, but I can't think of
18 21 - # nice default values for them. These values look fine only
19 22 - # in this case (of lazily adding new problems).
20 23 - @problem.available = true if @problem!=nil and @problem.available==nil
21 24 - @problem.test_allowed = true if @problem!=nil and @problem.test_allowed==nil
22 25 - @problem.output_only = false if @problem!=nil and @problem.output_only==nil
23 26 .checkbox
24 27 %label{:for => "problem_available"}
25 28 = check_box :problem, :available
26 29 Available?
@@ -12,47 +12,52
12 12 %b Quick New:
13 13 %label{:for => "problem_name"} Name
14 14 = text_field 'problem', 'name'
15 15 |
16 16 %label{:for => "problem_full_name"} Full name
17 17 = text_field 'problem', 'full_name'
18 18 = submit_tag "Create"
19 19 %table.table.table-condense.table-hover
20 20 %thead
21 21 %th Name
22 22 %th Full name
23 23 %th.text-right Full score
24 + %th Tags
24 25 %th
25 26 Submit
26 27 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Admin can always submit to any problem' } [?]
27 28 %th Date added
28 29 %th.text-center
29 30 Avail?
30 31 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user submits to this problem?' } [?]
31 32 %th.text-center
32 33 View Data?
33 34 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user view the testcase of this problem?' } [?]
34 35 %th.text-center
35 36 Test?
36 37 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user uses test interface on this problem?' } [?]
37 38 - if GraderConfiguration.multicontests?
38 39 %th Contests
39 40 - for problem in @problems
40 41 %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"}
41 42 - @problem=problem
42 43 %td= problem.name #in_place_editor_field :problem, :name, {}, :rows=>1
43 44 %td
44 45 = problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1
45 46 = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem
46 47 %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1
48 + %td
49 + - problem.tags.each do |t|
50 + - #%button.btn.btn-default.btn-xs= t.name
51 + %span.label.label-default= t.name
47 52 %td= link_to "Submit", direct_edit_problem_submissions_path(problem,@current_user.id), class: 'btn btn-xs btn-primary'
48 53 %td= problem.date_added
49 54 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
50 55 %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}")
51 56 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
52 57 - if GraderConfiguration.multicontests?
53 58 %td
54 59 = problem.contests.collect { |c| c.name }.join(', ')
55 60 %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn-info btn-xs btn-block'
56 61 %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn-info btn-xs btn-block'
57 62 %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn-info btn-xs btn-block'
58 63 %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :delete, class: 'btn btn-danger btn-xs btn-block'
@@ -40,68 +40,79
40 40
41 41 = form_tag :action=>'do_manage' do
42 42 .panel.panel-primary
43 43 .panel-heading
44 44 Action
45 45 .panel-body
46 46 .submit-box
47 47 What do you want to do to the selected problem?
48 48 %br/
49 49 (You can shift-click to select a range of problems)
50 50 %ul.form-inline
51 51 %li
52 - Change date added to
52 + Change "Date added" to
53 53 .input-group.date
54 54 = text_field_tag :date_added, class: 'form-control'
55 55 %span.input-group-addon
56 56 %span.glyphicon.glyphicon-calendar
57 57 -# = select_date Date.current, :prefix => 'date_added'
58 58 &nbsp;&nbsp;&nbsp;
59 59 = submit_tag 'Change', :name => 'change_date_added', class: 'btn btn-primary btn-sm'
60 60 %li
61 - Set available to
61 + Set "Available" to
62 62 = submit_tag 'True', :name => 'enable_problem', class: 'btn btn-primary btn-sm'
63 63 = submit_tag 'False', :name => 'disable_problem', class: 'btn btn-primary btn-sm'
64 64
65 65 - if GraderConfiguration.multicontests?
66 66 %li
67 - Add to
67 + Add selected problems to contest
68 68 = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
69 69 = submit_tag 'Add', :name => 'add_to_contest', class: 'btn btn-primary btn-sm'
70 70 %li
71 - Add problems to group
71 + Add selected problems to user group
72 72 = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2'
73 - = submit_tag 'Add', name: 'add_group', class: 'btn btn-default'
74 -
73 + = submit_tag 'Add', name: 'add_group', class: 'btn btn-primary'
74 + %li
75 + Add the following tags to the selected problems
76 + = 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"}
77 + = submit_tag 'Add', name: 'add_tags', class: 'btn btn-primary'
75 78
76 - %table.table.table-hover
77 - %tr{style: "text-align: left;"}
78 - %th= check_box_tag 'select_all'
79 - %th Name
80 - %th Full name
81 - %th Available
82 - %th Date added
83 - - if GraderConfiguration.multicontests?
84 - %th Contests
79 + %table.table.table-hover.datatable
80 + %thead
81 + %tr{style: "text-align: left;"}
82 + %th= check_box_tag 'select_all'
83 + %th Name
84 + %th Full name
85 + %th Tags
86 + %th Available
87 + %th Date added
88 + - if GraderConfiguration.multicontests?
89 + %th Contests
85 90
86 - - num = 0
87 - - for problem in @problems
88 - - num += 1
89 - %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
90 - %td= check_box_tag "prob-#{problem.id}-#{num}"
91 - %td= problem.name
92 - %td= problem.full_name
93 - %td= problem.available
94 - %td= problem.date_added
95 - - if GraderConfiguration.multicontests?
91 + %tbody
92 + - num = 0
93 + - for problem in @problems
94 + - num += 1
95 + %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
96 + %td= check_box_tag "prob-#{problem.id}-#{num}"
97 + %td= problem.name
98 + %td= problem.full_name
96 99 %td
97 - - problem.contests.each do |contest|
98 - = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
100 + - problem.tags.each do |t|
101 + %span.label.label-default= t.name
102 + %td= problem.available
103 + %td= problem.date_added
104 + - if GraderConfiguration.multicontests?
105 + %td
106 + - problem.contests.each do |contest|
107 + = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
99 108
100 109 :javascript
101 110 $('.input-group.date').datetimepicker({
102 111 format: 'DD/MMM/YYYY',
103 112 showTodayButton: true,
104 113 widgetPositioning: {horizontal: 'auto', vertical: 'bottom'},
105 114
106 115 });
107 -
116 + $('.datatable').DataTable({
117 + paging: false
118 + });
@@ -22,14 +22,15
22 22 .actions
23 23 = f.submit "Update", class: 'btn btn-primary'
24 24 .col-md-8
25 25
26 26 = link_to 'Show', @site
27 27 |
28 28 = link_to 'Back', sites_path
29 29
30 30
31 31 :javascript
32 32 $('.input-group.date').datetimepicker({
33 33 format: 'DD/MMM/YYYY HH:mm',
34 + showTodayButton: true,
34 35 });
35 36
You need to be logged in to leave comments. Login now