Browse Source

Add Subgroup-reference to participant

Rudimentary filtering in activity#show, needs more work and equivalent
in mobile view
Maarten van den Berg 7 years ago
parent
commit
f9e22be538

+ 10 - 0
app/assets/javascripts/activities.coffee

@@ -2,6 +2,7 @@ $(document).on 'turbolinks:load', ->
2 2
   clipboard = new Clipboard('.copy-reactions', {
3 3
     'text': clipreactions
4 4
   })
5
+  $('#subgroup_filter').on('change', (e) -> filterparticipants(e))
5 6
 
6 7
 @clipreactions = (trigger) ->
7 8
   id = trigger.dataset['activity']
@@ -24,3 +25,12 @@ $(document).on 'turbolinks:load', ->
24 25
     res.push(resp['unknown']['message'])
25 26
 
26 27
   res.join('\n')
28
+
29
+@filterparticipants = (e) ->
30
+  show = e.target.value
31
+  if (show != 'all')
32
+	  selector = "[data-subgroup-id=" + e.target.value + "]"
33
+	  $('.participant-row').hide()
34
+	  $(selector).show()
35
+  else
36
+    $('.participant-row').show()

+ 4 - 0
app/controllers/activities_controller.rb

@@ -38,6 +38,10 @@ class ActivitiesController < ApplicationController
38 38
       .where(is_assignable: true)
39 39
       .order(name: :asc)
40 40
       .pluck(:name)
41
+    @subgroup_ids = @activity.subgroups
42
+      .order(name: :asc)
43
+      .pluck(:name, :id)
44
+    @subgroup_ids.prepend( ['*' , 'all'] )
41 45
   end
42 46
 
43 47
   # GET /activities/new

+ 1 - 0
app/models/participant.rb

@@ -17,6 +17,7 @@ class Participant < ApplicationRecord
17 17
 
18 18
   belongs_to :person
19 19
   belongs_to :activity
20
+  belongs_to :subgroup, optional: true
20 21
 
21 22
   validates :person_id,
22 23
     uniqueness: {

+ 1 - 0
app/models/subgroup.rb

@@ -1,5 +1,6 @@
1 1
 class Subgroup < ApplicationRecord
2 2
   belongs_to :activity
3
+  has_many :participants
3 4
 
4 5
   validates :name, presence: true, uniqueness: { scope: :activity, case_sensitive: false }
5 6
   validates :activity, presence: true

+ 9 - 5
app/views/activities/show.html.haml

@@ -87,14 +87,18 @@
87 87
             emptytext: t('activities.participant.add_notes')
88 88
 
89 89
 .hidden-xs
90
-  %h2
91
-    = @num_participants
92
-    = t 'activities.participant.plural'
93
-    = render partial: "state_counts", locals: {counts: @counts}
90
+  .row
91
+    .col-md-6
92
+      %h2
93
+        = @num_participants
94
+        = t 'activities.participant.plural'
95
+        = render partial: "state_counts", locals: {counts: @counts}
96
+    .col-md-6
97
+      = select_tag(:subgroup_filter, options_for_select(@subgroup_ids), class: 'form-control')
94 98
 
95 99
   %table.table.table-bordered
96 100
     - @participants.each do |p|
97
-      %tr{class: p.row_class, data: {person_id: p.person.id, activity_id: @activity.id}}
101
+      %tr.participant-row{class: p.row_class, data: {person_id: p.person.id, activity_id: @activity.id, subgroup_id: p.subgroup_id}}
98 102
         %td
99 103
           = p.person.full_name
100 104
           - if p.is_organizer

+ 5 - 0
db/migrate/20171001150124_add_subgroup_to_participants.rb

@@ -0,0 +1,5 @@
1
+class AddSubgroupToParticipants < ActiveRecord::Migration[5.0]
2
+  def change
3
+    add_reference :participants, :subgroup, foreign_key: true
4
+  end
5
+end

+ 3 - 1
db/schema.rb

@@ -10,7 +10,7 @@
10 10
 #
11 11
 # It's strongly recommended that you check this file into your version control system.
12 12
 
13
-ActiveRecord::Schema.define(version: 20171001124009) do
13
+ActiveRecord::Schema.define(version: 20171001150124) do
14 14
 
15 15
   create_table "activities", force: :cascade do |t|
16 16
     t.string   "name"
@@ -76,9 +76,11 @@ ActiveRecord::Schema.define(version: 20171001124009) do
76 76
     t.text     "notes"
77 77
     t.datetime "created_at",   null: false
78 78
     t.datetime "updated_at",   null: false
79
+    t.integer  "subgroup_id"
79 80
     t.index ["activity_id"], name: "index_participants_on_activity_id"
80 81
     t.index ["person_id", "activity_id"], name: "index_participants_on_person_id_and_activity_id", unique: true
81 82
     t.index ["person_id"], name: "index_participants_on_person_id"
83
+    t.index ["subgroup_id"], name: "index_participants_on_subgroup_id"
82 84
   end
83 85
 
84 86
   create_table "people", force: :cascade do |t|