Maarten van den Berg 7 years ago
parent
commit
ebf69ce0aa

+ 19 - 1
app/controllers/groups_controller.rb

@@ -1,9 +1,9 @@
1 1
 class GroupsController < ApplicationController
2 2
   include GroupsHelper
3
+  before_action :set_group, only: [:show, :edit, :update, :destroy]
3 4
   before_action :require_admin!, only: [:index]
4 5
   before_action :require_membership!, only: [:show]
5 6
   before_action :require_leader!, only: [:edit, :update, :destroy]
6
-  before_action :set_group, only: [:show, :edit, :update, :destroy]
7 7
 
8 8
   # GET /groups
9 9
   # GET /groups.json
@@ -18,6 +18,24 @@ class GroupsController < ApplicationController
18 18
   # GET /groups/1
19 19
   # GET /groups/1.json
20 20
   def show
21
+    @organized_activities = current_person.organized_activities.
22
+      joins(:activity).where(
23
+        'activities.group_id': @group.id
24
+    )
25
+    if @organized_activities.count > 0
26
+      @groupmenu = 'col-md-6'
27
+    else
28
+      @groupmenu = 'col-md-12'
29
+    end
30
+
31
+    @upcoming = @group.activities
32
+      .where('start > ?', Date.today)
33
+      .order('start ASC')
34
+    @upcoming_ps = Participant
35
+      .where(person: current_person)
36
+      .where(activity: @upcoming)
37
+      .map{ |p| [p.activity_id, p]}
38
+      .to_h
21 39
   end
22 40
 
23 41
   # GET /groups/new

+ 4 - 4
app/helpers/groups_helper.rb

@@ -1,19 +1,19 @@
1 1
 module GroupsHelper
2 2
   def require_membership!
3 3
     require_login!
4
-    if !(Member.exists?(group: @group, person: current_person) || current_person.is_admin?)
4
+    if !(@group.is_member?(current_person) || current_person.is_admin?)
5 5
       flash_message(:danger, "You need to be a member of that group to do that.")
6
-      redirect_to dashboard_url
6
+      redirect_to dashboard_home_path
7 7
     end
8 8
   end
9 9
 
10 10
   def require_leader!
11 11
     require_login!
12 12
 
13
-    if !(Member.exists?(group: @group, is_leader: true, person: current_person) ||
13
+    if !(@group.is_leader?(current_person) ||
14 14
          current_person.is_admin?)
15 15
       flash_message(:danger, "You need to be a group leader to do that.")
16
-      redirect_to dashboard_url
16
+      redirect_to dashboard_home_path
17 17
     end
18 18
   end
19 19
 end

+ 8 - 0
app/models/group.rb

@@ -29,6 +29,14 @@ class Group < ApplicationRecord
29 29
     self.activities.where('start > ?', DateTime.now)
30 30
   end
31 31
 
32
+  # Determine whether the passed person is a member of the group.
33
+  def is_member?(person)
34
+    Member.exists?(
35
+      person: person,
36
+      group: self
37
+    ) || person.is_admin?
38
+  end
39
+
32 40
   # Determine whether the passed person is a group leader.
33 41
   def is_leader?(person)
34 42
     Member.exists?(

+ 1 - 1
app/models/person.rb

@@ -65,7 +65,7 @@ class Person < ApplicationRecord
65 65
 
66 66
   # All activities where this person is an organizer.
67 67
   def organized_activities
68
-    self.participants.includes(:activity).where(is_leader: true)
68
+    self.participants.includes(:activity).where(is_organizer: true)
69 69
   end
70 70
 
71 71
   private

+ 59 - 21
app/views/groups/show.html.haml

@@ -1,30 +1,68 @@
1 1
 %h2
2 2
   = @group.name
3 3
 
4
-%h3 Upcoming activities
5
-%h3
6
-  Members
4
+.row
5
+  .groupmenu(class=@groupmenu)
6
+    .panel.panel-default
7
+      .panel-heading
8
+        = @group.name
7 9
 
8
-%ul
9
-  - @group.members.each do |m|
10
-    %li
11
-      - if m.is_leader
12
-        %i.fa.fa-angle-up
10
+      .panel-body
11
+        .list-group
12
+          = link_to group_members_path(@group), class: 'list-group-item' do
13
+            = @group.members.count
14
+            members
13 15
 
14
-      = m.person.full_name
16
+          = link_to group_activities_path(@group), class: 'list-group-item' do
17
+            = @group.activities.count
18
+            activities
15 19
 
16
-= link_to 'Manage members', group_members_path(@group)
20
+          - if @group.is_leader?(current_person)
21
+            = link_to new_group_activity_path(@group), class: 'list-group-item' do
22
+              New event
17 23
 
18
-%h3
19
-  Events
24
+            = link_to edit_group_path(@group), class: 'list-group-item' do
25
+              Edit group
20 26
 
21
-%ul
22
-  - @group.activities.each do |e|
23
-    %li
24
-      = e.public_name
25
-= link_to "Manage activities", group_activities_path(@group)
27
+  - if @organized_activities && @organized_activities.count > 0
28
+    .col-md-6
29
+      .panel.panel-default
30
+        .panel-heading
31
+          Upcoming activities organized by you
26 32
 
27
-%div
28
-  = link_to 'Edit', edit_group_path(@group)
29
-  |
30
-  = link_to 'Back', groups_path
33
+        .panel-body
34
+          %table.table
35
+            %tr
36
+              %th
37
+                What
38
+              %th
39
+                When
40
+
41
+            - @organized_activities.each do |p|
42
+              - a = p.activity
43
+              %tr
44
+                %td
45
+                  = link_to group_activity_path(@group, a) do
46
+                    = a.public_name
47
+                    = render partial: "activities/state_counts", locals: {counts: a.state_counts}
48
+                %td
49
+                  = distance_of_time_in_words_to_now(a.start.to_date)
50
+
51
+.row
52
+  .col-md-12
53
+    .panel.panel-default
54
+      .panel-heading
55
+        Your activities
56
+
57
+      .panel-body
58
+        %table.table.table-striped
59
+          %tbody
60
+            - @upcoming.each do |a|
61
+              - p = @upcoming_ps[a.id]
62
+              %tr{class: p.row_class, data: {activity_id: e.id, person_id: current_person.id}}
63
+                %td
64
+                  = e.public_name
65
+                %td
66
+                  = render partial: "activities/presence_buttons", locals: {activity: e, person: current_person, state: p.attending}
67
+                %td
68
+                  = editable p, :notes, url: presence_group_activity_path(e.group, e, person_id: current_person.id), title: "Notes", value: p.notes, emptytext: 'Notes'