Pārlūkot izejas kodu

Add Subgroup-reference to participant

Rudimentary filtering in activity#show, needs more work and equivalent
in mobile view
Maarten van den Berg 7 gadi atpakaļ
vecāks
revīzija
f9e22be538

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

2
   clipboard = new Clipboard('.copy-reactions', {
2
   clipboard = new Clipboard('.copy-reactions', {
3
     'text': clipreactions
3
     'text': clipreactions
4
   })
4
   })
5
+  $('#subgroup_filter').on('change', (e) -> filterparticipants(e))
5
 
6
 
6
 @clipreactions = (trigger) ->
7
 @clipreactions = (trigger) ->
7
   id = trigger.dataset['activity']
8
   id = trigger.dataset['activity']
24
     res.push(resp['unknown']['message'])
25
     res.push(resp['unknown']['message'])
25
 
26
 
26
   res.join('\n')
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
       .where(is_assignable: true)
38
       .where(is_assignable: true)
39
       .order(name: :asc)
39
       .order(name: :asc)
40
       .pluck(:name)
40
       .pluck(:name)
41
+    @subgroup_ids = @activity.subgroups
42
+      .order(name: :asc)
43
+      .pluck(:name, :id)
44
+    @subgroup_ids.prepend( ['*' , 'all'] )
41
   end
45
   end
42
 
46
 
43
   # GET /activities/new
47
   # GET /activities/new

+ 1 - 0
app/models/participant.rb

17
 
17
 
18
   belongs_to :person
18
   belongs_to :person
19
   belongs_to :activity
19
   belongs_to :activity
20
+  belongs_to :subgroup, optional: true
20
 
21
 
21
   validates :person_id,
22
   validates :person_id,
22
     uniqueness: {
23
     uniqueness: {

+ 1 - 0
app/models/subgroup.rb

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

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

87
             emptytext: t('activities.participant.add_notes')
87
             emptytext: t('activities.participant.add_notes')
88
 
88
 
89
 .hidden-xs
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
   %table.table.table-bordered
99
   %table.table.table-bordered
96
     - @participants.each do |p|
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
         %td
102
         %td
99
           = p.person.full_name
103
           = p.person.full_name
100
           - if p.is_organizer
104
           - if p.is_organizer

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

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