Skip to content

Commit c7d3b82

Browse files
committed
Merge remote-tracking branch 'origin/master' into framework-ui
2 parents 2a9b288 + d10c3f6 commit c7d3b82

File tree

19 files changed

+278
-67
lines changed

19 files changed

+278
-67
lines changed

CHANGELOG.rdoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
- Support hashes in update_columns, keys are association names or :__root__ to refresh fields on subforms or at top of the form, values are list of columns or nested hashes.
1515
- Add custom_modules, in active_scaffold_config and global, to add modules which will be included after ActiveScaffold action modules, to customize the controllers.
1616
- Add active_scaffold_subform_record_actions helper to render the destroy action on the rows of a subform, so it can be used to add more actions
17+
- Improve ActiveStorage bridge to keep existing files in has_many_attachments
18+
- Helpers used by file upload bridges have been renamed and moved the JS code to active_scaffold.js
19+
- Support action link groups to open with click, like actions showing dynamic action link group
20+
- Open dynamic action link group nested in the menu tree, under the action opening it
1721

18-
= 4-1-stable
22+
= 4.1.4
1923
- Fix dirty attributes on refresh_field action, record is built on unsaved instance copying attributes, but it reports only changed attributes from the form now
24+
- Fix incompatibility with Rails renderable objects (ViewComponent, Turbo Streams)
2025

