avo 3.0.0.pre9 → 3.0.0.pre10

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c753dc99c778487821cb4c4a73f67fb2408ea2f5e0becb69da6efa2bc66eaece
4
- data.tar.gz: 594e206c1029f10ce74e5815bac2cbc9a0fd119cbac25536adf85f672d856e43
3
+ metadata.gz: 883d169ce316d8345f84fd5a0a7f7faf181c0413a6bc88c85c6e0c1c96327324
4
+ data.tar.gz: 3278c58cc427a66c926bccd3c64a80048e60ca21c1620059884628cc2ed5813e
5
5
  SHA512:
6
- metadata.gz: 84872aebb1988fa4e25323031c4ac6f9be0ced56db0913a2073026946c85888e0824d075f8c46e02d9230037480ed4e8057c565f525a18ce5a5df2975302df39
7
- data.tar.gz: 2e059cfce06864f424a132347f2f957d6e138ae721ca9a73a177cf2af371598b9eec00f1ec9ce0e92ded29f79ba7efbbf3382388b8a092a4d2f0e072ec95d7d9
6
+ metadata.gz: c158e071e12fb5171dcd1f139baba1fe17fd223d31a9d6c12cd40b02cca3222c856804ab25b9154609a441131a400bb57845c0993245ac6e307883f929f31989
7
+ data.tar.gz: 7694320d99342f71280894eb0b448a5e22c69cdfe12325ab85c4dcf4acf49ba17f245bcc035a98447fe15a2599975eb81ef3f0e7fd90a286d33bb31149a9b5aa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.0.0.pre9)
4
+ avo (3.0.0.pre10)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -56,13 +56,15 @@ class Avo::ActionsComponent < ViewComponent::Base
56
56
 
57
57
  def single_record_path(id)
58
58
  Avo::Services::URIService.parse(@resource.record_path)
59
- .append_paths("actions", id)
59
+ .append_paths("actions")
60
+ .append_query(action_id: id)
60
61
  .to_s
61
62
  end
62
63
 
63
64
  def many_records_path(id)
64
65
  Avo::Services::URIService.parse(@resource.records_path)
65
- .append_paths("actions", id)
66
+ .append_paths("actions")
67
+ .append_query(action_id: id)
66
68
  .to_s
67
69
  end
68
70
  end
@@ -4,7 +4,7 @@
4
4
  <%= js_map(resource_location_markers, **resource_mapkick_options) %>
5
5
  </div>
6
6
  <% if render_table? %>
7
- <div class="overflow-auto<%= table_component_order_class %>">
7
+ <div class="overflow-auto <%= table_component_order_class %>">
8
8
  <%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, pagy: @pagy, query: @query)) %>
9
9
  </div>
10
10
  <% end %>
@@ -245,7 +245,6 @@ class Avo::ResourceComponent < Avo::BaseComponent
245
245
  a_link create_path,
246
246
  color: :primary,
247
247
  style: :primary,
248
- target: "_top",
249
248
  icon: "heroicons/outline/plus",
