effective_committees 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef9838f8461539b97096dc72613ac01253875dc41511773d0dbeb882545243c1
4
- data.tar.gz: 362122b9df304bd2c8fcc762dae5c769736002283199ed268bd77201cbc3fccb
3
+ metadata.gz: df8c75f5e33b7cfb2d7776ba54655cdbdd88a307eaf8b0d817685743b6bd3a0f
4
+ data.tar.gz: 22e99e41a9473983068db1b470621a97fcde2cdf0106e0b9de0621e878c7016f
5
5
  SHA512:
6
- metadata.gz: efe535f511f6f965735afdf8e9ae696422ee9fbfbcbf22a6fe5d7446e50f384d441d9489d3e6a113f7c9315d00bf2588d17935235d9de065a2175e005e87c4d5
7
- data.tar.gz: 8163275c582aa675ef646154931930f497fb5246ffa57f8b29115d7839902b7abfa8489df8bc56d3e904b0b290af4a2532384d6d2b88237d08f5b1e2de16e819
6
+ metadata.gz: ce05c9720c80bd99d4bce72f8e99143a12d625afea0feedc702179606cb49ef44908275c8cd6778a100045a4bb158d4124c06744a04a0c602afb8eec7cd11da6
7
+ data.tar.gz: f6ab66c124d105d761a83c0623ac24cd6792607efc3f4375669657c021640055bda8cfbb2ac1c59c59a2ef5b64d136a243c0e99bae5ba081e0e35362ca7b15b4
@@ -13,6 +13,13 @@ module Admin
13
13
  end
14
14
  end
15
15
 
16
+ col :start_on
17
+ col :end_on
18
+
19
+ col :expired do |committee_member|
20
+ badge('expired') if committee_member.expired?
21
+ end
22
+
16
23
  if EffectiveCommittees.use_effective_roles
17
24
  col :roles, search: roles_collection
18
25
  end
@@ -11,6 +11,9 @@ class EffectiveCommitteeMembersDatatable < Effective::Datatable
11
11
  end
12
12
  end
13
13
 
14
+ col :start_on
15
+ col :end_on
16
+
14
17
  if EffectiveCommittees.use_effective_roles
15
18
  col :roles, search: roles_collection
16
19
  end
@@ -25,6 +25,7 @@ class EffectiveCommitteesDatatable < Effective::Datatable
25
25
  end
26
26
 
27
27
  collection do
28
+ # This only displays active committees
28
29
  Effective::Committee.deep.where(id: current_user.committees)
29
30
  end
30
31
 
@@ -34,7 +34,7 @@ module EffectiveCommitteesUser
34
34
  end
35
35
 
36
36
  def committees
37
- committee_members.reject(&:marked_for_destruction?).map(&:committee)
37
+ committee_members.select { |cm| cm.active? && !cm.marked_for_destruction? }.map { |cm| cm.committee }
38
38
  end
39
39
 
40
40
  end
@@ -18,6 +18,9 @@ module Effective
18
18
  effective_resource do
19
19
  roles_mask :integer
20
20
 
21
+ start_on :date
22
+ end_on :date
23
+
21
24
  timestamps
22
25
  end
23
26
 
@@ -34,13 +37,13 @@ module Effective
34
37
 
35
38
  after_commit(if: -> { user_ids.present? }) do
36
39
  additional = (user_ids - CommitteeMember.where(committee_id: committee_id, user_id: user_ids).pluck(:user_id))
37
- additional = additional.map { |user_id| {committee_id: committee_id, committee_type: committee_type, user_id: user_id, user_type: user_type, roles_mask: roles_mask} }
40
+ additional = additional.map { |user_id| {committee_id: committee_id, committee_type: committee_type, user_id: user_id, user_type: user_type, roles_mask: roles_mask, start_on: start_on, end_on: end_on} }
38
41
  CommitteeMember.insert_all(additional)
39
42
  end
40
43
 
41
44
  after_commit(if: -> { committee_ids.present? }) do
42
45
  additional = (committee_ids - CommitteeMember.where(user_id: user_id, committee_id: committee_ids).pluck(:committee_id))
43
- additional = additional.map { |committee_id| {committee_id: committee_id, committee_type: committee_type, user_id: user_id, user_type: user_type, roles_mask: roles_mask} }
46
+ additional = additional.map { |committee_id| {committee_id: committee_id, committee_type: committee_type, user_id: user_id, user_type: user_type, roles_mask: roles_mask, start_on: start_on, end_on: end_on} }
44
47
  CommitteeMember.insert_all(additional)
45
48
  end
46
49
 
@@ -50,10 +53,27 @@ module Effective
50
53
  validates :user_id, if: -> { user_id && user_type && committee_id && committee_type },
51
54
  uniqueness: { scope: [:committee_id, :committee_type], message: 'already belongs to this committee' }
52
55
 
56
+ validate(if: -> { start_on && end_on }) do
57
+ self.errors.add(:end_on, 'must be after start date') unless end_on > start_on
58
+ end
59
+
53
60
  def to_s
