avo 1.22.3 → 1.22.4

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: '0638fa0ab76323be01a732489a1ba96def10bde4897fd4231c7a1f4c41ece424'
4
- data.tar.gz: 394c86583f0219b3f9c5d2cf1017db4348105ae8bc26cfbac1f5ca56e9ace62a
3
+ metadata.gz: 472b0c4d748a2cc35c595170f3abd2c83e8ef62ea2f41ec15ba2fac1b4fba4eb
4
+ data.tar.gz: 28de6b788064fb476e80234f058e192dae5bc1866bb544c7db197a53adf801dd
5
5
  SHA512:
6
- metadata.gz: 292f817a4cc4498a4db69268def16be6ac719e5eee1178deb8cad7a26181aacb73ec5cbd9145fea1a0dc627a52f4bc7b9a3e61e5e6099946148239227b313e4d
7
- data.tar.gz: bad4042ec546cb0c56e209a8c42b59a74a655a5bd8278c7f98baf5025f81d3457b566316fc4f7247d51e68d4add071d6207996e922449106ce3627357e1a2545
6
+ metadata.gz: a89890b81a8d26b13f7ace5e3854b21b503bf7ae3e61c08e4ba0a52257b4644cb29f3c8a03789726aa9e4479b2a0c5f334163536198f8685f9df516539191467
7
+ data.tar.gz: 14402ad63c9918b69789dd0161124a06f74829f400138ff8cf972a36df7ac677b9d62319355b26f6a8da9db38c686d28728431a4d6c81ab3202e7df3c4779df3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (1.22.3)
4
+ avo (1.22.4)
5
5
  active_link_to
6
6
  addressable
7
7
  breadcrumbs_on_rails
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::NavigationLinkComponent < ViewComponent::Base
4
- def initialize(label: nil, path: nil, active: :inclusive, size: :md, target: "_self")
4
+ def initialize(label: nil, path: nil, active: :inclusive, size: :md, target: nil)
5
5
  @label = label
6
6
  @path = path
7
7
  @active = active
@@ -13,6 +13,7 @@ module Avo
13
13
  protect_from_forgery with: :exception
14
14
  before_action :init_app
15
15
  before_action :check_avo_license
16
+ before_action :set_locale
16
17
  before_action :set_authorization
17
18
  before_action :_authenticate!
18
19
  before_action :set_container_classes
@@ -245,5 +246,11 @@ module Avo
245
246
  def model_param_key
246
247
  @resource.form_scope
247
248
  end
249
+
250
+ def set_locale
251
+ I18n.locale = params[:locale] || I18n.default_locale
252
+
253
+ I18n.default_locale = I18n.locale
254
+ end
248
255
  end
249
256
  end
@@ -84,7 +84,6 @@ module Avo
84
84
  def new
85
85
  @model = @resource.model_class.new
86
86
  @resource = @resource.hydrate(model: @model, view: :new, user: _current_user)
87
- # abort @model.course.inspect
88
87
 
89
88
  @page_title = @resource.default_panel_name
90
89
  add_breadcrumb resource_name.humanize, resources_path(resource: @resource)
@@ -8,4 +8,13 @@ export default class extends Controller {
8
8
 
9
9
  document.dispatchEvent(new Event('actions-modal:close'))
10
10
  }
11
+
12
+ delayedClose() {
13
+ const vm = this
14
+
15
+ setTimeout(() => {
16
+ vm.modalTarget.remove()
17
+ document.dispatchEvent(new Event('actions-modal:close'))
18
+ }, 500)
19
+ }
11
20
  }
@@ -177,11 +177,16 @@ export default class extends Controller {
177
177
  openOnFocus: true,
178
178
  detachedMediaQuery: '',
179
179
  getSources: ({ query }) => {
180
+ document.body.classList.add('search-loading')
180
181
  const endpoint = that.searchUrl(query)
181
182
 
182
183
  return that
183
184
  .debouncedFetch(endpoint)
184
- .then((response) => response.json())
185
+ .then((response) => {
186
+ document.body.classList.remove('search-loading')
187
+
188
+ return response.json()
189
+ })
185
190
  .then((data) => Object.keys(data).map((resourceName) => that.addSource(resourceName, data[resourceName])))
186
191
  },
187
192
  })
@@ -7,7 +7,11 @@
7
7
  data-resource-id="<%= params[:id] %>"
8
8
  class="hidden text-slate-800"
9
9
  >
10
- <%= form_with model: @model, scope: 'fields', url: "#{@resource.records_path}/actions/#{@action.param_id}", data: {'turbo-frame': '_top', 'action-target': 'form'} do |form| %>
10
+ <%= form_with model: @model,
11
+ scope: 'fields',
12
+ url: "#{@resource.records_path}/actions/#{@action.param_id}",
13
+ data: @action.class.form_data_attributes do |form|
14
+ %>
11
15
  <%= render Avo::ModalComponent.new do |c| %>
12
16
  <% c.heading do %>
13
17
  <%= @action.action_name %>
@@ -26,8 +30,8 @@
26
30
  <% end %>
27
31
 
28
32
  <% c.controls do %>
29
- <%= a_button @action.cancel_button_label, 'data-action': 'click->modal#close', size: :sm %>
30
- <%= a_button @action.confirm_button_label, type: :submit, color: :green, size: :sm %>
33
+ <%= a_button @action.cancel_button_label, data: { action: 'click->modal#close' }, size: :sm %>
34
+ <%= a_button @action.confirm_button_label, type: :submit, color: :green, size: :sm, data: @action.class.submit_button_data_attributes %>
31
35
  <% end %>
