avo 1.4.2 → 1.5.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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +63 -54
- data/README.md +5 -4
- data/app/components/avo/views/resource_index_component.html.erb +3 -3
- data/app/controllers/avo/application_controller.rb +14 -7
- data/app/controllers/avo/relations_controller.rb +1 -1
- data/app/controllers/avo/search_controller.rb +50 -35
- data/app/helpers/avo/application_helper.rb +4 -6
- data/app/packs/entrypoints/application.css +2 -1
- data/app/packs/entrypoints/application.js +3 -0
- data/app/packs/js/controllers/search_controller.js +120 -0
- data/app/packs/js/helpers/debounce_promise.js +13 -0
- data/app/packs/stylesheets/search.css +79 -0
- data/app/views/avo/base/index.html.erb +2 -2
- data/app/views/avo/base/show.html.erb +2 -2
- data/app/views/avo/partials/_global_search.html.erb +17 -0
- data/app/views/avo/partials/_profile_dropdown.html.erb +12 -8
- data/app/views/avo/partials/_resource_search.html.erb +10 -0
- data/app/views/avo/partials/_turbo_frame_wrap.html.erb +3 -0
- data/app/views/layouts/avo/application.html.erb +2 -4
- data/avo.gemspec +1 -0
- data/config/routes.rb +2 -6
- data/lib/avo/app.rb +3 -1
- data/lib/avo/base_resource.rb +83 -7
- data/lib/avo/configuration.rb +2 -0
- data/lib/avo/fields/base_field.rb +6 -0
- data/lib/avo/fields/external_image_field.rb +1 -0
- data/lib/avo/fields/file_field.rb +4 -0
- data/lib/avo/licensing/license.rb +10 -0
- data/lib/avo/licensing/license_manager.rb +0 -2
- data/lib/avo/licensing/pro_license.rb +3 -1
- data/lib/avo/services/authorization_service.rb +1 -1
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/templates/initializer/avo.tt +1 -0
- data/lib/generators/avo/templates/resource/resource.tt +3 -0
- data/lib/generators/avo/templates/tool/sidebar_item.tt +1 -1
- data/public/avo-packs/css/{application-68691c73.css → application-d69fe930.css} +183 -6
- data/public/avo-packs/css/application-d69fe930.css.br +0 -0
- data/public/avo-packs/css/application-d69fe930.css.gz +0 -0
- data/public/avo-packs/css/application-d69fe930.css.map +1 -0
- data/public/avo-packs/css/application-d69fe930.css.map.br +0 -0
- data/public/avo-packs/css/application-d69fe930.css.map.gz +0 -0
- data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js +26 -0
- data/public/avo-packs/js/{application-6a0b9e58526ae6bef242.js.LICENSE.txt → application-7b3d507875f4bc1f6677.js.LICENSE.txt} +0 -0
- data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.br +0 -0
- data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.gz +0 -0
- data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map +1 -0
- data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map.br +0 -0
- data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map.gz +0 -0
- data/public/avo-packs/manifest.json +15 -15
- metadata +35 -15
- data/public/avo-packs/css/application-68691c73.css.br +0 -0
- data/public/avo-packs/css/application-68691c73.css.gz +0 -0
- data/public/avo-packs/css/application-68691c73.css.map +0 -1
- data/public/avo-packs/css/application-68691c73.css.map.br +0 -0
- data/public/avo-packs/css/application-68691c73.css.map.gz +0 -0
- data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js +0 -26
- data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.br +0 -0
- data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.gz +0 -0
- data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.map +0 -1
- data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.map.br +0 -0
- data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.map.gz +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c18a2259ce520af87a947e167a6410e9accb3190e323ecf7c5403f8f65bdec5
|
4
|
+
data.tar.gz: 0d04edf92b4bc3f59b3be0281f61ecba66a04a897e6528ae03276df034c26c94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ddda49d846aa932c91acadfd88a917238efdbcd5b695ca8cafe25267ede23c4c52bf4758ba262a5ee45acfd83a243f77d3b32123c5113accb13b470867ae877
|
7
|
+
data.tar.gz: 2d8885cded2d11d46197248baf1fb2bb4aa5bbe349d129e810d24a8f58841db0e9a94d554f17f4cbd28fe08f4933fb5e0a9316ce12fe82259dfd2b6536a663ba
|
data/Gemfile
CHANGED
@@ -100,6 +100,7 @@ group :test do
|
|
100
100
|
gem "simplecov-cobertura"
|
101
101
|
gem "webmock"
|
102
102
|
gem "spring-commands-rspec"
|
103
|
+
gem "launchy", require: false
|
103
104
|
|
104
105
|
gem "test-prof"
|
105
106
|
end
|
@@ -125,3 +126,5 @@ gem 'meta-tags'
|
|
125
126
|
gem 'breadcrumbs_on_rails'
|
126
127
|
|
127
128
|
gem 'manifester'
|
129
|
+
|
130
|
+
gem 'ransack'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
avo (1.
|
4
|
+
avo (1.5.0)
|
5
5
|
active_link_to
|
6
6
|
addressable
|
7
7
|
breadcrumbs_on_rails
|
@@ -14,44 +14,45 @@ PATH
|
|
14
14
|
pagy
|
15
15
|
pundit
|
16
16
|
rails (>= 6.0)
|
17
|
+
ransack
|
17
18
|
view_component
|
18
19
|
zeitwerk
|
19
20
|
|
20
21
|
GEM
|
21
22
|
remote: https://rubygems.org/
|
22
23
|
specs:
|
23
|
-
actioncable (6.0.3.
|
24
|
-
actionpack (= 6.0.3.
|
24
|
+
actioncable (6.0.3.7)
|
25
|
+
actionpack (= 6.0.3.7)
|
25
26
|
nio4r (~> 2.0)
|
26
27
|
websocket-driver (>= 0.6.1)
|
27
|
-
actionmailbox (6.0.3.
|
28
|
-
actionpack (= 6.0.3.
|
29
|
-
activejob (= 6.0.3.
|
30
|
-
activerecord (= 6.0.3.
|
31
|
-
activestorage (= 6.0.3.
|
32
|
-
activesupport (= 6.0.3.
|
28
|
+
actionmailbox (6.0.3.7)
|
29
|
+
actionpack (= 6.0.3.7)
|
30
|
+
activejob (= 6.0.3.7)
|
31
|
+
activerecord (= 6.0.3.7)
|
32
|
+
activestorage (= 6.0.3.7)
|
33
|
+
activesupport (= 6.0.3.7)
|
33
34
|
mail (>= 2.7.1)
|
34
|
-
actionmailer (6.0.3.
|
35
|
-
actionpack (= 6.0.3.
|
36
|
-
actionview (= 6.0.3.
|
37
|
-
activejob (= 6.0.3.
|
35
|
+
actionmailer (6.0.3.7)
|
36
|
+
actionpack (= 6.0.3.7)
|
37
|
+
actionview (= 6.0.3.7)
|
38
|
+
activejob (= 6.0.3.7)
|
38
39
|
mail (~> 2.5, >= 2.5.4)
|
39
40
|
rails-dom-testing (~> 2.0)
|
40
|
-
actionpack (6.0.3.
|
41
|
-
actionview (= 6.0.3.
|
42
|
-
activesupport (= 6.0.3.
|
41
|
+
actionpack (6.0.3.7)
|
42
|
+
actionview (= 6.0.3.7)
|
43
|
+
activesupport (= 6.0.3.7)
|
43
44
|
rack (~> 2.0, >= 2.0.8)
|
44
45
|
rack-test (>= 0.6.3)
|
45
46
|
rails-dom-testing (~> 2.0)
|
46
47
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
47
|
-
actiontext (6.0.3.
|
48
|
-
actionpack (= 6.0.3.
|
49
|
-
activerecord (= 6.0.3.
|
50
|
-
activestorage (= 6.0.3.
|
51
|
-
activesupport (= 6.0.3.
|
48
|
+
actiontext (6.0.3.7)
|
49
|
+
actionpack (= 6.0.3.7)
|
50
|
+
activerecord (= 6.0.3.7)
|
51
|
+
activestorage (= 6.0.3.7)
|
52
|
+
activesupport (= 6.0.3.7)
|
52
53
|
nokogiri (>= 1.8.5)
|
53
|
-
actionview (6.0.3.
|
54
|
-
activesupport (= 6.0.3.
|
54
|
+
actionview (6.0.3.7)
|
55
|
+
activesupport (= 6.0.3.7)
|
55
56
|
builder (~> 3.1)
|
56
57
|
erubi (~> 1.4)
|
57
58
|
rails-dom-testing (~> 2.0)
|
@@ -59,20 +60,20 @@ GEM
|
|
59
60
|
active_link_to (1.0.5)
|
60
61
|
actionpack
|
61
62
|
addressable
|
62
|
-
activejob (6.0.3.
|
63
|
-
activesupport (= 6.0.3.
|
63
|
+
activejob (6.0.3.7)
|
64
|
+
activesupport (= 6.0.3.7)
|
64
65
|
globalid (>= 0.3.6)
|
65
|
-
activemodel (6.0.3.
|
66
|
-
activesupport (= 6.0.3.
|
67
|
-
activerecord (6.0.3.
|
68
|
-
activemodel (= 6.0.3.
|
69
|
-
activesupport (= 6.0.3.
|
70
|
-
activestorage (6.0.3.
|
71
|
-
actionpack (= 6.0.3.
|
72
|
-
activejob (= 6.0.3.
|
73
|
-
activerecord (= 6.0.3.
|
66
|
+
activemodel (6.0.3.7)
|
67
|
+
activesupport (= 6.0.3.7)
|
68
|
+
activerecord (6.0.3.7)
|
69
|
+
activemodel (= 6.0.3.7)
|
70
|
+
activesupport (= 6.0.3.7)
|
71
|
+
activestorage (6.0.3.7)
|
72
|
+
actionpack (= 6.0.3.7)
|
73
|
+
activejob (= 6.0.3.7)
|
74
|
+
activerecord (= 6.0.3.7)
|
74
75
|
marcel (~> 1.0.0)
|
75
|
-
activesupport (6.0.3.
|
76
|
+
activesupport (6.0.3.7)
|
76
77
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
77
78
|
i18n (>= 0.7, < 2)
|
78
79
|
minitest (~> 5.1)
|
@@ -156,6 +157,8 @@ GEM
|
|
156
157
|
i18n
|
157
158
|
jbuilder (2.10.1)
|
158
159
|
activesupport (>= 5.0.0)
|
160
|
+
launchy (2.5.0)
|
161
|
+
addressable (~> 2.7)
|
159
162
|
listen (3.5.1)
|
160
163
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
161
164
|
rb-inotify (~> 0.9, >= 0.9.10)
|
@@ -176,7 +179,7 @@ GEM
|
|
176
179
|
mime-types-data (3.2021.0225)
|
177
180
|
mini_magick (4.11.0)
|
178
181
|
mini_mime (1.1.0)
|
179
|
-
mini_portile2 (2.5.
|
182
|
+
mini_portile2 (2.5.1)
|
180
183
|
minitest (5.14.4)
|
181
184
|
msgpack (1.4.2)
|
182
185
|
multi_xml (0.6.0)
|
@@ -203,20 +206,20 @@ GEM
|
|
203
206
|
rack
|
204
207
|
rack-test (1.1.0)
|
205
208
|
rack (>= 1.0, < 3)
|
206
|
-
rails (6.0.3.
|
207
|
-
actioncable (= 6.0.3.
|
208
|
-
actionmailbox (= 6.0.3.
|
209
|
-
actionmailer (= 6.0.3.
|
210
|
-
actionpack (= 6.0.3.
|
211
|
-
actiontext (= 6.0.3.
|
212
|
-
actionview (= 6.0.3.
|
213
|
-
activejob (= 6.0.3.
|
214
|
-
activemodel (= 6.0.3.
|
215
|
-
activerecord (= 6.0.3.
|
216
|
-
activestorage (= 6.0.3.
|
217
|
-
activesupport (= 6.0.3.
|
209
|
+
rails (6.0.3.7)
|
210
|
+
actioncable (= 6.0.3.7)
|
211
|
+
actionmailbox (= 6.0.3.7)
|
212
|
+
actionmailer (= 6.0.3.7)
|
213
|
+
actionpack (= 6.0.3.7)
|
214
|
+
actiontext (= 6.0.3.7)
|
215
|
+
actionview (= 6.0.3.7)
|
216
|
+
activejob (= 6.0.3.7)
|
217
|
+
activemodel (= 6.0.3.7)
|
218
|
+
activerecord (= 6.0.3.7)
|
219
|
+
activestorage (= 6.0.3.7)
|
220
|
+
activesupport (= 6.0.3.7)
|
218
221
|
bundler (>= 1.3.0)
|
219
|
-
railties (= 6.0.3.
|
222
|
+
railties (= 6.0.3.7)
|
220
223
|
sprockets-rails (>= 2.0.0)
|
221
224
|
rails-controller-testing (1.0.5)
|
222
225
|
actionpack (>= 5.0.1.rc1)
|
@@ -227,14 +230,18 @@ GEM
|
|
227
230
|
nokogiri (>= 1.6)
|
228
231
|
rails-html-sanitizer (1.3.0)
|
229
232
|
loofah (~> 2.3)
|
230
|
-
railties (6.0.3.
|
231
|
-
actionpack (= 6.0.3.
|
232
|
-
activesupport (= 6.0.3.
|
233
|
+
railties (6.0.3.7)
|
234
|
+
actionpack (= 6.0.3.7)
|
235
|
+
activesupport (= 6.0.3.7)
|
233
236
|
method_source
|
234
237
|
rake (>= 0.8.7)
|
235
238
|
thor (>= 0.20.3, < 2.0)
|
236
239
|
rainbow (3.0.0)
|
237
240
|
rake (13.0.3)
|
241
|
+
ransack (2.4.2)
|
242
|
+
activerecord (>= 5.2.4)
|
243
|
+
activesupport (>= 5.2.4)
|
244
|
+
i18n
|
238
245
|
rb-fsevent (0.10.4)
|
239
246
|
rb-inotify (0.10.1)
|
240
247
|
ffi (~> 1.0)
|
@@ -242,7 +249,7 @@ GEM
|
|
242
249
|
responders (3.0.1)
|
243
250
|
actionpack (>= 5.0)
|
244
251
|
railties (>= 5.0)
|
245
|
-
rexml (3.2.
|
252
|
+
rexml (3.2.5)
|
246
253
|
rspec-core (3.9.2)
|
247
254
|
rspec-support (~> 3.9.3)
|
248
255
|
rspec-expectations (3.9.2)
|
@@ -382,6 +389,7 @@ DEPENDENCIES
|
|
382
389
|
image_processing (~> 1.2)
|
383
390
|
iso
|
384
391
|
jbuilder (~> 2.7)
|
392
|
+
launchy
|
385
393
|
listen (>= 3.5.1)
|
386
394
|
manifester
|
387
395
|
meta-tags
|
@@ -390,6 +398,7 @@ DEPENDENCIES
|
|
390
398
|
pundit
|
391
399
|
rails (~> 6.0.2, >= 6.0.2.2)
|
392
400
|
rails-controller-testing
|
401
|
+
ransack
|
393
402
|
rspec-rails (~> 4.0.0)
|
394
403
|
ruby-debug-ide
|
395
404
|
sass-rails (>= 6)
|
@@ -409,4 +418,4 @@ DEPENDENCIES
|
|
409
418
|
zeitwerk (~> 2.3)
|
410
419
|
|
411
420
|
BUNDLED WITH
|
412
|
-
2.2.
|
421
|
+
2.2.17
|
data/README.md
CHANGED
@@ -24,18 +24,19 @@ Avo is a beautiful next-generation framework that empowers you, the developer, t
|
|
24
24
|
- **Powered by Hotwire** - Rails ❤️ Hotwire
|
25
25
|
- **Code driven configuration** - Configure your Rails dashboard entirely by writing Ruby code.
|
26
26
|
- **Resource Management** - Create a CRUD interface for Active Record from one command. No more copy-pasting view and controller files around.
|
27
|
+
- **Resource Search** - Quickly run a search through one or more resources at once.
|
27
28
|
- **Active Storage support** - Amazingly easy, **one-line**, single or multi-file integration with **ActiveStorage**.
|
28
29
|
- **Grid view** - Beautiful card layout to showcase your content.
|
29
30
|
- **Actions** - Run custom actions to one or more of your resources with as little as pressing a button 💪
|
30
31
|
- **Filters** - Write your own custom filters to quickly segment your data.
|
31
32
|
- **Keeps your app clean** - You don't need to change your app to use Avo. Drop it in your existing app or add it to a new one and you're done 🙌
|
32
|
-
- **Custom fields
|
33
|
-
- **Dashboard widgets and metrics*** - Customize your dashboard with the tools and analytics you need.
|
33
|
+
- **Custom fields**- No worries if we missed a field you need. Generate a custom field in a jiffy.
|
34
34
|
- **Custom tools** - You need to add a page with something completely new, you've got it!
|
35
35
|
- **Authorization** - Leverage Pundit policies to build a robust and scalable authorization system.
|
36
|
-
- **
|
37
|
-
- **Localization*** - Have it available in any language you need.
|
36
|
+
- **Localization** - Have it available in any language you need.
|
38
37
|
- **No asset pipeline pollution** - Bring your own asset pipeline.
|
38
|
+
- **Dashboard widgets and metrics*** - Customize your dashboard with the tools and analytics you need.
|
39
|
+
- **Themable*** - Dress it up into your own colors.
|
39
40
|
|
40
41
|
*Features still under development
|
41
42
|
|
@@ -22,12 +22,12 @@
|
|
22
22
|
<% end %>
|
23
23
|
|
24
24
|
<% c.body do %>
|
25
|
-
<div class="flex justify-between
|
25
|
+
<div class="flex justify-between pt-2 pb-2 min-h-16"
|
26
26
|
data-selected-resources-name="<%= @resource.plural_name.downcase %>"
|
27
27
|
data-selected-resources="[]"
|
28
28
|
>
|
29
29
|
<div class="flex items-center px-6 w-64">
|
30
|
-
|
30
|
+
<%= render partial: 'avo/partials/resource_search', locals: {resource: @resource.route_key} if @resource.search_query.present? %>
|
31
31
|
</div>
|
32
32
|
<div class="flex justify-end items-center px-6 space-x-3">
|
33
33
|
<%= render partial: 'avo/partials/view_toggle_button', locals: { available_view_types: available_view_types, view_type: view_type, turbo_frame: @turbo_frame } if @models.present? %>
|
@@ -36,7 +36,7 @@
|
|
36
36
|
</div>
|
37
37
|
|
38
38
|
<% if view_type.to_sym == :table %>
|
39
|
-
<div class="w-full overflow-auto flex flex-col">
|
39
|
+
<div class="w-full overflow-auto flex flex-col mt-4">
|
40
40
|
<div class="relative flex-1 flex">
|
41
41
|
<%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_model: @parent_model)) %>
|
42
42
|
</div>
|
@@ -17,7 +17,7 @@ module Avo
|
|
17
17
|
add_flash_types :info, :warning, :success, :error
|
18
18
|
|
19
19
|
def init_app
|
20
|
-
Avo::App.init request: request, context: context
|
20
|
+
Avo::App.init request: request, context: context, current_user: _current_user
|
21
21
|
|
22
22
|
@license = Avo::App.license
|
23
23
|
end
|
@@ -38,18 +38,25 @@ module Avo
|
|
38
38
|
def render(*args)
|
39
39
|
raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:check_avo_license).source_location.first.match?(/.*\/app\/controllers\/avo\/application_controller\.rb/)
|
40
40
|
|
41
|
+
if params[:controller] == "avo/search" && params[:action] == "index"
|
42
|
+
raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:index).source_location.first.match?(/.*\/app\/controllers\/avo\/search_controller\.rb/)
|
43
|
+
end
|
44
|
+
|
41
45
|
super(*args)
|
42
46
|
end
|
43
47
|
|
44
48
|
def check_avo_license
|
49
|
+
# Check to see if the path is on a custom tool
|
45
50
|
unless on_root_path || on_resources_path || on_api_path
|
46
|
-
if
|
47
|
-
|
51
|
+
# Display alert on custom tool page if in development.
|
52
|
+
if @license.lacks(:custom_tools) || @license.invalid?
|
53
|
+
if Rails.env.development? || Rails.env.test?
|
48
54
|
@custom_tools_alert_visible = true
|
49
|
-
else
|
50
|
-
raise Avo::LicenseInvalidError, "Your license is invalid or doesn't support custom tools."
|
51
55
|
end
|
52
56
|
end
|
57
|
+
|
58
|
+
# Raise error in non-development environments.
|
59
|
+
raise Avo::LicenseInvalidError, "Your license is invalid or doesn't support custom tools." if @license.lacks_with_trial(:custom_tools)
|
53
60
|
end
|
54
61
|
end
|
55
62
|
|
@@ -157,9 +164,9 @@ module Avo
|
|
157
164
|
|
158
165
|
def authorize_action
|
159
166
|
if @model.present?
|
160
|
-
@authorization.set_record(@model).authorize_action
|
167
|
+
@authorization.set_record(@model).authorize_action action_name.to_sym
|
161
168
|
else
|
162
|
-
@authorization.set_record(@resource.model_class).authorize_action
|
169
|
+
@authorization.set_record(@resource.model_class).authorize_action action_name.to_sym
|
163
170
|
end
|
164
171
|
end
|
165
172
|
|
@@ -17,7 +17,7 @@ module Avo
|
|
17
17
|
@resource = @related_resource
|
18
18
|
@parent_model = @parent_resource.model_class.find(params[:id])
|
19
19
|
@parent_resource.hydrate(model: @parent_model)
|
20
|
-
@query = @parent_model.public_send(params[:related_name])
|
20
|
+
@query = @authorization.apply_policy @parent_model.public_send(params[:related_name])
|
21
21
|
|
22
22
|
super
|
23
23
|
end
|
@@ -2,56 +2,71 @@ require_dependency "avo/application_controller"
|
|
2
2
|
|
3
3
|
module Avo
|
4
4
|
class SearchController < ApplicationController
|
5
|
-
|
5
|
+
before_action :set_resource_name, only: [:show]
|
6
|
+
before_action :set_resource, only: [:show]
|
6
7
|
|
7
8
|
def index
|
8
|
-
|
9
|
-
resources = []
|
10
|
-
|
11
|
-
App.resources
|
12
|
-
.select { |resource| resource.search.present? }
|
13
|
-
.select { |resource| AuthorizationService.authorize_action _current_user, resource.model, "index" }
|
14
|
-
.each do |resource_model|
|
15
|
-
found_resources = add_link_to_search_results(search_resource(resource_model), resource_model)
|
16
|
-
resources.push({
|
17
|
-
label: resource_model.name,
|
18
|
-
resources: found_resources
|
19
|
-
})
|
20
|
-
end
|
9
|
+
raise ActionController::BadRequest.new("This feature requires the pro license https://avohq.io/purchase/pro") if App.license.lacks_with_trial(:global_search)
|
21
10
|
|
22
|
-
render json:
|
23
|
-
resources: resources
|
24
|
-
}
|
11
|
+
render json: search_resources(Avo::App.resources)
|
25
12
|
end
|
26
13
|
|
27
|
-
def
|
28
|
-
render json:
|
29
|
-
resources: add_link_to_search_results(search_resource(avo_resource), avo_resource)
|
30
|
-
}
|
14
|
+
def show
|
15
|
+
render json: search_resources([resource])
|
31
16
|
end
|
32
17
|
|
33
18
|
private
|
34
19
|
|
35
|
-
def
|
36
|
-
resources.map do |
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
20
|
+
def search_resources(resources)
|
21
|
+
resources.map do |resource|
|
22
|
+
# Apply authorization
|
23
|
+
next unless @authorization.set_record(resource.model_class).authorize_action(:index, raise_exception: false)
|
24
|
+
# Filter out the models without a search_query
|
25
|
+
next if resource.search_query.nil?
|
26
|
+
|
27
|
+
search_resource resource
|
42
28
|
end
|
29
|
+
.select do |payload|
|
30
|
+
payload.present?
|
31
|
+
end
|
32
|
+
.sort do |payload|
|
33
|
+
payload.last[:count]
|
34
|
+
end
|
35
|
+
.reverse
|
36
|
+
.to_h
|
43
37
|
end
|
44
38
|
|
45
|
-
def search_resource(
|
46
|
-
|
39
|
+
def search_resource(resource)
|
40
|
+
results = apply_search_metadata(resource.search_query.call(params: params).limit(8), resource)
|
41
|
+
|
42
|
+
result_object = {
|
43
|
+
header: resource.name.pluralize,
|
44
|
+
results: results,
|
45
|
+
count: results.length
|
46
|
+
}
|
47
|
+
|
48
|
+
[resource.name.pluralize.downcase, result_object]
|
47
49
|
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
def apply_search_metadata(models, avo_resource)
|
52
|
+
models.map do |model|
|
53
|
+
resource = avo_resource.dup.hydrate(model: model).hydrate_fields(model: model)
|
51
54
|
|
52
|
-
|
55
|
+
result = {
|
56
|
+
_id: model.id,
|
57
|
+
_label: resource.label,
|
58
|
+
_url: resource.avo_path,
|
59
|
+
model: model
|
60
|
+
}
|
53
61
|
|
54
|
-
|
55
|
-
|
62
|
+
if App.license.has_with_trial(:enhanced_search_results)
|
63
|
+
result[:_description] = resource.description
|
64
|
+
result[:_avatar] = resource.avatar
|
65
|
+
result[:_avatar_type] = resource.avatar_type
|
66
|
+
end
|
67
|
+
|
68
|
+
result
|
69
|
+
end
|
70
|
+
end
|
56
71
|
end
|
57
72
|
end
|