fluxbit_view_components 0.5.0 → 0.5.1

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: 6f66b9f23ca4ef3e2fe559a212875eda72091ec0e44473efdeade01655b01ddf
4
- data.tar.gz: 5d17abad070b64489453dde8cc700f3c464d4b97d60f0cb8aab4aa0137013385
3
+ metadata.gz: 3ff7c36152723efea00fcb464ac64ca6462b5f2a0f80cd7eab5298f5129bab1a
4
+ data.tar.gz: aa51123027b44b8e2a268275c15ed192bcb8bc111f5ec82d1d9ad74597b3f0c1
5
5
  SHA512:
6
- metadata.gz: 0f893f775299b24f11ebc2c8120099c13999f525502d314d9ad87709a02fbbf6dd194bede20193e0cf5a5a7bd53b2b9e58d1298113df77f3ee7b958988c81bfd
7
- data.tar.gz: 802ffce4186aa7fe55a32c56b904e084b4c346b6e50a5891bab9683eaa636cde5654b97e0c9b4502e30ad20e4d21b4bdcb2e68260cd66fd9d1aad72a7fd1ea73
6
+ metadata.gz: 2051c7d64576f3a0f8996475e184b164adc767241c52e33837472b7a28f011a2fe5e67fc86ad122599a7679dd252a019834489a795fae7b4bb558f4a444200d5
7
+ data.tar.gz: 5d62cc33db45e466341d46fbef8c35b128c4c16d8311a66ec0052a7133e4d7a344527577c66df08a609a48fa142e051a952dda15f041bada8c2ecc54919706a0
@@ -6,7 +6,10 @@ class Fluxbit::AccordionComponent < Fluxbit::Component
6
6
  include Fluxbit::Config::AccordionComponent
7
7
 
8
8
  renders_many :panels, lambda { |**attrs, &block|
9
+ @panel_index ||= 0
10
+ attrs[:index] = @panel_index unless attrs.key?(:index)
9
11
  panel = Panel.new(accordion_id: fx_id, flush: @flush, color: @color, **attrs)
12
+ @panel_index += 1
10
13
  block.call(panel) if block_given?
11
14
  panel
12
15
  }
@@ -58,7 +61,7 @@ class Fluxbit::AccordionComponent < Fluxbit::Component
58
61
  # @param [Boolean] flush (false) Whether the panel should use flush styling.
59
62
  # @param [Symbol, String] color (:default) The color theme for this panel.
60
63
  # @param [Boolean] open (false) Whether the panel should start in an expanded state.
61
- # @param [Integer] index (0) The panel's position index for proper styling (first, middle, last).
64
+ # @param [Integer] index The panel's position index for proper styling (first, middle, last). Automatically increments for each panel if not specified.
62
65
  # @param [Hash] **props Additional HTML attributes for the panel container.
63
66
  #
64
67
  # @return [Fluxbit::AccordionComponent::Panel]
@@ -99,7 +99,7 @@ class Fluxbit::Form::TextFieldComponent < Fluxbit::Form::FieldComponent
99
99
  first_element: true,
100
100
  class: [
101
101
  styles[:default],
102
- (@props.key?(:readonly) || @props.key?(:disabled) ? styles[:text][@color] : nil),
102
+ (@props.key?(:readonly) || @props.key?(:disabled) ? styles[:text][@color] : styles[:text][:default]),
103
103
  styles[:ring][@color],
104
104
  styles[:bg][@color],
105
105
  styles[:placeholder][@color],
@@ -1,5 +1,5 @@
1
1
  module Fluxbit
2
2
  module ViewComponents
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -89,6 +89,8 @@ module Fluxbit
89
89
  # Generate i18n
90
90
  template "i18n.en.yml.tt", File.join("config", "locales", "#{file_name.pluralize}.en.yml")
91
91
  template "i18n.pt-BR.yml.tt", File.join("config", "locales", "#{file_name.pluralize}.pt-BR.yml")
92
+ template "i18n.general.en.yml.tt", File.join("config", "locales", "general.en.yml")
93
+ template "i18n.general.pt-BR.yml.tt", File.join("config", "locales", "general.pt-BR.yml")
92
94
 
93
95
  # Generate Policy
94
96
  template "policy.rb.tt", File.join("app/policies", "#{file_name.singularize}_policy.rb")
@@ -97,6 +99,7 @@ module Fluxbit
97
99
  template "_alert.html.erb.tt", File.join("app/views/shared", "_alert.html.erb")
98
100
  template "send_alert_via_drawer.html.erb.tt", File.join("app/views/shared", "send_alert_via_drawer_alert.html.erb")
99
101
  template "_flash.html.erb.tt", File.join("app/views/shared", "_flash.html.erb")
102
+ template "sortable.rb.tt", File.join("app/controllers/concerns", "sortable.rb")
100
103
  end
101
104
 
102
105
  private
@@ -6,10 +6,12 @@
6
6
  "warning" => :warning
7
7
  } %>
