Browse Source

Responsive activity view

Maarten van den Berg 7 years ago
parent
commit
0bcd10d692

+ 6 - 0
app/assets/javascripts/buttonhandlers.jsx.js

@@ -100,6 +100,12 @@ function activity_changed(data, textStatus, xhr)
100 100
       .html(new_confirm_icon);
101 101
     $(`.btn-absent[data-person-id=${target.person}][data-activity-id=${target.activity}]`)
102 102
       .html(new_decline_icon);
103
+
104
+    // Add text to all 'wide' buttons
105
+    $(`.btn-present[data-person-id=${target.person}][data-activity-id=${target.activity}][data-wide=1]`)
106
+      .append(" Present");
107
+    $(`.btn-absent[data-person-id=${target.person}][data-activity-id=${target.activity}][data-wide=1]`)
108
+      .append(" Absent");
103 109
 }
104 110
 
105 111
 function alert_failure(data, textStatus, xhr)

+ 22 - 0
app/assets/stylesheets/application.scss

@@ -66,3 +66,25 @@ table .btn-group {
66 66
 .editable.editable-empty {
67 67
   color: inherit;
68 68
 }
69
+
70
+/* https://stackoverflow.com/questions/26923543/why-does-a-table-in-a-collapsible-bootstrap-panel-change-width */
71
+table.collapse.in {
72
+  display: table;
73
+}
74
+
75
+/* Toggles visibility based on aria-expanded of parent. */
76
+[aria-expanded="true"] > .sv-show-expanded {
77
+  display: inline;
78
+}
79
+
80
+[aria-expanded="true"] > .sv-show-collapsed {
81
+  display: none;
82
+}
83
+
84
+[aria-expanded="false"] > .sv-show-expanded {
85
+  display: none;
86
+}
87
+
88
+[aria-expanded="false"] > .sv-show-collapsed {
89
+  display: inline;
90
+}

+ 8 - 0
app/controllers/activities_controller.rb

@@ -17,6 +17,14 @@ class ActivitiesController < ApplicationController
17 17
       .joins(:person)
18 18
       .order(attending: :desc)
19 19
       .order('people.first_name ASC')
20
+    @organizers = @activity.participants
21
+      .joins(:person)
22
+      .where(is_organizer: true)
23
+      .order('people.first_name ASC')
24
+      .map{|p| p.person.full_name}
25
+      .join(', ')
26
+    @ownparticipant = @activity.participants
27
+      .find_by(person: current_person)
20 28
     @counts = @activity.state_counts
21 29
     @num_participants = @counts.values.sum
22 30
   end

+ 16 - 0
app/views/activities/_wide_presence_buttons.haml

@@ -0,0 +1,16 @@
1
+.btn-group.btn-group-justified{role: "group"}
2
+  .btn-group
3
+    %button.btn.btn-success.btn-present.btn-presence{data: {wide: 1, person_id: person.id, activity_id: activity.id, group_id: activity.group.id, new_state: "present"}}
4
+      - if !state
5
+        %i.fa.fa-check
6
+      - else
7
+        %i.fa.fa-check-circle
8
+      Present
9
+
10
+  .btn-group
11
+    %button.btn.btn-danger.btn-absent.btn-presence{data: {wide: 1, person_id: person.id, activity_id: activity.id, group_id: activity.group.id, new_state: "absent"}}
12
+      - if state == false
13
+        %i.fa.fa-times-circle
14
+      - else
15
+        %i.fa.fa-times
16
+      Absent

+ 0 - 35
app/views/activities/show.html.erb

@@ -1,35 +0,0 @@
1
-<h2><%= @activity.public_name %></h2>
2
-
3
-<ul>
4
-  <% if @activity.secret_name %>
5
-  <li>Secretly <%= @activity.secret_name %></li>
6
-  <% end %>
7
-  <li>Description:<%= @activity.description %></li>
8
-  <li>Location:<%= @activity.location %></li>
9
-  <li>Start: <%= @activity.start %> - <%= @activity.end %></li>
10
-  <li>Deadline: <%= @activity.deadline %></li>
11
-</ul>
12
-
13
-<h2>
14
-  <%= @num_participants %> participants
15
-  <%= render partial: "state_counts", locals: {counts:@counts}%>
16
-</h2>
17
-<table class="table table-bordered">
18
-  <% @participants.each do |p| %>
19
-    <tr class="<%= p.row_class %>" data-person-id="<%= p.person.id %>" data-activity-id="<%= @activity.id %>">
20
-      <td>
21
-        <%= p.person.full_name %>
22
-        <% if p.is_organizer %><i class="fa fa-star-o"></i><% end %>
23
-      </td>
24
-      <td>
25
-        <%=
26
-          editable p, :notes, url: presence_group_activity_path(@activity.group, @activity, person_id: p.person_id), title: "Notes", value: p.notes, emptytext: "--"
27
-        %>
28
-      </td>
29
-      <td>
30
-        <%= render partial: "activities/presence_buttons", locals: {activity: @activity, person: p.person, state: p.attending} %>
31
-  <% end %>
32
-</table>
33
-
34
-<%= link_to 'Edit', edit_group_activity_path(@group, @activity) %> |
35
-<%= link_to 'Back', group_activities_path(@group) %>

+ 180 - 0
app/views/activities/show.html.haml

@@ -0,0 +1,180 @@
1
+.row
2
+  .col-md-9
3
+    .panel.panel-default
4
+      .panel-heading
5
+        = @activity.public_name
6
+        - if @activity.may_change?(current_person)
7
+          = link_to edit_group_activity_path(@group, @activity), class: 'pull-right' do
8
+            %i.fa.fa-pencil
9
+
10
+
11
+      %table.table
12
+        %tr
13
+          %td
14
+            Organizers:
15
+          %td
16
+            = @organizers
17
+        %tr
18
+          %td
19
+            Description:
20
+          %td
21
+            = @activity.description
22
+
23
+        %tr
24
+          %td
25
+            Location:
26
+          %td
27
+            = @activity.location
28
+
29
+        %tr
30
+          %td
31
+            When:
32
+
33
+          %td
34
+            = @activity.start
35
+            \-
36
+            = @activity.end
37
+
38
+        %tr
39
+          %td
40
+            Deadline:
41
+
42
+          %td
43
+            = @activity.deadline
44
+
45
+  - if @ownparticipant
46
+    .col-md-3
47
+      .panel.panel-default
48
+        .panel-heading
49
+          Your response
50
+        .panel-body
51
+          = render partial: "activities/wide_presence_buttons", locals: {activity: @activity, person: @ownparticipant.person, state: @ownparticipant.attending}
52
+
53
+          -#.btn-group.btn-group-justified
54
+            -#.btn-group
55
+              -#%button.btn.btn-success
56
+                -#Present
57
+
58
+            -#.btn-group
59
+              -#%button.btn.btn-danger
60
+                -#Absent
61
+
62
+          = editable @ownparticipant,
63
+            :notes,
64
+            url: presence_group_activity_path(@activity.group, @activity, person_id: @ownparticipant.person_id),
65
+            title: "Notes",
66
+            value: "",
67
+            emptytext: "Add notes..."
68
+
69
+.hidden-xs
70
+  %h2
71
+    = @num_participants
72
+    participants
73
+    = render partial: "state_counts", locals: {counts: @counts}
74
+
75
+  %table.table.table-bordered
76
+    - @participants.each do |p|
77
+      %tr{class: p.row_class, data: {person_id: p.person.id, activity_id: @activity.id}}
78
+        %td
79
+          = p.person.full_name
80
+          - if p.is_organizer
81
+            %i.fa.fa-star-o
82
+
83
+        %td
84
+          = editable p, :notes, url: presence_group_activity_path(@activity.group, @activity, person_id: p.person_id), title: "Notes", value: p.notes, emptytext: "--"
85
+
86
+        %td
87
+          = render partial: "activities/presence_buttons", locals: {activity: @activity, person: p.person, state: p.attending}
88
+
89
+.hidden-sm.hidden-md.hidden-lg
90
+  .panel.panel-default.panel-success
91
+    .panel-heading
92
+      -#%button.btn.btn-default.btn-sm{data: {toggle: 'collapse', target: '#present-collapse'}}
93
+        -#%i.fa.fa-arrows-v
94
+
95
+      %a{role: 'button', href: '#present-collapse', data: {toggle: 'collapse'}, 'aria-expanded': 'false'}
96
+
97
+        %span.sv-show-collapsed
98
+          %i.fa.fa-angle-down
99
+
100
+        %span.sv-show-expanded
101
+          %i.fa.fa-angle-up
102
+
103
+        Present
104
+        %span.badge
105
+          = @counts[true]
106
+
107
+    %table.table.collapse#present-collapse
108
+      %tbody
109
+        - @participants.where(attending: true).each do |p|
110
+          %tr{data: {person_id: p.person.id, activity_id: @activity.id}}
111
+            %td
112
+              = p.person.full_name
113
+              - if p.is_organizer
114
+                %i.fa.fa-star-o
115
+
116
+            %td
117
+              = render partial: "activities/presence_buttons", locals: {activity: @activity, person: p.person, state: p.attending}
118
+
119
+          %tr{data: {person_id: p.person_id, activity_id: @activity.id}}
120
+            %td{colspan: "2"}
121
+              = editable p, :notes, url: presence_group_activity_path(@activity.group, @activity, person_id: p.person_id), title: "Notes", value: p.notes, emptytext: "--"
122
+
123
+
124
+  .panel.panel-default
125
+    .panel-heading
126
+      %a{role: 'button', href: '#unknown-collapse', data: {toggle: 'collapse'}, 'aria-expanded': 'false'}
127
+
128
+        %span.sv-show-collapsed
129
+          %i.fa.fa-angle-down
130
+
131
+        %span.sv-show-expanded
132
+          %i.fa.fa-angle-up
133
+        No reaction
134
+        %span.badge
135
+          = @counts[nil]
136
+
137
+    %table.table.collapse#unknown-collapse
138
+      %tbody
139
+        - @participants.where(attending: nil).each do |p|
140
+          %tr{data: {person_id: p.person.id, activity_id: @activity.id}}
141
+            %td
142
+              = p.person.full_name
143
+              - if p.is_organizer
144
+                %i.fa.fa-star-o
145
+
146
+            %td
147
+              = render partial: "activities/presence_buttons", locals: {activity: @activity, person: p.person, state: p.attending}
148
+
149
+          %tr{data: {person_id: p.person_id, activity_id: @activity.id}}
150
+            %td{colspan: "2"}
151
+              = editable p, :notes, url: presence_group_activity_path(@activity.group, @activity, person_id: p.person_id), title: "Notes", value: p.notes, emptytext: "--"
152
+
153
+  .panel.panel-default.panel-danger
154
+    .panel-heading
155
+      %a{role: 'button', href: '#absent-collapse', data: {toggle: 'collapse'}, 'aria-expanded': 'false'}
156
+
157
+        %span.sv-show-collapsed
158
+          %i.fa.fa-angle-down
159
+
160
+        %span.sv-show-expanded
161
+          %i.fa.fa-angle-up
162
+        Absent
163
+        %span.badge
164
+          = @counts[false]
165
+
166
+    %table.table.collapse#absent-collapse
167
+      %tbody
168
+        - @participants.where(attending: false).each do |p|
169
+          %tr{data: {person_id: p.person.id, activity_id: @activity.id}}
170
+            %td
171
+              = p.person.full_name
172
+              - if p.is_organizer
173
+                %i.fa.fa-star-o
174
+
175
+            %td
176
+              = render partial: "activities/presence_buttons", locals: {activity: @activity, person: p.person, state: p.attending}
177
+
178
+          %tr{data: {person_id: p.person_id, activity_id: @activity.id}}
179
+            %td{colspan: "2"}
180
+              = editable p, :notes, url: presence_group_activity_path(@activity.group, @activity, person_id: p.person_id), title: "Notes", value: p.notes, emptytext: "--"