avo 2.11.2.pre.3 → 2.11.3.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/assets/stylesheets/avo.css +1 -0
  4. data/app/assets/stylesheets/css/scrollbar.css +30 -0
  5. data/app/components/avo/actions_component.html.erb +3 -3
  6. data/app/components/avo/actions_component.rb +12 -3
  7. data/app/components/avo/button_component.rb +1 -3
  8. data/app/components/avo/paginator_component.html.erb +35 -33
  9. data/app/components/avo/paginator_component.rb +3 -1
  10. data/app/components/avo/panel_component.html.erb +1 -1
  11. data/app/components/avo/resource_component.rb +6 -4
  12. data/app/components/avo/sidebar_component.html.erb +1 -1
  13. data/app/components/avo/tab_switcher_component.html.erb +1 -1
  14. data/app/components/avo/views/resource_index_component.html.erb +3 -3
  15. data/app/components/avo/views/resource_show_component.html.erb +143 -52
  16. data/app/components/avo/views/resource_show_component.rb +1 -0
  17. data/app/controllers/avo/base_controller.rb +8 -7
  18. data/app/javascript/avo.js +1 -1
  19. data/app/javascript/js/controllers/fields/date_field_controller.js +7 -3
  20. data/app/views/avo/debug/report.html.erb +1 -0
  21. data/app/views/avo/private/design.html.erb +1 -1
  22. data/lib/avo/base_resource.rb +5 -1
  23. data/lib/avo/concerns/has_editable_controls.rb +34 -0
  24. data/lib/avo/fields/date_time_field.rb +2 -2
  25. data/lib/avo/fields/has_base_field.rb +2 -0
  26. data/lib/avo/licensing/pro_license.rb +1 -0
  27. data/lib/avo/resources/controls/action.rb +32 -0
  28. data/lib/avo/resources/controls/actions_list.rb +19 -0
  29. data/lib/avo/resources/controls/back_button.rb +13 -0
  30. data/lib/avo/resources/controls/base_control.rb +59 -0
  31. data/lib/avo/resources/controls/delete_button.rb +13 -0
  32. data/lib/avo/resources/controls/detach_button.rb +13 -0
  33. data/lib/avo/resources/controls/edit_button.rb +13 -0
  34. data/lib/avo/resources/controls/execution_context.rb +59 -0
  35. data/lib/avo/resources/controls/items_holder.rb +19 -0
  36. data/lib/avo/resources/controls/link_to.rb +27 -0
  37. data/lib/avo/version.rb +1 -1
  38. data/lib/generators/avo/templates/action.tt +1 -1
  39. data/lib/generators/avo/templates/resource_tools/partial.tt +1 -1
  40. data/lib/generators/avo/templates/standalone_action.tt +1 -1
  41. data/public/avo-assets/avo.css +602 -43
  42. data/public/avo-assets/avo.js +2 -2
  43. data/public/avo-assets/avo.js.map +2 -2
  44. metadata +14 -3
  45. data/lib/avo/concerns/has_model.rb +0 -11
@@ -0,0 +1,34 @@
1
+ module Avo
2
+ module Concerns
3
+ module HasEditableControls
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ class_attribute :show_controls
8
+ class_attribute :show_controls_holder
9
+ class_attribute :show_controls_holder_called, default: false
10
+ end
11
+
12
+ def has_show_controls?
13
+ return false if ::Avo::App.license.lacks_with_trial(:resource_show_controls)
14
+
15
+ self.class.show_controls.present?
16
+ end
17
+
18
+ def render_show_controls
19
+ return [] if ::Avo::App.license.lacks_with_trial(:resource_show_controls)
20
+
21
+ if show_controls.present?
22
+ Avo::Resources::Controls::ExecutionContext.new(
23
+ block: show_controls,
24
+ resource: self,
25
+ model: model,
26
+ view: view
27
+ ).handle.items
28
+ else
29
+ []
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -28,8 +28,8 @@ module Avo
28
28
  end
29
29
 
30
30
  def fill_field(model, key, value, params)
