avo 2.11.3.pre.3 → 2.13.0

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -4
  3. data/README.md +2 -1
  4. data/app/components/avo/actions_component.html.erb +3 -3
  5. data/app/components/avo/actions_component.rb +12 -3
  6. data/app/components/avo/button_component.rb +1 -3
  7. data/app/components/avo/card_component.html.erb +8 -8
  8. data/app/components/avo/fields/common/gravatar_viewer_component.html.erb +1 -1
  9. data/app/components/avo/fields/date_field/edit_component.html.erb +0 -3
  10. data/app/components/avo/fields/date_time_field/edit_component.html.erb +0 -2
  11. data/app/components/avo/fields/has_one_field/show_component.html.erb +1 -1
  12. data/app/components/avo/fields/tags_field/show_component.rb +0 -2
  13. data/app/components/avo/index/ordering/buttons_component.html.erb +1 -1
  14. data/app/components/avo/index/resource_controls_component.rb +1 -1
  15. data/app/components/avo/item_switcher_component.html.erb +1 -1
  16. data/app/components/avo/panel_component.html.erb +1 -1
  17. data/app/components/avo/panel_component.rb +3 -4
  18. data/app/components/avo/resource_component.rb +6 -4
  19. data/app/components/avo/tab_group_component.html.erb +1 -1
  20. data/app/components/avo/tab_switcher_component.rb +2 -2
  21. data/app/components/avo/views/resource_edit_component.html.erb +1 -1
  22. data/app/components/avo/views/resource_edit_component.rb +1 -21
  23. data/app/components/avo/views/resource_index_component.html.erb +49 -97
  24. data/app/components/avo/views/resource_index_component.rb +19 -0
  25. data/app/components/avo/views/resource_show_component.html.erb +139 -53
  26. data/app/components/avo/views/resource_show_component.rb +1 -0
  27. data/app/controllers/avo/application_controller.rb +7 -3
  28. data/app/controllers/avo/associations_controller.rb +2 -2
  29. data/app/controllers/avo/base_controller.rb +11 -18
  30. data/app/controllers/avo/cards_controller.rb +5 -18
  31. data/app/controllers/avo/dashboards_controller.rb +2 -4
  32. data/app/controllers/avo/search_controller.rb +57 -20
  33. data/app/javascript/js/controllers/{card_controller.js → dashboard_card_controller.js} +0 -0
  34. data/app/javascript/js/controllers/menu_controller.js +2 -2
  35. data/app/javascript/js/controllers/search_controller.js +42 -15
  36. data/app/javascript/js/controllers.js +2 -2
  37. data/app/views/avo/associations/new.html.erb +1 -0
  38. data/app/views/avo/cards/_metric_card.html.erb +2 -2
  39. data/app/views/avo/dashboards/show.html.erb +20 -3
  40. data/app/views/avo/debug/index.html.erb +1 -1
  41. data/app/views/avo/debug/report.html.erb +1 -0
  42. data/app/views/avo/home/index.html.erb +1 -1
  43. data/app/views/avo/partials/_resource_search.html.erb +6 -0
  44. data/app/views/avo/private/design.html.erb +2 -2
  45. data/config/routes.rb +0 -3
  46. data/lib/avo/base_card.rb +21 -40
  47. data/lib/avo/base_resource.rb +5 -2
  48. data/lib/avo/concerns/has_editable_controls.rb +34 -0
  49. data/lib/avo/concerns/has_fields.rb +11 -10
  50. data/lib/avo/dashboards/base_dashboard.rb +50 -15
  51. data/lib/avo/dashboards/base_divider.rb +1 -5
  52. data/lib/avo/dashboards/chartkick_card.rb +4 -5
  53. data/lib/avo/fields/base_field.rb +13 -7
  54. data/lib/avo/fields/date_field.rb +1 -3
  55. data/lib/avo/fields/field_extensions/has_include_blank.rb +1 -1
  56. data/lib/avo/fields/field_extensions/visible_in_different_views.rb +1 -12
  57. data/lib/avo/fields/has_base_field.rb +18 -1
  58. data/lib/avo/fields/key_value_field.rb +6 -6
  59. data/lib/avo/hosts/base_host.rb +2 -1
  60. data/lib/avo/hosts/dashboard_card.rb +1 -1
  61. data/lib/avo/hosts/search_scope_host.rb +7 -0
  62. data/lib/avo/licensing/h_q.rb +12 -4
  63. data/lib/avo/licensing/pro_license.rb +1 -0
  64. data/lib/avo/menu/builder.rb +2 -0
  65. data/lib/avo/resources/controls/action.rb +32 -0
  66. data/lib/avo/resources/controls/actions_list.rb +19 -0
  67. data/lib/avo/resources/controls/back_button.rb +13 -0
  68. data/lib/avo/resources/controls/base_control.rb +59 -0
  69. data/lib/avo/resources/controls/delete_button.rb +13 -0
  70. data/lib/avo/resources/controls/detach_button.rb +13 -0
  71. data/lib/avo/resources/controls/edit_button.rb +13 -0
  72. data/lib/avo/resources/controls/execution_context.rb +58 -0
  73. data/lib/avo/resources/controls/items_holder.rb +19 -0
  74. data/lib/avo/resources/controls/link_to.rb +27 -0
  75. data/lib/avo/tab.rb +1 -3
  76. data/lib/avo/version.rb +1 -1
  77. data/lib/generators/avo/templates/action.tt +1 -1
  78. data/lib/generators/avo/templates/cards/partial_card_partial.tt +1 -1
  79. data/lib/generators/avo/templates/initializer/avo.tt +1 -0
  80. data/lib/generators/avo/templates/resource/resource.tt +1 -1
  81. data/lib/generators/avo/templates/resource_tools/partial.tt +1 -1
  82. data/lib/generators/avo/templates/standalone_action.tt +1 -1
  83. data/public/avo-assets/avo.css +592 -124
  84. data/public/avo-assets/avo.js +48 -48
  85. data/public/avo-assets/avo.js.map +3 -3
  86. metadata +17 -10
  87. data/app/components/avo/cards_list_component.html.erb +0 -16
  88. data/app/components/avo/cards_list_component.rb +0 -13
  89. data/lib/avo/concerns/has_cards.rb +0 -88
  90. data/lib/avo/concerns/has_model.rb +0 -11
  91. data/lib/avo/concerns/styles_cards.rb +0 -48
