effective_committees 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63a0f1fb0d95dfae23974217952a389877c115b31e9ba3b73b616138ff0ae9b9
4
- data.tar.gz: 38c05e3f466ae93f9258dd9394caa177a1fa7c4dd944b776e6866b9ecef2253a
3
+ metadata.gz: cd2e7e60e604c2c37d662cde5abd1d4823b4400762bed564e734b50c65f16a5f
4
+ data.tar.gz: 713486d3de4e2aa4412762f243f0f9f352f5c74f7786cddc89e1781ef2b49de6
5
5
  SHA512:
6
- metadata.gz: 977e23882e20848a4b6aead2a8966e913664cf27ab396fc5ab24f3b85d58d47a9ae770ec368d2eb866ad88786beab86fb6982da6bf2956c805030f840ac8ab61
7
- data.tar.gz: 6ab21c11c4bfec46be1347c57c0fca82163e601671a752a85735187c66ed5c66b51dda390e45d3b934098a305a17e319a3fcece909b31a062c41d9c0c9d84577
6
+ metadata.gz: 4b3e9bd523495fb20bde48fac897b64bffd58f5197ef458008e95a7b6b752b74959dc2b67196c5471d9ceba45e0b5565fb334dd05fe3ddd33a6f60d03083c0bf
7
+ data.tar.gz: e3c37293212b4fd74121f1ca3fe2aba2a1d776199484cafba8821a0fc40466622f7df8bf9c06375bb4c60a26171e51adbd15562845ec0d2eb9cf3bb312f07423
@@ -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
 
@@ -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
 
@@ -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')}
@@ -0,0 +1,11 @@
1
+ en:
2
+ effective_committees:
3
+ name: 'Effective Committees'
4
+ acronym: 'Committees'
5
+
6
+ activerecord:
7
+ models:
8
+ effective/committee: 'Committee'
9
+ effective/committee_file: 'Committee File'
10
+ effective/committee_folder: 'Committee Folder'
11
+ effective/committee_member: 'Committee Member'
@@ -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.2'.freeze
2
+ VERSION = '0.2.1'.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.2
4
+ version: 0.2.1
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-09-27 00:00:00.000000000 Z
11
+ date: 2023-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -215,6 +215,7 @@ files:
215
215
  - app/views/effective/committees/_form_committee.html.haml
216
216
  - app/views/effective/committees/index.html.haml
217
217
  - config/effective_committees.rb
218
+ - config/locales/effective_committees.en.yml
218
219
  - config/routes.rb
219
220
  - db/migrate/01_create_effective_committees.rb.erb
220
221
  - db/seeds.rb