drewda_rails_admin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +53 -0
- data/LICENSE.md +20 -0
- data/README.md +160 -0
- data/Rakefile +19 -0
- data/app/assets/images/rails_admin/aristo/images/bg_fallback.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/icon_sprite.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/progress_bar.gif +0 -0
- data/app/assets/images/rails_admin/aristo/images/slider_handles.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
- data/app/assets/images/rails_admin/bullet_black.png +0 -0
- data/app/assets/images/rails_admin/bullet_white.png +0 -0
- data/app/assets/images/rails_admin/calendar.png +0 -0
- data/app/assets/images/rails_admin/clock.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_background.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hex.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_h.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_s.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_indic.gif +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_overlay.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_g.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_r.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_select.gif +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_submit.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_background.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hex.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_h.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_s.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_indic.gif +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_g.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_r.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_submit.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/select.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/select2.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/slider.png +0 -0
- data/app/assets/images/rails_admin/logo.png +0 -0
- data/app/assets/images/rails_admin/magnifier.png +0 -0
- data/app/assets/images/rails_admin/multiselect/icon_sprite.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-dark.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-light.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-dark.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-light.png +0 -0
- data/app/assets/javascripts/rails_admin/custom/ui.js +12 -0
- data/app/assets/javascripts/rails_admin/jquery.colorpicker.js +484 -0
- data/app/assets/javascripts/rails_admin/jquery.pjax.js +431 -0
- data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +1371 -0
- data/app/assets/javascripts/rails_admin/ra.datetimepicker.js +67 -0
- data/app/assets/javascripts/rails_admin/ra.filter-box.js +129 -0
- data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +280 -0
- data/app/assets/javascripts/rails_admin/ra.filtering-select.js +181 -0
- data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +40 -0
- data/app/assets/javascripts/rails_admin/ra.remote-form.js +150 -0
- data/app/assets/javascripts/rails_admin/rails_admin.js.erb +25 -0
- data/app/assets/javascripts/rails_admin/themes/default/ui.js +12 -0
- data/app/assets/javascripts/rails_admin/ui.js.coffee +61 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/jquery-ui-1.8.7.custom.css.scss +733 -0
- data/app/assets/stylesheets/rails_admin/base/README +2 -0
- data/app/assets/stylesheets/rails_admin/base/mixins.css.scss +1 -0
- data/app/assets/stylesheets/rails_admin/base/theming.css.scss +263 -0
- data/app/assets/stylesheets/rails_admin/base/variables.css.scss +1 -0
- data/app/assets/stylesheets/rails_admin/custom/mixins.css.scss +12 -0
- data/app/assets/stylesheets/rails_admin/custom/theming.css.scss +13 -0
- data/app/assets/stylesheets/rails_admin/custom/variables.css.scss +15 -0
- data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +76 -0
- data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +180 -0
- data/app/assets/stylesheets/rails_admin/jquery.ui.timepicker.css.scss +69 -0
- data/app/assets/stylesheets/rails_admin/ra.calendar-additions.css.scss +25 -0
- data/app/assets/stylesheets/rails_admin/ra.filtering-multiselect.css.scss +85 -0
- data/app/assets/stylesheets/rails_admin/rails_admin.css +4 -0
- data/app/assets/stylesheets/rails_admin/themes/default/mixins.css.scss +8 -0
- data/app/assets/stylesheets/rails_admin/themes/default/theming.css.scss +11 -0
- data/app/assets/stylesheets/rails_admin/themes/default/variables.css.scss +12 -0
- data/app/controllers/rails_admin/application_controller.rb +82 -0
- data/app/controllers/rails_admin/main_controller.rb +151 -0
- data/app/helpers/rails_admin/application_helper.rb +123 -0
- data/app/helpers/rails_admin/form_builder.rb +104 -0
- data/app/helpers/rails_admin/main_helper.rb +36 -0
- data/app/views/kaminari/twitter-bootstrap/_gap.html.haml +2 -0
- data/app/views/kaminari/twitter-bootstrap/_next_page.html.haml +4 -0
- data/app/views/kaminari/twitter-bootstrap/_page.html.haml +4 -0
- data/app/views/kaminari/twitter-bootstrap/_paginator.html.haml +10 -0
- data/app/views/kaminari/twitter-bootstrap/_prev_page.html.haml +4 -0
- data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +12 -0
- data/app/views/layouts/rails_admin/application.html.haml +39 -0
- data/app/views/rails_admin/main/_dashboard_history.html.haml +10 -0
- data/app/views/rails_admin/main/_delete_notice.html.haml +18 -0
- data/app/views/rails_admin/main/_form_colorpicker.html.haml +24 -0
- data/app/views/rails_admin/main/_form_datetime.html.haml +4 -0
- data/app/views/rails_admin/main/_form_enumeration.html.haml +4 -0
- data/app/views/rails_admin/main/_form_field.html.haml +1 -0
- data/app/views/rails_admin/main/_form_file_upload.html.haml +18 -0
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +59 -0
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +47 -0
- data/app/views/rails_admin/main/_form_nested_many.html.haml +41 -0
- data/app/views/rails_admin/main/_form_nested_one.html.haml +35 -0
- data/app/views/rails_admin/main/_form_polymorphic_association.html.haml +34 -0
- data/app/views/rails_admin/main/_form_text.html.haml +9 -0
- data/app/views/rails_admin/main/_submit_buttons.html.haml +15 -0
- data/app/views/rails_admin/main/bulk_delete.html.haml +11 -0
- data/app/views/rails_admin/main/dashboard.html.haml +31 -0
- data/app/views/rails_admin/main/delete.html.haml +18 -0
- data/app/views/rails_admin/main/edit.html.haml +2 -0
- data/app/views/rails_admin/main/export.html.haml +75 -0
- data/app/views/rails_admin/main/history.html.haml +42 -0
- data/app/views/rails_admin/main/index.html.haml +140 -0
- data/app/views/rails_admin/main/new.html.haml +2 -0
- data/app/views/rails_admin/main/show.html.haml +14 -0
- data/config/initializers/active_record_extensions.rb +19 -0
- data/config/initializers/devise_patch.rb +9 -0
- data/config/initializers/haml.rb +2 -0
- data/config/initializers/mongoid_extensions.rb +4 -0
- data/config/locales/fr.yml +24 -0
- data/config/locales/rails_admin.en.yml +130 -0
- data/config/routes.rb +12 -0
- data/lib/generators/rails_admin/install_generator.rb +84 -0
- data/lib/generators/rails_admin/templates/drop.rb +18 -0
- data/lib/generators/rails_admin/templates/initializer.erb +101 -0
- data/lib/generators/rails_admin/templates/migration.rb +18 -0
- data/lib/generators/rails_admin/uninstall_generator.rb +22 -0
- data/lib/generators/rails_admin/utils.rb +30 -0
- data/lib/rails_admin.rb +34 -0
- data/lib/rails_admin/abstract_model.rb +110 -0
- data/lib/rails_admin/adapters/active_record.rb +247 -0
- data/lib/rails_admin/adapters/active_record/abstract_object.rb +32 -0
- data/lib/rails_admin/adapters/mongoid.rb +333 -0
- data/lib/rails_admin/adapters/mongoid/abstract_object.rb +32 -0
- data/lib/rails_admin/adapters/mongoid/extension.rb +27 -0
- data/lib/rails_admin/config.rb +322 -0
- data/lib/rails_admin/config/actions.rb +121 -0
- data/lib/rails_admin/config/actions/base.rb +117 -0
- data/lib/rails_admin/config/actions/bulk_delete.rb +55 -0
- data/lib/rails_admin/config/actions/dashboard.rb +44 -0
- data/lib/rails_admin/config/actions/delete.rb +53 -0
- data/lib/rails_admin/config/actions/edit.rb +60 -0
- data/lib/rails_admin/config/actions/export.rb +40 -0
- data/lib/rails_admin/config/actions/history_index.rb +38 -0
- data/lib/rails_admin/config/actions/history_show.rb +38 -0
- data/lib/rails_admin/config/actions/index.rb +85 -0
- data/lib/rails_admin/config/actions/new.rb +64 -0
- data/lib/rails_admin/config/actions/show.rb +32 -0
- data/lib/rails_admin/config/actions/show_in_app.rb +28 -0
- data/lib/rails_admin/config/configurable.rb +92 -0
- data/lib/rails_admin/config/fields.rb +88 -0
- data/lib/rails_admin/config/fields/association.rb +108 -0
- data/lib/rails_admin/config/fields/base.rb +281 -0
- data/lib/rails_admin/config/fields/factories/belongs_to_association.rb +29 -0
- data/lib/rails_admin/config/fields/factories/carrierwave.rb +31 -0
- data/lib/rails_admin/config/fields/factories/devise.rb +27 -0
- data/lib/rails_admin/config/fields/factories/dragonfly.rb +27 -0
- data/lib/rails_admin/config/fields/factories/enum.rb +11 -0
- data/lib/rails_admin/config/fields/factories/paperclip.rb +26 -0
- data/lib/rails_admin/config/fields/factories/password.rb +17 -0
- data/lib/rails_admin/config/fields/factories/serialized.rb +17 -0
- data/lib/rails_admin/config/fields/group.rb +78 -0
- data/lib/rails_admin/config/fields/types.rb +27 -0
- data/lib/rails_admin/config/fields/types/all.rb +26 -0
- data/lib/rails_admin/config/fields/types/belongs_to_association.rb +41 -0
- data/lib/rails_admin/config/fields/types/boolean.rb +31 -0
- data/lib/rails_admin/config/fields/types/bson_object_id.rb +42 -0
- data/lib/rails_admin/config/fields/types/carrierwave.rb +31 -0
- data/lib/rails_admin/config/fields/types/color.rb +37 -0
- data/lib/rails_admin/config/fields/types/date.rb +24 -0
- data/lib/rails_admin/config/fields/types/datetime.rb +165 -0
- data/lib/rails_admin/config/fields/types/decimal.rb +14 -0
- data/lib/rails_admin/config/fields/types/dragonfly.rb +41 -0
- data/lib/rails_admin/config/fields/types/enum.rb +35 -0
- data/lib/rails_admin/config/fields/types/file_upload.rb +61 -0
- data/lib/rails_admin/config/fields/types/float.rb +14 -0
- data/lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb +14 -0
- data/lib/rails_admin/config/fields/types/has_many_association.rb +32 -0
- data/lib/rails_admin/config/fields/types/has_one_association.rb +39 -0
- data/lib/rails_admin/config/fields/types/hidden.rb +21 -0
- data/lib/rails_admin/config/fields/types/integer.rb +22 -0
- data/lib/rails_admin/config/fields/types/mongoid_type.rb +25 -0
- data/lib/rails_admin/config/fields/types/paperclip.rb +28 -0
- data/lib/rails_admin/config/fields/types/password.rb +39 -0
- data/lib/rails_admin/config/fields/types/polymorphic_association.rb +76 -0
- data/lib/rails_admin/config/fields/types/serialized.rb +22 -0
- data/lib/rails_admin/config/fields/types/string.rb +41 -0
- data/lib/rails_admin/config/fields/types/text.rb +36 -0
- data/lib/rails_admin/config/fields/types/time.rb +36 -0
- data/lib/rails_admin/config/fields/types/timestamp.rb +18 -0
- data/lib/rails_admin/config/groupable.rb +18 -0
- data/lib/rails_admin/config/has_fields.rb +135 -0
- data/lib/rails_admin/config/has_groups.rb +23 -0
- data/lib/rails_admin/config/hideable.rb +28 -0
- data/lib/rails_admin/config/model.rb +88 -0
- data/lib/rails_admin/config/proxyable.rb +12 -0
- data/lib/rails_admin/config/proxyable/proxy.rb +43 -0
- data/lib/rails_admin/config/sections.rb +38 -0
- data/lib/rails_admin/config/sections/base.rb +29 -0
- data/lib/rails_admin/config/sections/create.rb +11 -0
- data/lib/rails_admin/config/sections/edit.rb +11 -0
- data/lib/rails_admin/config/sections/export.rb +11 -0
- data/lib/rails_admin/config/sections/list.rb +27 -0
- data/lib/rails_admin/config/sections/nested.rb +10 -0
- data/lib/rails_admin/config/sections/show.rb +10 -0
- data/lib/rails_admin/config/sections/update.rb +10 -0
- data/lib/rails_admin/engine.rb +22 -0
- data/lib/rails_admin/extension.rb +29 -0
- data/lib/rails_admin/extensions/cancan.rb +5 -0
- data/lib/rails_admin/extensions/cancan/authorization_adapter.rb +59 -0
- data/lib/rails_admin/extensions/history.rb +5 -0
- data/lib/rails_admin/extensions/history/auditing_adapter.rb +37 -0
- data/lib/rails_admin/extensions/history/history.rb +69 -0
- data/lib/rails_admin/extensions/paper_trail.rb +5 -0
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +92 -0
- data/lib/rails_admin/i18n_support.rb +43 -0
- data/lib/rails_admin/support/core_extensions.rb +44 -0
- data/lib/rails_admin/support/csv_converter.rb +109 -0
- data/lib/rails_admin/version.rb +6 -0
- data/lib/tasks/prepare_ci_env.rake +27 -0
- data/lib/tasks/rails_admin.rake +18 -0
- data/spec/ci.sh +2 -0
- data/spec/controllers/application_controller_spec.rb +30 -0
- data/spec/controllers/main_controller_spec.rb +180 -0
- data/spec/database_helpers.rb +15 -0
- data/spec/dummy_app/Gemfile +58 -0
- data/spec/dummy_app/Rakefile +7 -0
- data/spec/dummy_app/app/assets/images/rails.png +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +15 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_app/app/controllers/players_controller.rb +5 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/locales/models.en.yml +16 -0
- data/spec/dummy_app/app/models/abstract.rb +5 -0
- data/spec/dummy_app/app/models/article.rb +9 -0
- data/spec/dummy_app/app/models/author.rb +6 -0
- data/spec/dummy_app/app/models/ball.rb +8 -0
- data/spec/dummy_app/app/models/category.rb +3 -0
- data/spec/dummy_app/app/models/cms.rb +5 -0
- data/spec/dummy_app/app/models/cms/basic_page.rb +7 -0
- data/spec/dummy_app/app/models/cms/unscoped_page.rb +3 -0
- data/spec/dummy_app/app/models/comment.rb +3 -0
- data/spec/dummy_app/app/models/division.rb +12 -0
- data/spec/dummy_app/app/models/draft.rb +11 -0
- data/spec/dummy_app/app/models/fan.rb +5 -0
- data/spec/dummy_app/app/models/field_test.rb +20 -0
- data/spec/dummy_app/app/models/hardball.rb +2 -0
- data/spec/dummy_app/app/models/league.rb +10 -0
- data/spec/dummy_app/app/models/mongoid_field_test.rb +22 -0
- data/spec/dummy_app/app/models/nested_field_test.rb +6 -0
- data/spec/dummy_app/app/models/player.rb +23 -0
- data/spec/dummy_app/app/models/rel_test.rb +6 -0
- data/spec/dummy_app/app/models/tag.rb +7 -0
- data/spec/dummy_app/app/models/team.rb +25 -0
- data/spec/dummy_app/app/models/user.rb +21 -0
- data/spec/dummy_app/app/uploaders/carrierwave_uploader.rb +53 -0
- data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_app/app/views/players/show.html.haml +1 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/config/application.rb +62 -0
- data/spec/dummy_app/config/boot.rb +6 -0
- data/spec/dummy_app/config/database.yml +25 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +37 -0
- data/spec/dummy_app/config/environments/production.rb +67 -0
- data/spec/dummy_app/config/environments/test.rb +37 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/config/initializers/devise.rb +148 -0
- data/spec/dummy_app/config/initializers/inflections.rb +15 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/config/initializers/rails_admin.rb +11 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
- data/spec/dummy_app/config/initializers/session_store.rb +8 -0
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_app/config/mongoid.yml +17 -0
- data/spec/dummy_app/config/routes.rb +10 -0
- data/spec/dummy_app/db/migrate/00000000000001_create_divisions_migration.rb +13 -0
- data/spec/dummy_app/db/migrate/00000000000002_create_drafts_migration.rb +19 -0
- data/spec/dummy_app/db/migrate/00000000000003_create_leagues_migration.rb +12 -0
- data/spec/dummy_app/db/migrate/00000000000004_create_players_migration.rb +20 -0
- data/spec/dummy_app/db/migrate/00000000000005_create_teams_migration.rb +22 -0
- data/spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb +49 -0
- data/spec/dummy_app/db/migrate/00000000000007_create_histories_table.rb +16 -0
- data/spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb +12 -0
- data/spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb +11 -0
- data/spec/dummy_app/db/migrate/00000000000010_add_revenue_to_team_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000011_add_suspended_to_player_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000012_add_avatar_columns_to_user.rb +16 -0
- data/spec/dummy_app/db/migrate/00000000000013_add_roles_to_user.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000014_add_color_to_team_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/20101223222233_create_rel_tests.rb +15 -0
- data/spec/dummy_app/db/migrate/20110103205808_create_comments.rb +15 -0
- data/spec/dummy_app/db/migrate/20110123042530_rename_histories_to_rails_admin_histories.rb +9 -0
- data/spec/dummy_app/db/migrate/20110224184303_create_field_tests.rb +22 -0
- data/spec/dummy_app/db/migrate/20110328193014_create_cms_basic_pages.rb +14 -0
- data/spec/dummy_app/db/migrate/20110329183136_remove_league_id_from_teams.rb +9 -0
- data/spec/dummy_app/db/migrate/20110607152842_add_format_to_field_test.rb +9 -0
- data/spec/dummy_app/db/migrate/20110714095433_create_balls.rb +12 -0
- data/spec/dummy_app/db/migrate/20110831090841_add_protected_field_and_restricted_field_to_field_tests.rb +6 -0
- data/spec/dummy_app/db/migrate/20110901131551_change_division_primary_key.rb +19 -0
- data/spec/dummy_app/db/migrate/20110901142530_rename_league_id_foreign_key_on_divisions.rb +5 -0
- data/spec/dummy_app/db/migrate/20110901150912_set_primary_key_not_null_for_divisions.rb +21 -0
- data/spec/dummy_app/db/migrate/20110901154834_change_length_for_rails_admin_histories.rb +9 -0
- data/spec/dummy_app/db/migrate/20111103174459_create_unscoped_pages.rb +9 -0
- data/spec/dummy_app/db/migrate/20111108143642_add_dragonfly_and_carrierwave_to_field_tests.rb +7 -0
- data/spec/dummy_app/db/migrate/20111115041025_add_type_to_balls.rb +5 -0
- data/spec/dummy_app/db/migrate/20111123092549_create_nested_field_tests.rb +10 -0
- data/spec/dummy_app/db/migrate/20111130075338_add_dragonfly_asset_name_to_field_tests.rb +5 -0
- data/spec/dummy_app/db/migrate/20111215083258_create_foo_bars.rb +8 -0
- data/spec/dummy_app/db/migrate/20120117151733_add_custom_field_to_teams.rb +5 -0
- data/spec/dummy_app/db/migrate/20120118122004_add_categories.rb +7 -0
- data/spec/dummy_app/db/seeds.rb +18 -0
- data/spec/dummy_app/doc/README_FOR_APP +2 -0
- data/spec/dummy_app/public/404.html +26 -0
- data/spec/dummy_app/public/422.html +26 -0
- data/spec/dummy_app/public/500.html +25 -0
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/robots.txt +5 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg.meta +1 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg.meta +1 -0
- data/spec/dummy_app/public/system/paperclip_assets/1/original/Boston City Flow.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/1/thumb/Boston City Flow.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/3/original/Costa Rican Frog.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/3/thumb/Costa Rican Frog.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/6/original/liste-electorale.pdf +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/6/thumb/liste-electorale.pdf +148 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/Boston_City_Flow.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/thumb_Boston_City_Flow.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/thumb_Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/thumb_Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/script/rails +6 -0
- data/spec/factories.rb +89 -0
- data/spec/helpers/application_helper_spec.rb +277 -0
- data/spec/integration/authorization/cancan_spec.rb +349 -0
- data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +25 -0
- data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +44 -0
- data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +154 -0
- data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +23 -0
- data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +27 -0
- data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +56 -0
- data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +109 -0
- data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +87 -0
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +392 -0
- data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +74 -0
- data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +31 -0
- data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +91 -0
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +219 -0
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +954 -0
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +509 -0
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +302 -0
- data/spec/integration/history/rails_admin_history_spec.rb +66 -0
- data/spec/integration/rails_admin_spec.rb +113 -0
- data/spec/integration/relation_spec.rb +26 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/support/tableless.rb +27 -0
- data/spec/unit/adapters/active_record/abstract_object_spec.rb +131 -0
- data/spec/unit/adapters/active_record_spec.rb +373 -0
- data/spec/unit/adapters/mongoid/abstract_object_spec.rb +30 -0
- data/spec/unit/adapters/mongoid_spec.rb +581 -0
- data/spec/unit/config/actions_spec.rb +181 -0
- data/spec/unit/config/fields/base_spec.rb +300 -0
- data/spec/unit/config/model_spec.rb +75 -0
- data/spec/unit/config/sections_spec.rb +123 -0
- data/spec/unit/config_spec.rb +273 -0
- metadata +823 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require File.expand_path('../utils', __FILE__)
|
3
|
+
|
4
|
+
module RailsAdmin
|
5
|
+
class UninstallGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
include Generators::Utils::InstanceMethods
|
8
|
+
extend Generators::Utils::ClassMethods
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
desc "RailsAdmin uninstall"
|
12
|
+
|
13
|
+
def uninstall
|
14
|
+
display "Why you leaving so soon? :("
|
15
|
+
migration_template 'drop.rb', 'db/migrate/drop_rails_admin_histories_table.rb'
|
16
|
+
remove_file 'config/initializers/rails_admin.rb'
|
17
|
+
remove_file 'config/initializers/rails_admin.rb.example'
|
18
|
+
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
|
19
|
+
display "Done! Devise has been left untouched."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Generators
|
3
|
+
module Utils
|
4
|
+
module InstanceMethods
|
5
|
+
def display(output, color = :green)
|
6
|
+
say(" - #{output}", color)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ask_for(wording, default_value = nil, override_if_present_value = nil)
|
10
|
+
override_if_present_value.present? ?
|
11
|
+
display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value :
|
12
|
+
ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def next_migration_number(dirname)
|
18
|
+
if ActiveRecord::Base.timestamped_migrations
|
19
|
+
migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
20
|
+
migration_number += 1
|
21
|
+
migration_number.to_s
|
22
|
+
else
|
23
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/lib/rails_admin.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rails_admin/engine'
|
2
|
+
require 'rails_admin/abstract_model'
|
3
|
+
require 'rails_admin/config'
|
4
|
+
require 'rails_admin/extension'
|
5
|
+
require 'rails_admin/extensions/cancan'
|
6
|
+
require 'rails_admin/extensions/paper_trail'
|
7
|
+
require 'rails_admin/extensions/history'
|
8
|
+
require 'rails_admin/support/csv_converter'
|
9
|
+
require 'rails_admin/support/core_extensions'
|
10
|
+
|
11
|
+
module RailsAdmin
|
12
|
+
# Setup RailsAdmin
|
13
|
+
#
|
14
|
+
# Given the first argument is a model class, a model class name
|
15
|
+
# or an abstract model object proxies to model configuration method.
|
16
|
+
#
|
17
|
+
# If only a block is passed it is stored to initializer stack to be evaluated
|
18
|
+
# on first request in production mode and on each request in development. If
|
19
|
+
# initialization has already occured (in other words RailsAdmin.setup has
|
20
|
+
# been called) the block will be added to stack and evaluated at once.
|
21
|
+
#
|
22
|
+
# Otherwise returns RailsAdmin::Config class.
|
23
|
+
#
|
24
|
+
# @see RailsAdmin::Config
|
25
|
+
def self.config(entity = nil, &block)
|
26
|
+
if entity
|
27
|
+
RailsAdmin::Config.model(entity, &block)
|
28
|
+
elsif block_given? && ENV['SKIP_RAILS_ADMIN_INITIALIZER'] != "true"
|
29
|
+
block.call(RailsAdmin::Config)
|
30
|
+
else
|
31
|
+
RailsAdmin::Config
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
class AbstractModel
|
3
|
+
cattr_accessor :all
|
4
|
+
attr_reader :adapter, :model_name
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def reset
|
8
|
+
@@all = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def all(adapter = nil)
|
12
|
+
@@all ||= Config.models_pool.map{ |m| new(m) }.compact
|
13
|
+
adapter ? @@all.select{|m| m.adapter == adapter} : @@all
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :old_new, :new
|
17
|
+
def new(m)
|
18
|
+
m = m.is_a?(Class) ? m : m.constantize
|
19
|
+
(am = old_new(m)).model && am.adapter ? am : nil
|
20
|
+
rescue LoadError, NameError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
@@polymorphic_parents = {}
|
25
|
+
|
26
|
+
def polymorphic_parents(adapter, name)
|
27
|
+
@@polymorphic_parents[adapter.to_sym] ||= {}.tap do |hash|
|
28
|
+
all(adapter).each do |am|
|
29
|
+
am.associations.select{|r| r[:as] }.each do |association|
|
30
|
+
(hash[association[:as].to_sym] ||= []) << am.model
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@@polymorphic_parents[adapter.to_sym][name.to_sym]
|
35
|
+
end
|
36
|
+
|
37
|
+
# For testing
|
38
|
+
def reset_polymorphic_parents
|
39
|
+
@@polymorphic_parents = {}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(m)
|
44
|
+
@model_name = m.to_s
|
45
|
+
if m.ancestors.map(&:to_s).include?('ActiveRecord::Base') && !m.abstract_class?
|
46
|
+
# ActiveRecord
|
47
|
+
@adapter = :active_record
|
48
|
+
require 'rails_admin/adapters/active_record'
|
49
|
+
extend Adapters::ActiveRecord
|
50
|
+
elsif m.ancestors.map(&:to_s).include?('Mongoid::Document')
|
51
|
+
# Mongoid
|
52
|
+
@adapter = :mongoid
|
53
|
+
require 'rails_admin/adapters/mongoid'
|
54
|
+
extend Adapters::Mongoid
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# do not store a reference to the model, does not play well with ActiveReload/Rails3.2
|
59
|
+
def model
|
60
|
+
@model_name.try :constantize
|
61
|
+
end
|
62
|
+
|
63
|
+
def config
|
64
|
+
Config.model self
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_param
|
68
|
+
model.to_s.split("::").map(&:underscore).join("~")
|
69
|
+
end
|
70
|
+
|
71
|
+
def param_key
|
72
|
+
model.to_s.split("::").map(&:underscore).join("_")
|
73
|
+
end
|
74
|
+
|
75
|
+
def pretty_name
|
76
|
+
model.model_name.human
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def get_filtering_duration(operator, value)
|
82
|
+
date_format = I18n.t("admin.misc.filter_date_format", :default => I18n.t("admin.misc.filter_date_format", :locale => :en)).gsub('dd', '%d').gsub('mm', '%m').gsub('yy', '%Y')
|
83
|
+
case operator
|
84
|
+
when 'between'
|
85
|
+
start_date = value[1].present? ? (beginning_of_date(Date.strptime(value[1], date_format)) rescue false) : false
|
86
|
+
end_date = value[2].present? ? (Date.strptime(value[2], date_format).end_of_day rescue false) : false
|
87
|
+
when 'today'
|
88
|
+
start_date = beginning_of_date(Date.today)
|
89
|
+
end_date = Date.today.end_of_day
|
90
|
+
when 'yesterday'
|
91
|
+
start_date = beginning_of_date(Date.yesterday)
|
92
|
+
end_date = Date.yesterday.end_of_day
|
93
|
+
when 'this_week'
|
94
|
+
start_date = beginning_of_date(Date.today.beginning_of_week)
|
95
|
+
end_date = Date.today.end_of_week.end_of_day
|
96
|
+
when 'last_week'
|
97
|
+
start_date = beginning_of_date(1.week.ago.to_date.beginning_of_week)
|
98
|
+
end_date = 1.week.ago.to_date.end_of_week.end_of_day
|
99
|
+
else # default
|
100
|
+
start_date = (beginning_of_date(Date.strptime(Array.wrap(value).first, date_format)) rescue false)
|
101
|
+
end_date = (Date.strptime(Array.wrap(value).first, date_format).end_of_day rescue false)
|
102
|
+
end
|
103
|
+
[start_date, end_date]
|
104
|
+
end
|
105
|
+
|
106
|
+
def beginning_of_date(date)
|
107
|
+
date.beginning_of_day
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'rails_admin/adapters/active_record/abstract_object'
|
3
|
+
|
4
|
+
module RailsAdmin
|
5
|
+
module Adapters
|
6
|
+
module ActiveRecord
|
7
|
+
DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary, :spatial]
|
8
|
+
AR_ADAPTER = ::ActiveRecord::Base.configurations[Rails.env]['adapter']
|
9
|
+
LIKE_OPERATOR = AR_ADAPTER == "postgresql" ? 'ILIKE' : 'LIKE'
|
10
|
+
|
11
|
+
def new(params = {})
|
12
|
+
AbstractObject.new(model.new(params))
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(id)
|
16
|
+
if object = model.where(model.primary_key => id).first
|
17
|
+
AbstractObject.new object
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def scoped
|
24
|
+
model.scoped
|
25
|
+
end
|
26
|
+
|
27
|
+
def first(options = {}, scope = nil)
|
28
|
+
all(options, scope).first
|
29
|
+
end
|
30
|
+
|
31
|
+
def all(options = {}, scope = nil)
|
32
|
+
scope ||= self.scoped
|
33
|
+
scope = scope.includes(options[:include]) if options[:include]
|
34
|
+
scope = scope.limit(options[:limit]) if options[:limit]
|
35
|
+
scope = scope.where(model.primary_key => options[:bulk_ids]) if options[:bulk_ids]
|
36
|
+
scope = scope.where(query_conditions(options[:query])) if options[:query]
|
37
|
+
scope = scope.where(filter_conditions(options[:filters])) if options[:filters]
|
38
|
+
scope = scope.page(options[:page]).per(options[:per]) if options[:page] && options[:per]
|
39
|
+
scope = scope.reorder("#{options[:sort]} #{options[:sort_reverse] ? 'asc' : 'desc'}") if options[:sort]
|
40
|
+
scope
|
41
|
+
end
|
42
|
+
|
43
|
+
def count(options = {}, scope = nil)
|
44
|
+
all(options.merge({:limit => false, :page => false}), scope).count
|
45
|
+
end
|
46
|
+
|
47
|
+
def destroy(objects)
|
48
|
+
Array.wrap(objects).each &:destroy
|
49
|
+
end
|
50
|
+
|
51
|
+
def primary_key
|
52
|
+
model.primary_key
|
53
|
+
end
|
54
|
+
|
55
|
+
def associations
|
56
|
+
model.reflect_on_all_associations.map do |association|
|
57
|
+
{
|
58
|
+
:name => association.name.to_sym,
|
59
|
+
:pretty_name => association.name.to_s.tr('_', ' ').capitalize,
|
60
|
+
:type => association.macro,
|
61
|
+
:model_proc => Proc.new { association_model_lookup(association) },
|
62
|
+
:primary_key_proc => Proc.new { association_primary_key_lookup(association) },
|
63
|
+
:foreign_key => association_foreign_key_lookup(association),
|
64
|
+
:foreign_type => association_foreign_type_lookup(association),
|
65
|
+
:as => association_as_lookup(association),
|
66
|
+
:polymorphic => association_polymorphic_lookup(association),
|
67
|
+
:inverse_of => association_inverse_of_lookup(association),
|
68
|
+
:read_only => association_read_only_lookup(association),
|
69
|
+
:nested_form => association_nested_attributes_options_lookup(association)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def properties
|
75
|
+
columns = model.columns.reject {|c| c.type.blank? || DISABLED_COLUMN_TYPES.include?(c.type.to_sym) }
|
76
|
+
columns.map do |property|
|
77
|
+
{
|
78
|
+
:name => property.name.to_sym,
|
79
|
+
:pretty_name => property.name.to_s.tr('_', ' ').capitalize,
|
80
|
+
:type => property.type,
|
81
|
+
:length => property.limit,
|
82
|
+
:nullable? => property.null,
|
83
|
+
:serial? => property.primary,
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def table_name
|
89
|
+
model.table_name
|
90
|
+
end
|
91
|
+
|
92
|
+
def serialized_attributes
|
93
|
+
model.serialized_attributes.keys
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def query_conditions(query, fields = config.list.fields.select(&:queryable?))
|
99
|
+
statements = []
|
100
|
+
values = []
|
101
|
+
|
102
|
+
fields.each do |field|
|
103
|
+
field.searchable_columns.flatten.each do |column_infos|
|
104
|
+
statement, value1, value2 = build_statement(column_infos[:column], column_infos[:type], query, field.search_operator)
|
105
|
+
statements << statement if statement
|
106
|
+
values << value1 unless value1.nil?
|
107
|
+
values << value2 unless value2.nil?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
[statements.join(' OR '), *values]
|
112
|
+
end
|
113
|
+
|
114
|
+
# filters example => {"string_field"=>{"0055"=>{"o"=>"like", "v"=>"test_value"}}, ...}
|
115
|
+
# "0055" is the filter index, no use here. o is the operator, v the value
|
116
|
+
def filter_conditions(filters, fields = config.list.fields.select(&:filterable?))
|
117
|
+
statements = []
|
118
|
+
values = []
|
119
|
+
|
120
|
+
filters.each_pair do |field_name, filters_dump|
|
121
|
+
filters_dump.each do |filter_index, filter_dump|
|
122
|
+
field_statements = []
|
123
|
+
fields.find{|f| f.name.to_s == field_name}.searchable_columns.each do |column_infos|
|
124
|
+
statement, value1, value2 = build_statement(column_infos[:column], column_infos[:type], filter_dump[:v], (filter_dump[:o] || 'default'))
|
125
|
+
field_statements << statement if statement.present?
|
126
|
+
values << value1 unless value1.nil?
|
127
|
+
values << value2 unless value2.nil?
|
128
|
+
end
|
129
|
+
statements << "(#{field_statements.join(' OR ')})" unless field_statements.empty?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
[statements.join(' AND '), *values]
|
134
|
+
end
|
135
|
+
|
136
|
+
def build_statement(column, type, value, operator)
|
137
|
+
# this operator/value has been discarded (but kept in the dom to override the one stored in the various links of the page)
|
138
|
+
return if operator == '_discard' || value == '_discard'
|
139
|
+
|
140
|
+
# filtering data with unary operator, not type dependent
|
141
|
+
if operator == '_blank' || value == '_blank'
|
142
|
+
return ["(#{column} IS NULL OR #{column} = '')"]
|
143
|
+
elsif operator == '_present' || value == '_present'
|
144
|
+
return ["(#{column} IS NOT NULL AND #{column} != '')"]
|
145
|
+
elsif operator == '_null' || value == '_null'
|
146
|
+
return ["(#{column} IS NULL)"]
|
147
|
+
elsif operator == '_not_null' || value == '_not_null'
|
148
|
+
return ["(#{column} IS NOT NULL)"]
|
149
|
+
elsif operator == '_empty' || value == '_empty'
|
150
|
+
return ["(#{column} = '')"]
|
151
|
+
elsif operator == '_not_empty' || value == '_not_empty'
|
152
|
+
return ["(#{column} != '')"]
|
153
|
+
end
|
154
|
+
|
155
|
+
# now we go type specific
|
156
|
+
case type
|
157
|
+
when :boolean
|
158
|
+
return ["(#{column} IS NULL OR #{column} = ?)", false] if ['false', 'f', '0'].include?(value)
|
159
|
+
return ["(#{column} = ?)", true] if ['true', 't', '1'].include?(value)
|
160
|
+
when :integer, :belongs_to_association
|
161
|
+
return if value.blank?
|
162
|
+
["(#{column} = ?)", value.to_i] if value.to_i.to_s == value
|
163
|
+
when :string, :text
|
164
|
+
return if value.blank?
|
165
|
+
value = case operator
|
166
|
+
when 'default', 'like'
|
167
|
+
"%#{value}%"
|
168
|
+
when 'starts_with'
|
169
|
+
"#{value}%"
|
170
|
+
when 'ends_with'
|
171
|
+
"%#{value}"
|
172
|
+
when 'is', '='
|
173
|
+
"#{value}"
|
174
|
+
else
|
175
|
+
return
|
176
|
+
end
|
177
|
+
["(#{column} #{LIKE_OPERATOR} ?)", value]
|
178
|
+
when :datetime, :timestamp, :date
|
179
|
+
start_date, end_date = get_filtering_duration(operator, value)
|
180
|
+
|
181
|
+
if start_date && end_date
|
182
|
+
["(#{column} BETWEEN ? AND ?)", start_date, end_date]
|
183
|
+
elsif start_date
|
184
|
+
["(#{column} >= ?)", start_date]
|
185
|
+
elsif end_date
|
186
|
+
["(#{column} <= ?)", end_date]
|
187
|
+
end
|
188
|
+
when :enum
|
189
|
+
return if value.blank?
|
190
|
+
["(#{column} IN (?))", Array.wrap(value)]
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
if AR_ADAPTER == "postgresql"
|
195
|
+
def beginning_of_date(date)
|
196
|
+
date.beginning_of_day
|
197
|
+
end
|
198
|
+
else
|
199
|
+
def beginning_of_date(date)
|
200
|
+
date.yesterday.end_of_day
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def association_model_lookup(association)
|
205
|
+
if association.options[:polymorphic]
|
206
|
+
RailsAdmin::AbstractModel.polymorphic_parents(:active_record, association.name) || []
|
207
|
+
else
|
208
|
+
association.klass
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def association_foreign_type_lookup(association)
|
213
|
+
if association.options[:polymorphic]
|
214
|
+
association.options[:foreign_type].try(:to_sym) || :"#{association.name}_type"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def association_nested_attributes_options_lookup(association)
|
219
|
+
model.nested_attributes_options.try { |o| o[association.name.to_sym] }
|
220
|
+
end
|
221
|
+
|
222
|
+
def association_as_lookup(association)
|
223
|
+
association.options[:as].try :to_sym
|
224
|
+
end
|
225
|
+
|
226
|
+
def association_polymorphic_lookup(association)
|
227
|
+
!!association.options[:polymorphic]
|
228
|
+
end
|
229
|
+
|
230
|
+
def association_primary_key_lookup(association)
|
231
|
+
association.options[:primary_key] || association.klass.primary_key
|
232
|
+
end
|
233
|
+
|
234
|
+
def association_inverse_of_lookup(association)
|
235
|
+
association.options[:inverse_of].try :to_sym
|
236
|
+
end
|
237
|
+
|
238
|
+
def association_read_only_lookup(association)
|
239
|
+
association.options[:readonly]
|
240
|
+
end
|
241
|
+
|
242
|
+
def association_foreign_key_lookup(association)
|
243
|
+
association.foreign_key.to_sym
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Adapters
|
3
|
+
module ActiveRecord
|
4
|
+
class AbstractObject
|
5
|
+
# undef almost all of this class's methods so it will pass almost
|
6
|
+
# everything through to its delegate using method_missing (below).
|
7
|
+
instance_methods.each { |m| undef_method m unless m.to_s =~ /(^__|^send$|^object_id$)/ }
|
8
|
+
# ^^^^^
|
9
|
+
# the unnecessary "to_s" above is a workaround for meta_where, see
|
10
|
+
# https://github.com/sferik/rails_admin/issues/374
|
11
|
+
|
12
|
+
attr_accessor :object
|
13
|
+
|
14
|
+
def initialize(object)
|
15
|
+
self.object = object
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_attributes(attributes, role = nil)
|
19
|
+
object.assign_attributes(attributes, :as => role)
|
20
|
+
end
|
21
|
+
|
22
|
+
def save(options = { :validate => true })
|
23
|
+
object.save(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(name, *args, &block)
|
27
|
+
self.object.send(name, *args, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|