8
8
 
9
- <%% flash.each do |type, msg| %>
10
- <%% next if msg.blank? %>
11
- <%% color = mapping[type.to_s] || :info %>
12
- <%%= fx_alert(color: color) do %>
13
- <%%= safe_join(Array(msg).map { |m| sanitize(m.to_s, tags: [], attributes: []) }, tag.br) %>
9
+ <div id="notice" class="fixed top-4 right-4 z-50 max-w-md w-auto">
10
+ <%% flash.each do |type, msg| %>
11
+ <%% next if msg.blank? %>
12
+ <%% color = mapping[type.to_s] || :info %>
13
+ <%%= fx_alert(color: color) do %>
14
+ <%%= safe_join(Array(msg).map { |m| sanitize(m.to_s, tags: [], attributes: []) }, tag.br) %>
15
+ <%% end %>
14
16
  <%% end %>
15
- <%% end %>
17
+ </div>
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class <%= namespaced? ? "#{namespace_module}::" : "" %><%= class_name.pluralize %>Controller < ApplicationController
5
+ include Sortable
5
6
  include Pundit::Authorization
6
7
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
7
8
 
@@ -241,7 +242,7 @@ class <%= namespaced? ? "#{namespace_module}::" : "" %><%= class_name.pluralize
241
242
  private
242
243
 
243
244
  def set_<%= singular %>
244
- @<%= singular %> = <%= class_name.singularize %>.find(params[:id])
245
+ @<%= singular %> = policy_scope(<%= class_name.singularize %>).find(params[:id])
245
246
  # Note: Pundit authorization for @<%= singular %> happens in each action
246
247
  rescue ActiveRecord::RecordNotFound
247
248
  @message = t("<%= plural %>.messages.not_found")
@@ -264,7 +265,7 @@ class <%= namespaced? ? "#{namespace_module}::" : "" %><%= class_name.pluralize
264
265
 
265
266
  def set_<%= plural %>_for_bulk_actions
266
267
  <%= singular %>_ids = Array(params[:<%= singular %>_ids]).reject(&:blank?)
267
- @<%= plural %> = <%= class_name.singularize %>.where(id: <%= singular %>_ids)
268
+ @<%= plural %> = policy_scope(<%= class_name.singularize %>).where(id: <%= singular %>_ids)
268
269
 
269
270
  if @<%= plural %>.empty?
270
271
  @message = t("<%= plural %>.messages.not_selected_for_action")
@@ -0,0 +1,4 @@
1
+ en:
2
+ general:
3
+ messages:
4
+ order_error: "Invalid order parameter."
@@ -0,0 +1,23 @@
1
+ module Sortable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ helper_method :apply_sorting
6
+ end
7
+
8
+ private
9
+
10
+ def apply_sorting(resource_class, order_param, order_options = %i[created_at updated_at], default_order = { created_at: :desc })
11
+ if order_param.present?
12
+ order = order_param.rpartition("_")
13
+ if order.length == 3 && %w[asc desc].include?(order.last) && order_options.include?(order.first.to_sym)
14
+ resource_class.order(order.first.to_sym => order.last.to_sym)
15
+ else
16
+ flash[:error] = t("general.messages.order_error")
17
+ resource_class.order(default_order)
18
+ end
19
+ else
20
+ resource_class.order(default_order) # Default order
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluxbit_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Molina
@@ -292,15 +292,18 @@ files:
292
292
  - lib/generators/fluxbit/templates/edit.html.erb.tt
293
293
  - lib/generators/fluxbit/templates/fluxbit_pagy.css
294
294
  - lib/generators/fluxbit/templates/i18n.en.yml.tt
295
+ - lib/generators/fluxbit/templates/i18n.general.en.yml.tt
296
+ - lib/generators/fluxbit/templates/i18n.general.pt-BR.yml.tt
295
297
  - lib/generators/fluxbit/templates/i18n.pt-BR.yml.tt
296
298
  - lib/generators/fluxbit/templates/index.html.erb.tt
297
299
  - lib/generators/fluxbit/templates/index.json.jbuilder.tt
298
300
  - lib/generators/fluxbit/templates/new.html.erb.tt
299
301
  - lib/generators/fluxbit/templates/partial.html.erb.tt
300
302
  - lib/generators/fluxbit/templates/policy.rb.tt
301
- - lib/generators/fluxbit/templates/send_alert_via_drawer.erb.tt
303
+ - lib/generators/fluxbit/templates/send_alert_via_drawer.html.erb.tt
302
304
  - lib/generators/fluxbit/templates/show.html.erb.tt
303
305
  - lib/generators/fluxbit/templates/show.json.jbuilder.tt
306
+ - lib/generators/fluxbit/templates/sortable.rb.tt
304
307
  - lib/generators/fluxbit/templates/update.turbo_stream.erb.tt
305
308
  - lib/generators/fluxbit/templates/update_all.turbo_stream.erb.tt
306
309
  - lib/install/install.rb