31
- if value.nil?
32
- model[id] = nil
31
+ if value.in?(["", nil])
32
+ model[id] = value
33
33
 
34
34
  return model
35
35
  end
@@ -5,6 +5,7 @@ module Avo
5
5
  attr_accessor :scope
6
6
  attr_accessor :attach_scope
7
7
  attr_accessor :description
8
+ attr_accessor :discreet_pagination
8
9
 
9
10
  def initialize(id, **args, &block)
10
11
  super(id, **args, &block)
@@ -14,6 +15,7 @@ module Avo
14
15
  @display = args[:display].present? ? args[:display] : :show
15
16
  @searchable = args[:searchable] == true
16
17
  @description = args[:description]
18
+ @discreet_pagination = args[:discreet_pagination] || false
17
19
  end
18
20
 
19
21
  def searchable
@@ -15,6 +15,7 @@ module Avo
15
15
  :dashboards,
16
16
  :menu_editor,
17
17
  :stimulus_js_integration,
18
+ :resource_show_controls,
18
19
  :advanced_fields
19
20
  ]
20
21
  end
@@ -0,0 +1,32 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class Action < BaseControl
5
+ attr_reader :klass
6
+
7
+ def initialize(klass, model: nil, resource: nil, view: nil, **args)
8
+ super(**args)
9
+
10
+ @klass = klass
11
+ @resource = resource
12
+ @model = model
13
+ @view = view
14
+ end
15
+
16
+ def action
17
+ return @instance if @instance.present?
18
+
19
+ @instance = @klass.new(model: @model, resource: @resource, view: @view)
20
+ end
21
+
22
+ def path
23
+ Avo::Services::URIService.parse(@resource.record_path).append_paths("actions", action.param_id).to_s
24
+ end
25
+
26
+ def label
27
+ @args[:label] || action.action_name
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class ActionsList < BaseControl
5
+ def exclude
6
+ Array.wrap(@args[:exclude]) || []
7
+ end
8
+
9
+ def color
10
+ @args[:color] || :primary
11
+ end
12
+
13
+ def style
14
+ @args[:style] || :outline
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class BackButton < BaseControl
5
+ def initialize(**args)
6
+ super(**args)
7
+
8
+ @label = I18n.t("avo.go_back")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class BaseControl
5
+ def initialize(**args)
6
+ @args = args
7
+ end
8
+
9
+ def label
10
+ @args[:label] || @label
11
+ end
12
+
13
+ def title
14
+ @args[:title]
15
+ end
16
+
17
+ def color
18
+ @args[:color] || :gray
19
+ end
20
+
21
+ def style
22
+ @args[:style] || :text
23
+ end
24
+
25
+ def icon
26
+ @args[:icon] || nil
27
+ end
28
+
29
+ def back_button?
30
+ is_a? Avo::Resources::Controls::BackButton
31
+ end
32
+
33
+ def edit_button?
34
+ is_a? Avo::Resources::Controls::EditButton
35
+ end
36
+
37
+ def delete_button?
38
+ is_a? Avo::Resources::Controls::DeleteButton
39
+ end
40
+
41
+ def actions_list?
42
+ is_a? Avo::Resources::Controls::ActionsList
43
+ end
44
+
45
+ def link_to?
46
+ is_a? Avo::Resources::Controls::LinkTo
47
+ end
48
+
49
+ def detach_button?
50
+ is_a? Avo::Resources::Controls::DetachButton
51
+ end
52
+
53
+ def action?
54
+ is_a? Avo::Resources::Controls::Action
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class DeleteButton < BaseControl
5
+ def initialize(**args)
6
+ super(**args)
7
+
8
+ @label = I18n.t("avo.delete").capitalize
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class DetachButton < BaseControl
5
+ def initialize(**args)
6
+ super(**args)
7
+
8
+ @label = I18n.t("avo.detach_item", item: title).capitalize
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class EditButton < BaseControl
5
+ def initialize(**args)
6
+ super(**args)
7
+
8
+ @label = I18n.t("avo.edit").capitalize
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ require "dry-initializer"
2
+
3
+ # This object holds some data tha is usually needed to compute blocks around the app.
4
+ module Avo
5
+ module Resources
6
+ module Controls
7
+ class ExecutionContext
8
+ extend Dry::Initializer
9
+
10
+ option :context, default: proc { Avo::App.context }
11
+ option :params, default: proc { Avo::App.params }
12
+ option :view_context, default: proc { Avo::App.view_context }
13
+ option :current_user, default: proc { Avo::App.current_user }
14
+ option :items_holder, default: proc { Avo::Resources::Controls::ItemsHolder.new }
15
+ option :resource, optional: true
16
+ option :model, optional: true
17
+ option :view, optional: true
18
+ option :block, optional: true
19
+
20
+ delegate :authorize, to: Avo::Services::AuthorizationService
21
+
22
+ def handle
23
+ instance_exec(&block)
24
+ end
25
+
26
+ private
27
+
28
+ def back_button(**args)
29
+ items_holder.add_item Avo::Resources::Controls::BackButton.new(**args)
30
+ end
31
+
32
+ def delete_button(**args)
33
+ items_holder.add_item Avo::Resources::Controls::DeleteButton.new(**args)
34
+ end
35
+
36
+ def detach_button(**args)
37
+ items_holder.add_item Avo::Resources::Controls::DetachButton.new(**args)
38
+ end
39
+
40
+ def edit_button(**args)
41
+ items_holder.add_item Avo::Resources::Controls::EditButton.new(**args)
42
+ end
43
+
44
+ def link_to(label, path, **args)
45
+ items_holder.add_item Avo::Resources::Controls::LinkTo.new(label: label, path: path, **args)
46
+ end
47
+
48
+ def actions_list(**args)
49
+ items_holder.add_item Avo::Resources::Controls::ActionsList.new(**args)
50
+ end
51
+
52
+ def action(klass, **args)
53
+ # abort model.inspect
54
+ items_holder.add_item Avo::Resources::Controls::Action.new(klass, model: model, resource: resource, view: view, **args)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,19 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class ItemsHolder
5
+ attr_reader :items
6
+
7
+ def initialize
8
+ @items = []
9
+ end
10
+
11
+ def add_item(instance)
12
+ @items << instance
13
+
14
+ self
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Avo
2
+ module Resources
3
+ module Controls
4
+ class LinkTo < BaseControl
5
+ def initialize(**args)
6
+ super(**args)
7
+ end
8
+
9
+ def path
10
+ @args[:path]
11
+ end
12
+
13
+ def target
14
+ @args[:target] || nil
15
+ end
16
+
17
+ def data
18
+ @args[:data] || {}
19
+ end
20
+
21
+ def class
22
+ @args[:class] || nil
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.11.2.pre.3" unless const_defined?(:VERSION)
2
+ VERSION = "2.11.3.pre.1" unless const_defined?(:VERSION)
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class <%= class_name.camelize %> < Avo::BaseAction
2
- self.name = '<%= name.underscore.humanize %>'
2
+ self.name = "<%= name.underscore.humanize %>"
3
3
 
4
4
  def handle(**args)
5
5
  models, fields, current_user, resource = args.values_at(:models, :fields, :current_user, :resource)
@@ -1,7 +1,7 @@
1
1
  <div class="flex flex-col">
2
2
  <%%= render Avo::PanelComponent.new(name: "<%= human_name %>") do |c| %>
3
3
  <%% c.tools do %>
4
- <%%= a_link('/avo', icon: 'heroicons/solid/academic-cap', style: :primary) do %>
4
+ <%%= a_link('/avo', icon: 'heroicons/solid/academic-cap', color: :primary, style: :primary) do %>
5
5
  Dummy link
6
6
  <%% end %>
7
7
  <%% end %>
@@ -1,5 +1,5 @@
1
1
  class <%= class_name.camelize %> < Avo::BaseAction
2
- self.name = '<%= name.underscore.humanize %>'
2
+ self.name = "<%= name.underscore.humanize %>"
3
3
  self.standalone = true
4
4
 
5
5
  def handle(fields:)