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,333 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
require 'rails_admin/config/sections/list'
|
3
|
+
require 'rails_admin/adapters/mongoid/abstract_object'
|
4
|
+
|
5
|
+
module RailsAdmin
|
6
|
+
module Adapters
|
7
|
+
module Mongoid
|
8
|
+
STRING_TYPE_COLUMN_NAMES = [:name, :title, :subject]
|
9
|
+
|
10
|
+
def new(params = {})
|
11
|
+
AbstractObject.new(model.new)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(id)
|
15
|
+
if object = model.where(:_id=>BSON::ObjectId(id)).first
|
16
|
+
AbstractObject.new object
|
17
|
+
else
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def scoped
|
23
|
+
model.scoped
|
24
|
+
end
|
25
|
+
|
26
|
+
def first(options = {},scope=nil)
|
27
|
+
all(options, scope).first
|
28
|
+
end
|
29
|
+
|
30
|
+
def all(options = {},scope=nil)
|
31
|
+
scope ||= self.scoped
|
32
|
+
scope = scope.includes(options[:include]) if options[:include]
|
33
|
+
scope = scope.limit(options[:limit]) if options[:limit]
|
34
|
+
scope = scope.any_in(:_id => options[:bulk_ids]) if options[:bulk_ids]
|
35
|
+
scope = scope.where(query_conditions(options[:query])) if options[:query]
|
36
|
+
scope = scope.where(filter_conditions(options[:filters])) if options[:filters]
|
37
|
+
scope = scope.page(options[:page]).per(options[:per]) if options[:page] && options[:per]
|
38
|
+
scope = if options[:sort] && options[:sort_reverse]
|
39
|
+
scope.desc(options[:sort])
|
40
|
+
elsif options[:sort]
|
41
|
+
scope.asc(options[:sort])
|
42
|
+
else
|
43
|
+
scope
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def count(options = {},scope=nil)
|
48
|
+
all(options.merge({:limit => false, :page => false}), scope).count
|
49
|
+
end
|
50
|
+
|
51
|
+
def destroy(objects)
|
52
|
+
Array.wrap(objects).each &:destroy
|
53
|
+
end
|
54
|
+
|
55
|
+
def primary_key
|
56
|
+
:_id
|
57
|
+
end
|
58
|
+
|
59
|
+
def associations
|
60
|
+
model.associations.values.map do |association|
|
61
|
+
{
|
62
|
+
:name => association.name.to_sym,
|
63
|
+
:pretty_name => association.name.to_s.tr('_', ' ').capitalize,
|
64
|
+
:type => association_type_lookup(association.macro),
|
65
|
+
:model_proc => Proc.new { association_model_proc_lookup(association) },
|
66
|
+
:primary_key_proc => Proc.new { association_primary_key_lookup(association) },
|
67
|
+
:foreign_key => association_foreign_key_lookup(association),
|
68
|
+
:foreign_type => association_foreign_type_lookup(association),
|
69
|
+
:as => association_as_lookup(association),
|
70
|
+
:polymorphic => association_polymorphic_lookup(association),
|
71
|
+
:inverse_of => association_inverse_of_lookup(association),
|
72
|
+
:read_only => nil,
|
73
|
+
:nested_form => nil
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def properties
|
79
|
+
@properties if @properties
|
80
|
+
@properties = model.fields.map do |name,field|
|
81
|
+
ar_type =
|
82
|
+
if name == '_type'
|
83
|
+
{ :type => :mongoid_type, :length => 1024 }
|
84
|
+
elsif field.type.to_s == 'String'
|
85
|
+
if (length = length_validation_lookup(name)) && length < 256
|
86
|
+
{ :type => :string, :length => length }
|
87
|
+
elsif STRING_TYPE_COLUMN_NAMES.include?(name.to_sym)
|
88
|
+
{ :type => :string, :length => 255 }
|
89
|
+
else
|
90
|
+
{ :type => :text, :length => nil }
|
91
|
+
end
|
92
|
+
else
|
93
|
+
{
|
94
|
+
"Array" => { :type => :serialized, :length => nil },
|
95
|
+
"BigDecimal" => { :type => :string, :length => 1024 },
|
96
|
+
"Boolean" => { :type => :boolean, :length => nil },
|
97
|
+
"BSON::ObjectId" => { :type => :bson_object_id, :length => nil },
|
98
|
+
"Date" => { :type => :date, :length => nil },
|
99
|
+
"DateTime" => { :type => :datetime, :length => nil },
|
100
|
+
"Float" => { :type => :float, :length => nil },
|
101
|
+
"Hash" => { :type => :serialized, :length => nil },
|
102
|
+
"Integer" => { :type => :integer, :length => nil },
|
103
|
+
"Time" => { :type => :datetime, :length => nil },
|
104
|
+
"Object" => { :type => :bson_object_id, :length => nil },
|
105
|
+
}[field.type.to_s] or raise "Need to map field #{field.type.to_s} for field name #{name} in #{model.inspect}"
|
106
|
+
end
|
107
|
+
|
108
|
+
{
|
109
|
+
:name => field.name.to_sym,
|
110
|
+
:pretty_name => field.name.to_s.gsub('_', ' ').strip.capitalize,
|
111
|
+
:nullable? => true,
|
112
|
+
:serial? => false,
|
113
|
+
}.merge(ar_type)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def table_name
|
118
|
+
model.collection.name
|
119
|
+
end
|
120
|
+
|
121
|
+
def serialized_attributes
|
122
|
+
# Mongoid Array and Hash type columns are mapped to RA serialized type
|
123
|
+
# through type detection in self#properties.
|
124
|
+
[]
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def query_conditions(query, fields = config.list.fields.select(&:queryable?))
|
130
|
+
statements = []
|
131
|
+
|
132
|
+
fields.each do |field|
|
133
|
+
conditions_per_collection = {}
|
134
|
+
field.searchable_columns.flatten.each do |column_infos|
|
135
|
+
collection_name, column_name = column_infos[:column].split('.')
|
136
|
+
statement = build_statement(column_name, column_infos[:type], query, field.search_operator)
|
137
|
+
if statement
|
138
|
+
conditions_per_collection[collection_name] ||= []
|
139
|
+
conditions_per_collection[collection_name] << statement
|
140
|
+
end
|
141
|
+
end
|
142
|
+
statements.concat make_condition_for_current_collection(field, conditions_per_collection)
|
143
|
+
end
|
144
|
+
|
145
|
+
if statements.any?
|
146
|
+
{ '$or' => statements }
|
147
|
+
else
|
148
|
+
{}
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# filters example => {"string_field"=>{"0055"=>{"o"=>"like", "v"=>"test_value"}}, ...}
|
153
|
+
# "0055" is the filter index, no use here. o is the operator, v the value
|
154
|
+
def filter_conditions(filters, fields = config.list.fields.select(&:filterable?))
|
155
|
+
statements = []
|
156
|
+
|
157
|
+
filters.each_pair do |field_name, filters_dump|
|
158
|
+
filters_dump.each do |filter_index, filter_dump|
|
159
|
+
conditions_per_collection = {}
|
160
|
+
field = fields.find{|f| f.name.to_s == field_name}
|
161
|
+
next unless field
|
162
|
+
field.searchable_columns.each do |column_infos|
|
163
|
+
collection_name, column_name = column_infos[:column].split('.')
|
164
|
+
statement = build_statement(column_name, column_infos[:type], filter_dump[:v], (filter_dump[:o] || 'default'))
|
165
|
+
if statement
|
166
|
+
conditions_per_collection[collection_name] ||= []
|
167
|
+
conditions_per_collection[collection_name] << statement
|
168
|
+
end
|
169
|
+
end
|
170
|
+
if conditions_per_collection.any?
|
171
|
+
field_statements = make_condition_for_current_collection(field, conditions_per_collection)
|
172
|
+
if field_statements.length > 1
|
173
|
+
statements << { '$or' => field_statements }
|
174
|
+
else
|
175
|
+
statements << field_statements.first
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
if statements.any?
|
182
|
+
{ '$and' => statements }
|
183
|
+
else
|
184
|
+
{}
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def build_statement(column, type, value, operator)
|
189
|
+
# this operator/value has been discarded (but kept in the dom to override the one stored in the various links of the page)
|
190
|
+
return if operator == '_discard' || value == '_discard'
|
191
|
+
|
192
|
+
# filtering data with unary operator, not type dependent
|
193
|
+
if operator == '_blank' || value == '_blank'
|
194
|
+
return { column => {'$in' => [nil, '']} }
|
195
|
+
elsif operator == '_present' || value == '_present'
|
196
|
+
return { column => {'$nin' => [nil, '']} }
|
197
|
+
elsif operator == '_null' || value == '_null'
|
198
|
+
return { column => nil }
|
199
|
+
elsif operator == '_not_null' || value == '_not_null'
|
200
|
+
return { column => {'$ne' => nil} }
|
201
|
+
elsif operator == '_empty' || value == '_empty'
|
202
|
+
return { column => '' }
|
203
|
+
elsif operator == '_not_empty' || value == '_not_empty'
|
204
|
+
return { column => {'$ne' => ''} }
|
205
|
+
end
|
206
|
+
# now we go type specific
|
207
|
+
case type
|
208
|
+
when :boolean
|
209
|
+
return { column => false } if ['false', 'f', '0'].include?(value)
|
210
|
+
return { column => true } if ['true', 't', '1'].include?(value)
|
211
|
+
when :integer, :belongs_to_association
|
212
|
+
return if value.blank?
|
213
|
+
{ column => value.to_i } if value.to_i.to_s == value
|
214
|
+
when :string, :text
|
215
|
+
return if value.blank?
|
216
|
+
value = case operator
|
217
|
+
when 'default', 'like'
|
218
|
+
Regexp.compile(Regexp.escape(value))
|
219
|
+
when 'starts_with'
|
220
|
+
Regexp.compile("^#{Regexp.escape(value)}")
|
221
|
+
when 'ends_with'
|
222
|
+
Regexp.compile("#{Regexp.escape(value)}$")
|
223
|
+
when 'is', '='
|
224
|
+
value.to_s
|
225
|
+
else
|
226
|
+
return
|
227
|
+
end
|
228
|
+
{ column => value }
|
229
|
+
when :datetime, :timestamp, :date
|
230
|
+
start_date, end_date = get_filtering_duration(operator, value)
|
231
|
+
|
232
|
+
if start_date && end_date
|
233
|
+
{ column => { '$gte' => start_date, '$lte' => end_date } }
|
234
|
+
elsif start_date
|
235
|
+
{ column => { '$gte' => start_date } }
|
236
|
+
elsif end_date
|
237
|
+
{ column => { '$lte' => end_date } }
|
238
|
+
end
|
239
|
+
when :enum
|
240
|
+
return if value.blank?
|
241
|
+
{ column => { "$in" => Array.wrap(value) } }
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def association_model_proc_lookup(association)
|
246
|
+
if association.polymorphic? && association.macro == :referenced_in
|
247
|
+
RailsAdmin::AbstractModel.polymorphic_parents(:mongoid, association.name) || []
|
248
|
+
else
|
249
|
+
association.klass
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def association_foreign_type_lookup(association)
|
254
|
+
if association.polymorphic? && association.macro == :referenced_in
|
255
|
+
association.inverse_type.try(:to_sym) || :"#{association.name}_type"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def association_as_lookup(association)
|
260
|
+
association.as.try :to_sym
|
261
|
+
end
|
262
|
+
|
263
|
+
def association_polymorphic_lookup(association)
|
264
|
+
!!association.polymorphic? && association.macro == :referenced_in
|
265
|
+
end
|
266
|
+
|
267
|
+
def association_primary_key_lookup(association)
|
268
|
+
:_id # todo
|
269
|
+
end
|
270
|
+
|
271
|
+
def association_inverse_of_lookup(association)
|
272
|
+
association.inverse_of.try :to_sym
|
273
|
+
end
|
274
|
+
|
275
|
+
def association_foreign_key_lookup(association)
|
276
|
+
association.foreign_key.to_sym rescue nil
|
277
|
+
end
|
278
|
+
|
279
|
+
def association_type_lookup(macro)
|
280
|
+
case macro.to_sym
|
281
|
+
when :referenced_in, :embedded_in
|
282
|
+
:belongs_to
|
283
|
+
when :references_one, :embeds_one
|
284
|
+
:has_one
|
285
|
+
when :references_many, :embeds_many
|
286
|
+
:has_many
|
287
|
+
when :references_and_referenced_in_many
|
288
|
+
:has_and_belongs_to_many
|
289
|
+
else
|
290
|
+
raise "Unknown association type: #{macro.inspect}"
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def length_validation_lookup(name)
|
295
|
+
shortest = model.validators.select do |validator|
|
296
|
+
validator.attributes.include?(name.to_sym) &&
|
297
|
+
validator.class == ActiveModel::Validations::LengthValidator
|
298
|
+
end.min{|a, b| a.options[:maximum] <=> b.options[:maximum] }
|
299
|
+
if shortest
|
300
|
+
shortest.options[:maximum]
|
301
|
+
else
|
302
|
+
false
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def make_condition_for_current_collection(target_field, conditions_per_collection)
|
307
|
+
result =[]
|
308
|
+
conditions_per_collection.each do |collection_name, conditions|
|
309
|
+
if collection_name == table_name
|
310
|
+
# conditions referring current model column are passed directly
|
311
|
+
result.concat conditions
|
312
|
+
else
|
313
|
+
# otherwise, collect ids of documents that satisfy search condition
|
314
|
+
result.concat perform_search_on_associated_collection(target_field.name, conditions)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
result
|
318
|
+
end
|
319
|
+
|
320
|
+
def perform_search_on_associated_collection(field_name, conditions)
|
321
|
+
target_association = associations.find{|a| a[:name] == field_name }
|
322
|
+
return [] unless target_association
|
323
|
+
model = target_association[:model_proc].call
|
324
|
+
case target_association[:type]
|
325
|
+
when :belongs_to, :has_and_belongs_to_many
|
326
|
+
[{ target_association[:foreign_key].to_s => { '$in' => model.where('$or' => conditions).all.map{|r| r.send(target_association[:primary_key_proc].call)} }}]
|
327
|
+
when :has_many
|
328
|
+
[{ target_association[:primary_key_proc].call.to_s => { '$in' => model.where('$or' => conditions).all.map{|r| r.send(target_association[:foreign_key])} }}]
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails_admin/adapters/active_record/abstract_object'
|
2
|
+
module RailsAdmin
|
3
|
+
module Adapters
|
4
|
+
module Mongoid
|
5
|
+
class AbstractObject < RailsAdmin::Adapters::ActiveRecord::AbstractObject
|
6
|
+
def initialize(object)
|
7
|
+
super
|
8
|
+
object.associations.each do |name, association|
|
9
|
+
if association.macro == :references_many
|
10
|
+
instance_eval <<-RUBY, __FILE__, __LINE__ + 1
|
11
|
+
def #{name.to_s.singularize}_ids
|
12
|
+
#{name}.map{|item| item.id }
|
13
|
+
end
|
14
|
+
|
15
|
+
def #{name.to_s.singularize}_ids=(items)
|
16
|
+
self.#{name} = items.
|
17
|
+
map{|item_id| self.#{name}.klass.find(item_id) rescue nil }.
|
18
|
+
compact
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
object.destroy
|
27
|
+
object
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Adapters
|
3
|
+
module Mongoid
|
4
|
+
module Extension
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def self.rails_admin(&block)
|
9
|
+
RailsAdmin::Config.model(self, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def rails_admin_default_object_label_method
|
14
|
+
self.new_record? ? "new #{self.class.to_s}" : "#{self.class.to_s} ##{self.id}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def safe_send(value)
|
18
|
+
if self.attributes.find{ |k,v| k.to_s == value.to_s }
|
19
|
+
self.read_attribute(value)
|
20
|
+
else
|
21
|
+
self.send(value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
require 'rails_admin/config/model'
|
2
|
+
require 'rails_admin/config/sections/list'
|
3
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
4
|
+
|
5
|
+
module RailsAdmin
|
6
|
+
module Config
|
7
|
+
# RailsAdmin is setup to try and authenticate with warden
|
8
|
+
# If warden is found, then it will try to authenticate
|
9
|
+
#
|
10
|
+
# This is valid for custom warden setups, and also devise
|
11
|
+
# If you're using the admin setup for devise, you should set RailsAdmin to use the admin
|
12
|
+
#
|
13
|
+
# @see RailsAdmin::Config.authenticate_with
|
14
|
+
# @see RailsAdmin::Config.authorize_with
|
15
|
+
DEFAULT_AUTHENTICATION = Proc.new do
|
16
|
+
request.env['warden'].try(:authenticate!)
|
17
|
+
end
|
18
|
+
|
19
|
+
DEFAULT_ATTR_ACCESSIBLE_ROLE = Proc.new { :default }
|
20
|
+
|
21
|
+
DEFAULT_AUTHORIZE = Proc.new {}
|
22
|
+
|
23
|
+
DEFAULT_AUDIT = Proc.new {}
|
24
|
+
|
25
|
+
DEFAULT_CURRENT_USER = Proc.new do
|
26
|
+
request.env["warden"].try(:user) || respond_to?(:current_user) && current_user
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class << self
|
31
|
+
# Application title, can be an array of two elements
|
32
|
+
attr_accessor :main_app_name
|
33
|
+
|
34
|
+
# Configuration option to specify which models you want to exclude.
|
35
|
+
attr_accessor :excluded_models
|
36
|
+
|
37
|
+
# Configuration option to specify a whitelist of models you want to RailsAdmin to work with.
|
38
|
+
# The excluded_models list applies against the whitelist as well and further reduces the models
|
39
|
+
# RailsAdmin will use.
|
40
|
+
# If included_models is left empty ([]), then RailsAdmin will automatically use all the models
|
41
|
+
# in your application (less any excluded_models you may have specified).
|
42
|
+
attr_accessor :included_models
|
43
|
+
|
44
|
+
# Fields to be hidden in show, create and update views
|
45
|
+
attr_accessor :default_hidden_fields
|
46
|
+
|
47
|
+
# Default items per page value used if a model level option has not
|
48
|
+
# been configured
|
49
|
+
attr_accessor :default_items_per_page
|
50
|
+
|
51
|
+
attr_reader :default_search_operator
|
52
|
+
|
53
|
+
# Configuration option to specify which method names will be searched for
|
54
|
+
# to be used as a label for object records. This defaults to [:name, :title]
|
55
|
+
attr_accessor :label_methods
|
56
|
+
|
57
|
+
# hide blank fields in show view if true
|
58
|
+
attr_accessor :compact_show_view
|
59
|
+
|
60
|
+
# Set the max width of columns in list view before a new set is created
|
61
|
+
attr_accessor :total_columns_width
|
62
|
+
|
63
|
+
# Stores model configuration objects in a hash identified by model's class
|
64
|
+
# name.
|
65
|
+
#
|
66
|
+
# @see RailsAdmin::Config.model
|
67
|
+
attr_reader :registry
|
68
|
+
|
69
|
+
# Setup authentication to be run as a before filter
|
70
|
+
# This is run inside the controller instance so you can setup any authentication you need to
|
71
|
+
#
|
72
|
+
# By default, the authentication will run via warden if available
|
73
|
+
# and will run the default.
|
74
|
+
#
|
75
|
+
# If you use devise, this will authenticate the same as _authenticate_user!_
|
76
|
+
#
|
77
|
+
# @example Devise admin
|
78
|
+
# RailsAdmin.config do |config|
|
79
|
+
# config.authenticate_with do
|
80
|
+
# authenticate_admin!
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# @example Custom Warden
|
85
|
+
# RailsAdmin.config do |config|
|
86
|
+
# config.authenticate_with do
|
87
|
+
# warden.authenticate! :scope => :paranoid
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# @see RailsAdmin::Config::DEFAULT_AUTHENTICATION
|
92
|
+
def authenticate_with(&blk)
|
93
|
+
@authenticate = blk if blk
|
94
|
+
@authenticate || DEFAULT_AUTHENTICATION
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def attr_accessible_role(&blk)
|
99
|
+
@attr_accessible_role = blk if blk
|
100
|
+
@attr_accessible_role || DEFAULT_ATTR_ACCESSIBLE_ROLE
|
101
|
+
end
|
102
|
+
|
103
|
+
# Setup auditing/history/versioning provider that observe objects lifecycle
|
104
|
+
def audit_with(*args, &block)
|
105
|
+
extension = args.shift
|
106
|
+
if(extension)
|
107
|
+
@audit = Proc.new {
|
108
|
+
@auditing_adapter = RailsAdmin::AUDITING_ADAPTERS[extension].new(*([self] + args).compact)
|
109
|
+
}
|
110
|
+
else
|
111
|
+
@audit = block if block
|
112
|
+
end
|
113
|
+
@audit || DEFAULT_AUDIT
|
114
|
+
end
|
115
|
+
|
116
|
+
# Setup authorization to be run as a before filter
|
117
|
+
# This is run inside the controller instance so you can setup any authorization you need to.
|
118
|
+
#
|
119
|
+
# By default, there is no authorization.
|
120
|
+
#
|
121
|
+
# @example Custom
|
122
|
+
# RailsAdmin.config do |config|
|
123
|
+
# config.authorize_with do
|
124
|
+
# redirect_to root_path unless warden.user.is_admin?
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# To use an authorization adapter, pass the name of the adapter. For example,
|
129
|
+
# to use with CanCan[https://github.com/ryanb/cancan], pass it like this.
|
130
|
+
#
|
131
|
+
# @example CanCan
|
132
|
+
# RailsAdmin.config do |config|
|
133
|
+
# config.authorize_with :cancan
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# See the wiki[https://github.com/sferik/rails_admin/wiki] for more on authorization.
|
137
|
+
#
|
138
|
+
# @see RailsAdmin::Config::DEFAULT_AUTHORIZE
|
139
|
+
def authorize_with(*args, &block)
|
140
|
+
extension = args.shift
|
141
|
+
if(extension)
|
142
|
+
@authorize = Proc.new {
|
143
|
+
@authorization_adapter = RailsAdmin::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact)
|
144
|
+
}
|
145
|
+
else
|
146
|
+
@authorize = block if block
|
147
|
+
end
|
148
|
+
@authorize || DEFAULT_AUTHORIZE
|
149
|
+
end
|
150
|
+
|
151
|
+
# Setup configuration using an extension-provided ConfigurationAdapter
|
152
|
+
#
|
153
|
+
# @example Custom configuration for role-based setup.
|
154
|
+
# RailsAdmin.config do |config|
|
155
|
+
# config.configure_with(:custom) do |config|
|
156
|
+
# config.models = ['User', 'Comment']
|
157
|
+
# config.roles = {
|
158
|
+
# 'Admin' => :all,
|
159
|
+
# 'User' => ['User']
|
160
|
+
# }
|
161
|
+
# end
|
162
|
+
# end
|
163
|
+
def configure_with(extension)
|
164
|
+
configuration = RailsAdmin::CONFIGURATION_ADAPTERS[extension].new
|
165
|
+
yield(configuration) if block_given?
|
166
|
+
end
|
167
|
+
|
168
|
+
# Setup a different method to determine the current user or admin logged in.
|
169
|
+
# This is run inside the controller instance and made available as a helper.
|
170
|
+
#
|
171
|
+
# By default, _request.env["warden"].user_ or _current_user_ will be used.
|
172
|
+
#
|
173
|
+
# @example Custom
|
174
|
+
# RailsAdmin.config do |config|
|
175
|
+
# config.current_user_method do
|
176
|
+
# current_admin
|
177
|
+
# end
|
178
|
+
# end
|
179
|
+
#
|
180
|
+
# @see RailsAdmin::Config::DEFAULT_CURRENT_USER
|
181
|
+
def current_user_method(&block)
|
182
|
+
@current_user = block if block
|
183
|
+
@current_user || DEFAULT_CURRENT_USER
|
184
|
+
end
|
185
|
+
|
186
|
+
def default_search_operator=(operator)
|
187
|
+
if %w{ default like starts_with ends_with is = }.include? operator
|
188
|
+
@default_search_operator = operator
|
189
|
+
else
|
190
|
+
raise ArgumentError, "Search operator '#{operator}' not supported"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# pool of all found model names from the whole application
|
195
|
+
def models_pool
|
196
|
+
possible =
|
197
|
+
included_models.map(&:to_s).presence || (
|
198
|
+
@@system_models ||= # memoization for tests
|
199
|
+
([Rails.application] + Rails::Application::Railties.engines).map do |app|
|
200
|
+
(app.paths['app/models'] + app.config.autoload_paths).map do |load_path|
|
201
|
+
Dir.glob(app.root.join(load_path)).map do |load_dir|
|
202
|
+
Dir.glob(load_dir + "/**/*.rb").map do |filename|
|
203
|
+
# app/models/module/class.rb => module/class.rb => module/class => Module::Class
|
204
|
+
lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end.flatten
|
209
|
+
)
|
210
|
+
|
211
|
+
excluded = (excluded_models.map(&:to_s) + ['RailsAdmin::History'])
|
212
|
+
|
213
|
+
(possible - excluded).uniq.sort
|
214
|
+
end
|
215
|
+
|
216
|
+
# Loads a model configuration instance from the registry or registers
|
217
|
+
# a new one if one is yet to be added.
|
218
|
+
#
|
219
|
+
# First argument can be an instance of requested model, its class object,
|
220
|
+
# its class name as a string or symbol or a RailsAdmin::AbstractModel
|
221
|
+
# instance.
|
222
|
+
#
|
223
|
+
# If a block is given it is evaluated in the context of configuration instance.
|
224
|
+
#
|
225
|
+
# Returns given model's configuration
|
226
|
+
#
|
227
|
+
# @see RailsAdmin::Config.registry
|
228
|
+
def model(entity, &block)
|
229
|
+
key = begin
|
230
|
+
if entity.kind_of?(RailsAdmin::AbstractModel)
|
231
|
+
entity.model.try(:name).try :to_sym
|
232
|
+
elsif entity.kind_of?(Class)
|
233
|
+
entity.name.to_sym
|
234
|
+
elsif entity.kind_of?(String) || entity.kind_of?(Symbol)
|
235
|
+
entity.to_sym
|
236
|
+
else
|
237
|
+
entity.class.name.to_sym
|
238
|
+
end
|
239
|
+
end
|
240
|
+
config = @registry[key] ||= RailsAdmin::Config::Model.new(entity)
|
241
|
+
config.instance_eval(&block) if block
|
242
|
+
config
|
243
|
+
end
|
244
|
+
|
245
|
+
def default_hidden_fields=(fields)
|
246
|
+
if fields.is_a?(Array)
|
247
|
+
@default_hidden_fields = {}
|
248
|
+
@default_hidden_fields[:edit] = fields
|
249
|
+
@default_hidden_fields[:show] = fields
|
250
|
+
else
|
251
|
+
@default_hidden_fields = fields
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# Returns action configuration object
|
256
|
+
def actions(&block)
|
257
|
+
RailsAdmin::Config::Actions.instance_eval(&block) if block
|
258
|
+
end
|
259
|
+
|
260
|
+
# Returns all model configurations
|
261
|
+
#
|
262
|
+
# If a block is given it is evaluated in the context of configuration
|
263
|
+
# instances.
|
264
|
+
#
|
265
|
+
# @see RailsAdmin::Config.registry
|
266
|
+
def models(&block)
|
267
|
+
RailsAdmin::AbstractModel.all.map{|m| model(m, &block)}
|
268
|
+
end
|
269
|
+
|
270
|
+
# Reset all configurations to defaults.
|
271
|
+
#
|
272
|
+
# @see RailsAdmin::Config.registry
|
273
|
+
def reset
|
274
|
+
@compact_show_view = true
|
275
|
+
@authenticate = nil
|
276
|
+
@authorize = nil
|
277
|
+
@audit = nil
|
278
|
+
@current_user = nil
|
279
|
+
@default_hidden_fields = {}
|
280
|
+
@default_hidden_fields[:edit] = [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]
|
281
|
+
@default_hidden_fields[:show] = [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]
|
282
|
+
@default_items_per_page = 20
|
283
|
+
@default_search_operator = 'default'
|
284
|
+
@attr_accessible_role = nil
|
285
|
+
@excluded_models = []
|
286
|
+
@included_models = []
|
287
|
+
@total_columns_width = 697
|
288
|
+
@label_methods = [:name, :title]
|
289
|
+
@main_app_name = Proc.new { [Rails.application.engine_name.titleize.chomp(' Application'), 'Admin'] }
|
290
|
+
@registry = {}
|
291
|
+
RailsAdmin::Config::Actions.reset
|
292
|
+
end
|
293
|
+
|
294
|
+
# Reset a provided model's configuration.
|
295
|
+
#
|
296
|
+
# @see RailsAdmin::Config.registry
|
297
|
+
def reset_model(model)
|
298
|
+
key = model.kind_of?(Class) ? model.name.to_sym : model.to_sym
|
299
|
+
@registry.delete(key)
|
300
|
+
end
|
301
|
+
|
302
|
+
# Get all models that are configured as visible sorted by their weight and label.
|
303
|
+
#
|
304
|
+
# @see RailsAdmin::Config::Hideable
|
305
|
+
|
306
|
+
def visible_models(bindings)
|
307
|
+
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model)}.sort do |a, b|
|
308
|
+
(weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
private
|
313
|
+
|
314
|
+
def lchomp(base, arg)
|
315
|
+
base.to_s.reverse.chomp(arg.to_s.reverse).reverse
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
# Set default values for configuration options on load
|
320
|
+
self.reset
|
321
|
+
end
|
322
|
+
end
|