@@ -1,7 +1,24 @@
1
- <%= render Avo::PanelComponent.new(title: @dashboard.name, description: @dashboard.description) do |c| %>
1
+ <%= render Avo::PanelComponent.new(name: @dashboard.name, description: @dashboard.description) do |c| %>
2
2
  <% c.bare_content do %>
3
- <% if @dashboard.cards.present? %>
4
- <%= render Avo::CardsListComponent.new parent: @dashboard %>
3
+ <% if @dashboard.items.present? %>
4
+ <div class="min-h-24">
5
+ <%= content_tag(:div, class: "grid gap-4 grid-cols-1 #{@dashboard.classes}") do %>
6
+ <% @dashboard.items.each do |item| %>
7
+ <% if item.is_divider? %>
8
+ <%= render Avo::Dashboards::DividerComponent.new(divider: item) %>
9
+ <% elsif item.is_card? %>
10
+ <%= content_tag(:div, class: "relative bg-white rounded shadow-panel space-y-2 #{item.card_classes} overflow-hidden") do %>
11
+ <turbo-frame id="<%= item.turbo_frame %>"
12
+ src="<%= item.frame_url(enforced_range: @range, params: params) %>"
13
+ data-card-index="<%= item.index %>"
14
+ >
15
+ <%= render(Avo::LoadingComponent.new(title: item.label)) %>
16
+ </turbo-frame>
17
+ <% end %>
18
+ <% end %>
19
+ <% end %>
20
+ <% end %>
21
+ </div>
5
22
  <% else %>
