Quellcode durchsuchen

Subgroup division plumbing

Maarten van den Berg vor 7 Jahren
Ursprung
Commit
7120226027

+ 26 - 1
app/models/activity.rb

38
   # @!attribute reminder_done
38
   # @!attribute reminder_done
39
   #   @return [Boolean]
39
   #   @return [Boolean]
40
   #     whether or not sending the reminder has finished.
40
   #     whether or not sending the reminder has finished.
41
+  #
42
+  # @!attribute subgroup_division_enabled
43
+  #   @return [Boolean]
44
+  #     whether automatic subgroup division on the deadline is enabled.
45
+  #
46
+  # @!attribute subgroup_division_done
47
+  #   @return [Boolean]
48
+  #     whether subgroup division has been performed.
41
 
49
 
42
   belongs_to :group
50
   belongs_to :group
43
 
51
 
53
   validate  :deadline_before_start, unless: "self.deadline.blank?"
61
   validate  :deadline_before_start, unless: "self.deadline.blank?"
54
   validate  :end_after_start,       unless: "self.end.blank?"
62
   validate  :end_after_start,       unless: "self.end.blank?"
55
   validate  :reminder_before_deadline, unless: "self.reminder_at.blank?"
63
   validate  :reminder_before_deadline, unless: "self.reminder_at.blank?"
64
+  validate  :subgroups_for_division_present, on: :update
56
 
65
 
57
   after_create :create_missing_participants!
66
   after_create :create_missing_participants!
58
   after_create :copy_default_subgroups!
67
   after_create :copy_default_subgroups!
59
-  after_commit :schedule_reminder, if: Proc.new {|a| a.previous_changes["reminder_at"] }
68
+  after_commit :schedule_reminder,
69
+               if: Proc.new { |a| a.previous_changes["reminder_at"] }
70
+  after_commit :schedule_subgroup_division,
71
+               if: Proc.new { |a| (a.previous_changes['deadline'] ||
72
+                                   a.previous_changes['subgroup_division_enabled']) &&
73
+                                  !a.subgroup_division_done &&
74
+                                  a.subgroup_division_enabled }
60
 
75
 
61
   # Get all people (not participants) that are organizers. Does not include
76
   # Get all people (not participants) that are organizers. Does not include
62
   # group leaders, although they may modify the activity as well.
77
   # group leaders, although they may modify the activity as well.
123
   def copy_default_subgroups!
138
   def copy_default_subgroups!
124
     defaults = self.group.default_subgroups
139
     defaults = self.group.default_subgroups
125
 
140
 
141
+    # If there are no subgroups, there cannot be subgroup division.
142
+    self.update_attribute(:subgroup_division_enabled, false) if defaults.none?
143
+
126
     defaults.each do |dsg|
144
     defaults.each do |dsg|
127
       sg = Subgroup.new(activity: self)
145
       sg = Subgroup.new(activity: self)
128
       sg.name = dsg.name
146
       sg.name = dsg.name
129
       sg.is_assignable = dsg.is_assignable
147
       sg.is_assignable = dsg.is_assignable
130
       sg.save! # Should never fail, as DSG and SG have identical validation, and names cannot clash.
148
       sg.save! # Should never fail, as DSG and SG have identical validation, and names cannot clash.
131
     end
149
     end
150
+
132
   end
151
   end
133
 
152
 
134
   # Create multiple Activities from data in a CSV file, assign to a group, return.
153
   # Create multiple Activities from data in a CSV file, assign to a group, return.
183
     self.delay(run_at: self.reminder_at).send_reminder
202
     self.delay(run_at: self.reminder_at).send_reminder
184
   end
203
   end
185
 
204
 
205
+  def schedule_subgroup_division
206
+    return if self.deadline.nil? || self.subgroup_division_done
207
+
208
+    self.delay(run_at: self.deadline).assign_subgroups!
209
+  end
210
+
186
   # Assign a subgroup to all attending participants without one.
211
   # Assign a subgroup to all attending participants without one.
187
   def assign_subgroups!
212
   def assign_subgroups!
188
     # Sanity check: we need subgroups to divide into.
213
     # Sanity check: we need subgroups to divide into.

+ 5 - 0
app/views/activities/_form.html.erb

44
       <%= f.label :reminder_at %>
44
       <%= f.label :reminder_at %>
45
       <%= f.datetime_field :reminder_at, class: 'form-control' %>
45
       <%= f.datetime_field :reminder_at, class: 'form-control' %>
46
     </div>
46
     </div>
47
+    <div class="form-group">
48
+      <div class="check-box">
49
+        <%= f.check_box(:subgroup_division_enabled) %>
50
+        <%= t 'activerecord.attributes.activity.subgroup_division_enabled' %>
51
+      </div>
47
     <%= f.submit class: 'btn btn-primary' %>
52
     <%= f.submit class: 'btn btn-primary' %>
48
   </div>
53
   </div>
49
 <% end %>
54
 <% end %>

+ 2 - 2
app/views/activities/index.html.haml

11
   %thead
11
   %thead
12
     %tr
12
     %tr
13
       %th
13
       %th
14
-        = t 'activerecord.attributes.activities.name'
14
+        = t 'activerecord.attributes.activity.name'
15
 
15
 
16
       %th
16
       %th
17
-        = t 'activerecord.attributes.activities.start'
17
+        = t 'activerecord.attributes.activity.start'
18
 
18
 
19
       %th
19
       %th
20
         P/A/?
20
         P/A/?

+ 2 - 0
config/locales/activities/en.yml

19
     errors:
19
     errors:
20
       must_be_before_start: "must be before start"
20
       must_be_before_start: "must be before start"
21
       must_be_after_start: "must be after start"
21
       must_be_after_start: "must be after start"
22
+      must_be_before_deadline: "must be before deadline"
22
       already_in: "person already participates in activity"
23
       already_in: "person already participates in activity"
24
+      cannot_divide_without_subgroups: "a divisible subgroup must exist"
23
 
25
 
24
     participant:
26
     participant:
25
       singular: "participant"
27
       singular: "participant"

+ 1 - 0
config/locales/activities/nl.yml

21
       must_be_after_start: "moet na start zijn"
21
       must_be_after_start: "moet na start zijn"
22
       must_be_before_deadline: "moet voor deadline zijn"
22
       must_be_before_deadline: "moet voor deadline zijn"
23
       already_in: "persoon doet al mee aan activiteit"
23
       already_in: "persoon doet al mee aan activiteit"
24
+      cannot_divide_without_subgroups: "moet indeelbare subgroep hebben"
24
 
25
 
25
     participant:
26
     participant:
26
       singular: "deelnemer"
27
       singular: "deelnemer"

+ 2 - 0
config/locales/translation_nl.yml

46
         reminder_at: Herinnering om
46
         reminder_at: Herinnering om
47
         reminder_done: Herinnering verstuurd
47
         reminder_done: Herinnering verstuurd
48
         subgroups: :activerecord.models.subgroup.other
48
         subgroups: :activerecord.models.subgroup.other
49
+        subgroup_division_enabled: Subgroepen indelen
50
+        subgroup_division_done: Subgroepen ingedeeld
49
 
51
 
50
       group:
52
       group:
51
         activities: Activiteiten  #g
53
         activities: Activiteiten  #g