spree 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of spree might be problematic. Click here for more details.
- data/CHANGELOG +30 -0
- data/CONTRIBUTORS +38 -20
- data/app/controllers/admin/creditcard_payments_controller.rb +10 -3
- data/app/controllers/admin/orders_controller.rb +17 -16
- data/app/controllers/admin/products_controller.rb +12 -14
- data/app/controllers/admin/reports_controller.rb +12 -14
- data/app/controllers/admin/users_controller.rb +10 -5
- data/app/controllers/admin/zones_controller.rb +4 -1
- data/app/controllers/application.rb +0 -1
- data/app/controllers/checkout_controller.rb +96 -0
- data/app/controllers/content_controller.rb +11 -1
- data/app/controllers/orders_controller.rb +12 -33
- data/app/controllers/products_controller.rb +12 -7
- data/app/controllers/spree/base_controller.rb +1 -1
- data/app/controllers/states_controller.rb +14 -2
- data/app/controllers/taxons_controller.rb +6 -2
- data/app/controllers/users_controller.rb +9 -6
- data/app/helpers/application_helper.rb +1 -11
- data/app/helpers/products_helper.rb +3 -1
- data/app/helpers/spree/base_helper.rb +0 -26
- data/app/models/address.rb +3 -3
- data/app/models/app_configuration.rb +1 -0
- data/app/models/country.rb +4 -0
- data/app/models/creditcard.rb +6 -1
- data/app/models/creditcard_payment.rb +1 -1
- data/app/models/inventory_unit.rb +4 -1
- data/app/models/order.rb +37 -21
- data/app/models/product.rb +19 -8
- data/{vendor/extensions/shipping/app → app}/models/shipment.rb +20 -4
- data/{vendor/extensions/shipping/app → app}/models/shipping_category.rb +0 -0
- data/{vendor/extensions/shipping/app → app}/models/shipping_method.rb +6 -4
- data/app/models/state.rb +5 -0
- data/app/models/user.rb +4 -2
- data/app/models/variant.rb +19 -1
- data/app/presenters/checkout_presenter.rb +58 -0
- data/app/views/admin/creditcard_payments/edit.html.erb +1 -1
- data/app/views/admin/option_types/available.html.erb +1 -1
- data/app/views/admin/orders/index.html.erb +28 -18
- data/app/views/admin/orders/show.html.erb +1 -1
- data/app/views/admin/payments/index.html.erb +1 -1
- data/app/views/admin/products/_images.html.erb +1 -1
- data/app/views/admin/products/index.html.erb +17 -13
- data/app/views/admin/users/index.html.erb +8 -8
- data/app/views/admin/zones/index.html.erb +5 -2
- data/app/views/checkout/_form.html.erb +165 -0
- data/app/views/{creditcards → checkout}/cvv.html.erb +1 -1
- data/app/views/checkout/new.html.erb +6 -0
- data/app/views/layouts/admin.html.erb +2 -3
- data/app/views/layouts/application.html.erb +1 -1
- data/app/views/orders/_form.html.erb +6 -4
- data/app/views/orders/_google_order.html.erb +24 -0
- data/app/views/orders/_line_item.html.erb +2 -1
- data/app/views/orders/show.html.erb +4 -1
- data/app/views/products/index.html.erb +2 -1
- data/app/views/products/show.html.erb +4 -4
- data/app/views/shared/_footer.html.erb +12 -1
- data/app/views/shared/_login.html.erb +1 -1
- data/app/views/shared/_order_details.html.erb +8 -9
- data/app/views/shared/_products.html.erb +1 -1
- data/app/views/shared/_report_criteria.html.erb +28 -28
- data/app/views/states/index.js.erb +10 -1
- data/config/environment.rb +10 -4
- data/config/initializers/searchlogic.rb +6 -0
- data/config/locales/de.yml +14 -0
- data/config/locales/en-GB.yml +20 -6
- data/config/locales/en-US.yml +20 -4
- data/config/locales/es.yml +14 -0
- data/config/locales/fr-FR.yml +463 -0
- data/config/locales/fr-FR_rails.yml +115 -0
- data/config/locales/it.yml +14 -0
- data/config/locales/nb-NO.yml +457 -0
- data/config/locales/nb-NO_rails.yml +105 -0
- data/config/locales/pl.yml +14 -0
- data/config/locales/pt-BR.yml +14 -0
- data/config/locales/pt-PT.yml +14 -0
- data/config/locales/ru-RU.yml +458 -0
- data/config/locales/ru-RU_rails.yml +154 -0
- data/config/routes.rb +11 -4
- data/db/migrate/20090204200045_add_order_permalink.rb +13 -0
- data/db/migrate/20090225231119_add_more_needed_keys_items_and_conf.rb +19 -0
- data/db/migrate/20090302221152_give_all_users_user_role.rb +13 -0
- data/db/sample/orders.yml +1 -1
- data/lib/generators/instance/instance_generator.rb +1 -1
- data/lib/spree.rb +1 -1
- data/lib/spree/setup.rb +1 -1
- data/lib/tasks/database.rake +5 -2
- data/lib/tasks/release.rake +1 -1
- data/lib/tasks/upgrade.rake +11 -0
- data/public/assets/products/1009/mini/sean.jpg +0 -0
- data/public/assets/products/1009/original/sean.jpg +0 -0
- data/public/assets/products/1009/product/sean.jpg +0 -0
- data/public/assets/products/1009/small/sean.jpg +0 -0
- data/public/images/ajax_loader.gif +0 -0
- data/public/javascripts/checkout.js +284 -0
- data/public/javascripts/jquery-1.3.2.min.js +19 -0
- data/public/javascripts/jquery.validate.pack.js +15 -0
- data/public/stylesheets/checkout.css +25 -0
- data/public/stylesheets/spree-admin.css +6 -2
- data/public/stylesheets/spree.css +419 -432
- data/spec/controllers/countries_controller_spec.rb +3 -2
- data/spec/controllers/orders_controller_spec.rb +7 -5
- data/spec/controllers/states_controller_spec.rb +4 -2
- data/spec/models/creditcard_payment_spec.rb +6 -2
- data/spec/models/order_spec.rb +164 -157
- data/spec/models/product_spec.rb +2 -2
- data/vendor/extensions/payment_gateway/db/migrate/20090218091936_create_protx_gateway.rb +18 -0
- data/vendor/extensions/payment_gateway/lib/spree/payment_gateway.rb +7 -5
- data/vendor/extensions/shipping/app/controllers/admin/shipments_controller.rb +6 -5
- data/vendor/extensions/shipping/app/views/admin/shipments/index.html.erb +1 -1
- data/vendor/extensions/shipping/config/locales/nb-NO.yml +25 -0
- data/vendor/extensions/shipping/config/locales/ru-RU.yml +25 -0
- data/vendor/extensions/shipping/db/sample/shipping_methods.yml +5 -1
- data/vendor/extensions/shipping/db/sample/zone_members.yml +9 -1
- data/vendor/extensions/shipping/db/sample/zones.yml +4 -1
- data/vendor/extensions/shipping/lib/spree/shipping_calculator.rb +0 -16
- data/vendor/extensions/shipping/shipping_extension.rb +0 -15
- data/vendor/extensions/shipping/spec/models/shipping_method_spec.rb +16 -10
- data/vendor/extensions/shipping/spec/models/shipping_order_spec.rb +3 -17
- data/vendor/extensions/tax_calculator/config/locales/nb-NO.yml +30 -0
- data/vendor/extensions/tax_calculator/spec/models/{order_spec.rb → order_tax_calc_spec.rb} +2 -2
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/.specification +3 -5
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/LICENSE +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/README +9 -2
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/Rakefile +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/active_presenter.rb +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/active_presenter/base.rb +38 -8
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/active_presenter/version.rb +1 -1
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/tasks/doc.rake +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/tasks/gem.rake +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/test/base_test.rb +66 -30
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/test/test_helper.rb +36 -0
- data/vendor/plugins/attribute_fu/lib/attribute_fu/associated_form_helper.rb +12 -4
- data/vendor/plugins/find_by_param/MIT-LICENSE +1 -1
- data/vendor/plugins/find_by_param/{README → README.markdown} +7 -1
- data/vendor/plugins/find_by_param/init.rb +0 -1
- data/vendor/plugins/find_by_param/lib/find_by_param.rb +23 -87
- data/vendor/plugins/find_by_param/test/find_by_param_test.rb +22 -8
- data/vendor/plugins/find_by_param/test/test_helper.rb +0 -1
- metadata +65 -193
- data/app/controllers/creditcards_controller.rb +0 -73
- data/app/models/order_filter.rb +0 -28
- data/app/models/user_filter.rb +0 -6
- data/app/views/creditcards/_form_credit_card.html.erb +0 -30
- data/app/views/creditcards/new.html.erb +0 -25
- data/app/views/shared/_paginate.html.erb +0 -34
- data/lib/plugins/paginating_find/CHANGELOG +0 -120
- data/lib/plugins/paginating_find/README +0 -89
- data/lib/plugins/paginating_find/init.rb +0 -2
- data/lib/plugins/paginating_find/lib/paginating_find.rb +0 -138
- data/lib/plugins/paginating_find/lib/paging_enumerator.rb +0 -158
- data/lib/plugins/paginating_find/lib/paging_helper.rb +0 -47
- data/lib/plugins/paginating_find/test_app/Rakefile +0 -10
- data/lib/plugins/paginating_find/test_app/app/controllers/application.rb +0 -2
- data/lib/plugins/paginating_find/test_app/config/boot.rb +0 -44
- data/lib/plugins/paginating_find/test_app/config/database.yml +0 -6
- data/lib/plugins/paginating_find/test_app/config/environment.rb +0 -53
- data/lib/plugins/paginating_find/test_app/config/environments/test.rb +0 -19
- data/lib/plugins/paginating_find/test_app/config/routes.rb +0 -22
- data/lib/plugins/paginating_find/test_app/script/breakpointer +0 -3
- data/lib/plugins/paginating_find/test_app/script/console +0 -3
- data/lib/plugins/paginating_find/test_app/test/fixtures/articles.yml +0 -19
- data/lib/plugins/paginating_find/test_app/test/fixtures/authors.yml +0 -7
- data/lib/plugins/paginating_find/test_app/test/fixtures/edits.yml +0 -11
- data/lib/plugins/paginating_find/test_app/test/fixtures/models.rb +0 -18
- data/lib/plugins/paginating_find/test_app/test/test_helper.rb +0 -33
- data/lib/plugins/paginating_find/test_app/test/unit/abstract_test.rb +0 -7
- data/lib/plugins/paginating_find/test_app/test/unit/group_test.rb +0 -40
- data/lib/plugins/paginating_find/test_app/test/unit/paginating_find_test.rb +0 -194
- data/lib/plugins/paginating_find/test_app/test/unit/paging_enumerator_test.rb +0 -143
- data/public/assets/products/1012/mini/bt.jpg +0 -0
- data/public/assets/products/1012/original/bt.jpg +0 -0
- data/public/assets/products/1012/product/bt.jpg +0 -0
- data/public/assets/products/1012/small/bt.jpg +0 -0
- data/spec/views/products/index.html.erb_spec.rb +0 -46
- data/spec/views/products/show.html.erb_spec.rb +0 -46
- data/vendor/extensions/shipping/app/controllers/shipments_controller.rb +0 -96
- data/vendor/extensions/shipping/app/helpers/shipments_helper.rb +0 -20
- data/vendor/extensions/shipping/app/views/orders/fatal_shipping.html.erb +0 -6
- data/vendor/extensions/shipping/app/views/shipments/_form.html.erb +0 -46
- data/vendor/extensions/shipping/app/views/shipments/edit.html.erb +0 -57
- data/vendor/extensions/shipping/app/views/shipments/new.html.erb +0 -10
@@ -1,73 +0,0 @@
|
|
1
|
-
class CreditcardsController < Spree::BaseController
|
2
|
-
before_filter :load_data
|
3
|
-
before_filter :validate_payment, :only => :create
|
4
|
-
before_filter :state_check, :except => [:country_changed, :cvv]
|
5
|
-
ssl_required :new, :create
|
6
|
-
layout 'application'
|
7
|
-
resource_controller
|
8
|
-
|
9
|
-
belongs_to :order
|
10
|
-
actions :new, :create
|
11
|
-
|
12
|
-
# override the r_c create since we need special logic to deal with the presenter in the create case
|
13
|
-
def create
|
14
|
-
creditcard = @payment_presenter.creditcard
|
15
|
-
creditcard.address = @payment_presenter.address
|
16
|
-
creditcard.order = @order
|
17
|
-
|
18
|
-
begin
|
19
|
-
creditcard.authorize(@order.total)
|
20
|
-
rescue Spree::GatewayError => ge
|
21
|
-
flash.now[:error] = "Authorization Error: #{ge.message}"
|
22
|
-
render :action => "new" and return
|
23
|
-
end
|
24
|
-
creditcard.save
|
25
|
-
@order.next!
|
26
|
-
redirect_to checkout_order_url(@order)
|
27
|
-
end
|
28
|
-
|
29
|
-
def cvv
|
30
|
-
render :layout => false
|
31
|
-
end
|
32
|
-
|
33
|
-
def country_changed
|
34
|
-
render :partial => "shared/states", :locals => {:presenter_type => "creditcard"}
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
def load_data
|
39
|
-
load_object
|
40
|
-
@selected_country_id = params[:payment_presenter][:address_country_id].to_i if params.has_key?('payment_presenter')
|
41
|
-
@selected_country_id ||= @order.ship_address.country_id unless @order.nil? || @order.ship_address.nil?
|
42
|
-
@selected_country_id ||= Spree::Config[:default_country_id]
|
43
|
-
|
44
|
-
@states = State.find_all_by_country_id(@selected_country_id, :order => 'name')
|
45
|
-
@countries = Country.find(:all)
|
46
|
-
end
|
47
|
-
|
48
|
-
def build_object
|
49
|
-
address = parent_object.ship_address ? parent_object.ship_address : Address.new(:country_id => @selected_country_id)
|
50
|
-
@payment_presenter ||= PaymentPresenter.new(:address => address)
|
51
|
-
end
|
52
|
-
|
53
|
-
def validate_payment
|
54
|
-
# load the object so that its available to the form in the event of a validation error
|
55
|
-
load_object
|
56
|
-
load_payment_presenter
|
57
|
-
render :action => "new" unless @payment_presenter.valid?
|
58
|
-
end
|
59
|
-
|
60
|
-
def load_payment_presenter
|
61
|
-
payment_presenter = PaymentPresenter.new(params[:payment_presenter])
|
62
|
-
payment_presenter.creditcard.first_name = payment_presenter.address.firstname
|
63
|
-
payment_presenter.creditcard.last_name = payment_presenter.address.lastname
|
64
|
-
@payment_presenter = payment_presenter
|
65
|
-
end
|
66
|
-
|
67
|
-
def state_check
|
68
|
-
if @order.checkout_complete
|
69
|
-
# if order has already completed user shouldn't be able to enter new cc information
|
70
|
-
redirect_to checkout_order_url(@order) and return
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/app/models/order_filter.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# Tableless model based on a forum post by Rick Olson
|
2
|
-
class OrderFilter < ActiveRecord::Base
|
3
|
-
#Search criteria does not need to be stored in the database so these two methods will spoof the column stuff
|
4
|
-
def self.columns() @columns ||= []; end
|
5
|
-
def self.column(name, sql_type = nil, default = nil, null = true)
|
6
|
-
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
|
7
|
-
end
|
8
|
-
|
9
|
-
column :start, :string
|
10
|
-
column :stop, :string
|
11
|
-
column :number, :string
|
12
|
-
column :state, :string
|
13
|
-
column :customer, :string
|
14
|
-
column :checkout, :string
|
15
|
-
column :firstname, :string
|
16
|
-
column :lastname, :string
|
17
|
-
|
18
|
-
def validate
|
19
|
-
date_pattern = /^(0[1-9]|1[012])[\/][0-9]{2}[\/](19|20)[0-9]{2}$/
|
20
|
-
errors.add(:start, "Must specify a start date") and return if start.blank? and not stop.blank?
|
21
|
-
errors.add(:start, "Date must be formatted MM/DD/YYYY") unless start.blank? or date_pattern.match start.to_s
|
22
|
-
errors.add(:stop, "Date must be formatted MM/DD/YYYY") unless stop.blank? or date_pattern.match stop.to_s
|
23
|
-
unless stop.blank?
|
24
|
-
errors.add(:stop, "Stop date must be after start date") if DateTime.parse(stop) < DateTime.parse(start)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/app/models/user_filter.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
<h4><%= t("payment_information") %></h4>
|
2
|
-
<table id="creditcard">
|
3
|
-
<tr>
|
4
|
-
<td colspan=2>
|
5
|
-
<%= image_tag "creditcard.gif", :id => 'creditcard-image' %>
|
6
|
-
</td>
|
7
|
-
</tr>
|
8
|
-
<tr>
|
9
|
-
<!-- use this sample (visa) cc# for testing 4111111111111111 -->
|
10
|
-
<td width="120"><%= t("card_number") %></td>
|
11
|
-
<td><%= f.text_field :creditcard_number, :size=> 19 -%></td>
|
12
|
-
</tr>
|
13
|
-
<tr>
|
14
|
-
<td><%= t("expiration_month") %></td>
|
15
|
-
<td><%= f.text_field :creditcard_month, :size => 4 -%></td>
|
16
|
-
</tr>
|
17
|
-
<tr>
|
18
|
-
<td><%= t("expiration_year") %></td>
|
19
|
-
<td><%= f.text_field :creditcard_year, :size => 4 -%></td>
|
20
|
-
</tr>
|
21
|
-
<tr>
|
22
|
-
<td><%= t("card_code") %></td>
|
23
|
-
<td>
|
24
|
-
<%= f.text_field :creditcard_verification_value, {:style => "width:40px"} -%>
|
25
|
-
<a href="" onclick="window.open('/creditcards/cvv','mywin','left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1');return false">
|
26
|
-
(<%= t("whats_this") %>)
|
27
|
-
</a>
|
28
|
-
</td>
|
29
|
-
</tr>
|
30
|
-
</table>
|
@@ -1,25 +0,0 @@
|
|
1
|
-
<div id="creditcard">
|
2
|
-
<%=error_messages_for :payment_presenter %>
|
3
|
-
<h1><%= t("payment")%></h1>
|
4
|
-
<% form_for(:payment_presenter, :url => order_creditcards_url(@order)) do |f| %>
|
5
|
-
<table cellpadding="5" width="100%">
|
6
|
-
<tr>
|
7
|
-
<td valign="top" wdith="50%">
|
8
|
-
<%= render :partial => 'form_credit_card', :locals => {:f => f} %>
|
9
|
-
</td>
|
10
|
-
<td>
|
11
|
-
<h4><%= t("billing_address")%></h4>
|
12
|
-
<%= render :partial => 'shared/form_address', :locals => {:f => f, :presenter_type => "payment"} %>
|
13
|
-
</td>
|
14
|
-
</tr>
|
15
|
-
</table>
|
16
|
-
<div align="right" style="font-size:120%;">
|
17
|
-
<br />
|
18
|
-
<%= t("order_total_message") %> <strong><%= number_to_currency @order.total%></strong>
|
19
|
-
</div>
|
20
|
-
<div align="right">
|
21
|
-
<br/>
|
22
|
-
<%= submit_tag t('continue') %>
|
23
|
-
</div>
|
24
|
-
<% end %>
|
25
|
-
</div>
|
@@ -1,34 +0,0 @@
|
|
1
|
-
<!-- Code by Ilya Grigorik - http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/ -->
|
2
|
-
<% if collection.page_count != collection.first_page -%>
|
3
|
-
<div class="pagination">
|
4
|
-
<ul>
|
5
|
-
<% if collection.previous_page? -%>
|
6
|
-
<li class="nextpage">
|
7
|
-
<%= link_to "« #{t('previous')}", { :p => collection.previous_page }.merge(options) %>
|
8
|
-
</li>
|
9
|
-
<% else -%>
|
10
|
-
<li class="disablepage">« <%= t('previous') %></li>
|
11
|
-
<% end -%>
|
12
|
-
|
13
|
-
<% last_page = 0 -%>
|
14
|
-
<% windowed_pagination_links(collection, :window_size => 2, :link_to_current_page => true, :always_show_anchors => true) do |n| -%>
|
15
|
-
<% if collection.page == n -%>
|
16
|
-
<li class="currentpage"><%= n %></li>
|
17
|
-
<% else -%>
|
18
|
-
<li><%= "..." if last_page+1 < n %>
|
19
|
-
<%= link_to n, {:id => params[:id], :p => n}.merge(options) %>
|
20
|
-
</li>
|
21
|
-
<% end -%>
|
22
|
-
<% last_page = n -%>
|
23
|
-
<% end -%>
|
24
|
-
|
25
|
-
<% if collection.next_page? -%>
|
26
|
-
<li class="nextpage">
|
27
|
-
<%= link_to "#{t('next')} »", { :p => collection.next_page }.merge(options) %>
|
28
|
-
</li>
|
29
|
-
<% else -%>
|
30
|
-
<li class="disablepage">« <%= t('next') %></li>
|
31
|
-
<% end -%>
|
32
|
-
</ul>
|
33
|
-
</div>
|
34
|
-
<% end -%>
|
@@ -1,120 +0,0 @@
|
|
1
|
-
2008-02-08
|
2
|
-
* Count query now uses the :from find option, if specified. Thanks to Rich Wertz.
|
3
|
-
|
4
|
-
2007-11-13
|
5
|
-
* Removed extraneous statement from collect_count_options. Thanks to Wolfgang Postler.
|
6
|
-
|
7
|
-
2007-9-14
|
8
|
-
* Count query now respects the distinct keyword if it is included in the :select option. Thanks to Luke Pearce.
|
9
|
-
|
10
|
-
2007-8-25
|
11
|
-
* PagingEnumerator#each now returns self. Thanks to Takeru Sasaki.
|
12
|
-
* Addeed #to_xml to the PagingEnumerator.
|
13
|
-
|
14
|
-
2007-8-24
|
15
|
-
* No longer overwrite the AR #validate_find_options method. Instead just append :page to VALID_FIND_OPTIONS. Thanks for the suggestion Pratik.
|
16
|
-
|
17
|
-
2007-7-24
|
18
|
-
* Fixed a bug in handling the HAVING having clause. Thanks to Daniel Aborg for the patch!
|
19
|
-
* Added support for Array#extract_options! added to Rails edge (9087). Thanks to Alex Payne!
|
20
|
-
* Tests no longer use with_scope since it became protected in Rails edge.
|
21
|
-
|
22
|
-
2007-5-7
|
23
|
-
* Now uses alias_method_chain. Thanks to Jeremy Larkin for the patch.
|
24
|
-
|
25
|
-
2007-4-27
|
26
|
-
* PagingEnumerator now supports Marshal.dump and Marshal.load. When marshaled, the enumerator loses its callback, so :auto => true is not supported in this scenario.
|
27
|
-
|
28
|
-
2007-02-05
|
29
|
-
* :current < 1 is now gracefully handled. Thanks again to Benjamin Curtis and 21st Century Music.
|
30
|
-
|
31
|
-
2007-01-24
|
32
|
-
* Added paging_helper that provides paginating_links and paginating_links_each to ActionView::Base. Special thanks to Benjamin Curtis and 21st Century Music (http://21cmusic.com/)!
|
33
|
-
|
34
|
-
2007-01-07
|
35
|
-
* :first now defaults to 1 rather than the value of :page. Thanks to Jack Baty for bringing this to my attention.
|
36
|
-
|
37
|
-
2006-12-28
|
38
|
-
* primary_key used to build count select statement rather than "id" column. Thanks to Rich Cox.
|
39
|
-
|
40
|
-
2006-12-21
|
41
|
-
* Applied another fix to counting with :group option. Special thanks to Ben Weiner.
|
42
|
-
* Placed tests for grouping in a separate class.
|
43
|
-
|
44
|
-
2006-12-12
|
45
|
-
* Removed rails from vendor directory.
|
46
|
-
|
47
|
-
2006-11-27
|
48
|
-
* For purposes of counting, the HAVING statement is now extracted from the :group option as a convenience for users that are hacking around the lack of a AR#find :having option. Thanks to Gavin Joyce for pointing out this usage of :group. More info here: http://www.mail-archive.com/rails-core@lists.rubyonrails.org/msg01876.html.
|
49
|
-
* For purposes of counting, the :select option is now ignored in favor of table_name.id. Thanks to Aron Atkins for reporting a bug that led to this fix.
|
50
|
-
|
51
|
-
2006-10-17
|
52
|
-
* Count query no longer uses :limit. This option doesn't have the same effect on count as it does on find. The :limit is applied to the count after the query is performed, if necessary.
|
53
|
-
* Count query no longer uses :group. Grouping during a count doesn't get any different count than not grouping.
|
54
|
-
* Count query no longer uses :order for the same reasons that :group is no longer used.
|
55
|
-
|
56
|
-
2006-09-26
|
57
|
-
* Change log is now in reverse chronological order
|
58
|
-
* Count query now respects :group and :order. Previous changes removing this functionality are no longer applicable.
|
59
|
-
|
60
|
-
2006-09-19
|
61
|
-
* Added :count option. Using this will cause the plugin to skip the automatic database count query (which can sometimes be slow).
|
62
|
-
* The :limit option no longer affects whether the count query will run.
|
63
|
-
* Fixed a bug reported by Lisa, where the count query was choking on grouped results. The count query now ignores :group.
|
64
|
-
|
65
|
-
2006-09-14
|
66
|
-
* Scoping now works correctly, even when enumeration is done outside the #with_scope code block.
|
67
|
-
* Added the #empty? method.
|
68
|
-
* Added #first_item and #last_item, which return the index of the first and last items on the current page. Thanks, Ilya!
|
69
|
-
|
70
|
-
2006-09-10
|
71
|
-
* Now works correctly :with_scope, nested :with_scope, and :include.
|
72
|
-
* Now correctly counts when querying on through associations.
|
73
|
-
* Rewrote paginating_find_test so that it uses real AR::Base models, rather than mocks.
|
74
|
-
* Trying out a bare-bones instance of rails in order to run tests without having to install the plugin.
|
75
|
-
|
76
|
-
2006-09-10
|
77
|
-
* next_page? and previous_page? now return booleans rather than the page number. Thanks, Hammed.
|
78
|
-
* next_page and previous_page have been added.
|
79
|
-
* The total count now correctly respects conditions, includes, etc. Thanks, Ilya
|
80
|
-
|
81
|
-
2006-09-09
|
82
|
-
* ArgumentError is now correctly thrown if options[:offset] is used. Thanks, jonni!
|
83
|
-
|
84
|
-
2006-09-08
|
85
|
-
* :conditions are now correctly respected when paging is enabled
|
86
|
-
* :size now defaults to total number of records if less than ten.
|
87
|
-
|
88
|
-
2006-09-06
|
89
|
-
* Added #last_page! method. Only works when :auto => true.
|
90
|
-
* Added #first_page! method. Only works when :auto => true.
|
91
|
-
* Added the #move!(page) method. Only works when :auto => true.
|
92
|
-
* Added the #previous_page!(page) method. Only works when :auto => true.
|
93
|
-
* Added the #page_exists?(page) method.
|
94
|
-
* The #load_page method is no longer protected.
|
95
|
-
* Fixed bug in #to_a that was causing :limit to be exceeded.
|
96
|
-
* An ArgumentError is now raised if both :page and :offset options are specified
|
97
|
-
* The first page and current page can be specified separately, using the :first and :current options respectively.
|
98
|
-
* Reversed semantics of automatic pagination. By default, the enumerator will stop after all records on current page. To enumerate all records, pass option :auto => true.
|
99
|
-
* :manual_paging is no longer supported. Use the :auto option instead. :auto defaults to false.
|
100
|
-
* All paging options are now specified in a hash, keyed by :page. This is mostly an aesthetics issue:
|
101
|
-
# The old way:
|
102
|
-
cogs = Cog.find(:all,
|
103
|
-
:limit => 3000,
|
104
|
-
:page_size => 10,
|
105
|
-
:page => 1,
|
106
|
-
:manual_paging => true)
|
107
|
-
|
108
|
-
# The new way:
|
109
|
-
cogs = Cog.find(:all,
|
110
|
-
:limit => 3000,
|
111
|
-
:page => {:size => 10,
|
112
|
-
:current => 1})
|
113
|
-
|
114
|
-
* The following :page options are supported in this revision:
|
115
|
-
:size => Number of records in each page of results. Defaults to 1/10
|
116
|
-
the total size if total size > 10, otherwise defaults to
|
117
|
-
the total size.
|
118
|
-
:current => The current page. Optional, defaults to the first page: 1.
|
119
|
-
:first => The first page. Optional, defaults to the current page.
|
120
|
-
:auto => Automatically load the next page during invocation of #each. Defaults to false.
|
@@ -1,89 +0,0 @@
|
|
1
|
-
Visit http://cardboardrocket.com/pages/paginating_find for more documentation.
|
2
|
-
|
3
|
-
This plugin makes it easy to page through your model instances by enhancing the default ActiveRecord::Base#find method. In general, you can expect pagination to work with the standard #find options, including :conditions, :group, :order, :limit, and :include. To activate paging, just specify the :page option. You may also provide additional paging options that will control the behavior of the enumerator returned by the #find method. The following options are supported:
|
4
|
-
|
5
|
-
:size => Number of records in each page of results. Defaults to the total
|
6
|
-
record count or 10, whichever is smaller.
|
7
|
-
:current => The current page. Optional, defaults to the first page: 1.
|
8
|
-
:first => The first page. Optional, defaults to the current page.
|
9
|
-
:auto => Automatically load the next page during invocation of #each. Defaults to false.
|
10
|
-
:count => Number of records used to determine #page_count. Specifying this
|
11
|
-
option prevents the plugin from running a count query, which may
|
12
|
-
be helpful if the table to be queried is very large.
|
13
|
-
|
14
|
-
Note: if :page is specified, then the :offset option is not supported and an Exception to that effect will be raised.
|
15
|
-
|
16
|
-
Some handy methods you can call on the result returned by #find, when paging is enabled:
|
17
|
-
|
18
|
-
#each => Iterate over the results
|
19
|
-
#size => Number of records on all pages combined (total size)
|
20
|
-
#page_size => Number of records on each page
|
21
|
-
#page_count => Number of pages
|
22
|
-
#empty? => Are there any results?
|
23
|
-
#to_a => Create an array of the records on the current page, or all pages if :auto => true
|
24
|
-
#move!(num) => Move to a specific page number
|
25
|
-
#page_exists?(num) => Does this page number exist?
|
26
|
-
#first_page! => Move to the first page
|
27
|
-
#first_page => Page number of the first page
|
28
|
-
#last_page! => Move to the last page
|
29
|
-
#last_page => Page number of the last page
|
30
|
-
#next_page? => Is there another page available?
|
31
|
-
#next_page! => Move to the next page, if one exists
|
32
|
-
#next_page => Page number of the next page
|
33
|
-
#previous_page? => Does a previous page exist?
|
34
|
-
#previous_page! => Move to the previous page, if one exists
|
35
|
-
#previous_page => Page number of the previous pages
|
36
|
-
#first_item => The index of the first item on the page
|
37
|
-
#last_item => The index of the last item on the page
|
38
|
-
#load_page => Reload the current page
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
- Simple Example -------------------------------------------------------
|
43
|
-
|
44
|
-
# Get the first page of 'new' Cogs. Each page contains
|
45
|
-
# 10 cogs, and no more than 100 cogs will be returned.
|
46
|
-
cogs = Cog.find(:all,
|
47
|
-
:page,
|
48
|
-
:conditions => ["category = 'new'"],
|
49
|
-
:limit => 100)
|
50
|
-
|
51
|
-
# Print the name of each cog on the 1st page. Calling #each
|
52
|
-
# more than once will cause the 1st page to be printed for
|
53
|
-
# each invocation.
|
54
|
-
cogs.each { |cog| puts cog.name }
|
55
|
-
|
56
|
-
# The next_page! method must be used to move to the 2nd page.
|
57
|
-
cogs.next_page!
|
58
|
-
|
59
|
-
# Print the name of each cog on the 2nd page
|
60
|
-
cogs.each { |cog| puts cog.name }
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
- Scope Example -------------------------------------------------------
|
67
|
-
|
68
|
-
# Get the second page of 'new' Cogs, using the #with_scope method.
|
69
|
-
# Each page contains 15 cogs, and no more than 100 cogs will be returned.
|
70
|
-
Cog.with_scope(:find => {:conditions => "category = 'new'", :include => :widget}) do
|
71
|
-
cogs = Cog.find(:all,
|
72
|
-
:limit => 100,
|
73
|
-
:page => { :start => 1,
|
74
|
-
:current => 2,
|
75
|
-
:size => 15 })
|
76
|
-
end
|
77
|
-
|
78
|
-
# Print the name of each cog on the 2nd page.
|
79
|
-
cogs.each { |cog| puts cog.name }
|
80
|
-
|
81
|
-
# Move to the 3rd page of cogs. The options specified by
|
82
|
-
# with_scope apply, even though a new page is loaded outside
|
83
|
-
# the with_scope block.
|
84
|
-
cogs.next_page!
|
85
|
-
|
86
|
-
|
87
|
-
... more examples soon.
|
88
|
-
|
89
|
-
|
@@ -1,138 +0,0 @@
|
|
1
|
-
require 'paging_enumerator'
|
2
|
-
require 'paging_helper'
|
3
|
-
|
4
|
-
module PaginatingFind
|
5
|
-
|
6
|
-
def self.included(base)
|
7
|
-
base.extend(ClassMethods)
|
8
|
-
base.class_eval do
|
9
|
-
class << self
|
10
|
-
VALID_FIND_OPTIONS << :page
|
11
|
-
alias_method_chain :find, :pagination
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
module ClassMethods
|
17
|
-
DEFAULT_PAGE_SIZE = 10
|
18
|
-
VALID_COUNT_OPTIONS = [:select, :conditions, :joins, :distinct, :include, :having, :group]
|
19
|
-
|
20
|
-
# Enhancements to Base find method to support record paging. The :page option
|
21
|
-
# is used to specify additional paging options. The supported :page options are:
|
22
|
-
#
|
23
|
-
# * <tt>:size</tt>: Number of records in each page of results. Defaults to 1/10
|
24
|
-
# the total size if total size > 10, otherwise defaults to 1.
|
25
|
-
# * <tt>:current</tt>: The current page. Optional, defaults to the first page: 1.
|
26
|
-
# * <tt>:first</tt>: The first page. Optional, defaults to the first page: 1.
|
27
|
-
# * <tt>:auto</tt>: Automatically load the next page during invocation of #each. Defaults to false.
|
28
|
-
# * <tt>:count</tt>: The total record count used to determine the number of pages
|
29
|
-
# to be loaded. Optional. If not specified, the plugin will
|
30
|
-
# use the AR::Calculations#count method.
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# If :page is specified, then the enumerable returned will automatically page the
|
34
|
-
# result set for this find operation according to the additional options. Note that
|
35
|
-
# if you specify :page, you are getting back and Enumerable, not an Array.
|
36
|
-
#
|
37
|
-
# You can, however, invoke the #to_a method on the Enumerable. If you’ve got
|
38
|
-
# :auto paging turned off (default), then you’ll get back just the items on
|
39
|
-
# the current page. Otherwise, you’ll get all items on all pages.
|
40
|
-
#
|
41
|
-
# Heres a sample of how the paging options might be specified:
|
42
|
-
#
|
43
|
-
# cogs = Cog.find(:all,
|
44
|
-
# :limit => 3000,
|
45
|
-
# :page => {:size => 10,
|
46
|
-
# :first => 1,
|
47
|
-
# :current => 1,
|
48
|
-
# :auto => true})
|
49
|
-
#
|
50
|
-
def find_with_pagination(*args)
|
51
|
-
options = if args.respond_to?(:extract_options!)
|
52
|
-
args.extract_options!
|
53
|
-
else
|
54
|
-
extract_options_from_args!(args)
|
55
|
-
end
|
56
|
-
page_options = options.delete(:page) || (args.delete(:page) ? {} : nil)
|
57
|
-
if page_options
|
58
|
-
# The :page option was specified, so page the query results
|
59
|
-
raise ArgumentError, ":offset option is not supported when paging results" if options[:offset]
|
60
|
-
current = page_options[:current] && page_options[:current].to_i > 0 ? page_options[:current] : 1
|
61
|
-
first = page_options[:first] || 1
|
62
|
-
auto = page_options[:auto] || false
|
63
|
-
|
64
|
-
# Specify :count to prevent a count query.
|
65
|
-
unless (count = page_options.delete(:count))
|
66
|
-
original_table_name = self.table_name
|
67
|
-
count = count(collect_count_options(options))
|
68
|
-
count = count.length if options[:group]
|
69
|
-
end
|
70
|
-
|
71
|
-
# Total size is either count or limit, whichever is less
|
72
|
-
limit = options.delete(:limit)
|
73
|
-
total_size = limit ? [limit, count].min : count
|
74
|
-
|
75
|
-
# If :size isn't specified, then use the lesser of the total_size
|
76
|
-
# and the default page size
|
77
|
-
page_size = page_options[:size] || [total_size, DEFAULT_PAGE_SIZE].min
|
78
|
-
|
79
|
-
# Cache the :with_scope options so that they can be reused
|
80
|
-
# during enumerator callback invocation
|
81
|
-
cached_scoped_methods = self.scoped_methods.last
|
82
|
-
|
83
|
-
PagingEnumerator.new(page_size, total_size, auto, current, first) do |page|
|
84
|
-
args.pop if args.last.is_a?(Hash)
|
85
|
-
|
86
|
-
# Set appropriate :offset and :limit options for this page
|
87
|
-
options[:offset] = (page - 1) * page_size
|
88
|
-
options[:limit] = (page_size) < total_size ? page_size : total_size
|
89
|
-
|
90
|
-
if cached_scoped_methods
|
91
|
-
# :with_scope options were specified, so
|
92
|
-
# the with_scope method must be invoked
|
93
|
-
self.with_scope(cached_scoped_methods) do
|
94
|
-
find_without_pagination(*(args << options))
|
95
|
-
end
|
96
|
-
else
|
97
|
-
find_without_pagination(*(args << options))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
else
|
101
|
-
# The :page option was not specified, so invoke the
|
102
|
-
# usual AR::Base#find method
|
103
|
-
find_without_pagination(*(args << options))
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def collect_count_options(options)
|
108
|
-
rtn = {}.merge(options)
|
109
|
-
|
110
|
-
table = options[:from] || table_name
|
111
|
-
|
112
|
-
# If original :select includes the distinct keyword, then
|
113
|
-
# also include it in the count query
|
114
|
-
if rtn[:select].to_s.index(/\s*DISTINCT\s+/i) != nil
|
115
|
-
rtn[:select] = "DISTINCT #{table}.#{primary_key}"
|
116
|
-
else
|
117
|
-
rtn[:select] = "#{table}.#{primary_key}"
|
118
|
-
end
|
119
|
-
|
120
|
-
# AR::Base#find does not support :having, but some folks tack it on to the :group option,
|
121
|
-
# and it is supported by calculations, so we'll support it here.
|
122
|
-
scope = scope(:find)
|
123
|
-
group = options[:group] || (scope ? scope[:group] : nil)
|
124
|
-
if group
|
125
|
-
having = group.split(/\s+HAVING\s+/i)
|
126
|
-
if having.size == 2 # 'HAVING' was tacked on to the :group option.
|
127
|
-
rtn[:group] = having[0]
|
128
|
-
rtn[:having] = having[1]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# Eliminate count options like :order, :limit, :offset.
|
133
|
-
rtn.delete_if { |k, v| !VALID_COUNT_OPTIONS.include?(k.to_sym) }
|
134
|
-
rtn
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
end
|