|
@@ -5,7 +5,7 @@ class ActivitiesController < ApplicationController
|
5
|
5
|
has_activity_id = [
|
6
|
6
|
:show, :edit, :edit_subgroups, :update, :update_subgroups, :destroy,
|
7
|
7
|
:presence, :change_organizer, :create_subgroup, :update_subgroup,
|
8
|
|
- :destroy_subgroup
|
|
8
|
+ :destroy_subgroup, :immediate_subgroups, :clear_subgroups
|
9
|
9
|
]
|
10
|
10
|
before_action :set_activity_and_group, only: has_activity_id
|
11
|
11
|
before_action :set_group, except: has_activity_id
|
|
@@ -17,7 +17,8 @@ class ActivitiesController < ApplicationController
|
17
|
17
|
]
|
18
|
18
|
before_action :require_organizer!, only: [
|
19
|
19
|
:edit, :update, :change_organizer, :create_subgroup, :update_subgroup,
|
20
|
|
- :destroy_subgroup, :edit_subgroups, :update_subgroups
|
|
20
|
+ :destroy_subgroup, :edit_subgroups, :update_subgroups, :immediate_subgroups,
|
|
21
|
+ :clear_subgroups
|
21
|
22
|
]
|
22
|
23
|
|
23
|
24
|
# GET /groups/:id/activities
|
|
@@ -88,26 +89,18 @@ class ActivitiesController < ApplicationController
|
88
|
89
|
|
89
|
90
|
# POST /activities/1/update_subgroups
|
90
|
91
|
def update_subgroups
|
91
|
|
- # TODO:
|
92
|
|
- # voor elke key in participant_subgroups
|
93
|
|
- # pak participant, subgroup
|
94
|
|
- # verifieer participant hoort bij activiteit
|
95
|
|
- # verifieer subgroup hoort bij activiteit
|
96
|
|
- # (impl dat editen mogen al gecheckt is, check of dit zo is!)
|
97
|
|
- # doe veranderen
|
98
|
|
- # knikker alles in een transactie want dan atomisch enzo cool en leuk
|
99
|
|
- # S: on error netjes bleren maar wat er mis kan gaan is bijna alleen gekut dus meh
|
100
|
|
- kappen = false
|
101
|
|
-
|
102
|
92
|
Participant.transaction do
|
|
93
|
+ # For each key in participant_subgroups:
|
103
|
94
|
params[:participant_subgroups].each do |k, v|
|
|
95
|
+ # Get Participant, Subgroup
|
104
|
96
|
p = Participant.find_by id: k
|
105
|
97
|
sg = Subgroup.find_by id: v unless v == 'nil'
|
106
|
98
|
|
|
99
|
+ # Verify that the Participant and Subgroup belong to this activity
|
|
100
|
+ # Edit-capability is enforced by before_filter.
|
107
|
101
|
if !p || p.activity != @activity || (!sg && v != 'nil') || (sg && sg.activity != @activity)
|
108
|
102
|
flash_message(:danger, I18n.t(:somethingbroke))
|
109
|
103
|
redirect_to group_activity_edit_subgroups_path(@group, @activity)
|
110
|
|
- kappen = true
|
111
|
104
|
raise ActiveRecord::Rollback
|
112
|
105
|
end
|
113
|
106
|
|
|
@@ -121,10 +114,33 @@ class ActivitiesController < ApplicationController
|
121
|
114
|
end
|
122
|
115
|
end
|
123
|
116
|
|
124
|
|
- unless kappen
|
125
|
|
- flash_message(:success, I18n.t('activities.subgroups.edited'))
|
126
|
|
- redirect_to edit_group_activity_path(@group, @activity)
|
|
117
|
+ flash_message(:success, I18n.t('activities.subgroups.edited'))
|
|
118
|
+ redirect_to edit_group_activity_path(@group, @activity)
|
|
119
|
+ end
|
|
120
|
+
|
|
121
|
+ # POST /activities/1/immediate_subgroups
|
|
122
|
+ def immediate_subgroups
|
|
123
|
+ if params[:overwrite]
|
|
124
|
+ @activity.clear_subgroups!
|
127
|
125
|
end
|
|
126
|
+
|
|
127
|
+ @activity.assign_subgroups!
|
|
128
|
+
|
|
129
|
+ if params[:overwrite]
|
|
130
|
+ flash_message(:success, I18n.t('activities.subgroups.redistributed'))
|
|
131
|
+ else
|
|
132
|
+ flash_message(:success, I18n.t('activities.subgroups.remaining_distributed'))
|
|
133
|
+ end
|
|
134
|
+
|
|
135
|
+ redirect_to edit_group_activity_path(@group, @activity)
|
|
136
|
+ end
|
|
137
|
+
|
|
138
|
+ # POST /activities/1/clear_subgroups
|
|
139
|
+ def clear_subgroups
|
|
140
|
+ @activity.clear_subgroups!
|
|
141
|
+
|
|
142
|
+ flash_message(:success, I18n.t('activities.subgroups.cleared'))
|
|
143
|
+ redirect_to edit_group_activity_path(@group, @activity)
|
128
|
144
|
end
|
129
|
145
|
|
130
|
146
|
# Shared lookups for rendering the edit-view
|