54
61
  user.to_s
55
62
  end
56
63
 
64
+ def active?(date: nil)
65
+ return true if start_on.blank? && end_on.blank?
66
+
67
+ date ||= Time.zone.now
68
+ date = date.to_date if date.respond_to?(:to_date)
69
+
70
+ (start_on..end_on).cover?(date) # Endless ranges
71
+ end
72
+
73
+ def expired?(date: nil)
74
+ active?(date: date) == false
75
+ end
76
+
57
77
  def user_ids
58
78
  Array(@user_ids) - [nil, '']
59
79
  end
@@ -10,21 +10,28 @@
10
10
  = f.hidden_field :committee_type
11
11
  = f.hidden_field :committee_id
12
12
 
13
+ - ajax_url = (@select2_ajax_path || effective_resources.users_admin_select2_ajax_index_path) unless Rails.env.test?
14
+
13
15
  - if f.object.new_record?
14
16
  - if inline_datatable? && inline_datatable.attributes[:committee_id].present?
15
- = f.select :user_ids, current_user.class.sorted, label: 'Add user(s)', hint: 'Add one or more users'
17
+ = f.select :user_ids, current_user.class.sorted, label: 'Add user(s)', required: true, ajax_url: ajax_url, hint: 'Add one or more users'
16
18
 
17
19
  - if inline_datatable? && inline_datatable.attributes[:user_id].present?
18
20
  = f.select :committee_ids, committees, label: 'Add committee(s)', hint: 'Add one or more committees'
19
21
 
20
22
  - unless inline_datatable?
21
23
  = f.select :committee_id, committees, label: 'Committee'
22
- = f.select :user_ids, current_user.class.sorted, label: 'User(s)', hint: 'Add one or more user at a time'
24
+
25
+ = f.select :user_ids, current_user.class.sorted, label: 'User(s)', required: true, ajax_url: ajax_url, hint: 'Add one or more user at a time'
23
26
 
24
27
  - if f.object.persisted?
25
28
  = f.static_field :committee
26
29
  = f.static_field :user, label: 'Committee Member'
27
30
 
31
+ .row
32
+ .col= f.date_field :start_on, hint: 'optional start date'
33
+ .col= f.date_field :end_on, hint: 'optional end date'
34
+
28
35
  - if EffectiveCommittees.use_effective_roles
29
36
  = f.checks :roles, EffectiveRoles.roles_collection(f.object, skip_disabled: true)
30
37
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  .effective-committee-folder
8
8
  - if committee_folder.rich_text_body.present?
9
- .mb-4= committee_folder.rich_text_body
9
+ .mb-4= committee_folder.rich_text_body.to_s
10
10
 
11
11
  %table.table.table-striped
12
12
  %thead
@@ -10,6 +10,10 @@
10
10
  - unless inline_datatable? && inline_datatable.attributes[:committee_id].present?
11
11
  = f.select :committee, { 'Committees' => Effective::Committee.sorted }, polymorphic: true
12
12
 
13
+ .row
14
+ .col= f.date_field :start_on, hint: 'optional start date'
15
+ .col= f.date_field :end_on, hint: 'optional end date'
16
+
13
17
  - if EffectiveCommittees.use_effective_roles
14
18
  = f.checks :roles, EffectiveRoles.roles_collection(f.object, skip_disabled: true)
15
19
 
@@ -26,6 +30,10 @@
26
30
  - unless inline_datatable? && inline_datatable.attributes[:user_id].present?
27
31
  = f.static_field :user
28
32
 
33
+ .row
34
+ .col= f.date_field :start_on, hint: 'optional start date'
35
+ .col= f.date_field :end_on, hint: 'optional end date'
36
+
29
37
  - if EffectiveCommittees.use_effective_roles
30
38
  = f.checks :roles, EffectiveRoles.roles_collection(f.object, skip_disabled: true)
31
39
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  .effective-committee
7
7
  - if committee.rich_text_body.present?
8
- .mb-4= committee.rich_text_body
8
+ .mb-4= committee.rich_text_body.to_s
9
9
 
10
10
  %table.table.table-striped
11
11
  %thead
@@ -18,6 +18,6 @@
18
18
  %tr
19
19
  %td= link_to(icon('folder') + folder, effective_committees.committee_committee_folder_path(committee, folder))
20
20
  %td= pluralize(folder.committee_files.length, 'file')
21
- %td= folder.body
21
+ %td= folder.body.to_s
22
22
 
23
23
  %p Displaying #{pluralize(committee.committee_folders.length, 'folder')}
@@ -26,6 +26,9 @@ class CreateEffectiveCommittees < ActiveRecord::Migration[6.1]
26
26
 
27
27
  t.integer :roles_mask
28
28
 
29
+ t.date :start_on
30
+ t.date :end_on
31
+
29
32
  t.datetime :updated_at
30
33
  t.datetime :created_at
31
34
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveCommittees
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_committees
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-24 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails