avo 0.5.0.beta6 → 0.5.0.beta11
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 +124 -116
- 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 +34 -62
- data/lib/avo/base_action.rb +55 -52
- data/lib/avo/base_resource.rb +69 -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 +13 -14
- 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,35 +75,45 @@ 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
|
-
# get_resource_by_name('User') =>
|
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
|
131
89
|
|
132
90
|
# Returns the Avo resource by singular snake_cased name
|
133
91
|
#
|
134
|
-
# get_resource_by_name('user') =>
|
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
|
140
98
|
#
|
141
|
-
# get_resource_by_name('User') =>
|
142
|
-
# get_resource_by_name(User) =>
|
99
|
+
# get_resource_by_name('User') => UserResource
|
100
|
+
# get_resource_by_name(User) => UserResource
|
143
101
|
def get_resource_by_model_name(name)
|
144
102
|
get_resources.find do |resource|
|
145
103
|
resource.model_class.model_name.name == name.to_s
|
146
104
|
end
|
147
105
|
end
|
148
106
|
|
107
|
+
# Returns the Avo resource by singular snake_cased name
|
108
|
+
#
|
109
|
+
# get_resource_by_controller_name('delayed_backend_active_record_jobs') => DelayedJobResource
|
110
|
+
# get_resource_by_controller_name('users') => UserResource
|
111
|
+
def get_resource_by_controller_name(name)
|
112
|
+
get_resources.find do |resource|
|
113
|
+
resource.model_class.to_s.pluralize.underscore.tr("/", "_") == name.to_s
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
149
117
|
# Returns the Rails model class by singular snake_cased name
|
150
118
|
#
|
151
119
|
# get_model_class_by_name('user') => User
|
@@ -156,7 +124,7 @@ module Avo
|
|
156
124
|
def get_available_resources(user = nil)
|
157
125
|
App.get_resources
|
158
126
|
.select do |resource|
|
159
|
-
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
|
160
128
|
end
|
161
129
|
.sort_by { |r| r.name }
|
162
130
|
end
|
@@ -171,14 +139,18 @@ module Avo
|
|
171
139
|
# We should eager load all the classes so we find all descendants
|
172
140
|
Rails.application.eager_load!
|
173
141
|
|
174
|
-
|
142
|
+
proc do
|
175
143
|
BaseResource.descendants
|
176
144
|
.select do |resource|
|
177
|
-
resource != :
|
145
|
+
resource != :BaseResource
|
178
146
|
end
|
179
147
|
.map do |resource|
|
180
148
|
if resource.is_a? Class
|
181
|
-
route_key = resource.
|
149
|
+
route_key = if resource.model_class.present?
|
150
|
+
resource.model_class.model_name.route_key
|
151
|
+
else
|
152
|
+
resource.to_s.underscore.gsub("_resource", "").downcase.pluralize.to_sym
|
153
|
+
end
|
182
154
|
|
183
155
|
resources route_key
|
184
156
|
end
|
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
|
@@ -11,45 +13,33 @@ module Avo
|
|
11
13
|
class_attribute :title, default: :id
|
12
14
|
class_attribute :search, default: [:id]
|
13
15
|
class_attribute :includes, default: []
|
16
|
+
class_attribute :model_class
|
14
17
|
class_attribute :translation_key
|
15
18
|
class_attribute :default_view_type, default: :table
|
16
19
|
class_attribute :devise_password_optional, default: false
|
17
|
-
class_attribute :fields_loader
|
18
20
|
class_attribute :actions_loader
|
19
21
|
class_attribute :filters_loader
|
20
|
-
class_attribute :
|
21
|
-
class_attribute :
|
22
|
-
class_attribute :grid_body_loader
|
22
|
+
class_attribute :fields
|
23
|
+
class_attribute :grid_loader
|
23
24
|
|
24
25
|
class << self
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
yield(fields_loader)
|
29
|
-
end
|
30
|
-
|
31
|
-
def actions(&block)
|
32
|
-
self.actions_loader ||= Avo::Loaders::ActionsLoader.new
|
26
|
+
def grid(&block)
|
27
|
+
grid_collector = GridCollector.new
|
28
|
+
grid_collector.instance_eval(&block)
|
33
29
|
|
34
|
-
|
30
|
+
self.grid_loader = grid_collector
|
35
31
|
end
|
36
32
|
|
37
|
-
def
|
38
|
-
self.
|
33
|
+
def action(action_class)
|
34
|
+
self.actions_loader ||= Avo::Loaders::Loader.new
|
39
35
|
|
40
|
-
|
36
|
+
self.actions_loader.use action_class
|
41
37
|
end
|
42
38
|
|
43
|
-
def
|
44
|
-
self.
|
45
|
-
self.grid_title_loader ||= Avo::Loaders::FieldsLoader.new
|
46
|
-
self.grid_body_loader ||= Avo::Loaders::FieldsLoader.new
|
47
|
-
|
48
|
-
yield(grid_cover_loader, grid_title_loader, grid_body_loader)
|
49
|
-
end
|
39
|
+
def filter(filter_class)
|
40
|
+
self.filters_loader ||= Avo::Loaders::Loader.new
|
50
41
|
|
51
|
-
|
52
|
-
App.context
|
42
|
+
self.filters_loader.use filter_class
|
53
43
|
end
|
54
44
|
end
|
55
45
|
|
@@ -67,18 +57,26 @@ module Avo
|
|
67
57
|
self
|
68
58
|
end
|
69
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
|
+
|
70
68
|
def get_fields(panel: nil, reflection: nil)
|
71
69
|
fields = get_field_definitions.select do |field|
|
72
|
-
field.send("show_on_#{@view
|
73
|
-
end
|
74
|
-
.select do |field|
|
75
|
-
field.can_see.present? ? field.can_see.call : true
|
70
|
+
field.send("show_on_#{@view}")
|
76
71
|
end
|
77
|
-
|
72
|
+
.select do |field|
|
73
|
+
field.visible?
|
74
|
+
end
|
75
|
+
.select do |field|
|
78
76
|
unless field.respond_to?(:foreign_key) &&
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
reflection.present? &&
|
78
|
+
reflection.respond_to?(:foreign_key) &&
|
79
|
+
reflection.foreign_key == field.foreign_key
|
82
80
|
true
|
83
81
|
end
|
84
82
|
end
|
@@ -89,27 +87,15 @@ module Avo
|
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
92
|
-
fields
|
90
|
+
fields.map do |field|
|
93
91
|
field.hydrate(model: @model, view: @view, resource: self)
|
94
92
|
end
|
95
|
-
|
96
|
-
fields
|
97
93
|
end
|
98
94
|
|
99
95
|
def get_grid_fields
|
100
|
-
return if self.class.
|
96
|
+
return if self.class.grid_loader.blank?
|
101
97
|
|
102
|
-
|
103
|
-
cover: [*self.class.grid_cover_loader.bag],
|
104
|
-
title: [*self.class.grid_title_loader.bag],
|
105
|
-
body: [*self.class.grid_body_loader.bag],
|
106
|
-
}
|
107
|
-
|
108
|
-
card.each do |section, fields|
|
109
|
-
fields = fields.map do |field|
|
110
|
-
field.hydrate(model: @model, view: @view, resource: self)
|
111
|
-
end
|
112
|
-
end
|
98
|
+
self.class.grid_loader.hydrate(model: @model, view: @view, resource: self)
|
113
99
|
end
|
114
100
|
|
115
101
|
def get_filters
|
@@ -124,43 +110,35 @@ module Avo
|
|
124
110
|
self.class.actions_loader.bag
|
125
111
|
end
|
126
112
|
|
127
|
-
def get_field_definitions
|
128
|
-
return [] if self.class.fields_loader.blank?
|
129
|
-
|
130
|
-
self.class.fields_loader.bag.map do |field|
|
131
|
-
field.hydrate(resource: self, panel_name: default_panel_name, user: user)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
113
|
def default_panel_name
|
136
114
|
return @params[:related_name].capitalize if @params[:related_name].present?
|
137
115
|
|
138
116
|
case @view
|
139
117
|
when :show
|
140
|
-
I18n.t(
|
118
|
+
I18n.t("avo.resource_details", item: name.downcase, title: model_title).upcase_first
|
141
119
|
when :edit
|
142
|
-
I18n.t(
|
120
|
+
I18n.t("avo.update_item", item: name.downcase, title: model_title).upcase_first
|
143
121
|
when :new
|
144
|
-
I18n.t(
|
122
|
+
I18n.t("avo.create_new_item", item: name.downcase).upcase_first
|
145
123
|
end
|
146
124
|
end
|
147
125
|
|
148
126
|
def panels
|
149
|
-
|
127
|
+
[
|
150
128
|
{
|
151
129
|
name: default_panel_name,
|
152
130
|
type: :fields,
|
153
|
-
in_panel: true
|
131
|
+
in_panel: true
|
154
132
|
}
|
155
133
|
]
|
156
|
-
|
157
|
-
panels
|
158
134
|
end
|
159
135
|
|
160
136
|
def model_class
|
137
|
+
return self.class.model_class if self.class.model_class.present?
|
138
|
+
|
161
139
|
return @model.class if @model.present?
|
162
140
|
|
163
|
-
self.class.name.demodulize.chomp(
|
141
|
+
self.class.name.demodulize.chomp("Resource").safe_constantize
|
164
142
|
end
|
165
143
|
|
166
144
|
def model_title
|
@@ -174,7 +152,7 @@ module Avo
|
|
174
152
|
|
175
153
|
return I18n.t(@translation_key, count: 1).capitalize if @translation_key
|
176
154
|
|
177
|
-
self.class.name.demodulize.chomp(
|
155
|
+
self.class.name.demodulize.chomp("Resource").titlecase
|
178
156
|
end
|
179
157
|
|
180
158
|
def singular_name
|
@@ -206,14 +184,10 @@ module Avo
|
|
206
184
|
end
|
207
185
|
|
208
186
|
def context
|
209
|
-
|
187
|
+
self.class.context
|
210
188
|
end
|
211
189
|
|
212
|
-
|
213
|
-
# raise NotImplementedError
|
214
|
-
# end
|
215
|
-
|
216
|
-
def query_search(query: '', via_resource_name: , via_resource_id:, user:)
|
190
|
+
def query_search(via_resource_name:, via_resource_id:, user:, query: "")
|
217
191
|
# model_class = self.model
|
218
192
|
|
219
193
|
db_query = AuthorizationService.apply_policy(user, model_class)
|
@@ -221,18 +195,18 @@ module Avo
|
|
221
195
|
if via_resource_name.present?
|
222
196
|
related_model = App.get_resource_by_name(via_resource_name).model
|
223
197
|
|
224
|
-
db_query = related_model.find(via_resource_id).public_send(
|
198
|
+
db_query = related_model.find(via_resource_id).public_send(plural_name.downcase)
|
225
199
|
end
|
226
200
|
|
227
201
|
new_query = []
|
228
202
|
|
229
|
-
[
|
230
|
-
new_query.push
|
203
|
+
[search].flatten.each_with_index do |search_by, index|
|
204
|
+
new_query.push "or" if index != 0
|
231
205
|
|
232
206
|
new_query.push "text(#{search_by}) ILIKE '%#{query}%'"
|
233
207
|
end
|
234
208
|
|
235
|
-
db_query.where(new_query.join(
|
209
|
+
db_query.where(new_query.join(" "))
|
236
210
|
end
|
237
211
|
|
238
212
|
def attached_file_fields
|
@@ -243,7 +217,7 @@ module Avo
|
|
243
217
|
|
244
218
|
def fill_model(model, params)
|
245
219
|
# Map the received params to their actual fields
|
246
|
-
fields_by_database_id =
|
220
|
+
fields_by_database_id = get_field_definitions.map { |field| [field.database_id(model).to_s, field] }.to_h
|
247
221
|
|
248
222
|
params.each do |key, value|
|
249
223
|
field = fields_by_database_id[key]
|
@@ -261,16 +235,16 @@ module Avo
|
|
261
235
|
end
|
262
236
|
|
263
237
|
def file_hash
|
264
|
-
content_to_be_hashed =
|
238
|
+
content_to_be_hashed = ""
|
265
239
|
|
266
240
|
# resource file hash
|
267
|
-
resource_path = Rails.root.join(
|
241
|
+
resource_path = Rails.root.join("app", "avo", "resources", "#{name.underscore}.rb").to_s
|
268
242
|
if File.file? resource_path
|
269
243
|
content_to_be_hashed += File.read(resource_path)
|
270
244
|
end
|
271
245
|
|
272
246
|
# policy file hash
|
273
|
-
policy_path = Rails.root.join(
|
247
|
+
policy_path = Rails.root.join("app", "policies", "#{name.underscore}_policy.rb").to_s
|
274
248
|
if File.file? policy_path
|
275
249
|
content_to_be_hashed += File.read(policy_path)
|
276
250
|
end
|
@@ -280,9 +254,9 @@ module Avo
|
|
280
254
|
|
281
255
|
def cache_hash(parent_model)
|
282
256
|
if parent_model.present?
|
283
|
-
[
|
257
|
+
[model, file_hash, parent_model]
|
284
258
|
else
|
285
|
-
[
|
259
|
+
[model, file_hash]
|
286
260
|
end
|
287
261
|
end
|
288
262
|
|
@@ -292,24 +266,24 @@ module Avo
|
|
292
266
|
default_values = get_fields.select do |field|
|
293
267
|
!field.computed
|
294
268
|
end
|
295
|
-
|
296
|
-
|
297
|
-
|
269
|
+
.map do |field|
|
270
|
+
id = field.id
|
271
|
+
value = field.value
|
298
272
|
|
299
|
-
|
300
|
-
|
273
|
+
if field.respond_to? :foreign_key
|
274
|
+
id = field.foreign_key.to_sym
|
301
275
|
|
302
|
-
|
276
|
+
reflection = @model._reflections[@params[:via_relation]]
|
303
277
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
278
|
+
if reflection.present? && reflection.foreign_key.present?
|
279
|
+
value = @params[:via_resource_id]
|
280
|
+
end
|
281
|
+
end
|
308
282
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
283
|
+
[id, value]
|
284
|
+
end
|
285
|
+
.to_h
|
286
|
+
.select do |id, value|
|
313
287
|
value.present?
|
314
288
|
end
|
315
289
|
|