avo 2.5.2.pre.6 → 2.5.2.pre.7
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 +2 -0
- data/Gemfile.lock +4 -1
- data/app/assets/builds/avo.css +766 -301
- data/app/assets/builds/avo.js +212 -123
- data/app/assets/builds/avo.js.map +3 -3
- data/app/assets/stylesheets/avo.css +3 -33
- data/app/assets/stylesheets/css/alerts.css +35 -0
- data/app/assets/stylesheets/css/search.css +1 -1
- data/app/assets/stylesheets/css/tags.css +16 -0
- data/app/assets/svgs/heroicons/solid/user-remove.svg +1 -1
- data/app/components/avo/actions_component.html.erb +1 -2
- data/app/components/avo/alert_component.html.erb +1 -1
- data/app/components/avo/alert_component.rb +5 -24
- data/app/components/avo/button_component.rb +7 -46
- data/app/components/avo/fields/tags_field/edit_component.html.erb +27 -0
- data/app/components/avo/fields/tags_field/edit_component.rb +4 -0
- data/app/components/avo/fields/tags_field/index_component.html.erb +14 -0
- data/app/components/avo/fields/tags_field/index_component.rb +7 -0
- data/app/components/avo/fields/tags_field/show_component.html.erb +7 -0
- data/app/components/avo/fields/tags_field/show_component.rb +11 -0
- data/app/components/avo/fields/tags_field/tag_component.html.erb +9 -0
- data/app/components/avo/fields/tags_field/tag_component.rb +11 -0
- data/app/components/avo/filters_component.html.erb +1 -1
- data/app/components/avo/index/field_wrapper_component.html.erb +1 -1
- data/app/components/avo/index/grid_cover_empty_state_component.html.erb +1 -1
- data/app/components/avo/index/resource_table_component.html.erb +1 -1
- data/app/components/avo/index/table_row_component.html.erb +1 -1
- data/app/components/avo/panel_component.html.erb +3 -3
- data/app/components/avo/panel_component.rb +1 -1
- data/app/components/avo/resource_component.rb +0 -50
- data/app/components/avo/sidebar/group_component.html.erb +2 -4
- data/app/components/avo/sidebar/heading_component.html.erb +1 -1
- data/app/components/avo/sidebar/link_component.html.erb +1 -1
- data/app/components/avo/sidebar/link_component.rb +1 -1
- data/app/components/avo/sidebar_component.html.erb +13 -5
- data/app/components/avo/sidebar_profile_component.html.erb +1 -1
- data/app/components/avo/views/resource_edit_component.html.erb +3 -28
- data/app/components/avo/views/resource_edit_component.rb +6 -4
- data/app/components/avo/views/resource_index_component.html.erb +9 -17
- data/app/components/avo/views/resource_new_component.html.erb +2 -8
- data/app/components/avo/views/resource_show_component.html.erb +6 -16
- data/app/components/avo/views/resource_show_component.rb +45 -0
- data/app/controllers/avo/actions_controller.rb +8 -23
- data/app/controllers/avo/associations_controller.rb +3 -3
- data/app/controllers/avo/base_controller.rb +16 -25
- data/app/controllers/avo/private_controller.rb +0 -1
- data/app/controllers/avo/search_controller.rb +2 -2
- data/app/helpers/avo/application_helper.rb +1 -1
- data/app/javascript/js/application.js +1 -1
- data/app/javascript/js/controllers/alerts_controller.js +26 -0
- data/app/javascript/js/controllers/base_controller.js +22 -0
- data/app/javascript/js/controllers/fields/key_value_controller.js +1 -1
- data/app/javascript/js/controllers/fields/tags_field_controller.js +86 -0
- data/app/javascript/js/controllers/fields/tags_field_helpers.js +47 -0
- data/app/javascript/js/controllers/filter_controller.js +1 -4
- data/app/javascript/js/controllers.js +4 -0
- data/app/views/avo/actions/show.html.erb +2 -5
- data/app/views/avo/partials/_logo.html.erb +1 -1
- data/app/views/avo/partials/_navbar.html.erb +6 -9
- data/app/views/avo/partials/_table_header.html.erb +2 -3
- data/app/views/avo/private/_links_and_buttons.html.erb +2 -2
- data/app/views/layouts/avo/application.html.erb +53 -50
- data/db/factories.rb +2 -0
- data/lib/avo/base_action.rb +6 -24
- data/lib/avo/base_resource.rb +6 -0
- data/lib/avo/concerns/handles_field_args.rb +36 -0
- data/lib/avo/engine.rb +1 -1
- data/lib/avo/fields/base_field.rb +2 -1
- data/lib/avo/fields/belongs_to_field.rb +4 -4
- data/lib/avo/fields/has_and_belongs_to_many_field.rb +2 -2
- data/lib/avo/fields/has_base_field.rb +0 -2
- data/lib/avo/fields/has_many_field.rb +2 -2
- data/lib/avo/fields/has_one_field.rb +2 -2
- data/lib/avo/fields/tags_field.rb +82 -0
- data/lib/avo/hosts/record_host.rb +7 -0
- data/lib/avo/licensing/pro_license.rb +2 -1
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/templates/locales/avo.en.yml +4 -0
- data/public/avo-assets/avo.css +825 -262
- data/public/avo-assets/avo.js +212 -123
- data/public/avo-assets/avo.js.map +3 -3
- metadata +19 -2
@@ -84,12 +84,9 @@ export default class extends Controller {
|
|
84
84
|
|
85
85
|
if (this.keepFiltersPanelOpenValue) {
|
86
86
|
// eslint-disable-next-line camelcase
|
87
|
-
query.keep_filters_panel_open = this.keepFiltersPanelOpenValue
|
87
|
+
query.keep_filters_panel_open = this.keepFiltersPanelOpenValue
|
88
88
|
}
|
89
89
|
|
90
|
-
// force to go to the first page if the filters changed
|
91
|
-
query.page = 1
|
92
|
-
|
93
90
|
if (encodedFilters) {
|
94
91
|
query.filters = encodedFilters
|
95
92
|
} else {
|
@@ -2,6 +2,7 @@ import { application } from './application'
|
|
2
2
|
|
3
3
|
import ActionController from './controllers/action_controller'
|
4
4
|
import ActionsPickerController from './controllers/actions_picker_controller'
|
5
|
+
import AlertsController from './controllers/alerts_controller'
|
5
6
|
import AttachmentsController from './controllers/attachments_controller'
|
6
7
|
import BelongsToFieldController from './controllers/fields/belongs_to_field_controller'
|
7
8
|
import BooleanFilterController from './controllers/boolean_filter_controller'
|
@@ -24,6 +25,7 @@ import SearchController from './controllers/search_controller'
|
|
24
25
|
import SelectController from './controllers/select_controller'
|
25
26
|
import SelectFilterController from './controllers/select_filter_controller'
|
26
27
|
import SimpleMdeController from './controllers/fields/simple_mde_controller'
|
28
|
+
import TagsFieldController from './controllers/fields/tags_field_controller'
|
27
29
|
import TextFilterController from './controllers/text_filter_controller'
|
28
30
|
import TippyController from './controllers/tippy_controller'
|
29
31
|
import TogglePanelController from './controllers/toggle_panel_controller'
|
@@ -31,6 +33,7 @@ import TrixFieldController from './controllers/fields/trix_field_controller'
|
|
31
33
|
|
32
34
|
application.register('action', ActionController)
|
33
35
|
application.register('actions-picker', ActionsPickerController)
|
36
|
+
application.register('alerts', AlertsController)
|
34
37
|
application.register('attachments', AttachmentsController)
|
35
38
|
application.register('boolean-filter', BooleanFilterController)
|
36
39
|
application.register('copy-to-clipboard', CopyToClipboardController)
|
@@ -48,6 +51,7 @@ application.register('per-page', PerPageController)
|
|
48
51
|
application.register('search', SearchController)
|
49
52
|
application.register('select', SelectController)
|
50
53
|
application.register('select-filter', SelectFilterController)
|
54
|
+
application.register('tags-field', TagsFieldController)
|
51
55
|
application.register('text-filter', TextFilterController)
|
52
56
|
application.register('tippy', TippyController)
|
53
57
|
application.register('toggle-panel', TogglePanelController)
|
@@ -29,14 +29,11 @@
|
|
29
29
|
</div>
|
30
30
|
<% end %>
|
31
31
|
<% c.controls do %>
|
32
|
-
<%= a_button data: { action: 'click->modal#close' },
|
33
|
-
size: :sm,
|
34
|
-
color: :primary do %>
|
32
|
+
<%= a_button data: { action: 'click->modal#close' }, size: :sm do %>
|
35
33
|
<%= @action.cancel_button_label %>
|
36
34
|
<% end %>
|
37
35
|
<%= a_button type: :submit,
|
38
|
-
color: :
|
39
|
-
style: :primary,
|
36
|
+
color: :green,
|
40
37
|
size: :sm,
|
41
38
|
data: @action.class.submit_button_data_attributes do %>
|
42
39
|
<%= @action.confirm_button_label %>
|
@@ -1,17 +1,14 @@
|
|
1
1
|
<div
|
2
|
-
class="
|
2
|
+
class="relative bg-white p-2 w-full flex flex-shrink-0 items-center z-50 px-4 lg:px-8 border-b space-x-4 lg:space-x-0 min-h-[4rem] <%= 'print:hidden' if Avo.configuration.hide_layout_when_printing %>"
|
3
3
|
v-if="layout !== 'blank'"
|
4
4
|
>
|
5
|
-
|
6
|
-
|
7
|
-
<%= render partial: "avo/partials/logo" %>
|
8
|
-
</div>
|
9
|
-
<div class="flex-1 flex items-center justify-between lg:justify-start space-x-8 lg:pl-4">
|
10
|
-
<div class="flex">
|
11
|
-
<%= render partial: "avo/partials/global_search" if ::Avo::App.license.has_with_trial(:global_search) && ::Avo.configuration.feature_enabled?(:global_search) %>
|
12
|
-
</div>
|
5
|
+
<%= a_button class: 'lg:hidden', icon: 'menu', data: { action: 'click->mobile#toggleSidebar' } %>
|
6
|
+
<div class="flex-1 flex items-center justify-between lg:justify-start space-x-8">
|
13
7
|
<div class="m-0">
|
14
8
|
<%= render partial: "avo/partials/header" %>
|
15
9
|
</div>
|
10
|
+
<div class="flex">
|
11
|
+
<%= render partial: "avo/partials/global_search" if ::Avo::App.license.has_with_trial(:global_search) && ::Avo.configuration.feature_enabled?(:global_search) %>
|
12
|
+
</div>
|
16
13
|
</div>
|
17
14
|
</div>
|
@@ -29,9 +29,8 @@
|
|
29
29
|
sort_by = field.id
|
30
30
|
sort_direction = 'desc'
|
31
31
|
end
|
32
|
-
classes = "text-gray-500 tracking-tight leading-tight text-
|
33
|
-
|
34
|
-
<th class="text-left uppercase px-3 py-2 whitespace-nowrap rounded-l">
|
32
|
+
classes = "text-gray-500 tracking-tight leading-tight text-sm font-semibold" %>
|
33
|
+
<th class="text-left uppercase px-3 py-4 whitespace-nowrap rounded-l">
|
35
34
|
<% if field.sortable %>
|
36
35
|
<%= link_to params.permit!.merge(sort_by: sort_by, sort_direction: sort_direction), class: "flex items-center #{classes} #{'cursor-pointer' if field.sortable}", 'data-turbo-frame': params[:turbo_frame] do %>
|
37
36
|
<%= field.name %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%
|
2
2
|
entities = [:button, :link]
|
3
|
-
sizes = [:
|
4
|
-
styles = [:primary, :outline
|
3
|
+
sizes = [:lg, :md, :sm, :xs]
|
4
|
+
styles = [:primary, :outline]
|
5
5
|
colors = [:primary, :gray, :red, :orange, :green]
|
6
6
|
states = [:regular, :hover, :disabled, :active]
|
7
7
|
%>
|
@@ -1,57 +1,60 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
5
|
+
<%= display_meta_tags site: Avo.configuration.app_name, reverse: true, separator: "—" %>
|
6
|
+
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
<%= csp_meta_tag %>
|
9
|
+
|
10
|
+
<%= render partial: 'avo/partials/javascript' %>
|
11
|
+
<%= render partial: 'avo/partials/head' %>
|
12
|
+
|
13
|
+
<% if Avo::PACKED %>
|
14
|
+
<%= javascript_include_tag "/avo-assets/avo", "data-turbo-track": "reload", defer: true %>
|
15
|
+
<%= stylesheet_link_tag "/avo-assets/avo", "data-turbo-track": "reload", defer: true %>
|
16
|
+
<% else %>
|
17
|
+
<%= javascript_include_tag "avo", "data-turbo-track": "reload", defer: true %>
|
18
|
+
<%= stylesheet_link_tag "avo", "data-turbo-track": "reload", defer: true %>
|
19
|
+
<% if Rails.env.development? %>
|
20
|
+
<%= javascript_include_tag "hotwire-livereload", defer: true %>
|
19
21
|
<% end %>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
</div>
|
36
|
-
</div>
|
22
|
+
<% end %>
|
23
|
+
</head>
|
24
|
+
<body class="bg-application os-mac">
|
25
|
+
<div class="relative flex flex-1 w-full min-h-full" data-controller="mobile">
|
26
|
+
<%= render Avo::SidebarComponent.new %>
|
27
|
+
|
28
|
+
<div class="lg:pl-64 flex-1 flex flex-col min-h-full max-w-full">
|
29
|
+
<%= render partial: "avo/partials/navbar" %>
|
30
|
+
|
31
|
+
<div class="content py-4 lg:py-8 px-4 lg:px-8 flex-1 flex flex-col justify-between items-stretch <%= @container_classes %>">
|
32
|
+
<%= render partial: "avo/partials/custom_tools_alert" if @custom_tools_alert_visible %>
|
33
|
+
|
34
|
+
<div class="flex flex-1 flex-col justify-between items-stretch space-y-8">
|
35
|
+
<%= yield %>
|
36
|
+
<%= render partial: "avo/partials/footer" %>
|
37
37
|
</div>
|
38
38
|
</div>
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<%= turbo_frame_tag 'actions_show' %>
|
43
|
+
<%= turbo_frame_tag 'attach_modal' %>
|
44
|
+
<%= turbo_frame_tag 'destroy_attachment_form' %>
|
45
|
+
|
46
|
+
<%= turbo_frame_tag 'alerts', class: "fixed inset-0 bottom-0 flex flex-col space-y-4 items-end justify-right px-4 py-6 sm:p-6 justify-end z-50 pointer-events-none" do %>
|
47
|
+
<%= render Avo::FlashAlertsComponent.new flashes: flash %>
|
48
|
+
|
49
|
+
<% # In case we have other general error messages %>
|
50
|
+
<% if @errors.present? %>
|
51
|
+
<% @errors.each do |message| %>
|
52
|
+
<%= render Avo::AlertComponent.new :error, message %>
|
50
53
|
<% end %>
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
<% end %>
|
55
|
+
<% end %>
|
56
|
+
|
57
|
+
<%= render partial: "avo/partials/scripts" %>
|
58
|
+
<!-- Avo version: <%= Avo::VERSION %> -->
|
59
|
+
</body>
|
57
60
|
</html>
|
data/db/factories.rb
CHANGED
@@ -25,6 +25,7 @@ FactoryBot.define do
|
|
25
25
|
Time.now - rand(10...365).days
|
26
26
|
end
|
27
27
|
end
|
28
|
+
tag_list { ["1", "2", "five", "seven"].shuffle }
|
28
29
|
status { ::Post.statuses.keys.sample }
|
29
30
|
end
|
30
31
|
|
@@ -64,6 +65,7 @@ FactoryBot.define do
|
|
64
65
|
|
65
66
|
factory :course do
|
66
67
|
name { Faker::Educator.unique.course_name }
|
68
|
+
skills { [Faker::Educator.subject, Faker::Educator.subject, Faker::Educator.subject, Faker::Educator.subject, Faker::Educator.subject] }
|
67
69
|
country { Course.countries.sample }
|
68
70
|
city { Course.cities.stringify_keys[country].sample }
|
69
71
|
end
|
data/lib/avo/base_action.rb
CHANGED
@@ -61,7 +61,8 @@ module Avo
|
|
61
61
|
self.class.cancel_button_label ||= I18n.t("avo.cancel")
|
62
62
|
|
63
63
|
@response ||= {}
|
64
|
-
@response[:
|
64
|
+
@response[:message_type] ||= :notice
|
65
|
+
@response[:message] ||= I18n.t("avo.action_ran_successfully")
|
65
66
|
end
|
66
67
|
|
67
68
|
def context
|
@@ -130,25 +131,15 @@ module Avo
|
|
130
131
|
end
|
131
132
|
|
132
133
|
def succeed(text)
|
133
|
-
|
134
|
+
response[:message_type] = :notice
|
135
|
+
response[:message] = text
|
134
136
|
|
135
137
|
self
|
136
138
|
end
|
137
139
|
|
138
140
|
def fail(text)
|
139
|
-
|
140
|
-
|
141
|
-
self
|
142
|
-
end
|
143
|
-
|
144
|
-
def inform(text)
|
145
|
-
add_message text, :info
|
146
|
-
|
147
|
-
self
|
148
|
-
end
|
149
|
-
|
150
|
-
def warn(text)
|
151
|
-
add_message text, :warning
|
141
|
+
response[:message_type] = :alert
|
142
|
+
response[:message] = text
|
152
143
|
|
153
144
|
self
|
154
145
|
end
|
@@ -177,14 +168,5 @@ module Avo
|
|
177
168
|
|
178
169
|
self
|
179
170
|
end
|
180
|
-
|
181
|
-
private
|
182
|
-
|
183
|
-
def add_message(body, type = :info)
|
184
|
-
response[:messages] << {
|
185
|
-
type: type,
|
186
|
-
body: body
|
187
|
-
}
|
188
|
-
end
|
189
171
|
end
|
190
172
|
end
|
data/lib/avo/base_resource.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Avo
|
2
|
+
module Concerns
|
3
|
+
module HandlesFieldArgs
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
# Add an instance variable from args
|
9
|
+
# That may be a string, boolean, or array
|
10
|
+
# Each args should also have a default value
|
11
|
+
def add_prop_from_args(args = {}, name: nil, type: :string, default: nil)
|
12
|
+
value = default
|
13
|
+
|
14
|
+
if type == :boolean
|
15
|
+
value = args[name.to_sym] == true
|
16
|
+
else
|
17
|
+
value = args[name.to_sym] unless args.dig(name.to_sym).nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
instance_variable_set(:"@#{name}", value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_boolean_prop(args, name, default = false)
|
24
|
+
add_prop_from_args args, name: name, default: default, type: :boolean
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_array_prop(args, name, default = [])
|
28
|
+
add_prop_from_args args, name: name, default: default, type: :array
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_string_prop(args, name, default = [])
|
32
|
+
add_prop_from_args args, name: name, default: default, type: :string
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/avo/engine.rb
CHANGED
@@ -4,8 +4,9 @@ module Avo
|
|
4
4
|
extend ActiveSupport::DescendantsTracker
|
5
5
|
extend Avo::Fields::FieldExtensions::HasFieldName
|
6
6
|
|
7
|
-
include ActionView::Helpers::UrlHelper
|
8
7
|
include Avo::Fields::FieldExtensions::VisibleInDifferentViews
|
8
|
+
include Avo::Concerns::HandlesFieldArgs
|
9
|
+
include ActionView::Helpers::UrlHelper
|
9
10
|
|
10
11
|
delegate :view_context, to: "Avo::App"
|
11
12
|
delegate :main_app, to: :view_context
|
@@ -62,7 +62,7 @@ module Avo
|
|
62
62
|
attr_reader :relation_method
|
63
63
|
attr_reader :types # for Polymorphic associations
|
64
64
|
attr_reader :allow_via_detaching
|
65
|
-
attr_reader :
|
65
|
+
attr_reader :scope
|
66
66
|
attr_reader :polymorphic_help
|
67
67
|
|
68
68
|
def initialize(id, **args, &block)
|
@@ -75,7 +75,7 @@ module Avo
|
|
75
75
|
@types = args[:types]
|
76
76
|
@relation_method = id.to_s.parameterize.underscore
|
77
77
|
@allow_via_detaching = args[:allow_via_detaching] == true
|
78
|
-
@
|
78
|
+
@scope = args[:scope]
|
79
79
|
@polymorphic_help = args[:polymorphic_help]
|
80
80
|
end
|
81
81
|
|
@@ -117,8 +117,8 @@ module Avo
|
|
117
117
|
|
118
118
|
query = Avo::Services::AuthorizationService.apply_policy(user, resource.class.query_scope)
|
119
119
|
|
120
|
-
if
|
121
|
-
query = Avo::Hosts::AssociationScopeHost.new(block:
|
120
|
+
if scope.present?
|
121
|
+
query = Avo::Hosts::AssociationScopeHost.new(block: scope, query: query, parent: get_model).handle
|
122
122
|
end
|
123
123
|
|
124
124
|
query.all.map do |model|
|
@@ -3,14 +3,12 @@ module Avo
|
|
3
3
|
class HasBaseField < BaseField
|
4
4
|
attr_accessor :display
|
5
5
|
attr_accessor :scope
|
6
|
-
attr_accessor :attach_scope
|
7
6
|
attr_accessor :description
|
8
7
|
|
9
8
|
def initialize(id, **args, &block)
|
10
9
|
super(id, **args, &block)
|
11
10
|
|
12
11
|
@scope = args[:scope].present? ? args[:scope] : nil
|
13
|
-
@attach_scope = args[:attach_scope].present? ? args[:attach_scope] : nil
|
14
12
|
@display = args[:display].present? ? args[:display] : :show
|
15
13
|
@searchable = args[:searchable] == true
|
16
14
|
@description = args[:description]
|
@@ -4,10 +4,10 @@ module Avo
|
|
4
4
|
attr_accessor :relation_method
|
5
5
|
|
6
6
|
def initialize(id, **args, &block)
|
7
|
-
hide_on :new, :edit
|
8
|
-
|
9
7
|
super(id, **args, &block)
|
10
8
|
|
9
|
+
hide_on :new, :edit
|
10
|
+
|
11
11
|
@placeholder ||= I18n.t "avo.choose_an_option"
|
12
12
|
|
13
13
|
@relation_method = name.to_s.parameterize.underscore
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Avo
|
2
|
+
module Fields
|
3
|
+
class TagsField < BaseField
|
4
|
+
attr_reader :acts_as_taggable_on
|
5
|
+
attr_reader :close_on_select
|
6
|
+
attr_reader :delimiters
|
7
|
+
attr_reader :enforce_suggestions
|
8
|
+
|
9
|
+
def initialize(id, **args, &block)
|
10
|
+
super(id, **args, &block)
|
11
|
+
|
12
|
+
add_boolean_prop args, :close_on_select
|
13
|
+
add_boolean_prop args, :enforce_suggestions
|
14
|
+
add_string_prop args, :acts_as_taggable_on
|
15
|
+
add_array_prop args, :blacklist
|
16
|
+
add_array_prop args, :delimiters, [","]
|
17
|
+
add_array_prop args, :suggestions
|
18
|
+
end
|
19
|
+
|
20
|
+
def field_value
|
21
|
+
return json_value if acts_as_taggable_on.present?
|
22
|
+
|
23
|
+
value || []
|
24
|
+
end
|
25
|
+
|
26
|
+
def json_value
|
27
|
+
value.map do |item|
|
28
|
+
{
|
29
|
+
value: item.name
|
30
|
+
}
|
31
|
+
end.as_json
|
32
|
+
end
|
33
|
+
|
34
|
+
def fill_field(model, key, value, params)
|
35
|
+
if acts_as_taggable_on.present?
|
36
|
+
model.send(act_as_taggable_attribute(key), parsed_value(value))
|
37
|
+
else
|
38
|
+
model.send("#{key}=", parsed_value(value))
|
39
|
+
end
|
40
|
+
|
41
|
+
model
|
42
|
+
end
|
43
|
+
|
44
|
+
def suggestions
|
45
|
+
return @suggestions if @suggestions.is_a? Array
|
46
|
+
|
47
|
+
if @suggestions.respond_to? :call
|
48
|
+
return Avo::Hosts::RecordHost.new(block: @suggestions, record: model).handle
|
49
|
+
end
|
50
|
+
|
51
|
+
[]
|
52
|
+
end
|
53
|
+
|
54
|
+
def blacklist
|
55
|
+
return @blacklist if @blacklist.is_a? Array
|
56
|
+
|
57
|
+
if @blacklist.respond_to? :call
|
58
|
+
return Avo::Hosts::RecordHost.new(block: @blacklist, record: model).handle
|
59
|
+
end
|
60
|
+
|
61
|
+
[]
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def act_as_taggable_attribute(key)
|
67
|
+
"#{key.singularize}_list="
|
68
|
+
end
|
69
|
+
|
70
|
+
def parsed_value(value)
|
71
|
+
JSON.parse(value).pluck("value")
|
72
|
+
rescue
|
73
|
+
[]
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def parse_suggestions_from_args(args)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/avo/version.rb
CHANGED