effective_committees 0.8.0 → 0.9.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: e6806153b45de4da4f91304e9ec17c0ddd0d95c08b50e5146cb337ee5bff08da
4
- data.tar.gz: 020324e85cf563846560aaf8fc3f687a4879af060e32d2dcec55a85f04692fdb
3
+ metadata.gz: '028cb7fc1b4194a805ffc494fc6d2c7e8429b87f3a6ea559481e467c33dc0ac6'
4
+ data.tar.gz: 07f3eca18fb18cd17e2cdea403b84d21fbcf1a2196a6d22d233cec4c48308224
5
5
  SHA512:
6
- metadata.gz: 0d1b17f664da9c321f122671106b97dc0d6fb9e83d29fc33d6b4d88d66c2c1dbb1e23f7c5cd233a96504729e72a3d181e40e3eb7e58f5ce26603fc2fb55e617a
7
- data.tar.gz: 13e80bc61b9abb5fa24774d3e34f88a2799189caf12b973e165a898c7254551a0a564122074dd0503a5f4b2f4647a37dbc4fd67f2ad94b4d75c977eb603faf2d
6
+ metadata.gz: caac2747b32561bc4dfb1e2c93e5a46b5be7c932d064ab30d4588de8a2d9530d0c2ef49cd3cac6ba78bdee9f67cecb15fa440016d9e8e914165fde0f7af93843
7
+ data.tar.gz: 74df738c96c21cbd8617e4b04ff5f1c9d3b29e90f799b035f1c07c5ea5b4b7fab6d21c515973f2fc15c0f796755d71f293c7950edbd7d5eee5bc9ed876fb17e0
@@ -1,10 +1,12 @@
1
1
  module Admin
2
2
  class EffectiveCommitteeMembersDatatable < Effective::Datatable
3
3
  datatable do
4
+ reorder :position if attributes[:committee]
4
5
  length 100
5
6
 
6
7
  col :id, visible: false
7
8
  col :user_id, visible: false
9
+ col :position, visible: false
8
10
 
9
11
  col :committee
10
12
  col :user
@@ -18,7 +18,7 @@ module Admin
18
18
  col :display_on_dashboard
19
19
 
20
20
  col(:committee_members, label: committee_members_label, visible: false) do |committee|
21
- committee.committee_members.select(&:active?).sort_by(&:to_s).map do |member|
21
+ committee.committee_members.select(&:active?).map do |member|
22
22
  content_tag(:div, class: 'col-resource_item') do
23
23
  label = link_to(member.to_s, "/admin/users/#{member.user_id}/edit")
24
24
  badge = badge(member.category) if member.category.present?
@@ -23,10 +23,12 @@ module Effective
23
23
  start_on :date
24
24
  end_on :date
25
25
 
26
+ position :integer
27
+
26
28
  timestamps
27
29
  end
28
30
 
29
- scope :sorted, -> { order(:id) }
31
+ scope :sorted, -> { order(:position) }
30
32
  scope :deep, -> { includes(:user, :committee) }
31
33
 
32
34
  before_validation(if: -> { user_ids.present? }) do
@@ -39,18 +41,25 @@ module Effective
39
41
 
40
42
  after_commit(if: -> { user_ids.present? }) do
41
43
  additional = (user_ids - CommitteeMember.where(committee_id: committee_id, user_id: user_ids).pluck(:user_id))
42
- 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} }
44
+ max_position = CommitteeMember.where(committee_id: committee_id, committee_type: committee_type).maximum(:position) || -1
45
+ additional = additional.each_with_index.map { |user_id, index| {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, position: max_position + index + 1} }
43
46
  CommitteeMember.insert_all(additional)
44
47
  end
45
48
 
46
49
  after_commit(if: -> { committee_ids.present? }) do
47
50
  additional = (committee_ids - CommitteeMember.where(user_id: user_id, committee_id: committee_ids).pluck(:committee_id))
48
- 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} }
51
+ max_positions = CommitteeMember.where(committee_id: additional, committee_type: committee_type).group(:committee_id).maximum(:position)
52
+ 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, position: (max_positions[committee_id] || -1) + 1} }
49
53
  CommitteeMember.insert_all(additional)
50
54
  end
51
55
 
56
+ before_validation do
57
+ self.position ||= (self.class.where(committee_id: committee_id, committee_type: committee_type).maximum(:position) || -1) + 1
58
+ end
59
+
52
60
  validates :committee, presence: true
53
61
  validates :user, presence: true
62
+ validates :position, presence: true
54
63
 
55
64
  validates :user_id, if: -> { user_id && user_type && committee_id && committee_type },
56
65
  uniqueness: { scope: [:committee_id, :committee_type], message: 'already belongs to this committee' }
@@ -28,7 +28,7 @@
28
28
  .col-lg
29
29
  %h3= committee_members_label
30
30
 
31
- - members = committee.committee_members.select(&:active?).sort_by(&:to_s)
31
+ - members = committee.committee_members.select(&:active?)
32
32
 
33
33
  %ul
34
34
  - members.each do |member|
@@ -34,6 +34,8 @@ class CreateEffectiveCommittees < ActiveRecord::Migration[6.0]
34
34
  t.date :start_on
35
35
  t.date :end_on
36
36
 
37
+ t.integer :position
38
+
37
39
  t.datetime :updated_at
38
40
  t.datetime :created_at
39
41
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveCommittees
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.9.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.8.0
4
+ version: 0.9.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: 2026-03-11 00:00:00.000000000 Z
11
+ date: 2026-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails