brisk-bills 0.7.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +55 -0
- data/TODO.txt +36 -67
- data/app/controllers/admin/activities_controller.rb +4 -3
- data/app/controllers/admin/activities_with_prices_controller.rb +28 -14
- data/app/controllers/admin/client_accounting_controller.rb +11 -8
- data/app/controllers/admin/client_representatives_controller.rb +34 -5
- data/app/controllers/admin/clients_controller.rb +1 -1
- data/app/controllers/admin/draft_invoices_controller.rb +92 -0
- data/app/controllers/admin/{employee_client_labor_rate_controller.rb → employee_client_labor_rates_controller.rb} +1 -1
- data/app/controllers/admin/employees_controller.rb +3 -4
- data/app/controllers/admin/invoices_controller.rb +111 -53
- data/app/controllers/admin/payments_controller.rb +168 -41
- data/app/controllers/authentication_controller.rb +3 -3
- data/app/helpers/admin/activities_helper.rb +16 -13
- data/app/helpers/admin/activities_helper/labor_helper.rb +4 -4
- data/app/helpers/admin/activities_helper/proposal_helper.rb +1 -1
- data/app/helpers/admin/activities_helper/slimtimer_helper.rb +1 -1
- data/app/helpers/admin/activities_with_prices_helper.rb +2 -2
- data/app/helpers/admin/activity_type_controller_helper.rb +6 -0
- data/app/helpers/admin/activity_type_field_helper.rb +9 -9
- data/app/helpers/admin/adjustments_helper.rb +9 -1
- data/app/helpers/admin/client_accounting_helper.rb +2 -2
- data/app/helpers/admin/client_financial_transactions_helper.rb +1 -1
- data/app/helpers/admin/client_representatives_helper.rb +16 -12
- data/app/helpers/admin/clients_helper.rb +2 -0
- data/app/helpers/admin/draft_invoices_helper.rb +24 -0
- data/app/helpers/admin/{employee_client_labor_rate_helper.rb → employee_client_labor_rates_helper.rb} +8 -8
- data/app/helpers/admin/employees_helper.rb +6 -0
- data/app/helpers/admin/has_credential_column_helper.rb +8 -8
- data/app/helpers/admin/invoices_helper.rb +71 -16
- data/app/helpers/admin/is_active_column_helper.rb +2 -2
- data/app/helpers/admin/labors_helper.rb +12 -1
- data/app/helpers/admin/labors_helper/slimtimer_helper.rb +1 -1
- data/app/helpers/admin/materials_helper.rb +11 -0
- data/app/helpers/admin/payments_helper.rb +204 -29
- data/app/helpers/admin/proposals_helper.rb +10 -0
- data/app/helpers/admin/settings_helper.rb +1 -1
- data/app/helpers/admin_layout_helper.rb +3 -6
- data/app/helpers/authentication_helper.rb +7 -10
- data/app/helpers/money_model_helper.rb +1 -2
- data/app/models/activity.rb +17 -7
- data/app/models/client.rb +35 -8
- data/app/{model_views → models}/client_financial_transaction.rb +0 -0
- data/app/models/client_representative.rb +6 -14
- data/app/models/credential.rb +1 -1
- data/app/models/employee.rb +9 -11
- data/app/models/invoice.rb +13 -9
- data/app/models/invoice_payment.rb +1 -1
- data/app/models/notifier.rb +2 -2
- data/app/models/payment.rb +51 -7
- data/app/models/setting.rb +3 -1
- data/app/views/active_scaffold_overrides/add_existing.js.rjs +25 -0
- data/app/views/admin/activities/_adjustment_column.html.erb +10 -0
- data/app/views/admin/activities/{_form.rhtml → _form.html.erb} +0 -0
- data/app/views/admin/activities/{_form_attribute.rhtml → _form_attribute.html.erb} +0 -0
- data/app/views/admin/activities/{_labor_column.rhtml → _labor_column.html.erb} +0 -0
- data/app/views/admin/activities/{_material_column.rhtml → _material_column.html.erb} +0 -0
- data/app/views/admin/activities/{_proposal_column.rhtml → _proposal_column.html.erb} +0 -0
- data/app/views/admin/activities_with_prices/{move_to_invoice.rhtml → move_to_invoice.html.erb} +2 -2
- data/app/views/admin/activities_with_prices/move_to_invoice.js.rjs +5 -0
- data/app/views/admin/draft_invoices/batch_create.html.erb +73 -0
- data/app/views/admin/draft_invoices/batch_create.js.rjs +5 -0
- data/app/views/admin/invoices/confirm_publish_modal.html.erb +48 -0
- data/app/views/admin/payments/commit_payment_warning.html.erb +8 -0
- data/app/views/admin/payments/observation_error.js.rjs +28 -0
- data/app/views/admin/payments/on_assignment_observation.js.rjs +28 -0
- data/app/views/authentication/{email.rjs → email.js.rjs} +0 -0
- data/app/views/authentication/{login.rhtml → login.html.erb} +21 -26
- data/app/views/authentication/{login.rjs → login.js.rjs} +0 -0
- data/app/views/authentication/{reset_password_via_token.rhtml → reset_password_via_token.html.erb} +0 -0
- data/app/views/authentication/{reset_password_via_token.rjs → reset_password_via_token.js.rjs} +0 -0
- data/app/views/authentication/{sign_in_error.rjs → sign_in_error.js.rjs} +0 -0
- data/app/views/layouts/{_navigation_tree.rhtml → _navigation_tree.html.erb} +0 -0
- data/app/views/layouts/{admin.rhtml → admin.html.erb} +0 -0
- data/app/views/layouts/{public.rhtml → public.html.erb} +0 -0
- data/app/views/notifier/{_email_footer.html.rhtml → _email_footer.html.erb} +0 -0
- data/app/views/notifier/{_email_footer.plain.rhtml → _email_footer.plain.erb} +0 -0
- data/app/views/notifier/{_email_header.html.rhtml → _email_header.html.erb} +0 -0
- data/app/views/notifier/invoice_available.html.erb +5 -0
- data/app/views/notifier/{invoice_available.plain.rhtml → invoice_available.plain.erb} +1 -1
- data/app/views/notifier/{reset_password_requested.html.rhtml → reset_password_requested.html.erb} +2 -2
- data/app/views/notifier/{reset_password_requested.plain.rhtml → reset_password_requested.plain.erb} +1 -1
- data/config/environment.rb +6 -5
- data/config/locale/en.rb +9 -0
- data/db/migrate/001_create_employees.rb +1 -1
- data/db/migrate/002_create_employee_slimtimers.rb +1 -1
- data/db/migrate/003_create_slimtimer_tasks.rb +1 -1
- data/db/migrate/004_create_slimtimer_time_entries.rb +1 -1
- data/db/migrate/005_create_clients.rb +1 -1
- data/db/migrate/006_create_client_representatives.rb +1 -1
- data/db/migrate/008_create_activities.rb +1 -1
- data/db/migrate/009_create_activity_labors.rb +1 -1
- data/db/migrate/010_create_employee_client_labor_rates.rb +1 -1
- data/db/migrate/011_create_activity_adjustments.rb +1 -1
- data/db/migrate/012_create_activity_materials.rb +1 -1
- data/db/migrate/013_create_activity_proposals.rb +1 -1
- data/db/migrate/014_create_invoices.rb +1 -1
- data/db/migrate/015_create_payments.rb +1 -1
- data/db/migrate/016_create_payment_methods.rb +1 -1
- data/db/migrate/017_create_invoice_payments.rb +1 -1
- data/db/migrate/018_create_activity_types.rb +2 -2
- data/db/migrate/019_create_settings.rb +1 -1
- data/db/migrate/023_create_credentials_migrate_representatives.rb +2 -2
- data/db/migrate/028_money_to_cents.rb +2 -2
- data/db/schema.rb +10 -10
- data/lib/brisk-bills.rb +2 -2
- data/lib/brisk-bills/initializer.rb +2 -2
- data/lib/generators/instance/templates/instance_environment.rb +1 -1
- data/lib/libpptable.rb +48 -0
- data/lib/tasks/create_last_months_invoices.rake +1 -14
- data/lib/tasks/first_time_setup.rake +2 -2
- data/lib/tasks/package.rake +2 -1
- data/lib/tasks/payment_assignment_consistency_check.rake +110 -0
- data/lib/utilities.rb +4 -4
- data/public/images/page-new.gif +0 -0
- data/public/javascripts/active_scaffold/default/active_scaffold.js +532 -430
- data/public/javascripts/active_scaffold/default/dhtml_history.js +1 -1
- data/public/javascripts/active_scaffold/default/form_enhancements.js +7 -4
- data/public/stylesheets/active_scaffold/default/stylesheet-ie.css +5 -5
- data/public/stylesheets/active_scaffold/default/stylesheet.css +54 -18
- data/public/stylesheets/admin/global.css +1 -1
- data/public/stylesheets/admin/pages.css +29 -0
- data/test/unit/activity/adjustment_test.rb +1 -1
- data/test/unit/activity/labor_test.rb +1 -1
- data/test/unit/activity/material_test.rb +1 -1
- data/test/unit/activity/proposal_test.rb +1 -1
- data/test/unit/activity_test.rb +1 -1
- data/test/unit/activity_type_test.rb +1 -1
- data/test/unit/client_eventlog_test.rb +1 -1
- data/test/unit/client_financial_transaction_test.rb +1 -1
- data/test/unit/client_representative_test.rb +1 -1
- data/test/unit/client_test.rb +37 -6
- data/test/unit/credential_test.rb +1 -1
- data/test/unit/employee/slimtimer_test.rb +1 -1
- data/test/unit/employee_client_labor_rate_test.rb +1 -1
- data/test/unit/employee_test.rb +1 -1
- data/test/unit/helpers/admin/draft_invoices_helper_test.rb +4 -0
- data/test/unit/invoice_payment_test.rb +90 -50
- data/test/unit/invoice_test.rb +48 -8
- data/test/unit/notifier_test.rb +1 -1
- data/test/unit/payment_method_test.rb +1 -1
- data/test/unit/payment_test.rb +7 -7
- data/test/unit/setting_test.rb +1 -1
- data/test/unit/slimtimer_task_test.rb +1 -1
- data/test/unit/slimtimer_time_entry_test.rb +1 -1
- data/vendor/plugins/active_scaffold/CHANGELOG +3 -1
- data/vendor/plugins/active_scaffold/README +18 -5
- data/vendor/plugins/active_scaffold/environment.rb +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/active_scaffold.js +532 -430
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/dhtml_history.js +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/form_enhancements.js +7 -4
- data/vendor/plugins/active_scaffold/frontends/default/stylesheets/stylesheet-ie.css +5 -5
- data/vendor/plugins/active_scaffold/frontends/default/stylesheets/stylesheet.css +54 -18
- data/vendor/plugins/active_scaffold/frontends/default/views/_add_existing_form.html.erb +3 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_create_form.html.erb +10 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_field_search.html.erb +7 -12
- data/vendor/plugins/active_scaffold/frontends/default/views/_form.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association.html.erb +15 -20
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association_footer.html.erb +8 -10
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_attribute.html.erb +5 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_hidden_attribute.html.erb +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform.html.erb +19 -21
- data/vendor/plugins/active_scaffold/frontends/default/views/{_form_association_header.html.erb → _horizontal_subform_header.html.erb} +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform_record.html.erb +31 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list.html.erb +4 -18
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_actions.html.erb +18 -5
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_calculations.html.erb +2 -9
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_column_headings.html.erb +4 -4
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_header.html.erb +6 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_inline_adapter.html.erb +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_messages.html.erb +20 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_pagination.html.erb +11 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_pagination_links.html.erb +3 -5
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_record.html.erb +2 -26
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_record_columns.html.erb +9 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_nested.html.erb +3 -12
- data/vendor/plugins/active_scaffold/frontends/default/views/_render_fields.js.rjs +11 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_search.html.erb +17 -11
- data/vendor/plugins/active_scaffold/frontends/default/views/_show.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_show_columns.html.erb +8 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_update_actions.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_update_form.html.erb +9 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/_vertical_subform.html.erb +7 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/add_existing.js.rjs +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/delete.html.erb +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/destroy.js.rjs +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/edit_associated.js.rjs +20 -15
- data/vendor/plugins/active_scaffold/frontends/default/views/list.html.erb +12 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/list.js.rjs +1 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/mark.js.rjs +6 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/on_create.js.rjs +12 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/on_update.js.rjs +13 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/render_field.js.rjs +1 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/search.html.erb +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/update.html.erb +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/update_column.js.rjs +4 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/update_row.js.rjs +2 -0
- data/vendor/plugins/active_scaffold/init.rb +2 -2
- data/vendor/plugins/active_scaffold/install.rb +1 -2
- data/vendor/plugins/active_scaffold/install_assets.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/active_record_permissions.rb +53 -42
- data/vendor/plugins/active_scaffold/lib/active_scaffold.rb +96 -23
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/common_search.rb +18 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/core.rb +152 -102
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/create.rb +81 -49
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/delete.rb +44 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/field_search.rb +60 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/list.rb +42 -37
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/mark.rb +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/nested.rb +94 -92
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/search.rb +54 -40
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/show.rb +30 -10
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/update.rb +62 -47
- data/vendor/plugins/active_scaffold/lib/active_scaffold/attribute_params.rb +187 -185
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/base.rb +28 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb +43 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/create.rb +8 -15
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/delete.rb +3 -4
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/field_search.rb +19 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/form.rb +2 -9
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/list.rb +46 -9
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/nested.rb +17 -7
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/search.rb +36 -16
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/show.rb +5 -12
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/subform.rb +8 -6
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/update.rb +12 -8
- data/vendor/plugins/active_scaffold/lib/active_scaffold/configurable.rb +2 -2
- data/vendor/plugins/active_scaffold/lib/active_scaffold/constraints.rb +173 -178
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_columns.rb +101 -97
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_link.rb +29 -19
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb +74 -34
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb +74 -74
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb +57 -62
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/sorting.rb +73 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/finder.rb +304 -234
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/association_helpers.rb +40 -40
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb +39 -24
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/country_helpers.rb +32 -28
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/form_column_helpers.rb +157 -86
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/id_helpers.rb +7 -7
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/list_column_helpers.rb +278 -85
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/pagination_helpers.rb +38 -12
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb +74 -35
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/show_column_helpers.rb +53 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/view_helpers.rb +51 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/de.yml +69 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/en.yml +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/es.yml +23 -13
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/fr.yml +68 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/hu.yml +24 -14
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/ja.yml +69 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/ru.yml +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/marked_model.rb +38 -0
- data/vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb +47 -13
- data/vendor/plugins/active_scaffold/lib/bridges/dependent_protect/bridge.rb +10 -0
- data/vendor/plugins/active_scaffold/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb +11 -0
- data/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb +3 -6
- data/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/form_ui.rb +10 -2
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/bridge.rb +13 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/form_ui.rb +20 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/list_ui.rb +16 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge.rb +32 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb +18 -0
- data/vendor/plugins/active_scaffold/lib/bridges/record_select/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/record_select/lib/record_select_bridge.rb +79 -0
- data/vendor/plugins/active_scaffold/lib/bridges/semantic_attributes/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/vendor/plugins/active_scaffold/lib/bridges/tiny_mce/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +57 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/bridge.rb +9 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb +14 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb +15 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb +16 -0
- data/vendor/plugins/active_scaffold/lib/bridges/validation_reflection/bridge.rb +9 -0
- data/vendor/plugins/active_scaffold/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb +19 -0
- data/vendor/plugins/active_scaffold/lib/extensions/action_view_rendering.rb +20 -8
- data/vendor/plugins/active_scaffold/lib/extensions/generic_view_paths.rb +2 -2
- data/vendor/plugins/active_scaffold/lib/extensions/paginator_extensions.rb +26 -0
- data/vendor/plugins/active_scaffold/lib/extensions/resources.rb +6 -5
- data/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb +26 -20
- data/vendor/plugins/active_scaffold/lib/extensions/unsaved_associated.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/paginator.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/responds_to_parent.rb +1 -1
- data/vendor/plugins/active_scaffold/shoulda_macros/macros.rb +136 -0
- data/vendor/plugins/active_scaffold/test/bridges/active_scaffold_dependent_protect_test.rb +34 -0
- data/vendor/plugins/active_scaffold/test/bridges/bridge_test.rb +43 -0
- data/vendor/plugins/active_scaffold/test/bridges/company.rb +81 -0
- data/vendor/plugins/active_scaffold/test/bridges/paperclip_test.rb +68 -0
- data/vendor/plugins/active_scaffold/test/bridges/tiny_mce_test.rb +27 -0
- data/vendor/plugins/active_scaffold/test/bridges/unobtrusive_date_picker_test.rb +49 -0
- data/vendor/plugins/active_scaffold/test/bridges/validation_reflection_test.rb +57 -0
- data/vendor/plugins/active_scaffold/test/config/base_test.rb +15 -0
- data/vendor/plugins/active_scaffold/test/config/core_test.rb +58 -0
- data/vendor/plugins/active_scaffold/test/config/create_test.rb +9 -6
- data/vendor/plugins/active_scaffold/test/config/delete_test.rb +33 -0
- data/vendor/plugins/active_scaffold/test/config/field_search_test.rb +47 -0
- data/vendor/plugins/active_scaffold/test/config/list_test.rb +66 -11
- data/vendor/plugins/active_scaffold/test/config/nested_test.rb +62 -0
- data/vendor/plugins/active_scaffold/test/config/search_test.rb +60 -0
- data/vendor/plugins/active_scaffold/test/config/show_test.rb +43 -0
- data/vendor/plugins/active_scaffold/test/config/subform_test.rb +17 -0
- data/vendor/plugins/active_scaffold/test/config/update_test.rb +27 -4
- data/vendor/plugins/active_scaffold/test/data_structures/action_columns_test.rb +2 -8
- data/vendor/plugins/active_scaffold/test/data_structures/action_link_test.rb +11 -11
- data/vendor/plugins/active_scaffold/test/data_structures/action_links_test.rb +5 -5
- data/vendor/plugins/active_scaffold/test/data_structures/association_column_test.rb +4 -3
- data/vendor/plugins/active_scaffold/test/data_structures/column_test.rb +29 -5
- data/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb +31 -1
- data/vendor/plugins/active_scaffold/test/data_structures/standard_column_test.rb +3 -13
- data/vendor/plugins/active_scaffold/test/data_structures/virtual_column_test.rb +0 -11
- data/vendor/plugins/active_scaffold/test/extensions/{array.rb → array_test.rb} +0 -0
- data/vendor/plugins/active_scaffold/test/helpers/form_column_helpers_test.rb +31 -0
- data/vendor/plugins/active_scaffold/test/helpers/list_column_helpers_test.rb +42 -0
- data/vendor/plugins/active_scaffold/test/helpers/pagination_helpers_test.rb +59 -0
- data/vendor/plugins/active_scaffold/test/misc/active_record_permissions_test.rb +154 -0
- data/vendor/plugins/active_scaffold/test/misc/attribute_params_test.rb +146 -0
- data/vendor/plugins/active_scaffold/test/misc/configurable_test.rb +2 -2
- data/vendor/plugins/active_scaffold/test/misc/constraints_test.rb +26 -8
- data/vendor/plugins/active_scaffold/test/misc/finder_test.rb +41 -19
- data/vendor/plugins/active_scaffold/test/misc/lang_test.rb +5 -6
- data/vendor/plugins/active_scaffold/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/vendor/plugins/active_scaffold/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/boot.rb +110 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environment.rb +43 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/development.rb +17 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/production.rb +28 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/test.rb +28 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/inflections.rb +10 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/session_store.rb +15 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/locales/en.yml +5 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/routes.rb +43 -0
- data/vendor/plugins/active_scaffold/test/mock_app/db/test.sqlite3 +1 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/blank.html +33 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +845 -0
- data/vendor/plugins/active_scaffold/test/model_stub.rb +17 -1
- data/vendor/plugins/active_scaffold/test/test_helper.rb +31 -5
- data/vendor/plugins/active_scaffold/uninstall.rb +2 -1
- data/vendor/plugins/active_scaffold_form_observation/init.rb +1 -1
- data/vendor/plugins/active_scaffold_form_observation/lib/active_scaffold_form_observation.rb +1 -2
- data/vendor/plugins/active_scaffold_full_refresh/init.rb +2 -0
- data/vendor/plugins/active_scaffold_full_refresh/lib/active_scaffold_full_refresh.rb +29 -0
- data/vendor/plugins/acts_as_money/{tasks → lib/tasks}/money_tasks.rake +0 -0
- metadata +668 -563
- data/app/model_views/client_accounting.rb +0 -5
- data/app/model_views/invoices_with_total.rb +0 -41
- data/app/views/admin/activities/_adjustment_column.rhtml +0 -23
- data/app/views/admin/activities_with_prices/move_to_invoice.rjs +0 -9
- data/app/views/notifier/invoice_available.html.rhtml +0 -5
- data/public/javascripts/prototype.js-1.6.0.3 +0 -4320
- data/test/functional/admin/activities_controller_test.rb +0 -8
- data/test/functional/admin/adjustments_controller_test.rb +0 -8
- data/test/functional/admin/client_accounting_controller_test.rb +0 -8
- data/test/functional/admin/client_financial_transactions_controller_test.rb +0 -8
- data/test/functional/admin/client_representatives_controller_test.rb +0 -8
- data/test/functional/admin/clients_controller_test.rb +0 -8
- data/test/functional/admin/employee_client_labor_rate_controller_test.rb +0 -8
- data/test/functional/admin/employees/slimtimer_controller_test.rb +0 -8
- data/test/functional/admin/employees_controller_test.rb +0 -8
- data/test/functional/admin/invoices_controller_test.rb +0 -8
- data/test/functional/admin/labors_controller_test.rb +0 -8
- data/test/functional/admin/materials_controller_test.rb +0 -8
- data/test/functional/admin/payments_controller_test.rb +0 -8
- data/test/functional/admin/proposals_controller_test.rb +0 -8
- data/test/functional/admin/settings_controller_test.rb +0 -8
- data/test/functional/authentication_controller_test.rb +0 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association_record.html.erb +0 -27
- data/vendor/plugins/active_scaffold/frontends/default/views/_live_search.html.erb +0 -25
- data/vendor/plugins/active_scaffold/frontends/default/views/form_messages_on_create.js.rjs +0 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/form_messages_on_update.js.rjs +0 -2
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/live_search.rb +0 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/live_search.rb +0 -52
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/en.rb +0 -66
- data/vendor/plugins/active_scaffold/lib/extensions/name_option_for_datetime.rb +0 -12
- data/vendor/plugins/active_scaffold/test/misc/active_record_permissions.rb +0 -154
@@ -1,75 +1,75 @@
|
|
1
|
-
module ActiveScaffold::DataStructures
|
2
|
-
class Columns
|
3
|
-
include Enumerable
|
4
|
-
include ActiveScaffold::Configurable
|
5
|
-
|
6
|
-
# The motivation for this collection is that this Columns data structure fills two roles: it provides
|
7
|
-
# the master list of all known columns, and it provides an inheritable list for all other actions (e.g.
|
8
|
-
# Create and Update and List). Well we actually want to *know* about as many columns as possible, so
|
9
|
-
# we don't want people actually removing columns from @set. But at the same time, we want to be able to
|
10
|
-
# manage which columns get inherited. Tada!
|
11
|
-
#
|
12
|
-
# This collection is referenced by other parts of ActiveScaffold and by methods within this DataStructure.
|
13
|
-
# IT IS NOT MEANT FOR PUBLIC USE (but if you know what you're doing, go ahead)
|
14
|
-
def _inheritable=(value)
|
15
|
-
@sorted = true
|
16
|
-
@_inheritable = value
|
17
|
-
end
|
18
|
-
|
19
|
-
# This accessor is used by ActionColumns to create new Column objects without adding them to this set
|
20
|
-
attr_reader :active_record_class
|
21
|
-
|
22
|
-
def initialize(active_record_class, *args)
|
23
|
-
@active_record_class = active_record_class
|
24
|
-
@_inheritable = []
|
25
|
-
@set = []
|
26
|
-
|
27
|
-
self.add *args
|
28
|
-
end
|
29
|
-
|
30
|
-
# the way to add columns to the set. this is primarily useful for virtual columns.
|
31
|
-
# note that this also makes columns inheritable
|
32
|
-
def add(*args)
|
33
|
-
args.flatten! # allow [] as a param
|
34
|
-
args = args.collect{ |a| a.to_sym }
|
35
|
-
|
36
|
-
# make the columns inheritable
|
37
|
-
@_inheritable.concat(args)
|
38
|
-
# then add columns to @set (unless they already exist)
|
39
|
-
args.each { |a| @set << ActiveScaffold::DataStructures::Column.new(a.to_sym, @active_record_class) unless find_by_name(a) }
|
40
|
-
end
|
41
|
-
alias_method :<<, :add
|
42
|
-
|
43
|
-
def exclude(*args)
|
44
|
-
# only remove columns from _inheritable. we never want to completely forget about a column.
|
45
|
-
args.each { |a| @_inheritable.delete a }
|
46
|
-
end
|
47
|
-
|
48
|
-
# returns an array of columns with the provided names
|
49
|
-
def find_by_names(*names)
|
50
|
-
@set.find_all { |column| names.include? column.name }
|
51
|
-
end
|
52
|
-
|
53
|
-
# returns the column of the given name.
|
54
|
-
def find_by_name(name)
|
55
|
-
# this works because of `def column.=='
|
56
|
-
column = @set.find { |c| c == name }
|
57
|
-
column
|
58
|
-
end
|
59
|
-
alias_method :[], :find_by_name
|
60
|
-
|
61
|
-
def each
|
62
|
-
@set.each {|i| yield i }
|
63
|
-
end
|
64
|
-
|
65
|
-
def _inheritable
|
66
|
-
if @sorted
|
67
|
-
@_inheritable
|
68
|
-
else
|
69
|
-
@_inheritable.sort do |a, b|
|
70
|
-
self[a] <=> self[b]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
module ActiveScaffold::DataStructures
|
2
|
+
class Columns
|
3
|
+
include Enumerable
|
4
|
+
include ActiveScaffold::Configurable
|
5
|
+
|
6
|
+
# The motivation for this collection is that this Columns data structure fills two roles: it provides
|
7
|
+
# the master list of all known columns, and it provides an inheritable list for all other actions (e.g.
|
8
|
+
# Create and Update and List). Well we actually want to *know* about as many columns as possible, so
|
9
|
+
# we don't want people actually removing columns from @set. But at the same time, we want to be able to
|
10
|
+
# manage which columns get inherited. Tada!
|
11
|
+
#
|
12
|
+
# This collection is referenced by other parts of ActiveScaffold and by methods within this DataStructure.
|
13
|
+
# IT IS NOT MEANT FOR PUBLIC USE (but if you know what you're doing, go ahead)
|
14
|
+
def _inheritable=(value)
|
15
|
+
@sorted = true
|
16
|
+
@_inheritable = value
|
17
|
+
end
|
18
|
+
|
19
|
+
# This accessor is used by ActionColumns to create new Column objects without adding them to this set
|
20
|
+
attr_reader :active_record_class
|
21
|
+
|
22
|
+
def initialize(active_record_class, *args)
|
23
|
+
@active_record_class = active_record_class
|
24
|
+
@_inheritable = []
|
25
|
+
@set = []
|
26
|
+
|
27
|
+
self.add *args
|
28
|
+
end
|
29
|
+
|
30
|
+
# the way to add columns to the set. this is primarily useful for virtual columns.
|
31
|
+
# note that this also makes columns inheritable
|
32
|
+
def add(*args)
|
33
|
+
args.flatten! # allow [] as a param
|
34
|
+
args = args.collect{ |a| a.to_sym }
|
35
|
+
|
36
|
+
# make the columns inheritable
|
37
|
+
@_inheritable.concat(args)
|
38
|
+
# then add columns to @set (unless they already exist)
|
39
|
+
args.each { |a| @set << ActiveScaffold::DataStructures::Column.new(a.to_sym, @active_record_class) unless find_by_name(a) }
|
40
|
+
end
|
41
|
+
alias_method :<<, :add
|
42
|
+
|
43
|
+
def exclude(*args)
|
44
|
+
# only remove columns from _inheritable. we never want to completely forget about a column.
|
45
|
+
args.each { |a| @_inheritable.delete a }
|
46
|
+
end
|
47
|
+
|
48
|
+
# returns an array of columns with the provided names
|
49
|
+
def find_by_names(*names)
|
50
|
+
@set.find_all { |column| names.include? column.name }
|
51
|
+
end
|
52
|
+
|
53
|
+
# returns the column of the given name.
|
54
|
+
def find_by_name(name)
|
55
|
+
# this works because of `def column.=='
|
56
|
+
column = @set.find { |c| c == name }
|
57
|
+
column
|
58
|
+
end
|
59
|
+
alias_method :[], :find_by_name
|
60
|
+
|
61
|
+
def each
|
62
|
+
@set.each {|i| yield i }
|
63
|
+
end
|
64
|
+
|
65
|
+
def _inheritable
|
66
|
+
if @sorted
|
67
|
+
@_inheritable
|
68
|
+
else
|
69
|
+
@_inheritable.sort do |a, b|
|
70
|
+
self[a] <=> self[b]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
75
|
end
|
@@ -1,62 +1,57 @@
|
|
1
|
-
module ActiveScaffold::DataStructures
|
2
|
-
class Set
|
3
|
-
include Enumerable
|
4
|
-
include ActiveScaffold::Configurable
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# returns
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def
|
49
|
-
@set.
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@set.empty?
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
1
|
+
module ActiveScaffold::DataStructures
|
2
|
+
class Set
|
3
|
+
include Enumerable
|
4
|
+
include ActiveScaffold::Configurable
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
@set = []
|
8
|
+
self.add *args
|
9
|
+
end
|
10
|
+
|
11
|
+
# the way to add items to the set.
|
12
|
+
def add(*args)
|
13
|
+
args.flatten! # allow [] as a param
|
14
|
+
args.each { |arg|
|
15
|
+
arg = arg.to_sym if arg.is_a? String
|
16
|
+
@set << arg unless @set.include? arg # avoid duplicates
|
17
|
+
}
|
18
|
+
end
|
19
|
+
alias_method :<<, :add
|
20
|
+
|
21
|
+
# the way to remove items from the set.
|
22
|
+
def exclude(*args)
|
23
|
+
args.flatten! # allow [] as a param
|
24
|
+
args.collect! { |a| a.to_sym } # symbolize the args
|
25
|
+
# check respond_to? :to_sym, ActionColumns doesn't respond to to_sym
|
26
|
+
@set.reject! { |c| c.respond_to? :to_sym and args.include? c.to_sym } # reject all items specified
|
27
|
+
end
|
28
|
+
alias_method :remove, :exclude
|
29
|
+
|
30
|
+
# returns an array of items with the provided names
|
31
|
+
def find_by_names(*names)
|
32
|
+
@set.find_all { |item| names.include? item }
|
33
|
+
end
|
34
|
+
|
35
|
+
# returns the item of the given name.
|
36
|
+
def find_by_name(name)
|
37
|
+
# this works because of `def item.=='
|
38
|
+
item = @set.find { |c| c == name }
|
39
|
+
item
|
40
|
+
end
|
41
|
+
alias_method :[], :find_by_name
|
42
|
+
|
43
|
+
def each
|
44
|
+
@set.each {|i| yield i }
|
45
|
+
end
|
46
|
+
|
47
|
+
# returns the number of items in the set
|
48
|
+
def length
|
49
|
+
@set.length
|
50
|
+
end
|
51
|
+
|
52
|
+
def empty?
|
53
|
+
@set.empty?
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -7,7 +7,17 @@ module ActiveScaffold::DataStructures
|
|
7
7
|
@columns = columns
|
8
8
|
@clauses = []
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
def set_default_sorting(model)
|
12
|
+
last_scope = model.default_scoping.last
|
13
|
+
if last_scope.nil? || last_scope[:find].nil? || last_scope[:find][:order].nil?
|
14
|
+
set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key)
|
15
|
+
else
|
16
|
+
set_sorting_from_order_clause(last_scope[:find][:order].to_s, model.table_name)
|
17
|
+
@default_sorting = true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
# add a clause to the sorting, assuming the column is sortable
|
12
22
|
def add(column_name, direction = nil)
|
13
23
|
direction ||= 'ASC'
|
@@ -15,7 +25,7 @@ module ActiveScaffold::DataStructures
|
|
15
25
|
column = get_column(column_name)
|
16
26
|
raise ArgumentError, "Could not find column #{column_name}" if column.nil?
|
17
27
|
raise ArgumentError, "Sorting direction unknown" unless [:ASC, :DESC].include? direction.to_sym
|
18
|
-
@clauses << [column, direction] if column.sortable?
|
28
|
+
@clauses << [column, direction.untaint] if column.sortable?
|
19
29
|
raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting?
|
20
30
|
end
|
21
31
|
|
@@ -32,6 +42,7 @@ module ActiveScaffold::DataStructures
|
|
32
42
|
|
33
43
|
# clears the sorting
|
34
44
|
def clear
|
45
|
+
@default_sorting = false
|
35
46
|
@clauses = []
|
36
47
|
end
|
37
48
|
|
@@ -65,6 +76,22 @@ module ActiveScaffold::DataStructures
|
|
65
76
|
@clauses.first
|
66
77
|
end
|
67
78
|
|
79
|
+
# builds an order-by clause
|
80
|
+
def clause
|
81
|
+
return nil if sorts_by_method? || default_sorting?
|
82
|
+
|
83
|
+
# unless the sorting is by method, create the sql string
|
84
|
+
order = []
|
85
|
+
each do |sort_column, sort_direction|
|
86
|
+
sql = sort_column.sort[:sql]
|
87
|
+
next if sql.nil? or sql.empty?
|
88
|
+
|
89
|
+
order << "#{sql} #{sort_direction}"
|
90
|
+
end
|
91
|
+
|
92
|
+
order.join(', ') unless order.empty?
|
93
|
+
end
|
94
|
+
|
68
95
|
protected
|
69
96
|
|
70
97
|
# retrieves the sorting clause for the given column
|
@@ -85,5 +112,48 @@ module ActiveScaffold::DataStructures
|
|
85
112
|
def mixed_sorting?
|
86
113
|
sorts_by_method? and sorts_by_sql?
|
87
114
|
end
|
115
|
+
|
116
|
+
def default_sorting?
|
117
|
+
@default_sorting
|
118
|
+
end
|
119
|
+
|
120
|
+
def set_sorting_from_order_clause(order_clause, model_table_name = nil)
|
121
|
+
clear
|
122
|
+
order_clause.split(',').each do |criterion|
|
123
|
+
unless criterion.blank?
|
124
|
+
order_parts = extract_order_parts(criterion)
|
125
|
+
add(order_parts[:column_name], order_parts[:direction]) unless different_table?(model_table_name, order_parts[:table_name])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def extract_order_parts(criterion_parts)
|
131
|
+
column_name_part, direction_part = criterion_parts.strip.split(' ')
|
132
|
+
column_name_parts = column_name_part.split('.')
|
133
|
+
order = {:direction => extract_direction(direction_part),
|
134
|
+
:column_name => remove_quotes(column_name_parts.last)}
|
135
|
+
order[:table_name] = remove_quotes(column_name_parts[-2]) if column_name_parts.length >= 2
|
136
|
+
order
|
137
|
+
end
|
138
|
+
|
139
|
+
def different_table?(model_table_name, order_table_name)
|
140
|
+
!order_table_name.nil? && model_table_name != order_table_name
|
141
|
+
end
|
142
|
+
|
143
|
+
def remove_quotes(sql_name)
|
144
|
+
if sql_name.starts_with?('"') || sql_name.starts_with?('`')
|
145
|
+
sql_name[1, (sql_name.length - 2)]
|
146
|
+
else
|
147
|
+
sql_name
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def extract_direction(direction_part)
|
152
|
+
if direction_part.to_s.upcase == 'DESC'
|
153
|
+
'DESC'
|
154
|
+
else
|
155
|
+
'ASC'
|
156
|
+
end
|
157
|
+
end
|
88
158
|
end
|
89
|
-
end
|
159
|
+
end
|
@@ -1,234 +1,304 @@
|
|
1
|
-
module ActiveScaffold
|
2
|
-
module Finder
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
end
|
233
|
-
|
234
|
-
|
1
|
+
module ActiveScaffold
|
2
|
+
module Finder
|
3
|
+
def self.like_operator
|
4
|
+
@@like_operator ||= ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
# Takes a collection of search terms (the tokens) and creates SQL that
|
9
|
+
# searches all specified ActiveScaffold columns. A row will match if each
|
10
|
+
# token is found in at least one of the columns.
|
11
|
+
def create_conditions_for_columns(tokens, columns, text_search = :full)
|
12
|
+
# if there aren't any columns, then just return a nil condition
|
13
|
+
return unless columns.length > 0
|
14
|
+
like_pattern = like_pattern(text_search)
|
15
|
+
|
16
|
+
tokens = [tokens] if tokens.is_a? String
|
17
|
+
|
18
|
+
where_clauses = []
|
19
|
+
columns.each do |column|
|
20
|
+
where_clauses << ((column.column.nil? || column.column.text?) ? "#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?" : "#{column.search_sql} = ?")
|
21
|
+
end
|
22
|
+
phrase = "(#{where_clauses.join(' OR ')})"
|
23
|
+
|
24
|
+
sql = ([phrase] * tokens.length).join(' AND ')
|
25
|
+
tokens = tokens.collect do |value|
|
26
|
+
columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)}
|
27
|
+
end.flatten
|
28
|
+
|
29
|
+
[sql, *tokens]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Generates an SQL condition for the given ActiveScaffold column based on
|
33
|
+
# that column's database type (or form_ui ... for virtual columns?).
|
34
|
+
# TODO: this should reside on the column, not the controller
|
35
|
+
def condition_for_column(column, value, text_search = :full)
|
36
|
+
like_pattern = like_pattern(text_search)
|
37
|
+
if self.respond_to?("condition_for_#{column.name}_column")
|
38
|
+
return self.send("condition_for_#{column.name}_column", column, value, like_pattern)
|
39
|
+
end
|
40
|
+
return unless column and column.search_sql and not value.blank?
|
41
|
+
search_ui = column.search_ui || column.column.try(:type)
|
42
|
+
begin
|
43
|
+
if search_ui && self.respond_to?("condition_for_#{search_ui}_type")
|
44
|
+
self.send("condition_for_#{search_ui}_type", column, value, like_pattern)
|
45
|
+
else
|
46
|
+
case search_ui
|
47
|
+
when :boolean, :checkbox
|
48
|
+
["#{column.search_sql} = ?", column.column.type_cast(value)]
|
49
|
+
when :select, :multi_select, :country, :usa_state
|
50
|
+
["#{column.search_sql} in (?)", value]
|
51
|
+
else
|
52
|
+
if column.column.nil? || column.column.text?
|
53
|
+
["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
|
54
|
+
else
|
55
|
+
["#{column.search_sql} = ?", column.column.type_cast(value)]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
rescue Exception => e
|
60
|
+
logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{@controller.class}"
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def condition_for_integer_type(column, value, like_pattern = nil)
|
66
|
+
if column.options[:format]
|
67
|
+
if value.is_a?(Hash)
|
68
|
+
value[:from] = column.number_to_native(value[:from])
|
69
|
+
value[:to] = column.number_to_native(value[:to])
|
70
|
+
else
|
71
|
+
value = column.number_to_native(value)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if !value.is_a?(Hash)
|
76
|
+
["#{column.search_sql} = ?", column.column.nil? ? value.to_f : column.column.type_cast(value)]
|
77
|
+
elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt])
|
78
|
+
condition = "#{column.search_sql} #{value[:opt].humanize}"
|
79
|
+
elsif value[:from].blank?
|
80
|
+
nil
|
81
|
+
elsif value[:opt] == 'BETWEEN'
|
82
|
+
condition = "#{column.search_sql} BETWEEN ? AND ?"
|
83
|
+
if column.column.nil?
|
84
|
+
[condition, value[:from].to_f, value[:to].to_f]
|
85
|
+
else
|
86
|
+
[condition, column.column.type_cast(value[:from]), column.column.type_cast(value[:to])]
|
87
|
+
end
|
88
|
+
elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt])
|
89
|
+
["#{column.search_sql} #{value[:opt]} ?", column.column.nil? ? value[:from].to_f : column.column.type_cast(value[:from])]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
alias_method :condition_for_decimal_type, :condition_for_integer_type
|
93
|
+
alias_method :condition_for_float_type, :condition_for_integer_type
|
94
|
+
|
95
|
+
def condition_for_range_type(column, value, like_pattern = nil)
|
96
|
+
if !value.is_a?(Hash)
|
97
|
+
if column.column.nil? || column.column.text?
|
98
|
+
["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
|
99
|
+
else
|
100
|
+
["#{column.search_sql} = ?", column.column.type_cast(value)]
|
101
|
+
end
|
102
|
+
elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt])
|
103
|
+
condition = "#{column.search_sql} #{value[:opt].humanize}"
|
104
|
+
elsif value[:from].blank?
|
105
|
+
nil
|
106
|
+
elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt])
|
107
|
+
["#{column.search_sql} LIKE ?", value[:opt].sub('?', value[:from])]
|
108
|
+
elsif value[:opt] == 'BETWEEN'
|
109
|
+
["#{column.search_sql} BETWEEN ? AND ?", value[:from], value[:to]]
|
110
|
+
elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt])
|
111
|
+
["#{column.search_sql} #{value[:opt]} ?", value[:from]]
|
112
|
+
else
|
113
|
+
nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
alias_method :condition_for_string_type, :condition_for_range_type
|
117
|
+
|
118
|
+
def condition_for_datetime_type(column, value, like_pattern = nil)
|
119
|
+
conversion = value[:from][:hour].blank? && value[:to][:hour].blank? ? :to_date : :to_time
|
120
|
+
from_value, to_value = [:from, :to].collect do |field|
|
121
|
+
Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[field][part].to_i}) rescue nil
|
122
|
+
end
|
123
|
+
|
124
|
+
if from_value.nil? and to_value.nil?
|
125
|
+
nil
|
126
|
+
elsif !from_value
|
127
|
+
["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)]
|
128
|
+
elsif !to_value
|
129
|
+
["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)]
|
130
|
+
else
|
131
|
+
["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
alias_method :condition_for_date_type, :condition_for_datetime_type
|
135
|
+
alias_method :condition_for_time_type, :condition_for_datetime_type
|
136
|
+
alias_method :condition_for_timestamp_type, :condition_for_datetime_type
|
137
|
+
|
138
|
+
def condition_for_record_select_type(column, value, like_pattern = nil)
|
139
|
+
if value.is_a?(Array)
|
140
|
+
["#{column.search_sql} IN (?)", value]
|
141
|
+
else
|
142
|
+
["#{column.search_sql} = ?", value]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def like_pattern(text_search)
|
147
|
+
case text_search
|
148
|
+
when :full then '%?%'
|
149
|
+
when :start then '?%'
|
150
|
+
when :end then '%?'
|
151
|
+
else '?'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
NumericComparators = [
|
157
|
+
'=',
|
158
|
+
'>=',
|
159
|
+
'<=',
|
160
|
+
'>',
|
161
|
+
'<',
|
162
|
+
'!=',
|
163
|
+
'BETWEEN'
|
164
|
+
]
|
165
|
+
StringComparators = ActiveSupport::OrderedHash[
|
166
|
+
:contains, '%?%',
|
167
|
+
:begins_with, '?%',
|
168
|
+
:ends_with, '%?'
|
169
|
+
]
|
170
|
+
|
171
|
+
NullComparators = ['is_null', 'is_not_null']
|
172
|
+
|
173
|
+
def self.included(klass)
|
174
|
+
klass.extend ClassMethods
|
175
|
+
end
|
176
|
+
|
177
|
+
protected
|
178
|
+
|
179
|
+
attr_writer :active_scaffold_conditions
|
180
|
+
def active_scaffold_conditions
|
181
|
+
@active_scaffold_conditions ||= []
|
182
|
+
end
|
183
|
+
|
184
|
+
attr_writer :active_scaffold_includes
|
185
|
+
def active_scaffold_includes
|
186
|
+
@active_scaffold_includes ||= []
|
187
|
+
end
|
188
|
+
|
189
|
+
attr_writer :active_scaffold_habtm_joins
|
190
|
+
def active_scaffold_habtm_joins
|
191
|
+
@active_scaffold_habtm_joins ||= []
|
192
|
+
end
|
193
|
+
|
194
|
+
def all_conditions
|
195
|
+
merge_conditions(
|
196
|
+
active_scaffold_conditions, # from the search modules
|
197
|
+
conditions_for_collection, # from the dev
|
198
|
+
conditions_from_params, # from the parameters (e.g. /users/list?first_name=Fred)
|
199
|
+
conditions_from_constraints, # from any constraints (embedded scaffolds)
|
200
|
+
active_scaffold_session_storage[:conditions] # embedding conditions (weaker constraints)
|
201
|
+
)
|
202
|
+
end
|
203
|
+
|
204
|
+
# returns a single record (the given id) but only if it's allowed for the specified action.
|
205
|
+
# accomplishes this by checking model.#{action}_authorized?
|
206
|
+
# TODO: this should reside on the model, not the controller
|
207
|
+
def find_if_allowed(id, crud_type, klass = beginning_of_chain)
|
208
|
+
record = klass.find(id)
|
209
|
+
raise ActiveScaffold::RecordNotAllowed, "#{klass} with id = #{id}" unless record.authorized_for?(:crud_type => crud_type.to_sym)
|
210
|
+
return record
|
211
|
+
end
|
212
|
+
|
213
|
+
# returns a hash with options to find records
|
214
|
+
# valid options may include:
|
215
|
+
# * :sorting - a Sorting DataStructure (basically an array of hashes of field => direction, e.g. [{:field1 => 'asc'}, {:field2 => 'desc'}]). please note that multi-column sorting has some limitations: if any column in a multi-field sort uses method-based sorting, it will be ignored. method sorting only works for single-column sorting.
|
216
|
+
# * :per_page
|
217
|
+
# * :page
|
218
|
+
def finder_options(options = {})
|
219
|
+
options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select
|
220
|
+
|
221
|
+
search_conditions = all_conditions
|
222
|
+
full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes)
|
223
|
+
|
224
|
+
# create a general-use options array that's compatible with Rails finders
|
225
|
+
finder_options = { :order => options[:sorting].try(:clause),
|
226
|
+
:conditions => search_conditions,
|
227
|
+
:joins => joins_for_finder,
|
228
|
+
:include => full_includes}
|
229
|
+
|
230
|
+
finder_options.merge! custom_finder_options
|
231
|
+
finder_options
|
232
|
+
end
|
233
|
+
|
234
|
+
# Returns a hash with options to count records, rejecting select and order options
|
235
|
+
# See finder_options for valid options
|
236
|
+
def count_options(find_options = {}, count_includes = nil)
|
237
|
+
count_includes ||= find_options[:include] unless find_options[:conditions].nil?
|
238
|
+
options = find_options.reject{|k,v| [:select, :order].include? k}
|
239
|
+
options[:include] = count_includes
|
240
|
+
options
|
241
|
+
end
|
242
|
+
|
243
|
+
# returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters
|
244
|
+
# See finder_options for valid options
|
245
|
+
# TODO: this should reside on the model, not the controller
|
246
|
+
def find_page(options = {})
|
247
|
+
options[:per_page] ||= 999999999
|
248
|
+
options[:page] ||= 1
|
249
|
+
|
250
|
+
find_options = finder_options(options)
|
251
|
+
klass = beginning_of_chain
|
252
|
+
|
253
|
+
# NOTE: we must use :include in the count query, because some conditions may reference other tables
|
254
|
+
count = klass.count(count_options(find_options, options[:count_includes])) if options[:pagination] && options[:pagination] != :infinite
|
255
|
+
|
256
|
+
# Converts count to an integer if ActiveRecord returned an OrderedHash
|
257
|
+
# that happens when find_options contains a :group key
|
258
|
+
count = count.length if count.is_a? ActiveSupport::OrderedHash
|
259
|
+
|
260
|
+
# we build the paginator differently for method- and sql-based sorting
|
261
|
+
if options[:sorting] and options[:sorting].sorts_by_method?
|
262
|
+
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
263
|
+
sorted_collection = sort_collection_by_column(klass.all(find_options), *options[:sorting].first)
|
264
|
+
sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination]
|
265
|
+
sorted_collection
|
266
|
+
end
|
267
|
+
else
|
268
|
+
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
269
|
+
find_options.merge!(:offset => offset, :limit => per_page) if options[:pagination]
|
270
|
+
klass.all(find_options)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
pager.page(options[:page])
|
275
|
+
end
|
276
|
+
|
277
|
+
def joins_for_finder
|
278
|
+
case joins_for_collection
|
279
|
+
when String
|
280
|
+
[ joins_for_collection ]
|
281
|
+
when Array
|
282
|
+
joins_for_collection
|
283
|
+
else
|
284
|
+
[]
|
285
|
+
end + active_scaffold_habtm_joins
|
286
|
+
end
|
287
|
+
|
288
|
+
def merge_conditions(*conditions)
|
289
|
+
active_scaffold_config.model.merge_conditions(*conditions)
|
290
|
+
end
|
291
|
+
|
292
|
+
# TODO: this should reside on the column, not the controller
|
293
|
+
def sort_collection_by_column(collection, column, order)
|
294
|
+
sorter = column.sort[:method]
|
295
|
+
collection = collection.sort_by { |record|
|
296
|
+
value = (sorter.is_a? Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter)
|
297
|
+
value = '' if value.nil?
|
298
|
+
value
|
299
|
+
}
|
300
|
+
collection.reverse! if order.downcase == 'desc'
|
301
|
+
collection
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|