6
23
  <div class="w-full h-full">
7
24
  <% if Rails.env.development? %>
@@ -14,7 +14,7 @@
14
14
  hq_payload = Avo::Licensing::HQ.new(request).payload
15
15
  %>
16
16
  <div class="flex flex-col">
17
- <%= render Avo::PanelComponent.new(title: 'Debug Avo', description: 'Use this page to debug the Avo license.') do |c| %>
17
+ <%= render Avo::PanelComponent.new(name: 'Debug Avo', description: 'Use this page to debug the Avo license.') do |c| %>
18
18
  <% c.tools do %>
19
19
  <% end %>
20
20
  <% c.bare_content do %>
@@ -9,6 +9,7 @@
9
9
  </div>
10
10
  <div class="flex justify-end">
11
11
  <%= a_button icon: 'heroicons/outline/clipboard',
12
+ color: :primary,
12
13
  style: :primary,
13
14
  data: {
14
15
  controller: 'copy-to-clipboard',
@@ -1,5 +1,5 @@
1
1
  <div class="flex flex-col">
2
- <%= render Avo::PanelComponent.new(title: 'Welcome to Avo', description: 'This page is visible only in development. It will be hidden in other environments.') do |c| %>
2
+ <%= render Avo::PanelComponent.new(name: 'Welcome to Avo', description: 'This page is visible only in development. It will be hidden in other environments.') do |c| %>
3
3
  <% c.body do %>
4
4
  <div class="flex flex-col justify-between py-6 min-h-24">
5
5
  <div class="px-6 space-y-4">
@@ -3,6 +3,12 @@
3
3
  data-search-target="autocomplete"
4
4
  data-search-resource="<%= resource %>"
5
5
  data-translation-keys='{"no_item_found": "<%= I18n.translate 'avo.no_item_found' %>"}'
6
+ <% if via_reflection.present? %>
7
+ data-via-association="<%= via_reflection[:association] %>"
8
+ data-via-association-id="<%= via_reflection[:association_id] %>"
9
+ data-via-reflection-class="<%= via_reflection[:class] %>"
10
+ data-via-reflection-id="<%= via_reflection[:id] %>"
11
+ <% end %>
6
12
  >
7
13
  </div>
8
14
  <div class="hidden relative inline-flex text-gray-400 text-sm border border-gray-300 rounded cursor-pointer" data-search-target="button"></div>
@@ -1,7 +1,7 @@
1
1
  <div class="flex flex-col">
2
- <%= render Avo::PanelComponent.new(title: 'Welcome to Avo', description: 'This page is visible only in development. It will be hidden in other environments.') do |c| %>
2
+ <%= render Avo::PanelComponent.new(name: 'Welcome to Avo', description: 'This page is visible only in development. It will be hidden in other environments.') do |c| %>
3
3
  <% c.tools do %>
4
- <%= a_link('/admin', icon: 'arrow-left', style: :primary, is_link: true) do %>
4
+ <%= a_link('/admin', icon: 'arrow-left', color: :green, style: :primary, is_link: true) do %>
5
5
  Primary
6
6
  <% end %>
7
7
 
data/config/routes.rb CHANGED
@@ -35,9 +35,6 @@ Avo::Engine.routes.draw do
35
35
  # resources :posts
36
36
  Avo::DynamicRouter.routes(self)
37
37
 
38
- # Cards
39
- get "/:resource_name/:id/cards/:card_id", to: "cards#show"
40
-
41
38
  # Associations
42
39
  get "/:resource_name/:id/:related_name/new", to: "associations#new", as: "associations_new"
43
40
  get "/:resource_name/:id/:related_name/", to: "associations#index", as: "associations_index"
data/lib/avo/base_card.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  module Avo
2
2
  class BaseCard
3
- include Avo::Concerns::StylesCards
4
- include Avo::Fields::FieldExtensions::VisibleInDifferentViews
5
-
6
3
  class_attribute :id
7
4
  class_attribute :label
8
5
  class_attribute :description
6
+ class_attribute :cols, default: 1
7
+ class_attribute :rows, default: 1
9
8
  class_attribute :initial_range
10
9
  class_attribute :ranges, default: []
11
10
  class_attribute :refresh_every
@@ -14,7 +13,7 @@ module Avo
14
13
  class_attribute :result_data
15
14
  class_attribute :query_block
16
15
 
17
- attr_accessor :parent
16
+ attr_accessor :dashboard
18
17
  attr_accessor :options
19
18
  attr_accessor :index
20
19
  attr_accessor :params
@@ -27,8 +26,8 @@ module Avo
27
26
  end
28
27
  end
29
28
 
30
- def initialize(parent:, options: {}, index: 0, cols: nil, rows: nil, label: nil, description: nil, refresh_every: nil, **args)
31
- @parent = parent
29
+ def initialize(dashboard:, options: {}, index: 0, cols: nil, rows: nil, label: nil, description: nil, refresh_every: nil)
30
+ @dashboard = dashboard
32
31
  @options = options
33
32
  @index = index
34
33
  @cols = cols
@@ -36,8 +35,6 @@ module Avo
36
35
  @label = label
37
36
  @refresh_every = refresh_every
38
37
  @description = description
39
-
40
- initialize_visibility args
41
38
  end
42
39
 
43
40
  def label
@@ -56,21 +53,13 @@ module Avo
56
53
  end
57
54
 
58
55
  def turbo_frame
59
- if parent_is_dashboard?
60
- "#{parent.id}_#{id}"
61
- elsif parent_is_resource?
62
- "#{parent.id}_#{parent.model.id}_#{id}"
63
- end
56
+ "#{dashboard.id}_#{id}"
64
57
  end
65
58
 
66
59
  def frame_url(enforced_range: nil, params: {})
67
60
  enforced_range ||= initial_range || ranges.first
68
61
 
69
- if parent_is_dashboard?
70
- Avo::App.view_context.avo.dashboard_card_path(dashboard.id, id, turbo_frame: turbo_frame, index: index, range: enforced_range, **params.permit!.to_h)
71
- elsif parent_is_resource?
72
- Avo::App.root_path(paths: ["resources", parent.route_key, parent.model.id, "cards", id], query: {**params.permit!.to_h, turbo_frame: turbo_frame, index: index, range: enforced_range})
73
- end
62
+ Avo::App.view_context.avo.dashboard_card_path(dashboard.id, id, turbo_frame: turbo_frame, index: index, range: enforced_range, **params.permit!)
74
63
  end
75
64
 
76
65
  def card_classes
@@ -87,13 +76,14 @@ module Avo
87
76
  }