2126
= 4.1.3
2227
- Columns using bitfields are not treated as number columns (e.g. don't get numeric class in list)

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GIT
77
PATH
88
remote: .
99
specs:
10-
active_scaffold (4.1.3)
10+
active_scaffold (4.1.4)
1111
dartsass-sprockets (~> 3.2.0)
1212
html_attrs (~> 1.1)
1313
ice_nine (~> 0.11)

app/assets/javascripts/jquery/active_scaffold.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
jQuery(document).on('focus', ':input', function() { ActiveScaffold.last_focus = this; });
4141
jQuery(document).on('blur', ':input', function(e) { ActiveScaffold.last_focus = e.relatedTarget; });
4242
jQuery(document).click(function(event) {
43-
jQuery('.action_group.dyn > ul').hide(); // only hide so action links loading still work
43+
if (!jQuery(event.target).closest('.action_group.dyn').length) {
44+
jQuery('.action_group.dyn > ul').remove();
45+
}
4446
});
4547
jQuery(document).on('ajax:beforeSend', 'form.as_form', function(event) {
4648
var as_form = jQuery(this).closest("form");
@@ -257,6 +259,22 @@
257259
if (span.data('editInPlace')) span.trigger('click.editInPlace');
258260
else ActiveScaffold.in_place_editor_field_clicked(span);
259261
});
262+
jQuery(document).on('click', '.file-input-controls .remove-file-btn', function(event) {
263+
event.preventDefault();
264+
var btn = jQuery(this), file_line = btn.closest('.file-input-controls');
265+
if (file_line.find('.remove_file').val('true').length) {
266+
btn.parent().hide();
267+
file_line.find('input').show();
268+
if (file_line.attr('required')) file_line.find('input').attr('required', 'required');
269+
} else {
270+
file_line.remove();
271+
}
272+
return false;
273+
});
274+
jQuery(document).on('change', '.file-input-controls input[type=file]', function(event) {
275+
var file_line = jQuery(this).closest('.file-input-controls');
276+
file_line.find('.remove_file').val('false');
277+
});
260278
jQuery(document).on('ajax:before', 'a.as_paginate',function(event) {
261279
var as_paginate = jQuery(this);
262280
as_paginate.prevAll('img.loading-indicator').css('visibility','visible');
@@ -287,9 +305,13 @@
287305
} else return false;
288306
});
289307
jQuery(document).on('ajax:complete', '.action_group.dyn > ul a', function(event) {
290-
var action_link = ActiveScaffold.find_action_link(event.target);
291-
if (action_link && action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
292-
jQuery(event.target).closest('.action_group.dyn > ul').remove();
308+
var action_link = ActiveScaffold.find_action_link(event.target), link = jQuery(event.target);
309+
if (action_link && action_link.loading_indicator) action_link.loading_indicator.css('visibility', 'hidden');
310+
setTimeout(function() {
311+
if (!link.parent().is('.action_group.dyn')) {
312+
link.closest('.action_group.dyn > ul').remove();
313+
}
314+
}, 100);
293315
});
294316

295317
jQuery(document).on('change', 'input.update_form:not(.recordselect), textarea.update_form, select.update_form, .checkbox-list.update_form input:checkbox', function(event, additional_params) {

app/views/active_scaffold_overrides/_update_field_on_create.js.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ var field = jQuery('#<%= params[:from_field] %>');
77
field_options[:class] = "#{field_options[:class]} update_form" if field_options&.dig('data-update_url')
88
%>
99
if (field.is('select')) {
10-
field.append('<%= j content_tag(:option, label, value: id) %>');
10+
if (!field.find('option[value="<%= id %>"]').length) field.append('<%= j content_tag(:option, label, value: id) %>');
1111
field.val(<%= id %>);
1212
} else if (field.is('input.recordselect')) {
1313
field.val('<%= j label %>').addClass('selected');
1414
field.next().val(<%= id %>);
1515
} else if (field.is('.new-radio-container')) {
16-
field.append('<%= j active_scaffold_radio_option(@record, id, column, field_options, ui_options: column.form_ui_options || column.options) if column %>');
16+
if (!field.parent().find('input[type=radio][value="<%= id %>"]').length) {
17+
field.append('<%= j active_scaffold_radio_option(@record, id, column, field_options, ui_options: column.form_ui_options || column.options) if column %>');
18+
} else field = field.parent().find('input[type=radio][value="<%= id %>"]').prop('checked', true);
1719
}
1820
field.trigger('change');
1921
var action_link = ActiveScaffold.ActionLink.get(field.parent().find('a.as_action'));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= display_dynamic_action_group(@action_links, display_action_links(@action_links, @record, for: @record, output: []), @record) %>

gemfiles/Gemfile.rails-7.2.x.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
active_scaffold (4.1.3)
4+
active_scaffold (4.1.4)
55
dartsass-sprockets (~> 3.2.0)
66
html_attrs (~> 1.1)
77
ice_nine (~> 0.11)

lib/active_scaffold/actions/core.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,11 @@ def association_columns(columns)
548548

549549
private
550550

551-
def respond_to_action(action)
551+
def respond_to_action(action, formats = action_formats)
552552
return unless !conditional_get_support? || view_stale?
553553

554554
respond_to do |type|
555-
action_formats.each do |format|
555+
formats.each do |format|
556556
type.send(format) do
557557
method_name = respond_method_for(action, format)
558558
send(method_name) if method_name

lib/active_scaffold/actions/list.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ def self.included(base)
88
end
99

1010
def index
11-
if params[:id] && !params[:id].is_a?(Array) && request.xhr?
11+
if params[:action_links] && request.xhr?
12+
action_links_menu
13+
elsif params[:id] && !params[:id].is_a?(Array) && request.xhr?
1214
row
1315
else
1416
list
@@ -17,6 +19,18 @@ def index
1719

1820
protected
1921

22+
def action_links_menu
23+
@record = find_if_allowed(params[:id], :read) if params[:id]
24+
@action_links = params[:action_links].split('.').reduce(active_scaffold_config.action_links) do |links, submenu|
25+
links.subgroup(submenu)
26+
end
27+
respond_to_action(:action_links_menu, action_links_menu_formats)
28+
end
29+
30+
def action_links_menu_formats
31+
%i[js]
32+
end
33+
2034
# get just a single row
2135
def row
2236
get_row
@@ -66,6 +80,10 @@ def row_respond_to_js
6680
render action: 'row'
6781
end
6882

83+
def action_links_menu_respond_to_js
84+
render action: 'action_links_menu'
85+
end
86+
6987
# The actual algorithm to prepare for the list view
7088
def set_includes_for_columns(action = :list, sorting = active_scaffold_config.list.user.sorting)
7189
@cache_associations = true

lib/active_scaffold/bridges/active_storage/form_ui.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ def active_scaffold_input_active_storage_has_one(column, options, ui_options: co
88
record = options[:object]
99
active_storage = record.send(column.name.to_s)
1010
content = active_scaffold_column_active_storage_has_one(record, column, ui_options: ui_options) if active_storage.attached?
11-
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls', ui_options: ui_options)
11+
active_scaffold_file_with_content(column, options, content, 'delete_', 'active_storage_controls', ui_options: ui_options)
1212
end
1313

1414
def active_scaffold_input_active_storage_has_many(column, options, ui_options: column.options)
1515
record = options[:object]
1616
options[:multiple] = 'multiple'
17+
options[:include_hidden] = false
1718
options[:name] += '[]'
1819
active_storage = record.send(column.name.to_s)
19-
content = active_scaffold_column_active_storage_has_many(record, column, ui_options: ui_options) if active_storage.attached?
20-
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls', ui_options: ui_options)
20+
existing = active_storage.map do |file|
21+
content = hidden_field_tag(options[:name], file.signed_id) <<
22+
link_for_attachment(file, column, ui_options: ui_options) << h(' | ')
23+
active_scaffold_file_with_remove_link(content, options, 'active_storage_controls', :remove)
24+
end
25+
safe_join existing << hidden_field_tag(options[:name]) << file_field(:record, column.name, options)
2126
end
2227
end
2328
end

lib/active_scaffold/bridges/carrierwave/form_ui.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def active_scaffold_input_carrierwave(column, options, ui_options: column.option
77
record = options[:object]
88
carrierwave = record.send(column.name.to_s)
99
content = get_column_value(record, column) if carrierwave.file.present?
10-
active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'carrierwave_controls', ui_options: ui_options) do
10+
active_scaffold_file_with_content(column, options, content, 'remove_', 'carrierwave_controls', ui_options: ui_options) do
1111
cache_field_options = {
1212
name: options[:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]"),
1313
id: "#{options[:id]}_cache"

0 commit comments

Comments
 (0)