avo 0.5.0.beta7 → 0.5.0.beta12
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 +48 -47
- data/Gemfile.lock +28 -18
- data/Rakefile +14 -14
- data/app/components/avo/common/badge_viewer_component.html.erb +1 -1
- data/app/components/avo/common/gravatar_viewer_component.html.erb +2 -2
- data/app/components/avo/common/gravatar_viewer_component.rb +2 -1
- data/app/components/avo/common/multiple_file_viewer_component.rb +1 -1
- data/app/components/avo/common/single_file_viewer_component.rb +1 -1
- data/app/components/avo/edit/field_wrapper_component.rb +3 -3
- data/app/components/avo/edit/fields/trix_field_component.html.erb +1 -1
- data/app/components/avo/index/field_wrapper_component.html.erb +1 -1
- data/app/components/avo/index/field_wrapper_component.rb +1 -1
- data/app/components/avo/index/fields/belongs_to_field_component.html.erb +1 -5
- data/app/components/avo/index/fields/boolean_group_field_component.html.erb +1 -1
- data/app/components/avo/index/fields/gravatar_field_component.html.erb +2 -1
- data/app/components/avo/index/fields/has_one_field_component.html.erb +1 -5
- data/app/components/avo/index/fields/id_field_component.html.erb +1 -1
- data/app/components/avo/index/grid_item_component.html.erb +2 -2
- data/app/components/avo/index/grid_item_component.rb +10 -9
- data/app/components/avo/index/resource_controls_component.html.erb +12 -4
- data/app/components/avo/index/resource_controls_component.rb +2 -2
- data/app/components/avo/panel_component.rb +7 -6
- data/app/components/avo/resource_component.rb +4 -3
- data/app/components/avo/show/field_wrapper_component.html.erb +1 -1
- data/app/components/avo/show/field_wrapper_component.rb +3 -3
- data/app/components/avo/show/fields/boolean_group_field_component.html.erb +1 -1
- data/app/components/avo/show/fields/external_image_field_component.html.erb +1 -1
- data/app/components/avo/views/resource_edit_component.rb +4 -3
- data/app/components/avo/views/resource_index_component.rb +8 -7
- data/app/components/avo/views/resource_new_component.rb +4 -3
- data/app/components/avo/views/resource_show_component.html.erb +14 -2
- data/app/components/avo/views/resource_show_component.rb +21 -21
- data/app/controllers/avo/actions_controller.rb +34 -32
- data/app/controllers/avo/application_controller.rb +122 -119
- data/app/controllers/avo/attachments_controller.rb +3 -3
- data/app/controllers/avo/base_controller.rb +80 -82
- data/app/controllers/avo/home_controller.rb +2 -2
- data/app/controllers/avo/relations_controller.rb +29 -28
- data/app/controllers/avo/resources_controller.rb +1 -1
- data/app/controllers/avo/search_controller.rb +20 -19
- data/app/helpers/avo/application_helper.rb +49 -43
- data/app/helpers/avo/resources_helper.rb +11 -11
- data/app/mailers/avo/application_mailer.rb +2 -2
- data/app/{frontend/css → packs/entrypoints}/application.css +12 -11
- data/app/{frontend/packs → packs/entrypoints}/application.js +9 -3
- data/app/{frontend → packs}/fonts/nunito-v16-latin-700.eot +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-700.svg +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-700.ttf +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-700.woff +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-700.woff2 +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-regular.eot +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-regular.svg +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-regular.ttf +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-regular.woff +0 -0
- data/app/{frontend → packs}/fonts/nunito-v16-latin-regular.woff2 +0 -0
- data/app/{frontend → packs}/images/logo.png +0 -0
- data/app/{frontend → packs}/importmap.json.erb +0 -0
- data/app/{frontend → packs}/js/controllers/action_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/actions_picker_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/alerts_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/attachments_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/boolean_filter_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/fields/code_field_controller.js +14 -14
- data/app/{frontend → packs}/js/controllers/fields/date_field_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/fields/simple_mde_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/filter_controller.js +20 -3
- data/app/{frontend → packs}/js/controllers/hidden_input_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/item_selector_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/modal_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/per_page_controller.js +5 -1
- data/app/{frontend → packs}/js/controllers/select_filter_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/tippy_controller.js +0 -0
- data/app/{frontend → packs}/js/controllers/toggle_panel_controller.js +0 -0
- data/app/{frontend → packs}/js/helpers/cast_boolean.js +0 -0
- data/app/{frontend → packs}/js/toastr.js +1 -0
- data/app/{frontend/css → packs/stylesheets}/alerts.css +0 -0
- data/app/packs/stylesheets/components/code.css +11 -0
- data/app/{frontend/css → packs/stylesheets}/components/status.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/fonts.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/loader.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/pagination.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/tailwindcss/base.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/tailwindcss/components.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/tailwindcss/utilities.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/tooltips.css +0 -0
- data/app/{frontend/css → packs/stylesheets}/typography.css +0 -0
- data/app/{frontend → packs}/svgs/arrow-circle-right.svg +0 -0
- data/app/{frontend → packs}/svgs/arrow-left.svg +0 -0
- data/app/{frontend → packs}/svgs/avocado.svg +0 -0
- data/app/{frontend → packs}/svgs/badge-check-sm.svg +0 -0
- data/app/{frontend → packs}/svgs/check-circle.svg +0 -0
- data/app/{frontend → packs}/svgs/chevron-down.svg +0 -0
- data/app/{frontend → packs}/svgs/chevron-up.svg +0 -0
- data/app/{frontend → packs}/svgs/code.svg +0 -0
- data/app/{frontend → packs}/svgs/color-swatch.svg +0 -0
- data/app/{frontend → packs}/svgs/document-text.svg +0 -0
- data/app/{frontend → packs}/svgs/download.svg +0 -0
- data/app/{frontend → packs}/svgs/edit.svg +0 -0
- data/app/{frontend → packs}/svgs/exclamation-circle-sm.svg +0 -0
- data/app/{frontend → packs}/svgs/exclamation-sm.svg +0 -0
- data/app/{frontend → packs}/svgs/exclamation.svg +0 -0
- data/app/{frontend → packs}/svgs/eye.svg +0 -0
- data/app/{frontend → packs}/svgs/filter.svg +0 -0
- data/app/{frontend → packs}/svgs/fire.svg +0 -0
- data/app/{frontend → packs}/svgs/game-board.svg +0 -0
- data/app/{frontend → packs}/svgs/globe.svg +0 -0
- data/app/{frontend → packs}/svgs/information-circle-sm.svg +0 -0
- data/app/{frontend → packs}/svgs/information-circle.svg +0 -0
- data/app/{frontend → packs}/svgs/library.svg +0 -0
- data/app/{frontend → packs}/svgs/photograph.svg +0 -0
- data/app/{frontend → packs}/svgs/play.svg +0 -0
- data/app/{frontend → packs}/svgs/plus-circle.svg +0 -0
- data/app/{frontend → packs}/svgs/plus.svg +0 -0
- data/app/{frontend → packs}/svgs/question-mark-circle.svg +0 -0
- data/app/{frontend → packs}/svgs/save.svg +0 -0
- data/app/{frontend → packs}/svgs/selector.svg +0 -0
- data/app/{frontend → packs}/svgs/sort-ascending.svg +0 -0
- data/app/{frontend → packs}/svgs/sort-descending.svg +0 -0
- data/app/{frontend → packs}/svgs/switch-horizontal.svg +0 -0
- data/app/{frontend → packs}/svgs/thumbs-down.svg +0 -0
- data/app/{frontend → packs}/svgs/thumbs-up.svg +0 -0
- data/app/{frontend → packs}/svgs/times.svg +0 -0
- data/app/{frontend → packs}/svgs/trash-sm.svg +0 -0
- data/app/{frontend → packs}/svgs/trash.svg +0 -0
- data/app/{frontend → packs}/svgs/view-grid-add.svg +0 -0
- data/app/{frontend → packs}/svgs/view-grid.svg +0 -0
- data/app/{frontend → packs}/svgs/view-list.svg +0 -0
- data/app/{frontend → packs}/svgs/x-circle.svg +0 -0
- data/app/views/avo/actions/show.html.erb +3 -39
- data/app/views/avo/attachments/show.html.erb +8 -1
- data/app/views/avo/base/_boolean_filter.html.erb +1 -0
- data/app/views/avo/base/_filters.html.erb +1 -0
- data/app/views/avo/base/_select_filter.html.erb +1 -0
- data/app/views/avo/partials/_paginator.html.erb +24 -5
- data/app/views/avo/relations/new.html.erb +5 -1
- data/app/views/layouts/avo/application.html.erb +0 -5
- data/avo.gemspec +31 -30
- data/bin/helpers.rb +0 -0
- data/bin/rspec +1 -0
- data/bin/webpack +3 -1
- data/config/initializers/inline_svg.rb +1 -1
- data/config/initializers/pagy.rb +1 -1
- data/config/routes.rb +12 -12
- data/config/spring.rb +5 -5
- data/config/webpack/aliases.js +1 -1
- data/config/webpack/base.js +14 -0
- data/config/webpack/development.js +2 -2
- data/config/webpack/production.js +2 -2
- data/config/webpack/test.js +2 -2
- data/config/webpacker.yml +5 -44
- data/db/factories.rb +4 -5
- data/lib/avo.rb +6 -6
- data/lib/avo/action_model.rb +20 -0
- data/lib/avo/app.rb +18 -60
- data/lib/avo/base_action.rb +55 -52
- data/lib/avo/base_resource.rb +66 -95
- data/lib/avo/configuration.rb +16 -22
- data/lib/avo/engine.rb +30 -14
- data/lib/avo/fields/badge_field.rb +2 -2
- data/lib/avo/fields/base_field.rb +38 -29
- data/lib/avo/fields/belongs_to_field.rb +13 -12
- data/lib/avo/fields/boolean_field.rb +4 -4
- data/lib/avo/fields/boolean_group_field.rb +3 -3
- data/lib/avo/fields/code_field.rb +4 -4
- data/lib/avo/fields/country_field.rb +2 -2
- data/lib/avo/fields/currency_field.rb +3 -3
- data/lib/avo/fields/date_field.rb +3 -3
- data/lib/avo/fields/date_time_field.rb +2 -2
- data/lib/avo/fields/external_image_field.rb +2 -2
- data/lib/avo/fields/field_extensions/has_field_name.rb +2 -9
- data/lib/avo/fields/field_extensions/visible_in_different_views.rb +34 -33
- data/lib/avo/fields/file_field.rb +1 -1
- data/lib/avo/fields/files_field.rb +2 -2
- data/lib/avo/fields/gravatar_field.rb +10 -10
- data/lib/avo/fields/has_and_belongs_to_many_field.rb +1 -1
- data/lib/avo/fields/has_many_field.rb +1 -1
- data/lib/avo/fields/has_one_field.rb +2 -2
- data/lib/avo/fields/heading_field.rb +2 -2
- data/lib/avo/fields/hidden_field.rb +1 -1
- data/lib/avo/fields/id_field.rb +3 -3
- data/lib/avo/fields/key_value_field.rb +12 -12
- data/lib/avo/fields/markdown_field.rb +2 -2
- data/lib/avo/fields/number_field.rb +3 -3
- data/lib/avo/fields/password_field.rb +1 -1
- data/lib/avo/fields/select_field.rb +8 -12
- data/lib/avo/fields/status_field.rb +4 -4
- data/lib/avo/fields/text_field.rb +2 -2
- data/lib/avo/fields/textarea_field.rb +2 -2
- data/lib/avo/fields/trix_field.rb +1 -1
- data/lib/avo/fields_collector.rb +30 -0
- data/lib/avo/filters/base_filter.rb +6 -6
- data/lib/avo/filters/boolean_filter.rb +1 -1
- data/lib/avo/filters/select_filter.rb +1 -1
- data/lib/avo/grid_collector.rb +39 -0
- data/lib/avo/has_context.rb +7 -0
- data/lib/avo/licensing/h_q.rb +56 -55
- data/lib/avo/licensing/license.rb +5 -5
- data/lib/avo/licensing/license_manager.rb +4 -4
- data/lib/avo/licensing/null_license.rb +2 -2
- data/lib/avo/licensing/pro_license.rb +1 -1
- data/lib/avo/loaders/fields_loader.rb +4 -4
- data/lib/avo/services/authorization_service.rb +2 -2
- data/lib/avo/services/panel_service.rb +4 -4
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/action_generator.rb +4 -4
- data/lib/generators/avo/controller_generator.rb +4 -4
- data/lib/generators/avo/filter_generator.rb +5 -5
- data/lib/generators/avo/install_generator.rb +8 -8
- data/lib/generators/avo/locales_generator.rb +5 -5
- data/lib/generators/avo/partials_generator.rb +4 -4
- data/lib/generators/avo/resource_generator.rb +5 -5
- data/lib/generators/avo/templates/action.tt +1 -5
- data/lib/generators/avo/templates/resource/resource.tt +3 -13
- data/lib/tasks/avo_tasks.rake +0 -60
- data/public/avo-packs/css/application-4e16d6a6.css +5975 -0
- data/public/avo-packs/css/application-4e16d6a6.css.br +0 -0
- data/public/avo-packs/css/application-4e16d6a6.css.gz +0 -0
- data/public/avo-packs/css/application-4e16d6a6.css.map +1 -0
- data/public/avo-packs/css/application-4e16d6a6.css.map.br +0 -0
- data/public/avo-packs/css/application-4e16d6a6.css.map.gz +0 -0
- data/public/avo-packs/js/219-9aa2b689f44613118203.chunk.js +2 -0
- data/public/avo-packs/js/219-9aa2b689f44613118203.chunk.js.br +0 -0
- data/public/avo-packs/js/219-9aa2b689f44613118203.chunk.js.gz +0 -0
- data/public/avo-packs/js/219-9aa2b689f44613118203.chunk.js.map +1 -0
- data/public/avo-packs/js/219-9aa2b689f44613118203.chunk.js.map.br +0 -0
- data/public/avo-packs/js/219-9aa2b689f44613118203.chunk.js.map.gz +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js +26 -0
- data/public/avo-packs/js/{application-8849c6e2c8f75d55c666.js.LICENSE.txt → application-8eb130a4688f2c667703.js.LICENSE.txt} +17 -17
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.br +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.gz +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map +1 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map.br +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map.gz +0 -0
- data/public/avo-packs/manifest.json +46 -23
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-00fbd8a72a3708b8314cce5f0515640e.svg → images/13ae283c0d7cc04efe7e.svg} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-00fbd8a72a3708b8314cce5f0515640e.svg.br → images/13ae283c0d7cc04efe7e.svg.br} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-00fbd8a72a3708b8314cce5f0515640e.svg.gz → images/13ae283c0d7cc04efe7e.svg.gz} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-35bd1c96bc2e402cf22ea812ae067995.svg → images/195026a50008c53526ef.svg} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-35bd1c96bc2e402cf22ea812ae067995.svg.br → images/195026a50008c53526ef.svg.br} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-35bd1c96bc2e402cf22ea812ae067995.svg.gz → images/195026a50008c53526ef.svg.gz} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-cb632c9fe211ba2c2bf1564c9a9295cc.woff → images/1f30e08faa7c60d1f7ac.woff} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-2cc22f9c0cf217cbfc371f3b74992305.ttf → images/1fd17dabf6b7d2b15348.ttf} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-2cc22f9c0cf217cbfc371f3b74992305.ttf.br → images/1fd17dabf6b7d2b15348.ttf.br} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-2cc22f9c0cf217cbfc371f3b74992305.ttf.gz → images/1fd17dabf6b7d2b15348.ttf.gz} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-bcf84d6cb8a0ac214c8c14ba9af834f3.woff2 → images/39a18f443d434999b89b.woff2} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-412073df419ad5f6f8f2ea76eb4aced9.woff2 → images/4ad349571e28bb59c5a5.woff2} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-2fae1e2418251b68fe5d0505ab93dd5c.eot → images/57a5470848663767abbf.eot} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-df8c4bee41b6ca0ed2b7b71456ed7fbb.ttf → images/b2e4cf0fab6c8ca66b7f.ttf} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-df8c4bee41b6ca0ed2b7b71456ed7fbb.ttf.br → images/b2e4cf0fab6c8ca66b7f.ttf.br} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-regular-df8c4bee41b6ca0ed2b7b71456ed7fbb.ttf.gz → images/b2e4cf0fab6c8ca66b7f.ttf.gz} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-df7e79af617f98cd3b95d320e8b2a1af.eot → images/b78d61ab7e046de8c156.eot} +0 -0
- data/public/avo-packs/media/{fonts/nunito-v16-latin-700-7c472b19cb573f537bad8ef62ca917ac.woff → images/c9ab29becb76ddab01d0.woff} +0 -0
- data/public/avo-packs/media/images/{logo-edf8d8d0d263e0c1f73bb32a222d9991.png → f1b4befac91a3336db9a.png} +0 -0
- metadata +144 -127
- data/app/frontend/css/components/code.css +0 -27
- data/app/views/layouts/avo/application_vue.html.erb +0 -61
- data/config/webpack/environment.js +0 -18
- data/db/migrate/20210305082639_add_url_to_teams.rb +0 -5
- data/public/avo-packs/css/application-c75ac28c.css +0 -6
- data/public/avo-packs/css/application-c75ac28c.css.br +0 -0
- data/public/avo-packs/css/application-c75ac28c.css.gz +0 -0
- data/public/avo-packs/js/1-0565987ca0c3045602ad.chunk.js +0 -2
- data/public/avo-packs/js/1-0565987ca0c3045602ad.chunk.js.br +0 -0
- data/public/avo-packs/js/1-0565987ca0c3045602ad.chunk.js.gz +0 -0
- data/public/avo-packs/js/1-0565987ca0c3045602ad.chunk.js.map +0 -1
- data/public/avo-packs/js/1-0565987ca0c3045602ad.chunk.js.map.br +0 -0
- data/public/avo-packs/js/1-0565987ca0c3045602ad.chunk.js.map.gz +0 -0
- data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js +0 -26
- data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.br +0 -0
- data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.gz +0 -0
- data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.map +0 -1
- data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.map.br +0 -0
- data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.map.gz +0 -0
- data/public/avo-packs/manifest.json.br +0 -0
- data/public/avo-packs/manifest.json.gz +0 -0
data/lib/avo.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
3
|
-
require_relative
|
1
|
+
require "zeitwerk"
|
2
|
+
require_relative "avo/version"
|
3
|
+
require_relative "avo/engine" if defined?(Rails)
|
4
4
|
|
5
5
|
loader = Zeitwerk::Loader.for_gem
|
6
6
|
loader.setup
|
7
7
|
|
8
8
|
module Avo
|
9
|
-
ROOT_PATH = Pathname.new(File.join(__dir__,
|
10
|
-
IN_DEVELOPMENT = ENV[
|
9
|
+
ROOT_PATH = Pathname.new(File.join(__dir__, ".."))
|
10
|
+
IN_DEVELOPMENT = ENV["AVO_IN_DEVELOPMENT"] == "1"
|
11
11
|
PACKED = !IN_DEVELOPMENT
|
12
12
|
|
13
13
|
class << self
|
14
14
|
def webpacker
|
15
15
|
@webpacker ||= ::Webpacker::Instance.new(
|
16
16
|
root_path: ROOT_PATH,
|
17
|
-
config_path: ROOT_PATH.join(
|
17
|
+
config_path: ROOT_PATH.join("config/webpacker.yml")
|
18
18
|
)
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Avo
|
2
|
+
class ActionModel
|
3
|
+
include ActiveModel::Model
|
4
|
+
|
5
|
+
# This class augments a model the action form declaration.
|
6
|
+
def initialize(attributes = {})
|
7
|
+
set_attr_accessors attributes
|
8
|
+
|
9
|
+
super(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_attr_accessors(attributes)
|
15
|
+
attributes.each do |k, v|
|
16
|
+
self.class.class_eval { attr_accessor k }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/avo/app.rb
CHANGED
@@ -10,32 +10,15 @@ module Avo
|
|
10
10
|
class_attribute :license, default: nil
|
11
11
|
|
12
12
|
class << self
|
13
|
-
# def load_controllers
|
14
|
-
# BaseResource.descendants.each do |resource|
|
15
|
-
# controller_name = "#{resource.to_s.gsub('Resource', '').pluralize}Controller"
|
16
|
-
# puts controller_name.inspect
|
17
|
-
# # eval <<DYNAMIC
|
18
|
-
# # class #{controller_name} < Avo::ResourcesController
|
19
|
-
# # # title :Person
|
20
|
-
# # # attribute :name, String
|
21
|
-
# # # ...or substitute other stuff in here.
|
22
|
-
# # end
|
23
|
-
# # DYNAMIC
|
24
|
-
|
25
|
-
# Avo.const_set(controller_name.to_sym, Class.new(Avo::ResourcesController))
|
26
|
-
# # puts controller_name.inspect
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
|
30
13
|
def boot
|
31
14
|
init_fields
|
32
15
|
|
33
16
|
I18n.locale = Avo.configuration.language_code
|
34
17
|
|
35
|
-
if Rails.cache.
|
36
|
-
|
18
|
+
if Rails.cache.instance_of?(ActiveSupport::Cache::NullStore)
|
19
|
+
app[:cache_store] ||= ActiveSupport::Cache::MemoryStore.new
|
37
20
|
else
|
38
|
-
|
21
|
+
app[:cache_store] = Rails.cache
|
39
22
|
end
|
40
23
|
end
|
41
24
|
|
@@ -52,7 +35,7 @@ module Avo
|
|
52
35
|
end
|
53
36
|
|
54
37
|
def cache_store
|
55
|
-
|
38
|
+
app[:cache_store]
|
56
39
|
end
|
57
40
|
|
58
41
|
# This method will find all fields available in the Avo::Fields namespace and add them to the fields class_variable array
|
@@ -64,48 +47,23 @@ module Avo
|
|
64
47
|
# Avo::Fields::DateTimeField -> date_time
|
65
48
|
def init_fields
|
66
49
|
Avo::Fields::BaseField.descendants.each do |class_name|
|
67
|
-
next if class_name.to_s ==
|
50
|
+
next if class_name.to_s == "BaseField"
|
68
51
|
|
69
|
-
if class_name.to_s.end_with?
|
52
|
+
if class_name.to_s.end_with? "Field"
|
70
53
|
load_field class_name.get_field_name, class_name
|
71
54
|
end
|
72
55
|
end
|
73
56
|
end
|
74
57
|
|
75
58
|
def load_field(method_name, klass)
|
76
|
-
|
59
|
+
fields.push(
|
77
60
|
name: method_name,
|
78
|
-
class: klass
|
61
|
+
class: klass
|
79
62
|
)
|
80
|
-
|
81
|
-
# Avo::Loaders::FieldsLoader.define_method method_name.to_sym do |*args, &block|
|
82
|
-
# puts ['Avo::Loaders::FieldsLoader.define_method->', args, block.present?].inspect
|
83
|
-
|
84
|
-
# if block.present?
|
85
|
-
# puts '111->'.inspect
|
86
|
-
# field = klass.new(args[0], **args[1] || {}, &block)
|
87
|
-
# else
|
88
|
-
# puts '222->'.inspect
|
89
|
-
# field = klass.new(args[0], **args[1] || {})
|
90
|
-
# end
|
91
|
-
|
92
|
-
# puts field.inspect
|
93
|
-
|
94
|
-
# self.bag.push field
|
95
|
-
|
96
|
-
# # field
|
97
|
-
# # if block.present?
|
98
|
-
# # field_class = klass::new(args[0], **args[1] || {}, &block)
|
99
|
-
# # else
|
100
|
-
# # field_class = klass::new(args[0], **args[1] || {})
|
101
|
-
# # end
|
102
|
-
|
103
|
-
# # klass_entity.add_field(self, field_class)
|
104
|
-
# end
|
105
63
|
end
|
106
64
|
|
107
65
|
def init_resources
|
108
|
-
|
66
|
+
app[:resources] = BaseResource.descendants
|
109
67
|
.select do |resource|
|
110
68
|
resource != BaseResource
|
111
69
|
end
|
@@ -117,14 +75,14 @@ module Avo
|
|
117
75
|
end
|
118
76
|
|
119
77
|
def get_resources
|
120
|
-
|
78
|
+
app[:resources]
|
121
79
|
end
|
122
80
|
|
123
81
|
# Returns the Avo resource by camelized name
|
124
82
|
#
|
125
83
|
# get_resource_by_name('User') => UserResource
|
126
84
|
def get_resource(resource)
|
127
|
-
|
85
|
+
app[:resources].find do |available_resource|
|
128
86
|
"#{resource}Resource".safe_constantize == available_resource.class
|
129
87
|
end
|
130
88
|
end
|
@@ -133,7 +91,7 @@ module Avo
|
|
133
91
|
#
|
134
92
|
# get_resource_by_name('user') => UserResource
|
135
93
|
def get_resource_by_name(name)
|
136
|
-
|
94
|
+
get_resource name.singularize.camelize
|
137
95
|
end
|
138
96
|
|
139
97
|
# Returns the Avo resource by singular snake_cased name
|
@@ -152,7 +110,7 @@ module Avo
|
|
152
110
|
# get_resource_by_controller_name('users') => UserResource
|
153
111
|
def get_resource_by_controller_name(name)
|
154
112
|
get_resources.find do |resource|
|
155
|
-
resource.model_class.to_s.pluralize.underscore.
|
113
|
+
resource.model_class.to_s.pluralize.underscore.tr("/", "_") == name.to_s
|
156
114
|
end
|
157
115
|
end
|
158
116
|
|
@@ -166,7 +124,7 @@ module Avo
|
|
166
124
|
def get_available_resources(user = nil)
|
167
125
|
App.get_resources
|
168
126
|
.select do |resource|
|
169
|
-
Services::AuthorizationService.authorize user, resource.model, Avo.configuration.authorization_methods.stringify_keys[
|
127
|
+
Services::AuthorizationService.authorize user, resource.model, Avo.configuration.authorization_methods.stringify_keys["index"], raise_exception: false
|
170
128
|
end
|
171
129
|
.sort_by { |r| r.name }
|
172
130
|
end
|
@@ -181,17 +139,17 @@ module Avo
|
|
181
139
|
# We should eager load all the classes so we find all descendants
|
182
140
|
Rails.application.eager_load!
|
183
141
|
|
184
|
-
|
142
|
+
proc do
|
185
143
|
BaseResource.descendants
|
186
144
|
.select do |resource|
|
187
145
|
resource != :BaseResource
|
188
146
|
end
|
189
147
|
.map do |resource|
|
190
148
|
if resource.is_a? Class
|
191
|
-
if resource.model_class.present?
|
192
|
-
|
149
|
+
route_key = if resource.model_class.present?
|
150
|
+
resource.model_class.model_name.route_key
|
193
151
|
else
|
194
|
-
|
152
|
+
resource.to_s.underscore.gsub("_resource", "").downcase.pluralize.to_sym
|
195
153
|
end
|
196
154
|
|
197
155
|
resources route_key
|
data/lib/avo/base_action.rb
CHANGED
@@ -1,121 +1,124 @@
|
|
1
1
|
module Avo
|
2
2
|
class BaseAction
|
3
|
+
extend FieldsCollector
|
4
|
+
extend HasContext
|
5
|
+
|
3
6
|
class_attribute :name, default: self.class.to_s.demodulize.underscore.humanize(keep_id_suffix: true)
|
4
7
|
class_attribute :message
|
5
|
-
class_attribute :
|
6
|
-
class_attribute :
|
8
|
+
class_attribute :confirm_button_label
|
9
|
+
class_attribute :cancel_button_label
|
7
10
|
class_attribute :no_confirmation, default: false
|
8
|
-
class_attribute :
|
11
|
+
class_attribute :model
|
12
|
+
class_attribute :view
|
13
|
+
class_attribute :user
|
14
|
+
class_attribute :resource
|
15
|
+
class_attribute :fields
|
9
16
|
|
10
17
|
attr_accessor :response
|
11
18
|
attr_accessor :model
|
12
19
|
attr_accessor :resource
|
13
20
|
attr_accessor :user
|
21
|
+
attr_accessor :fields_loader
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
yield(fields_loader)
|
20
|
-
end
|
23
|
+
def initialize(model: nil, resource: nil, user: nil)
|
24
|
+
self.class.model = model if model.present?
|
25
|
+
self.class.resource = resource if resource.present?
|
26
|
+
self.class.user = user if user.present?
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize
|
28
|
-
self.class.message ||= I18n.t('avo.are_you_sure_you_want_to_run_this_option')
|
29
|
-
self.class.confirm_text ||= I18n.t('avo.run')
|
30
|
-
self.class.cancel_text ||= I18n.t('avo.cancel')
|
28
|
+
self.class.message ||= I18n.t("avo.are_you_sure_you_want_to_run_this_option")
|
29
|
+
self.class.confirm_button_label ||= I18n.t("avo.run")
|
30
|
+
self.class.cancel_button_label ||= I18n.t("avo.cancel")
|
31
31
|
|
32
32
|
@response ||= {}
|
33
33
|
@response[:message_type] ||= :notice
|
34
|
-
@response[:message] ||= I18n.t(
|
34
|
+
@response[:message] ||= I18n.t("avo.action_ran_successfully")
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
39
|
-
field.hydrate(action: self, model: @model)
|
40
|
-
end
|
41
|
-
.select do |field|
|
42
|
-
field.can_see.present? ? field.can_see.call : true
|
43
|
-
end
|
37
|
+
def context
|
38
|
+
self.class.context
|
44
39
|
end
|
45
40
|
|
46
41
|
def get_field_definitions
|
47
|
-
return [] if self.class.
|
42
|
+
return [] if self.class.fields.blank?
|
48
43
|
|
49
|
-
self.class.
|
44
|
+
self.class.fields.map do |field|
|
50
45
|
field.hydrate(action: self)
|
51
46
|
end
|
52
47
|
end
|
53
48
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
def get_fields
|
50
|
+
get_field_definitions.map do |field|
|
51
|
+
field.hydrate(action: self, model: @model)
|
52
|
+
end
|
53
|
+
.select do |field|
|
54
|
+
field.visible?
|
55
|
+
end
|
56
|
+
end
|
58
57
|
|
59
|
-
|
58
|
+
def get_attributes_for_action
|
59
|
+
get_fields.map do |field|
|
60
|
+
[field.id, field.value]
|
61
|
+
end
|
62
|
+
.to_h
|
60
63
|
end
|
61
64
|
|
62
|
-
def handle_action(
|
65
|
+
def handle_action(models:, fields:)
|
63
66
|
avo_fields = get_fields.map { |field| [field.id, field] }.to_h
|
64
67
|
|
65
|
-
if
|
66
|
-
|
68
|
+
if fields.present?
|
69
|
+
processed_fields = fields.to_unsafe_h.map do |name, value|
|
67
70
|
[name, avo_fields[name.to_sym].resolve_attribute(value)]
|
68
71
|
end
|
69
72
|
|
70
|
-
|
73
|
+
processed_fields = processed_fields.to_h
|
71
74
|
else
|
72
|
-
|
75
|
+
processed_fields = {}
|
73
76
|
end
|
74
77
|
|
75
|
-
|
78
|
+
handle models: models, fields: processed_fields
|
76
79
|
|
77
80
|
self
|
78
81
|
end
|
79
82
|
|
80
83
|
def param_id
|
81
|
-
self.class.to_s.demodulize.underscore.
|
84
|
+
self.class.to_s.demodulize.underscore.tr "/", "_"
|
82
85
|
end
|
83
86
|
|
84
87
|
def succeed(text)
|
85
|
-
|
86
|
-
|
88
|
+
response[:message_type] = :notice
|
89
|
+
response[:message] = text
|
87
90
|
|
88
91
|
self
|
89
92
|
end
|
90
93
|
|
91
94
|
def fail(text)
|
92
|
-
|
93
|
-
|
95
|
+
response[:message_type] = :alert
|
96
|
+
response[:message] = text
|
94
97
|
|
95
98
|
self
|
96
99
|
end
|
97
100
|
|
98
101
|
def redirect_to(path = nil, &block)
|
99
|
-
|
100
|
-
if block.present?
|
101
|
-
|
102
|
+
response[:type] = :redirect
|
103
|
+
response[:path] = if block.present?
|
104
|
+
block
|
102
105
|
else
|
103
|
-
|
106
|
+
path
|
104
107
|
end
|
105
108
|
|
106
109
|
self
|
107
110
|
end
|
108
111
|
|
109
112
|
def reload
|
110
|
-
|
113
|
+
response[:type] = :reload
|
111
114
|
|
112
115
|
self
|
113
116
|
end
|
114
117
|
|
115
118
|
def download(path, filename)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
+
response[:type] = :download
|
120
|
+
response[:path] = path
|
121
|
+
response[:filename] = filename
|
119
122
|
|
120
123
|
self
|
121
124
|
end
|
data/lib/avo/base_resource.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Avo
|
2
2
|
class BaseResource
|
3
3
|
extend ActiveSupport::DescendantsTracker
|
4
|
+
extend FieldsCollector
|
5
|
+
extend HasContext
|
4
6
|
|
5
7
|
attr_accessor :view
|
6
8
|
attr_accessor :model
|
@@ -15,42 +17,29 @@ module Avo
|
|
15
17
|
class_attribute :translation_key
|
16
18
|
class_attribute :default_view_type, default: :table
|
17
19
|
class_attribute :devise_password_optional, default: false
|
18
|
-
class_attribute :fields_loader
|
19
20
|
class_attribute :actions_loader
|
20
21
|
class_attribute :filters_loader
|
21
|
-
class_attribute :
|
22
|
-
class_attribute :
|
23
|
-
class_attribute :grid_body_loader
|
22
|
+
class_attribute :fields
|
23
|
+
class_attribute :grid_loader
|
24
24
|
|
25
25
|
class << self
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
yield(fields_loader)
|
30
|
-
end
|
31
|
-
|
32
|
-
def actions(&block)
|
33
|
-
self.actions_loader ||= Avo::Loaders::ActionsLoader.new
|
26
|
+
def grid(&block)
|
27
|
+
grid_collector = GridCollector.new
|
28
|
+
grid_collector.instance_eval(&block)
|
34
29
|
|
35
|
-
|
30
|
+
self.grid_loader = grid_collector
|
36
31
|
end
|
37
32
|
|
38
|
-
def
|
39
|
-
self.
|
33
|
+
def action(action_class)
|
34
|
+
self.actions_loader ||= Avo::Loaders::Loader.new
|
40
35
|
|
41
|
-
|
36
|
+
self.actions_loader.use action_class
|
42
37
|
end
|
43
38
|
|
44
|
-
def
|
45
|
-
self.
|
46
|
-
self.grid_title_loader ||= Avo::Loaders::FieldsLoader.new
|
47
|
-
self.grid_body_loader ||= Avo::Loaders::FieldsLoader.new
|
48
|
-
|
49
|
-
yield(grid_cover_loader, grid_title_loader, grid_body_loader)
|
50
|
-
end
|
39
|
+
def filter(filter_class)
|
40
|
+
self.filters_loader ||= Avo::Loaders::Loader.new
|
51
41
|
|
52
|
-
|
53
|
-
App.context
|
42
|
+
self.filters_loader.use filter_class
|
54
43
|
end
|
55
44
|
end
|
56
45
|
|
@@ -68,18 +57,26 @@ module Avo
|
|
68
57
|
self
|
69
58
|
end
|
70
59
|
|
60
|
+
def get_field_definitions
|
61
|
+
return [] if self.class.fields.blank?
|
62
|
+
|
63
|
+
self.class.fields.map do |field|
|
64
|
+
field.hydrate(resource: self, panel_name: default_panel_name, user: user)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
71
68
|
def get_fields(panel: nil, reflection: nil)
|
72
69
|
fields = get_field_definitions.select do |field|
|
73
|
-
field.send("show_on_#{@view
|
74
|
-
end
|
75
|
-
.select do |field|
|
76
|
-
field.can_see.present? ? field.can_see.call : true
|
70
|
+
field.send("show_on_#{@view}")
|
77
71
|
end
|
78
|
-
|
72
|
+
.select do |field|
|
73
|
+
field.visible?
|
74
|
+
end
|
75
|
+
.select do |field|
|
79
76
|
unless field.respond_to?(:foreign_key) &&
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
reflection.present? &&
|
78
|
+
reflection.respond_to?(:foreign_key) &&
|
79
|
+
reflection.foreign_key == field.foreign_key
|
83
80
|
true
|
84
81
|
end
|
85
82
|
end
|
@@ -90,27 +87,15 @@ module Avo
|
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
93
|
-
fields
|
90
|
+
fields.map do |field|
|
94
91
|
field.hydrate(model: @model, view: @view, resource: self)
|
95
92
|
end
|
96
|
-
|
97
|
-
fields
|
98
93
|
end
|
99
94
|
|
100
95
|
def get_grid_fields
|
101
|
-
return if self.class.
|
102
|
-
|
103
|
-
card = {
|
104
|
-
cover: [*self.class.grid_cover_loader.bag],
|
105
|
-
title: [*self.class.grid_title_loader.bag],
|
106
|
-
body: [*self.class.grid_body_loader.bag],
|
107
|
-
}
|
96
|
+
return if self.class.grid_loader.blank?
|
108
97
|
|
109
|
-
|
110
|
-
fields = fields.map do |field|
|
111
|
-
field.hydrate(model: @model, view: @view, resource: self)
|
112
|
-
end
|
113
|
-
end
|
98
|
+
self.class.grid_loader.hydrate(model: @model, view: @view, resource: self)
|
114
99
|
end
|
115
100
|
|
116
101
|
def get_filters
|
@@ -125,37 +110,27 @@ module Avo
|
|
125
110
|
self.class.actions_loader.bag
|
126
111
|
end
|
127
112
|
|
128
|
-
def get_field_definitions
|
129
|
-
return [] if self.class.fields_loader.blank?
|
130
|
-
|
131
|
-
self.class.fields_loader.bag.map do |field|
|
132
|
-
field.hydrate(resource: self, panel_name: default_panel_name, user: user)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
113
|
def default_panel_name
|
137
114
|
return @params[:related_name].capitalize if @params[:related_name].present?
|
138
115
|
|
139
116
|
case @view
|
140
117
|
when :show
|
141
|
-
I18n.t(
|
118
|
+
I18n.t("avo.resource_details", item: name.downcase, title: model_title).upcase_first
|
142
119
|
when :edit
|
143
|
-
I18n.t(
|
120
|
+
I18n.t("avo.update_item", item: name.downcase, title: model_title).upcase_first
|
144
121
|
when :new
|
145
|
-
I18n.t(
|
122
|
+
I18n.t("avo.create_new_item", item: name.downcase).upcase_first
|
146
123
|
end
|
147
124
|
end
|
148
125
|
|
149
126
|
def panels
|
150
|
-
|
127
|
+
[
|
151
128
|
{
|
152
129
|
name: default_panel_name,
|
153
130
|
type: :fields,
|
154
|
-
in_panel: true
|
131
|
+
in_panel: true
|
155
132
|
}
|
156
133
|
]
|
157
|
-
|
158
|
-
panels
|
159
134
|
end
|
160
135
|
|
161
136
|
def model_class
|
@@ -163,7 +138,7 @@ module Avo
|
|
163
138
|
|
164
139
|
return @model.class if @model.present?
|
165
140
|
|
166
|
-
self.class.name.demodulize.chomp(
|
141
|
+
self.class.name.demodulize.chomp("Resource").safe_constantize
|
167
142
|
end
|
168
143
|
|
169
144
|
def model_title
|
@@ -177,7 +152,7 @@ module Avo
|
|
177
152
|
|
178
153
|
return I18n.t(@translation_key, count: 1).capitalize if @translation_key
|
179
154
|
|
180
|
-
self.class.name.demodulize.chomp(
|
155
|
+
self.class.name.demodulize.chomp("Resource").titlecase
|
181
156
|
end
|
182
157
|
|
183
158
|
def singular_name
|
@@ -209,14 +184,10 @@ module Avo
|
|
209
184
|
end
|
210
185
|
|
211
186
|
def context
|
212
|
-
|
187
|
+
self.class.context
|
213
188
|
end
|
214
189
|
|
215
|
-
|
216
|
-
# raise NotImplementedError
|
217
|
-
# end
|
218
|
-
|
219
|
-
def query_search(query: '', via_resource_name: , via_resource_id:, user:)
|
190
|
+
def query_search(via_resource_name:, via_resource_id:, user:, query: "")
|
220
191
|
# model_class = self.model
|
221
192
|
|
222
193
|
db_query = AuthorizationService.apply_policy(user, model_class)
|
@@ -224,18 +195,18 @@ module Avo
|
|
224
195
|
if via_resource_name.present?
|
225
196
|
related_model = App.get_resource_by_name(via_resource_name).model
|
226
197
|
|
227
|
-
db_query = related_model.find(via_resource_id).public_send(
|
198
|
+
db_query = related_model.find(via_resource_id).public_send(plural_name.downcase)
|
228
199
|
end
|
229
200
|
|
230
201
|
new_query = []
|
231
202
|
|
232
|
-
[
|
233
|
-
new_query.push
|
203
|
+
[search].flatten.each_with_index do |search_by, index|
|
204
|
+
new_query.push "or" if index != 0
|
234
205
|
|
235
206
|
new_query.push "text(#{search_by}) ILIKE '%#{query}%'"
|
236
207
|
end
|
237
208
|
|
238
|
-
db_query.where(new_query.join(
|
209
|
+
db_query.where(new_query.join(" "))
|
239
210
|
end
|
240
211
|
|
241
212
|
def attached_file_fields
|
@@ -246,7 +217,7 @@ module Avo
|
|
246
217
|
|
247
218
|
def fill_model(model, params)
|
248
219
|
# Map the received params to their actual fields
|
249
|
-
fields_by_database_id =
|
220
|
+
fields_by_database_id = get_field_definitions.map { |field| [field.database_id(model).to_s, field] }.to_h
|
250
221
|
|
251
222
|
params.each do |key, value|
|
252
223
|
field = fields_by_database_id[key]
|
@@ -264,16 +235,16 @@ module Avo
|
|
264
235
|
end
|
265
236
|
|
266
237
|
def file_hash
|
267
|
-
content_to_be_hashed =
|
238
|
+
content_to_be_hashed = ""
|
268
239
|
|
269
240
|
# resource file hash
|
270
|
-
resource_path = Rails.root.join(
|
241
|
+
resource_path = Rails.root.join("app", "avo", "resources", "#{self.class.name.underscore}_resource.rb").to_s
|
271
242
|
if File.file? resource_path
|
272
243
|
content_to_be_hashed += File.read(resource_path)
|
273
244
|
end
|
274
245
|
|
275
246
|
# policy file hash
|
276
|
-
policy_path = Rails.root.join(
|
247
|
+
policy_path = Rails.root.join("app", "policies", "#{self.class.name.underscore.gsub("_resource", "")}_policy.rb").to_s
|
277
248
|
if File.file? policy_path
|
278
249
|
content_to_be_hashed += File.read(policy_path)
|
279
250
|
end
|
@@ -283,9 +254,9 @@ module Avo
|
|
283
254
|
|
284
255
|
def cache_hash(parent_model)
|
285
256
|
if parent_model.present?
|
286
|
-
[
|
257
|
+
[model, file_hash, parent_model]
|
287
258
|
else
|
288
|
-
[
|
259
|
+
[model, file_hash]
|
289
260
|
end
|
290
261
|
end
|
291
262
|
|
@@ -295,24 +266,24 @@ module Avo
|
|
295
266
|
default_values = get_fields.select do |field|
|
296
267
|
!field.computed
|
297
268
|
end
|
298
|
-
|
299
|
-
|
300
|
-
|
269
|
+
.map do |field|
|
270
|
+
id = field.id
|
271
|
+
value = field.value
|
301
272
|
|
302
|
-
|
303
|
-
|
273
|
+
if field.respond_to? :foreign_key
|
274
|
+
id = field.foreign_key.to_sym
|
304
275
|
|
305
|
-
|
276
|
+
reflection = @model._reflections[@params[:via_relation]]
|
306
277
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
278
|
+
if reflection.present? && reflection.foreign_key.present?
|
279
|
+
value = @params[:via_resource_id]
|
280
|
+
end
|
281
|
+
end
|
311
282
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
283
|
+
[id, value]
|
284
|
+
end
|
285
|
+
.to_h
|
286
|
+
.select do |id, value|
|
316
287
|
value.present?
|
317
288
|
end
|
318
289
|
|