32
36
  <% end %>
33
37
  <% end %>
@@ -15,6 +15,7 @@ module Avo
15
15
  class_attribute :fields
16
16
  class_attribute :standalone, default: false
17
17
  class_attribute :visible
18
+ class_attribute :may_download_file, default: false
18
19
 
19
20
  attr_accessor :response
20
21
  attr_accessor :model
@@ -22,6 +23,26 @@ module Avo
22
23
  attr_accessor :user
23
24
  attr_accessor :fields_loader
24
25
 
26
+ class << self
27
+ def form_data_attributes
28
+ # We can't respond with a file download from Turbo se we disable it on the form
29
+ if may_download_file
30
+ { 'turbo': false }
31
+ else
32
+ { 'turbo-frame': '_top', 'action-target': 'form' }
33
+ end
34
+ end
35
+
36
+ # We can't respond with a file download from Turbo se we disable close the modal manually after a while (it's a hack, we know)
37
+ def submit_button_data_attributes
38
+ if may_download_file
39
+ { action: 'click->modal#delayedClose' }
40
+ else
41
+ {}
42
+ end
43
+ end
44
+ end
45
+
25
46
  def action_name
26
47
  return name if name.present?
27
48
 
@@ -23,6 +23,12 @@ module Avo
23
23
 
24
24
  begin
25
25
  perform_and_cache_request
26
+ rescue Errno::EHOSTUNREACH => exception
27
+ cache_and_return_error "HTTP host not reachable error.", exception.message
28
+ rescue Errno::ECONNRESET => exception
29
+ cache_and_return_error "HTTP connection reset error.", exception.message
30
+ rescue Errno::ECONNREFUSED => exception
31
+ cache_and_return_error "HTTP connection refused error.", exception.message
26
32
  rescue HTTParty::Error => exception
27
33
  cache_and_return_error "HTTP client error.", exception.message
28
34
  rescue Net::OpenTimeout => exception
@@ -71,7 +77,55 @@ module Avo
71
77
  environment: Rails.env,
72
78
  ip: current_request.ip,
73
79
  host: current_request.host,
74
- port: current_request.port
80
+ port: current_request.port,
81
+ app_name: app_name
82
+ }
83
+ end
84
+
85
+ def app_name
86
+ Rails.application.class.to_s.split("::").first
87
+ rescue
88
+ nil
89
+ end
90
+
91
+ def avo_metadata
92
+ resources = App.resources
93
+ field_definitions = resources.map(&:get_field_definitions)
94
+ fields_count = field_definitions.map(&:count).sum
95
+ fields_per_resource = sprintf("%0.01f", fields_count / (resources.count + 0.0))
96
+
97
+ field_types = {}
98
+ custom_fields_count = 0
99
+ field_definitions.each do |fields|
100
+ fields.each do |field|
101
+ field_types[field.type] ||= 0
102
+ field_types[field.type] += 1
103
+
104
+ custom_fields_count += 1 if field.custom?
105
+ end
106
+ end
107
+
108
+ {
109
+ resources_count: resources.count,
110
+ fields_count: fields_count,
111
+ fields_per_resource: fields_per_resource,
112
+ custom_fields_count: custom_fields_count,
113
+ field_types: field_types,
114
+ **other_metadata(:actions),
115
+ **other_metadata(:filters),
116
+ }
117
+ end
118
+
119
+ def other_metadata(type = :actions)
120
+ resources = App.resources
121
+
122
+ types = resources.map(&:"get_#{type}")
123
+ type_count = types.flatten.uniq.count
124
+ type_per_resource = sprintf("%0.01f", types.map(&:count).sum / (resources.count + 0.0))
125
+
126
+ {
127
+ "#{type}_count": type_count,
128
+ "#{type}_per_resource": type_per_resource,
75
129
  }
76
130
  end
77
131
 
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "1.22.3"
2
+ VERSION = "1.22.4"
3
3
  end
@@ -83839,6 +83839,13 @@
83839
83839
  this.modalTarget.remove();
83840
83840
  document.dispatchEvent(new Event("actions-modal:close"));
83841
83841
  }
83842
+ delayedClose() {
83843
+ const vm = this;
83844
+ setTimeout(() => {
83845
+ vm.modalTarget.remove();
83846
+ document.dispatchEvent(new Event("actions-modal:close"));
83847
+ }, 500);
83848
+ }
83842
83849
  };
83843
83850
  __publicField(modal_controller_default, "targets", ["modal"]);
83844
83851
 
@@ -87614,8 +87621,12 @@
87614
87621
  openOnFocus: true,
87615
87622
  detachedMediaQuery: "",
87616
87623
  getSources: ({ query }) => {
87624
+ document.body.classList.add("search-loading");
87617
87625
  const endpoint = that.searchUrl(query);
87618
- return that.debouncedFetch(endpoint).then((response) => response.json()).then((data) => Object.keys(data).map((resourceName) => that.addSource(resourceName, data[resourceName])));
87626
+ return that.debouncedFetch(endpoint).then((response) => {
87627
+ document.body.classList.remove("search-loading");
87628
+ return response.json();
87629
+ }).then((data) => Object.keys(data).map((resourceName) => that.addSource(resourceName, data[resourceName])));
87619
87630
  }
87620
87631
  });
87621
87632
  if (this.buttonTarget.dataset.shouldBeDisabled !== "true") {