88
77
 
89
78
  classes_for_rows = {
90
- 1 => " min-h-[8rem] row-span-1",
91
- 2 => " min-h-[16rem] row-span-2",
92
- 3 => " min-h-[24rem] row-span-3",
93
- 4 => " min-h-[32rem] row-span-4",
94
- 5 => " min-h-[40rem] row-span-5",
95
- 6 => " min-h-[48rem] row-span-6"
79
+ 1 => " h-36",
80
+ 2 => " h-72",
81
+ 3 => " h-[27rem]",
82
+ 4 => " h-[36rem]",
83
+ 5 => " h-[45rem]",
84
+ 6 => " h-[54rem]"
96
85
  }
86
+ # puts ["cols->", cols, classes_for_cols, classes_for_rows, classes_for_cols[cols.to_i]].inspect
97
87
 
98
88
  result += classes_for_cols[cols.to_i] if classes_for_cols[cols.to_i].present?
99
89
  result += classes_for_rows[rows.to_i] if classes_for_rows[rows.to_i].present?
@@ -108,16 +98,15 @@ module Avo
108
98
  end
109
99
 
110
100
  def compute_result
111
- Avo::Hosts::DashboardCard.new(card: self, parent: parent, params: params, context: context, range: range, options: options)
101
+ Avo::Hosts::DashboardCard.new(card: self, dashboard: dashboard, params: params, context: context, range: range, options: options)
112
102
  .compute_result