250
249
  data: {
251
250
  target: :create
@@ -269,6 +268,43 @@ class Avo::ResourceComponent < Avo::BaseComponent
269
268
  end
270
269
  end
271
270
 
271
+ def render_link_to(link)
272
+ a_link link.path,
273
+ color: link.color,
274
+ style: link.style,
275
+ icon: link.icon,
276
+ icon_class: link.icon_class,
277
+ title: link.title, target: link.target,
278
+ class: link.classes,
279
+ size: link.size,
280
+ data: {
281
+ **link.data,
282
+ tippy: link.title ? :tooltip : nil,
283
+ } do
284
+ link.label
285
+ end
286
+ end
287
+
288
+ def render_action(action)
289
+ return unless can_see_the_actions_button?
290
+
291
+ a_link action.path,
292
+ color: action.color,
293
+ style: action.style,
294
+ icon: action.icon,
295
+ icon_class: action.icon_class,
296
+ title: action.title,
297
+ size: action.size,
298
+ data: {
299
+ turbo_frame: "actions_show",
300
+ action_name: action.action.action_name,
301
+ tippy: action.title ? :tooltip : nil,
302
+ action: "click->actions-picker#visitAction",
303
+ } do
304
+ action.label
305
+ end
306
+ end
307
+
272
308
  def is_a_related_resource?
273
309
  @reflection.present? && @resource.record.present?
274
310
  end
@@ -14,8 +14,8 @@
14
14
  <% c.with_body do %>
15
15
  <div class="flex flex-col">
16
16
  <%= render scopes_list if can_render_scopes? %>
17
- <div class="flex flex-col py-4 gap-4">
18
- <div class="flex flex-col xs:flex-row xs:justify-between space-y-2 xs:space-y-0 <%= 'hidden' unless header_visible? %>">
17
+ <div class="flex flex-col">
18
+ <div class="flex flex-col xs:flex-row xs:justify-between space-y-2 xs:space-y-0 py-4 <%= 'hidden' unless header_visible? %>">
19
19
  <div class="flex items-center px-4 w-64">
20
20
  <% if show_search_input %>
21
21
  <%= render partial: 'avo/partials/resource_search', locals: {resource: @resource.route_key, via_reflection: via_reflection} %>
@@ -34,7 +34,7 @@
34
34
  </div>
35
35
  </div>
36
36
  <% if Avo.avo_filters_installed? && resource.has_filters? %>
37
- <%= render AvoFilters::FiltersComponent.new resource: resource %>
37
+ <%= render AvoFilters::FiltersComponent.new resource: resource, turbo_frame: turbo_frame %>
38
38
  <% end %>
39
39
  </div>
40
40
  </div>
@@ -61,11 +61,8 @@ module Avo
61
61
  end
62
62
 
63
63
  def action_class
64
- klass_name = params[:action_id].gsub("avo_actions_", "").camelize
65
- klass_name = "Avo::Actions::#{klass_name}"
66
-
67
64
  Avo::BaseAction.descendants.find do |action|
68
- action.to_s == klass_name
65
+ action.to_s == params[:action_id]
69
66
  end
70
67
  end
71
68
 
@@ -115,10 +115,24 @@ module Avo
115
115
 
116
116
  def fill_record
117
117
  # We have to skip filling the the record if this is an attach action
118
- is_attach_action = params[model_param_key].blank? && params[:related_name].present? && params[:fields].present?
118
+ return if is_attach_action?
119
119
 
120
- unless is_attach_action
121
- @record = @resource.fill_record(@record_to_fill, cast_nullable(model_params), extra_params: extra_params)
120
+ @record = @resource.fill_record(@record_to_fill, cast_nullable(model_params), extra_params: extra_params)
121
+ assign_default_value_to_disabled_fields if @view == :create
122
+ end
123
+
124
+ def is_attach_action?
125
+ params[model_param_key].blank? && params[:related_name].present? && params[:fields].present?
126
+ end
127
+
128
+ def assign_default_value_to_disabled_fields
129
+ @resource.get_field_definitions.select do |field|
130
+ field.is_disabled? && field.visible? && !field.computed
131
+ end.each do |field|
132
+ # Get the default value from the field default definition
133
+ # If there is no default value specified on the resource, get the value from the record (DB, Callbacks, etc.)
134
+ default_value = field.default || @record.send(field.id)
135
+ field.fill_field @record, field.id, default_value, params
122
136
  end
123
137
  end
124
138
 
@@ -29,11 +29,6 @@ module Avo
29
29
  @query = @resource.class.query_scope
30
30
  end
31
31
 
32
- # Remove default_scope for index view if no parent_resource present
33
- if @resource.unscoped_queries_on_index && @parent_resource.blank?
34
- @query = @query.unscoped
35
- end
36
-
37
32
  # Eager load the associations
38
33
  if @resource.includes.present?
39
34
  @query = @query.includes(*@resource.includes)
@@ -9,7 +9,7 @@
9
9
  >
10
10
  <%= form_with model: @record,
11
11
  scope: 'fields',
12
- url: "#{@resource.records_path}/actions/#{@action.param_id}",
12
+ url: "#{@resource.records_path}/actions",
13
13
  local: true,
14
14
  data: @action.class.form_data_attributes do |form|
15
15
  %>
@@ -20,6 +20,7 @@
20
20
  <div class="flex-1 flex">
21
21
  <%= @action.get_message %>
22
22
  </div>
23
+ <%= hidden_field_tag :action_id, @action.param_id %>
23
24
  <%= form.hidden_field :avo_resource_ids, value: params[:id] || params[:resource_ids], 'data-action-target': 'resourceIds' %>
24
25
  <%= form.hidden_field :avo_selected_query, 'data-action-target': 'selectedAllQuery' %>
25
26
  <% if @action.get_fields.present? %>
@@ -74,8 +74,9 @@
74
74
  <div class="flex flex-col flex-1">
75
75
  <div>
76
76
  <ul>
77
+ <li>Avo <%= Avo::VERSION %></li>
77
78
  <% Avo.plugin_manager.plugins.each do |plugin| %>
78
- <li><%= plugin.klass.to_s.split("::").first %></li>
79
+ <li><%= plugin.klass.to_s.split("::").first %> <%= plugin.klass.version %></li>
79
80
  <% end %>
80
81
  </ul>
81
82
  </div>
data/config/routes.rb CHANGED
@@ -23,8 +23,8 @@ Avo::Engine.routes.draw do
23
23
  delete "/:resource_name/:id/active_storage_attachments/:attachment_name/:attachment_id", to: "attachments#destroy"
24
24
 
25
25
  # Actions
26
- get "/:resource_name(/:id)/actions/:action_id", to: "actions#show"
27
- post "/:resource_name(/:id)/actions/:action_id", to: "actions#handle"
26
+ get "/:resource_name(/:id)/actions/(:action_id)", to: "actions#show"
27
+ post "/:resource_name(/:id)/actions/(:action_id)", to: "actions#handle"
28
28
 
29
29
  # Generate resource routes as below:
30
30
  # resources :posts
data/lib/avo/app.rb CHANGED
@@ -29,6 +29,7 @@ module Avo
29
29
  init_logger
30
30
  init_fields
31
31
  self.cache_store = get_cache_store
32
+ ::Avo.plugin_manager.boot_plugins
32
33
  end
33
34
 
34
35
  def get_cache_store
@@ -149,7 +149,7 @@ module Avo
149
149
  end
150
150
 
151
151
  def param_id
152
- self.class.to_s.demodulize.underscore.tr "/", "_"
152
+ self.class.to_s
153
153
  end
154
154
 
155
155
  def succeed(text)
@@ -52,8 +52,9 @@ module Avo
52
52
  class_attribute :filters_loader
53
53
  class_attribute :grid_loader
54
54
  class_attribute :visible_on_sidebar, default: true
55
- class_attribute :unscoped_queries_on_index, default: false
56
- class_attribute :index_query
55
+ class_attribute :index_query, default: -> {
56
+ query
57
+ }
57
58
  class_attribute :find_record_method, default: -> {
58
59
  query.find id
59
60
  }
@@ -110,13 +111,10 @@ module Avo
110
111
 
111
112
  # This resolves the scope when doing "where" queries (not find queries)
112
113
  def query_scope
113
- final_scope = if index_query.present?
114
- Avo::ExecutionContext.new(target: index_query, query: model_class).handle
115
- else
116
- model_class
117
- end
118
-
119
- authorization.apply_policy final_scope
114
+ authorization.apply_policy Avo::ExecutionContext.new(
115
+ target: index_query,
116
+ query: model_class
117
+ ).handle
120
118
  end
121
119
 
122
120
  # This resolves the scope when finding records (not "where" queries)
@@ -6,7 +6,7 @@ module Avo
6
6
  class_methods do
7
7
  def deprecated_dsl_api(name = nil)
8
8
  message = "This API was deprecated. Please use the `#{name}` method inside the `fields` method."
9
- raise DeprecatedAPI.new message
9
+ raise DeprecatedAPIError.new message
10
10
  end
11
11
 
12
12
  # DSL methods
data/lib/avo/engine.rb CHANGED
@@ -24,7 +24,6 @@ module Avo
24
24
 
25
25
  # Boot Avo
26
26
  ::Avo::App.boot
27
- ::Avo.plugin_manager.boot_plugins
28
27
 
29
28
  # After deploy we want to make sure the license response is being cleared.
30
29
  # We need a fresh license response.
data/lib/avo/plugin.rb CHANGED
@@ -2,5 +2,15 @@ module Avo
2
2
  class Plugin
3
3
  def initialize(*, **, &block)
4
4
  end
5
+
6
+ class << self
7
+ def version
8
+ "#{namespace}::VERSION".safe_constantize
9
+ end
10
+
11
+ def namespace
12
+ to_s.split("::").first
13
+ end
14
+ end
5
15
  end
6
16
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.0.0.pre9" unless const_defined?(:VERSION)
2
+ VERSION = "3.0.0.pre10" unless const_defined?(:VERSION)
3
3
  end
data/lib/avo.rb CHANGED
@@ -61,7 +61,7 @@ module Avo
61
61
 
62
62
  class MissingGemError < StandardError; end
63
63
 
64
- class DeprecatedAPI < StandardError; end
64
+ class DeprecatedAPIError < StandardError; end
65
65
 
66
66
  class << self
67
67
  def avo_filters_installed?
@@ -14,6 +14,17 @@ module Generators
14
14
 
15
15
  template "initializer/avo.tt", "config/initializers/avo.rb"
16
16
  directory File.join(__dir__, "templates", "locales"), "config/locales"
17
+ create_resources
18
+ end
19
+
20
+ def create_resources
21
+ if defined?(User).present?
22
+ Rails::Generators.invoke("avo:resource", ["user", "-q"], {destination_root: Rails.root })
23
+ end
24
+
25
+ if defined?(Account).present?
26
+ Rails::Generators.invoke("avo:resource", ["account", "-q"], {destination_root: Rails.root })
27
+ end
17
28
  end
18
29
  end
19
30
  end
@@ -3,6 +3,11 @@
3
3
  # # Task goes here
4
4
  # end
5
5
 
6
+ desc "Runs the update command for all Avo gems."
7
+ task "avo:update" do
8
+ system "bundle update avo avo_pro avo_advanced avo_dashboards avo_filters avo_menu avo_upgrade"
9
+ end
10
+
6
11
  desc "Installs Avo assets and bundles them for when you want to use the GitHub repo in your app"
7
12
  task "avo:build-assets" do
8
13
  spec = get_gem_spec "avo"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre9
4
+ version: 3.0.0.pre10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-05-12 00:00:00.000000000 Z
12
+ date: 2023-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord