active_scaffold_child_memberships 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +8 -0
- data/app/assets/javascripts/active_scaffold_child_memberships.js +14 -0
- data/lib/active_scaffold_child_memberships/attribute_params.rb +25 -0
- data/lib/active_scaffold_child_memberships/engine.rb +13 -0
- data/lib/active_scaffold_child_memberships/helpers.rb +68 -0
- data/lib/active_scaffold_child_memberships/version.rb +9 -0
- data/lib/active_scaffold_child_memberships.rb +8 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 695eb1a91c4345770c5bc16711996ad375555906d762d191b8bd9b18d93ba063
|
4
|
+
data.tar.gz: 9e0c2123bff4f5de59075d4de5d298fa9123cffcb33a1587de0fbf216b61d46e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afc624967c0eb0f8d69e8a040cc601f18ee39a7752513513d863a54d0e84dced301d00aa3310f51ec05da9bee9d660ed977eb7bf2e0281ce00fed73bccf6e9f3
|
7
|
+
data.tar.gz: 658231e5a370393e870cd84432c3bbab28a4b20c314a37f1c0f33d7a564a09501edca8dabd45a41a35fcae15e6fe08beadbd9e48eef5522a18684e86d1ef4ab9
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 activescaffold
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
jQuery(document).ready(function () {
|
2
|
+
jQuery(document).on('click', '.child_memberships table caption a', function(e) {
|
3
|
+
e.preventDefault();
|
4
|
+
var link = jQuery(e.target), table = link.closest('table'), header = table.find('thead tr'),
|
5
|
+
checkbox = jQuery('<input type="checkbox" value="' + (header.find('th').length - 1) + '"/>'), th;
|
6
|
+
th = jQuery('<th>').html(link.parent().find('.as_inplace_pattern:first').html()).find('[disabled]').prop('disabled', false).end();
|
7
|
+
header.append(th);
|
8
|
+
table.find('tbody tr').each(function(){
|
9
|
+
var row = jQuery(this);
|
10
|
+
row.append(jQuery('<td>').html(checkbox.attr('name', table.data('name')+'[memberships]['+row.data('id')+'][]').clone()));
|
11
|
+
});
|
12
|
+
th.trigger('as:element_created');
|
13
|
+
});
|
14
|
+
});
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActiveScaffoldChildMemberships
|
2
|
+
module AttributeParams
|
3
|
+
protected
|
4
|
+
def update_column_association(parent_record, column, attribute, value, avoid_changes = false)
|
5
|
+
if column.form_ui == :child_memberships
|
6
|
+
source_col = active_scaffold_config_for(column.association.through_reflection.klass).columns[column.association.source_reflection.name]
|
7
|
+
value.each do |child, members|
|
8
|
+
update_column_association(child, source_col, attribute, members, avoid_changes)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def column_value_for_child_memberships_type(parent_record, column, value)
|
16
|
+
ids = value[:members].select(&:present?)
|
17
|
+
members = column.association.klass.find(ids)&.index_by { |member| member.id.to_s }
|
18
|
+
parent_record.send(column.association.through_reflection.name).map do |child|
|
19
|
+
ids = value.dig(:memberships, child.id.to_s)&.select(&:present?)&.map(&:to_i)
|
20
|
+
member_ids = value[:members].values_at(*ids).select(&:present?)
|
21
|
+
[child, members.values_at(*member_ids)]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveScaffoldChildMemberships
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
initializer 'active_scaffold_kanban.action_view' do
|
4
|
+
ActiveSupport.on_load :action_view do
|
5
|
+
ActionView::Base.send :include, ActiveScaffoldChildMemberships::Helpers
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer 'active_scaffold_kanban.controller' do
|
10
|
+
ActiveScaffold::AttributeParams.prepend(ActiveScaffoldChildMemberships::AttributeParams)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module ActiveScaffoldChildMemberships
|
2
|
+
module Helpers
|
3
|
+
def active_scaffold_input_child_memberships(column, options, ui_options: column.options)
|
4
|
+
raise "#{column.name} should be a has_many through association" unless column.association&.collection? && column.association.through?
|
5
|
+
source_col = active_scaffold_config_for(column.association.through_reflection.klass).columns[column.association.source_reflection.name]
|
6
|
+
raise "#{column.name}'s through reflection should be a habtm or has_many through association" unless source_col.association.habtm? || source_col.association.collection? && source_col.association.through?
|
7
|
+
through_col = active_scaffold_config.columns[column.association.through_reflection.name]
|
8
|
+
children = options[:object].send(through_col.name)
|
9
|
+
column_records = send(override_helper_per_model(:active_scaffold_child_memberships_members, column.active_record_class), column, children)
|
10
|
+
|
11
|
+
header = column_records.map do |member|
|
12
|
+
label = member.send(ui_options[:label_method] || :to_label)
|
13
|
+
hidden_field = hidden_field_tag("#{options[:name]}[members][]", member.id, id: nil)
|
14
|
+
content_tag(:th, h(label) << hidden_field)
|
15
|
+
end
|
16
|
+
header.unshift content_tag(:th, through_col.label)
|
17
|
+
|
18
|
+
rows = children.map do |record|
|
19
|
+
columns = column_records.map.with_index do |member, i|
|
20
|
+
content_tag(:td, check_box_tag("#{options[:name]}[memberships][#{record.id}][]", i, record.send(source_col.name).include?(member), id: nil))
|
21
|
+
end
|
22
|
+
label = record.send(ui_options[:child_label_method] || :to_label)
|
23
|
+
columns.unshift content_tag(:td, h(label))
|
24
|
+
content_tag(:tr, safe_join(columns), data: {id: record.id})
|
25
|
+
end
|
26
|
+
|
27
|
+
hidden_field = hidden_field_tag("#{options[:name]}[members][]", nil, id: nil) if column_records.empty?
|
28
|
+
add_label = ui_options[:add_label]
|
29
|
+
add_label = :add_column if add_label.nil?
|
30
|
+
if add_label
|
31
|
+
add_label = as_(add_label, model: source_col.association.klass.model_name.human) if add_label.is_a?(Symbol)
|
32
|
+
add_column = link_to(add_label, '#')
|
33
|
+
new_column = send(override_helper_per_model(:active_scaffold_child_memberships_new_column, column.active_record_class), column, "#{options[:name]}[members][]", source_col, ui_options)
|
34
|
+
end
|
35
|
+
|
36
|
+
content_tag(:table, data: {name: options[:name]}) do
|
37
|
+
content_tag(:caption, safe_join([add_column, new_column, hidden_field])) <<
|
38
|
+
content_tag(:thead, content_tag(:tr, safe_join(header))) <<
|
39
|
+
content_tag(:tbody, safe_join(rows))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def active_scaffold_child_memberships_members(column, row_records)
|
44
|
+
row_records.flat_map(&column.association.source_reflection.name).uniq
|
45
|
+
#column.association.klass.all
|
46
|
+
end
|
47
|
+
|
48
|
+
def active_scaffold_child_memberships_new_column(column, name, source_col, ui_options)
|
49
|
+
inplace_options = {object: source_col.active_record_class.new, id: '', disabled: true, associated: nil, class: 'inplace_field', name: name}
|
50
|
+
form_ui, form_ui_options = ui_options[:add_column_ui]
|
51
|
+
ui_method =
|
52
|
+
case form_ui
|
53
|
+
when :record_select then :active_scaffold_record_select
|
54
|
+
when :select, nil then :active_scaffold_input_singular_association
|
55
|
+
else
|
56
|
+
:"active_scaffold_input_#{form_ui}"
|
57
|
+
end
|
58
|
+
if form_ui == :record_select
|
59
|
+
args = [inplace_options[:object], source_col, inplace_options.merge(js: false), nil, false]
|
60
|
+
else
|
61
|
+
args = [source_col, inplace_options]
|
62
|
+
end
|
63
|
+
content_tag(:div, style: 'display:none;', class: inplace_edit_control_css_class) do
|
64
|
+
send(ui_method, *args, ui_options: form_ui_options || {})
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'active_scaffold_child_memberships/engine'
|
2
|
+
require 'active_scaffold_child_memberships/version'
|
3
|
+
|
4
|
+
module ActiveScaffoldChildMemberships
|
5
|
+
autoload :AttributeParams, 'active_scaffold_child_memberships/attribute_params'
|
6
|
+
autoload :Helpers, 'active_scaffold_child_memberships/helpers'
|
7
|
+
end
|
8
|
+
ActiveScaffold.javascripts << 'active_scaffold_child_memberships'
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_scaffold_child_memberships
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergio Cambra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: active_scaffold
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
description: A form UI for ActiveScaffold, allowing to edit membership association
|
28
|
+
for multiple children
|
29
|
+
email: activescaffold@googlegroups.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- app/assets/javascripts/active_scaffold_child_memberships.js
|
38
|
+
- lib/active_scaffold_child_memberships.rb
|
39
|
+
- lib/active_scaffold_child_memberships/attribute_params.rb
|
40
|
+
- lib/active_scaffold_child_memberships/engine.rb
|
41
|
+
- lib/active_scaffold_child_memberships/helpers.rb
|
42
|
+
- lib/active_scaffold_child_memberships/version.rb
|
43
|
+
homepage: https://activescaffold.eu
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.5.11
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Form UI :child_memberships for ActiveScaffold
|
66
|
+
test_files: []
|