113
103
 
114
104
  self
115
105
  end
116
106
 
117
- def hydrate(parent: nil, params: nil, view: nil)
118
- @parent = parent if parent.present?
107
+ def hydrate(dashboard: nil, params: nil)
108
+ @dashboard = dashboard if dashboard.present?
119
109
  @params = params if params.present?
120
- @view = view if view.present?
121
110
 
122
111
  self
123
112
  end
@@ -146,20 +135,12 @@ module Avo
146
135
 
147
136
  private
148
137
 
149
- def parent_is_dashboard?
150
- parent.class.superclass == Avo::Dashboards::BaseDashboard
151
- end
152
-
153
- def parent_is_resource?
154
- parent.class.superclass == Avo::BaseResource
155
- end
156
-
157
- def resource
158
- parent if parent_is_resource?
138
+ def cols
139
+ @cols || self.class.cols
159
140
  end
160
141
 
161
- def dashboard
162
- parent if parent_is_dashboard?
142
+ def rows
143
+ @rows || self.class.rows
163
144
  end
164
145
  end
165
146
  end
@@ -3,9 +3,8 @@ module Avo
3
3
  extend ActiveSupport::DescendantsTracker
4
4
 
5
5
  include ActionView::Helpers::UrlHelper
6
- include Avo::Concerns::HasCards
7
- include Avo::Concerns::HasModel
8
6
  include Avo::Concerns::HasFields
7
+ include Avo::Concerns::HasEditableControls
9
8
  include Avo::Concerns::HasStimulusControllers
10
9
  include Avo::Concerns::ModelClassConstantized
11
10
 
@@ -440,5 +439,9 @@ module Avo
440
439
  def ordering_host(**args)
441
440
  Avo::Hosts::Ordering.new resource: self, options: self.class.ordering, **args
442
441
  end
442
+
443
+ def has_model_id?
444
+ model.present? && model.id.present?
445
+ end
443
446
  end
444
447
  end
@@ -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
+ record: model,
26
+ view: view
27
+ ).handle&.items || []
28
+ else
29
+ []
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -17,19 +17,19 @@ module Avo
17
17
  def field(name, **args, &block)
18
18
  ensure_items_holder_initialized
19
19
 
20
- self.items_holder.field name, **args, &block
20
+ items_holder.field name, **args, &block
21
21
  end
22
22
 
23
23
  def panel(name = nil, **args, &block)
24
24
  ensure_items_holder_initialized
25
25
 
26
- self.items_holder.panel name, **args, &block
26
+ items_holder.panel name, **args, &block
27
27
  end
28
28
 
29
29
  def tabs(&block)
30
30
  ensure_items_holder_initialized
31
31
 
32
- self.items_holder.tabs Avo::TabGroupBuilder.parse_block(&block)
32
+ items_holder.tabs Avo::TabGroupBuilder.parse_block(&block)
33
33
  end
34
34
 
35
35
  def tool(klass, **args)
@@ -39,27 +39,29 @@ module Avo
39
39
  end
40
40
 
41
41
  def heading(body, **args)
42
- self.items_holder.heading body, **args
42
+ ensure_items_holder_initialized
43
+
44
+ items_holder.heading body, **args
43
45
  end
44
46
  # END DSL methods
45
47
 
46
48
  def items
47
- if self.items_holder.present?
48
- self.items_holder.items
49
+ if items_holder.present?
50
+ items_holder.items
49
51
  else
50
52
  []
51
53
  end
52
54
  end
53
55
 
54
56
  def tools
55
- self.tools_holder
57
+ tools_holder
56
58
  end
57
59
 
58
60
  # Dives deep into panels and tabs to fetch all the fields for a resource.
59
61
  def fields(only_root: false)
60
62
  fields = []
61
63
 
62
- self.items.each do |item|
64
+ items.each do |item|
63
65
  next if item.nil?
64
66
 
65
67
  unless only_root
@@ -76,7 +78,6 @@ module Avo
76
78
  end
77
79
  end
78
80
 
79
-
80
81
  if item.is_field?
81
82
  fields << item
82
83
  end
@@ -86,7 +87,7 @@ module Avo
86
87
  end
87
88
 
88
89
  def tab_groups
89
- self.items.select do |item|
90
+ items.select do |item|
90
91
  item.instance_of? Avo::TabGroup
91
92
  end
92
93
  end
@@ -3,18 +3,63 @@ module Avo
3
3
  class BaseDashboard
4
4
  extend ActiveSupport::DescendantsTracker
5
5
 
6
- include Avo::Concerns::HasCards
7
-
8
6
  class_attribute :id
9
7
  class_attribute :name
10
8
  class_attribute :description
9
+ class_attribute :items_holder
10
+ class_attribute :grid_cols, default: 3
11
11
  class_attribute :visible, default: true
12
12
  class_attribute :index, default: 0
13
13
 
14
- attr_reader :view
15
- attr_reader :params
16
-
17
14
  class << self
15
+ def card(klass, label: nil, description: nil, cols: nil, rows: nil, refresh_every: nil, options: {})
16
+ self.items_holder ||= []
17
+
18
+ self.items_holder << klass.new(dashboard: self,
19
+ label: label,
20
+ description: description,
21
+ cols: cols,
22
+ rows: rows,
23
+ refresh_every: refresh_every,
24
+ options: options,
25
+ index: index
26
+ )
27
+ self.index += 1
28
+ end
29
+
30
+ def item_at_index(index)
31
+ items.find do |item|
32
+ next if item.index.blank?
33
+
34
+ item.index == index
35
+ end
36
+ end
37
+
38
+ def divider(**args)
39
+ self.items_holder ||= []
40
+
41
+ self.items_holder << BaseDivider.new(**args)
42
+ end
43
+
44
+ def items
45
+ self.items_holder
46
+ end
47
+
48
+ def classes
49
+ case grid_cols
50
+ when 3
51
+ "sm:grid-cols-3"
52
+ when 4
53
+ "sm:grid-cols-4"
54
+ when 5
55
+ "sm:grid-cols-5"
56
+ when 6
57
+ "sm:grid-cols-6"
58
+ else
59
+ "sm:grid-cols-3"
60
+ end
61
+ end
62
+
18
63
  def navigation_label
19
64
  name
20
65
  end
@@ -39,16 +84,6 @@ module Avo
39
84
  !is_visible?
40
85
  end
41
86
  end
42
-
43
- def initialize
44
- @view = :dashboard
45
- end
46
-
47
- def hydrate(params:)
48
- @params = params
49
-
50
- self
51
- end
52
87
  end
53
88
  end
54
89
  end
@@ -5,16 +5,12 @@ module Avo
5
5
  attr_reader :invisible
6
6
  attr_reader :index
7
7
 
8
- include Avo::Fields::FieldExtensions::VisibleInDifferentViews
9
-
10
8
  class_attribute :id
11
9
 
12
- def initialize(label: nil, invisible: false, index: nil, **args)
10
+ def initialize(label: nil, invisible: false, index: nil)
13
11
  @label = label
14
12
  @invisible = invisible
15
13
  @index = index
16
-
17
- initialize_visibility args
18
14
  end
19
15
 
20
16
  def is_divider?
@@ -23,12 +23,11 @@ module Avo
23
23
  end
24
24
 
25
25
  def chartkick_options
26
- card_height = 128
27
- card_heading = 32
26
+ card_height = 144
27
+ card_heading = 40
28
28
 
29
29
  default = {
30
- # figure our the available height for the chart.
31
- # It's not ideal to work with magic numbers, I know.
30
+ # figure our the available height for the chart
32
31
  height: "#{(rows * card_height) - card_heading}px",
33
32
  colors: %w[#0B8AE2 #34C683 #2AB1EE #34C6A8],
34
33
  library: {
@@ -36,7 +35,7 @@ module Avo
36
35
  points: false,
37
36
  animation: true
38
37
  },
39
- id: "#{parent.id}-#{rand(10_000..99_999)}"
38
+ id: "#{dashboard.id}-#{rand(10_000..99_999)}"
40
39
  }
41
40
 
42
41
  no_scale_options = {display: false}
@@ -54,7 +54,7 @@ module Avo
54
54
  class_attribute :item_type, default: :field
55
55
 
56
56
  def initialize(id, **args, &block)
57
- # super(id, **args, &block)
57
+ super(id, **args, &block)
58
58
 
59
59
  @id = id
60
60
  @name = args[:name]
@@ -83,7 +83,11 @@ module Avo
83
83
  @computed = block.present?
84
84
  @computed_value = nil
85
85
 
86
- initialize_visibility args
86
+ # Set the visibility
87
+ show_on args[:show_on] if args[:show_on].present?
88
+ hide_on args[:hide_on] if args[:hide_on].present?
89
+ only_on args[:only_on] if args[:only_on].present?
90
+ except_on args[:except_on] if args[:except_on].present?
87
91
  end
88
92
 
89
93
  def hydrate(model: nil, resource: nil, action: nil, view: nil, panel_name: nil, user: nil)
@@ -108,14 +112,12 @@ module Avo
108
112
  # Secondly we'll try to find a translation key
109
113
  # We'll fallback to humanizing the id
110
114
  def name
111
- default = @id.to_s.humanize(keep_id_suffix: true)
112
-
113
115
  return @name if custom_name?
114
116
 
115
117
  if translation_key && ::Avo::App.translation_enabled
116
- t(translation_key, count: 1, default: default).capitalize
118
+ t(translation_key, count: 1, default: default_name).capitalize
117
119
  else
118
- default
120
+ default_name
119
121
  end
120
122
  end
121
123
 
@@ -133,6 +135,10 @@ module Avo
133
135
  @name.present?
134
136
  end
135
137
 
138
+ def default_name
139
+ @id.to_s.humanize(keep_id_suffix: true)
140
+ end
141
+
136
142
  def placeholder
137
143
  return @placeholder if @placeholder.present?
138
144
 
@@ -154,7 +160,7 @@ module Avo
154
160
  final_value = @model.send(property) if (model_or_class(@model) == "model") && @model.respond_to?(property)
155
161
 
156
162
  # On new views and actions modals we need to prefill the fields
157
- if (@view === :new) || @action.present?
163
+ if @view.in?([:new, :create]) || @action.present?
158
164
  if default.present?
159
165
  final_value = if default.respond_to?(:call)
160
166
  default.call
@@ -5,15 +5,13 @@ module Avo
5
5
  attr_reader :picker_format
6
6
  attr_reader :disable_mobile
7
7
  attr_reader :format
8
- attr_reader :relative
9
8
 
10
9
  def initialize(id, **args, &block)
11
10
  super(id, **args, &block)
12
11
 
13
- add_string_prop args, :first_day_of_week, 0
12
+ add_string_prop args, :first_day_of_week, 1
14
13
  add_string_prop args, :picker_format, "Y-m-d"
15
14
  add_string_prop args, :format, "yyyy-LL-dd"
16
- add_boolean_prop args, :relative
17
15
  add_boolean_prop args, :disable_mobile
18
16
  end
19
17
 
@@ -4,7 +4,7 @@ module Avo
4
4
  module HasIncludeBlank
5
5
  def include_blank
6
6
  if @args[:include_blank] == true
7
- placeholder || ''
7
+ placeholder || ""
8
8
  elsif @args[:include_blank] == false
9
9
  false
10
10
  else
@@ -6,21 +6,12 @@ module Avo
6
6
  attr_accessor :show_on_show
7
7
  attr_accessor :show_on_new
8
8
  attr_accessor :show_on_edit
9
- attr_accessor :show_on_dashboard
10
9
 
11
- def initialize_visibility(args = {})
12
- # def initialize(id = nil, **args, &block)
10
+ def initialize(id = nil, **args, &block)
13
11
  @show_on_index = @show_on_index.nil? ? true : @show_on_index
14
12
  @show_on_show = @show_on_show.nil? ? true : @show_on_show
15
13
  @show_on_new = @show_on_new.nil? ? true : @show_on_new
16
14
  @show_on_edit = @show_on_edit.nil? ? true : @show_on_edit
17
- @show_on_dashboard = @show_on_dashboard.nil? ? true : @show_on_dashboard
18
-
19
- # Set the visibility
20
- show_on args[:show_on] if args[:show_on].present?
21
- hide_on args[:hide_on] if args[:hide_on].present?
22
- only_on args[:only_on] if args[:only_on].present?
23
- except_on args[:except_on] if args[:except_on].present?
24
15
  end
25
16
 
26
17
  # Validates if the field is visible on certain view
@@ -91,7 +82,6 @@ module Avo
91
82
  end
92
83
 
93
84
  def show_on_all
94
- @show_on_dashboard = true
95
85
  @show_on_index = true
96
86
  @show_on_show = true
97
87
  @show_on_edit = true
@@ -99,7 +89,6 @@ module Avo
99
89
  end
100
90
 
101
91
  def hide_on_all
102
- @show_on_dashboard = false
103
92
  @show_on_index = false
104
93
  @show_on_show = false
105
94
  @show_on_edit = false
@@ -6,6 +6,7 @@ module Avo
6
6
  attr_accessor :attach_scope
7
7
  attr_accessor :description
8
8
  attr_accessor :discreet_pagination
9
+ attr_accessor :hide_search_input
9
10
 
10
11
  def initialize(id, **args, &block)
11
12
  super(id, **args, &block)
@@ -14,7 +15,9 @@ module Avo
14
15
  @attach_scope = args[:attach_scope].present? ? args[:attach_scope] : nil
15
16
  @display = args[:display].present? ? args[:display] : :show
16
17
  @searchable = args[:searchable] == true
18
+ @hide_search_input = args[:hide_search_input] || false
17
19
  @description = args[:description]
20
+ @use_resource = args[:use_resource] || nil
18
21
  @discreet_pagination = args[:discreet_pagination] || false
19
22
  end
20
23
 
@@ -22,12 +25,16 @@ module Avo
22
25
  @searchable && ::Avo::App.license.has_with_trial(:searchable_associations)
23
26
  end
24
27
 
28
+ def use_resource
29
+ App.get_resource @use_resource
30
+ end
31
+
25
32
  def resource
26
33
  Avo::App.get_resource_by_model_name @model.class
27
34
  end
28
35
 
29
36
  def turbo_frame
30
- "#{self.class.name.demodulize.to_s.underscore}_#{display}_#{id}"
37
+ "#{self.class.name.demodulize.to_s.underscore}_#{display}_#{frame_id}"
31
38
  end
32
39
 
33
40
  def frame_url
@@ -91,6 +98,16 @@ module Avo
91
98
  true
92
99
  end
93
100
  end
101
+
102
+ def default_name
103
+ use_resource&.name || super
104
+ end
105
+
106
+ private
107
+
108
+ def frame_id
109
+ use_resource.present? ? use_resource.route_key.to_sym : @id
110
+ end
94
111
  end
95
112
  end
96
113
  end