solidus_pagy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +39 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +37 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +52 -0
- data/LICENSE +26 -0
- data/README.md +142 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/spree/backend/solidus_pagy.js +1 -0
- data/app/assets/javascripts/spree/frontend/solidus_pagy.js +2 -0
- data/app/assets/stylesheets/spree/backend/solidus_pagy.css +7 -0
- data/app/assets/stylesheets/spree/frontend/solidus_pagy.css +4 -0
- data/app/decorators/controllers/solidus_pagy/admin/base_controller_decorator.rb +13 -0
- data/app/decorators/controllers/solidus_pagy/admin/orders_controller_decorator.rb +63 -0
- data/app/decorators/controllers/solidus_pagy/admin/prices_controller_decorator.rb +51 -0
- data/app/decorators/controllers/solidus_pagy/admin/products_controller_decorator.rb +32 -0
- data/app/decorators/controllers/solidus_pagy/admin/promotion_codes_controller_decorator.rb +37 -0
- data/app/decorators/controllers/solidus_pagy/admin/promotions_controller_decorator.rb +32 -0
- data/app/decorators/controllers/solidus_pagy/admin/properties_controller_decorator.rb +32 -0
- data/app/decorators/controllers/solidus_pagy/admin/stock_items_controller_decorator.rb +42 -0
- data/app/decorators/controllers/solidus_pagy/admin/stock_locations_controller_decorator.rb +25 -0
- data/app/decorators/controllers/solidus_pagy/admin/stock_movements_controller_decorator.rb +25 -0
- data/app/decorators/controllers/solidus_pagy/admin/tax_rates_controller_decorator.rb +27 -0
- data/app/decorators/controllers/solidus_pagy/admin/users_controller_decorator.rb +68 -0
- data/app/decorators/controllers/solidus_pagy/admin/variants_controller_decorator.rb +33 -0
- data/app/decorators/controllers/solidus_pagy/admin/zones_controller_decorator.rb +28 -0
- data/app/overrides/spree/admin/orders/index/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/prices/_master_variant_table/insert_pagy_pagination.rb +11 -0
- data/app/overrides/spree/admin/prices/_table/insert_pagy_pagination.rb +11 -0
- data/app/overrides/spree/admin/products/index/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/promotion_codes/index/insert_pagy_pagination.rb +19 -0
- data/app/overrides/spree/admin/promotions/index/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/properties/index/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/stock_items/_stock_management/insert_pagy_pagination.rb +11 -0
- data/app/overrides/spree/admin/stock_locations/index/insert_pagy_pagination.rb +11 -0
- data/app/overrides/spree/admin/stock_movements/index/insert_pagy_pagination.rb +11 -0
- data/app/overrides/spree/admin/tax_rates/index/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/users/index/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/users/items/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/users/orders/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/variants/_table/insert_pagy_pagination.rb +9 -0
- data/app/overrides/spree/admin/zones/index/insert_pagy_pagination.rb +9 -0
- data/bin/console +17 -0
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +86 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +5 -0
- data/lib/generators/solidus_pagy/install/install_generator.rb +18 -0
- data/lib/generators/solidus_pagy/install/templates/initializer.rb +30 -0
- data/lib/generators/solidus_pagy/install/templates/pagy.rb +235 -0
- data/lib/solidus_pagy/configuration.rb +27 -0
- data/lib/solidus_pagy/engine.rb +16 -0
- data/lib/solidus_pagy/testing_support/factories.rb +4 -0
- data/lib/solidus_pagy/version.rb +5 -0
- data/lib/solidus_pagy.rb +11 -0
- data/solidus_pagy.gemspec +44 -0
- data/spec/controllers/spree/admin/orders_controller_spec.rb +100 -0
- data/spec/controllers/spree/admin/prices_controller_spec.rb +80 -0
- data/spec/controllers/spree/admin/products_controller_spec.rb +57 -0
- data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +38 -0
- data/spec/controllers/spree/admin/promotions_controller_spec.rb +90 -0
- data/spec/controllers/spree/admin/properties_controller_spec.rb +15 -0
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +35 -0
- data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +26 -0
- data/spec/controllers/spree/admin/stock_movements_controller_spec.rb +81 -0
- data/spec/controllers/spree/admin/tax_rates_controller_spec.rb +15 -0
- data/spec/controllers/spree/admin/users_controller_spec.rb +117 -0
- data/spec/controllers/spree/admin/variants_controller_spec.rb +76 -0
- data/spec/controllers/spree/admin/zones_controller_spec.rb +15 -0
- data/spec/solidus_pagy/configuration_spec.rb +55 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/devise.rb +8 -0
- data/spec/support/pagy.rb.rb +8 -0
- data/spec/support/solidus.rb +16 -0
- metadata +248 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
4
|
+
# | Option | Helper | Path |
|
|
5
|
+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
6
|
+
# | default | pagy_nav | |
|
|
7
|
+
# | bootstrap | pagy_bootstrap_nav | pagy/extras/bootstrap |
|
|
8
|
+
# | bulma | pagy_bulma_nav | pagy/extras/bulma |
|
|
9
|
+
# | foundation | pagy_foundation_nav | pagy/extras/foundation |
|
|
10
|
+
# | materialize| pagy_materialize_nav | pagy/extras/materialize |
|
|
11
|
+
# | semantic | pagy_semantic_nav | pagy/extras/semantic |
|
|
12
|
+
# | uikit | pagy_uikit_nav | pagy/extras/uikit |
|
|
13
|
+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
14
|
+
|
|
15
|
+
SolidusPagy.configure do |config|
|
|
16
|
+
config.nav_helper = 'pagy_nav'
|
|
17
|
+
config.page = 1
|
|
18
|
+
config.items = 20
|
|
19
|
+
config.outset = 0
|
|
20
|
+
config.orders_per_page = 15
|
|
21
|
+
config.properties_per_page = 15
|
|
22
|
+
config.promotions_per_page = 15
|
|
23
|
+
config.admin_products_per_page = 10
|
|
24
|
+
config.admin_variants_per_page = 20
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Pagy::DEFAULT[:page] = SolidusPagy.config.page
|
|
28
|
+
Pagy::DEFAULT[:items] = SolidusPagy.config.items
|
|
29
|
+
Pagy::DEFAULT[:outset] = SolidusPagy.config.outset
|
|
30
|
+
Pagy::DEFAULT.freeze
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Pagy initializer file (5.10.1)
|
|
4
|
+
# Customize only what you really need and notice that the core Pagy works also without any of the following lines.
|
|
5
|
+
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
|
6
|
+
|
|
7
|
+
# Pagy DEFAULT Variables
|
|
8
|
+
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
|
9
|
+
# All the Pagy::DEFAULT are set for all the Pagy instances but can be overridden per instance by just passing them to
|
|
10
|
+
# Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods
|
|
11
|
+
|
|
12
|
+
# Instance variables
|
|
13
|
+
# See https://ddnexus.github.io/pagy/api/pagy#instance-variables
|
|
14
|
+
# Pagy::DEFAULT[:page] = 1 # default
|
|
15
|
+
# Pagy::DEFAULT[:items] = 20 # default
|
|
16
|
+
# Pagy::DEFAULT[:outset] = 0 # default
|
|
17
|
+
|
|
18
|
+
# Other Variables
|
|
19
|
+
# See https://ddnexus.github.io/pagy/api/pagy#other-variables
|
|
20
|
+
# Pagy::DEFAULT[:size] = [1,4,4,1] # default
|
|
21
|
+
# Pagy::DEFAULT[:page_param] = :page # default
|
|
22
|
+
# The :params can be also set as a lambda e.g ->(params){ params.exclude('useless').merge!('custom' => 'useful') }
|
|
23
|
+
# Pagy::DEFAULT[:params] = {} # default
|
|
24
|
+
# Pagy::DEFAULT[:fragment] = '#fragment' # example
|
|
25
|
+
# Pagy::DEFAULT[:link_extra] = 'data-remote="true"' # example
|
|
26
|
+
# Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default
|
|
27
|
+
# Pagy::DEFAULT[:cycle] = true # example
|
|
28
|
+
|
|
29
|
+
# Extras
|
|
30
|
+
# See https://ddnexus.github.io/pagy/extras
|
|
31
|
+
|
|
32
|
+
# Backend Extras
|
|
33
|
+
|
|
34
|
+
# Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
|
|
35
|
+
# See https://ddnexus.github.io/pagy/extras/array
|
|
36
|
+
# require 'pagy/extras/array'
|
|
37
|
+
|
|
38
|
+
# Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
|
|
39
|
+
# See https://ddnexus.github.io/pagy/extras/calendar
|
|
40
|
+
# require 'pagy/extras/calendar'
|
|
41
|
+
# Default for each unit
|
|
42
|
+
# Pagy::Calendar::Year::DEFAULT[:order] = :asc # Time direction of pagination
|
|
43
|
+
# Pagy::Calendar::Year::DEFAULT[:format] = '%Y' # strftime format
|
|
44
|
+
#
|
|
45
|
+
# Pagy::Calendar::Quarter::DEFAULT[:order] = :asc # Time direction of pagination
|
|
46
|
+
# Pagy::Calendar::Quarter::DEFAULT[:format] = '%Y-Q%q' # strftime format
|
|
47
|
+
#
|
|
48
|
+
# Pagy::Calendar::Month::DEFAULT[:order] = :asc # Time direction of pagination
|
|
49
|
+
# Pagy::Calendar::Month::DEFAULT[:format] = '%Y-%m' # strftime format
|
|
50
|
+
#
|
|
51
|
+
# Pagy::Calendar::Week::DEFAULT[:order] = :asc # Time direction of pagination
|
|
52
|
+
# Pagy::Calendar::Week::DEFAULT[:format] = '%Y-%W' # strftime format
|
|
53
|
+
#
|
|
54
|
+
# Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination
|
|
55
|
+
# Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format
|
|
56
|
+
#
|
|
57
|
+
# Uncomment the following lines, if you need calendar localization without using the I18n extra
|
|
58
|
+
# module LocalizePagyCalendar
|
|
59
|
+
# def localize(time, opts)
|
|
60
|
+
# ::I18n.l(time, **opts)
|
|
61
|
+
# end
|
|
62
|
+
# end
|
|
63
|
+
# Pagy::Calendar.prepend LocalizePagyCalendar
|
|
64
|
+
|
|
65
|
+
# Countless extra: Paginate without any count, saving one query per rendering
|
|
66
|
+
# See https://ddnexus.github.io/pagy/extras/countless
|
|
67
|
+
# require 'pagy/extras/countless'
|
|
68
|
+
# Pagy::DEFAULT[:countless_minimal] = false # default (eager loading)
|
|
69
|
+
|
|
70
|
+
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
|
|
71
|
+
# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
|
72
|
+
# Default :pagy_search method: change only if you use also
|
|
73
|
+
# the searchkick or meilisearch extra that defines the same
|
|
74
|
+
# Pagy::DEFAULT[:elasticsearch_rails_pagy_search] = :pagy_search
|
|
75
|
+
# Default original :search method called internally to do the actual search
|
|
76
|
+
# Pagy::DEFAULT[:elasticsearch_rails_search] = :search
|
|
77
|
+
# require 'pagy/extras/elasticsearch_rails'
|
|
78
|
+
|
|
79
|
+
# Headers extra: http response headers (and other helpers) useful for API pagination
|
|
80
|
+
# See http://ddnexus.github.io/pagy/extras/headers
|
|
81
|
+
# require 'pagy/extras/headers'
|
|
82
|
+
# Pagy::DEFAULT[:headers] = { page: 'Current-Page',
|
|
83
|
+
# items: 'Page-Items',
|
|
84
|
+
# count: 'Total-Count',
|
|
85
|
+
# pages: 'Total-Pages' } # default
|
|
86
|
+
|
|
87
|
+
# Meilisearch extra: Paginate `Meilisearch` result objects
|
|
88
|
+
# See https://ddnexus.github.io/pagy/extras/meilisearch
|
|
89
|
+
# Default :pagy_search method: change only if you use also
|
|
90
|
+
# the elasticsearch_rails or searchkick extra that define the same method
|
|
91
|
+
# Pagy::DEFAULT[:meilisearch_pagy_search] = :pagy_search
|
|
92
|
+
# Default original :search method called internally to do the actual search
|
|
93
|
+
# Pagy::DEFAULT[:meilisearch_search] = :ms_search
|
|
94
|
+
# require 'pagy/extras/meilisearch'
|
|
95
|
+
|
|
96
|
+
# Metadata extra: Provides the pagination metadata to Javascript frameworks like Vue.js, react.js, etc.
|
|
97
|
+
# See https://ddnexus.github.io/pagy/extras/metadata
|
|
98
|
+
# you must require the shared internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
|
|
99
|
+
# require 'pagy/extras/shared'
|
|
100
|
+
# require 'pagy/extras/metadata'
|
|
101
|
+
# For performance reasons, you should explicitly set ONLY the metadata you use in the frontend
|
|
102
|
+
# Pagy::DEFAULT[:metadata] = %i[scaffold_url page prev next last] # example
|
|
103
|
+
|
|
104
|
+
# Searchkick extra: Paginate `Searchkick::Results` objects
|
|
105
|
+
# See https://ddnexus.github.io/pagy/extras/searchkick
|
|
106
|
+
# Default :pagy_search method: change only if you use also
|
|
107
|
+
# the elasticsearch_rails or meilisearch extra that defines the same
|
|
108
|
+
# DEFAULT[:searchkick_pagy_search] = :pagy_search
|
|
109
|
+
# Default original :search method called internally to do the actual search
|
|
110
|
+
# Pagy::DEFAULT[:searchkick_search] = :search
|
|
111
|
+
# require 'pagy/extras/searchkick'
|
|
112
|
+
# uncomment if you are going to use Searchkick.pagy_search
|
|
113
|
+
# Searchkick.extend Pagy::Searchkick
|
|
114
|
+
|
|
115
|
+
# Frontend Extras
|
|
116
|
+
|
|
117
|
+
# Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination
|
|
118
|
+
# See https://ddnexus.github.io/pagy/extras/bootstrap
|
|
119
|
+
# require 'pagy/extras/bootstrap'
|
|
120
|
+
|
|
121
|
+
# Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination
|
|
122
|
+
# See https://ddnexus.github.io/pagy/extras/bulma
|
|
123
|
+
# require 'pagy/extras/bulma'
|
|
124
|
+
|
|
125
|
+
# Foundation extra: Add nav, nav_js and combo_nav_js helpers and templates for Foundation pagination
|
|
126
|
+
# See https://ddnexus.github.io/pagy/extras/foundation
|
|
127
|
+
# require 'pagy/extras/foundation'
|
|
128
|
+
|
|
129
|
+
# Materialize extra: Add nav, nav_js and combo_nav_js helpers for Materialize pagination
|
|
130
|
+
# See https://ddnexus.github.io/pagy/extras/materialize
|
|
131
|
+
# require 'pagy/extras/materialize'
|
|
132
|
+
|
|
133
|
+
# Navs extra: Add nav_js and combo_nav_js javascript helpers
|
|
134
|
+
# Notice: the other frontend extras add their own framework-styled versions,
|
|
135
|
+
# so require this extra only if you need the unstyled version
|
|
136
|
+
# See https://ddnexus.github.io/pagy/extras/navs
|
|
137
|
+
# require 'pagy/extras/navs'
|
|
138
|
+
|
|
139
|
+
# Semantic extra: Add nav, nav_js and combo_nav_js helpers for Semantic UI pagination
|
|
140
|
+
# See https://ddnexus.github.io/pagy/extras/semantic
|
|
141
|
+
# require 'pagy/extras/semantic'
|
|
142
|
+
|
|
143
|
+
# UIkit extra: Add nav helper and templates for UIkit pagination
|
|
144
|
+
# See https://ddnexus.github.io/pagy/extras/uikit
|
|
145
|
+
# require 'pagy/extras/uikit'
|
|
146
|
+
|
|
147
|
+
# Multi size var used by the *_nav_js helpers
|
|
148
|
+
# See https://ddnexus.github.io/pagy/extras/navs#steps
|
|
149
|
+
# Pagy::DEFAULT[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example
|
|
150
|
+
|
|
151
|
+
# Feature Extras
|
|
152
|
+
|
|
153
|
+
# Gearbox extra: Automatically change the number of items per page depending on the page number
|
|
154
|
+
# See https://ddnexus.github.io/pagy/extras/gearbox
|
|
155
|
+
# require 'pagy/extras/gearbox'
|
|
156
|
+
# set to false only if you want to make :gearbox_extra an opt-in variable
|
|
157
|
+
# Pagy::DEFAULT[:gearbox_extra] = false # default true
|
|
158
|
+
# Pagy::DEFAULT[:gearbox_items] = [15, 30, 60, 100] # default
|
|
159
|
+
|
|
160
|
+
# Items extra: Allow the client to request a custom number of items per page with an optional selector UI
|
|
161
|
+
# See https://ddnexus.github.io/pagy/extras/items
|
|
162
|
+
# require 'pagy/extras/items'
|
|
163
|
+
# set to false only if you want to make :items_extra an opt-in variable
|
|
164
|
+
# Pagy::DEFAULT[:items_extra] = false # default true
|
|
165
|
+
# Pagy::DEFAULT[:items_param] = :items # default
|
|
166
|
+
# Pagy::DEFAULT[:max_items] = 100 # default
|
|
167
|
+
|
|
168
|
+
# Overflow extra: Allow for easy handling of overflowing pages
|
|
169
|
+
# See https://ddnexus.github.io/pagy/extras/overflow
|
|
170
|
+
# require 'pagy/extras/overflow'
|
|
171
|
+
# Pagy::DEFAULT[:overflow] = :empty_page # default (other options: :last_page and :exception)
|
|
172
|
+
|
|
173
|
+
# Support extra: Extra support for features like: incremental, infinite, auto-scroll pagination
|
|
174
|
+
# See https://ddnexus.github.io/pagy/extras/support
|
|
175
|
+
# require 'pagy/extras/support'
|
|
176
|
+
|
|
177
|
+
# Trim extra: Remove the page=1 param from links
|
|
178
|
+
# See https://ddnexus.github.io/pagy/extras/trim
|
|
179
|
+
# require 'pagy/extras/trim'
|
|
180
|
+
# set to false only if you want to make :trim_extra an opt-in variable
|
|
181
|
+
# Pagy::DEFAULT[:trim_extra] = false # default true
|
|
182
|
+
|
|
183
|
+
# Standalone extra: Use pagy in non Rack environment/gem
|
|
184
|
+
# See https://ddnexus.github.io/pagy/extras/standalone
|
|
185
|
+
# require 'pagy/extras/standalone'
|
|
186
|
+
# Pagy::DEFAULT[:url] = 'http://www.example.com/subdir' # optional default
|
|
187
|
+
|
|
188
|
+
# Rails
|
|
189
|
+
# Enable the .js file required by the helpers that use javascript
|
|
190
|
+
# (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js)
|
|
191
|
+
# See https://ddnexus.github.io/pagy/extras#javascript
|
|
192
|
+
|
|
193
|
+
# With the asset pipeline
|
|
194
|
+
# Sprockets need to look into the pagy javascripts dir, so add it to the assets paths
|
|
195
|
+
# Rails.application.config.assets.paths << Pagy.root.join('javascripts')
|
|
196
|
+
|
|
197
|
+
# I18n
|
|
198
|
+
|
|
199
|
+
# Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem
|
|
200
|
+
# See https://ddnexus.github.io/pagy/api/frontend#i18n
|
|
201
|
+
# Notice: No need to configure anything in this section if your app uses only "en"
|
|
202
|
+
# or if you use the i18n extra below
|
|
203
|
+
#
|
|
204
|
+
# Examples:
|
|
205
|
+
# load the "de" built-in locale:
|
|
206
|
+
# Pagy::I18n.load(locale: 'de')
|
|
207
|
+
#
|
|
208
|
+
# load the "de" locale defined in the custom file at :filepath:
|
|
209
|
+
# Pagy::I18n.load(locale: 'de', filepath: 'path/to/pagy-de.yml')
|
|
210
|
+
#
|
|
211
|
+
# load the "de", "en" and "es" built-in locales:
|
|
212
|
+
# (the first passed :locale will be used also as the default_locale)
|
|
213
|
+
# Pagy::I18n.load({ locale: 'de' },
|
|
214
|
+
# { locale: 'en' },
|
|
215
|
+
# { locale: 'es' })
|
|
216
|
+
#
|
|
217
|
+
# load the "en" built-in locale, a custom "es" locale,
|
|
218
|
+
# and a totally custom locale complete with a custom :pluralize proc:
|
|
219
|
+
# (the first passed :locale will be used also as the default_locale)
|
|
220
|
+
# Pagy::I18n.load({ locale: 'en' },
|
|
221
|
+
# { locale: 'es', filepath: 'path/to/pagy-es.yml' },
|
|
222
|
+
# { locale: 'xyz', # not built-in
|
|
223
|
+
# filepath: 'path/to/pagy-xyz.yml',
|
|
224
|
+
# pluralize: lambda{ |count| ... } )
|
|
225
|
+
|
|
226
|
+
# I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory
|
|
227
|
+
# than the default pagy internal i18n (see above)
|
|
228
|
+
# See https://ddnexus.github.io/pagy/extras/i18n
|
|
229
|
+
# require 'pagy/extras/i18n'
|
|
230
|
+
|
|
231
|
+
# Default i18n key
|
|
232
|
+
# Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default
|
|
233
|
+
|
|
234
|
+
# When you are done setting your own default freeze it, so it will not get changed accidentally
|
|
235
|
+
# Pagy::DEFAULT.freeze
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusPagy
|
|
4
|
+
class Configuration
|
|
5
|
+
attr_accessor :nav_helper,
|
|
6
|
+
:page,
|
|
7
|
+
:items,
|
|
8
|
+
:outset,
|
|
9
|
+
:promotions_per_page,
|
|
10
|
+
:properties_per_page,
|
|
11
|
+
:orders_per_page,
|
|
12
|
+
:admin_products_per_page,
|
|
13
|
+
:admin_variants_per_page
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
def configuration
|
|
18
|
+
@configuration ||= Configuration.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
alias config configuration
|
|
22
|
+
|
|
23
|
+
def configure
|
|
24
|
+
yield configuration
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusPagy
|
|
4
|
+
class Engine < Rails::Engine
|
|
5
|
+
include SolidusSupport::EngineExtensions
|
|
6
|
+
|
|
7
|
+
isolate_namespace ::Spree
|
|
8
|
+
|
|
9
|
+
engine_name 'solidus_pagy'
|
|
10
|
+
|
|
11
|
+
# use rspec for tests
|
|
12
|
+
config.generators do |g|
|
|
13
|
+
g.test_framework :rspec
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/solidus_pagy.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/solidus_pagy/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = 'solidus_pagy'
|
|
7
|
+
s.version = SolidusPagy::VERSION
|
|
8
|
+
s.authors = ['Jonathan Tapia']
|
|
9
|
+
s.email = 'jonathan.tapia@magmalabs.io'
|
|
10
|
+
|
|
11
|
+
s.summary = 'Solidus extension using Pagy pagination.'
|
|
12
|
+
s.description = 'Solidus extension using Pagy pagination.'
|
|
13
|
+
s.homepage = 'https://github.com/solidusio-contrib/solidus_pagy#readme'
|
|
14
|
+
s.license = 'BSD-3-Clause'
|
|
15
|
+
|
|
16
|
+
if s.respond_to?(:metadata)
|
|
17
|
+
s.metadata['homepage_uri'] = s.homepage
|
|
18
|
+
s.metadata['source_code_uri'] = 'https://github.com/jtapia/solidus_pagy'
|
|
19
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
20
|
+
s.metadata['changelog_uri'] = 'https://github.com/jtapia/solidus_pagy/blob/master/CHANGELOG.md'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.5')
|
|
24
|
+
|
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
27
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
|
28
|
+
|
|
29
|
+
s.files = files.grep_v(%r{^(test|spec|features)/})
|
|
30
|
+
s.test_files = files.grep(%r{^(test|spec|features)/})
|
|
31
|
+
s.bindir = 'exe'
|
|
32
|
+
s.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
|
+
s.require_paths = ['lib']
|
|
34
|
+
|
|
35
|
+
solidus_version = ['>= 2.5', '< 4']
|
|
36
|
+
|
|
37
|
+
s.add_dependency 'pagy', '~> 5.10'
|
|
38
|
+
s.add_dependency 'solidus_core', solidus_version
|
|
39
|
+
s.add_dependency 'solidus_support', '~> 0.5'
|
|
40
|
+
|
|
41
|
+
s.add_development_dependency 'solidus_backend', solidus_version
|
|
42
|
+
s.add_development_dependency 'solidus_dev_support', '~> 2.5'
|
|
43
|
+
s.add_development_dependency 'solidus_frontend', solidus_version
|
|
44
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Spree::Admin::OrdersController, type: :controller do
|
|
6
|
+
let(:store) { create(:store) }
|
|
7
|
+
|
|
8
|
+
context 'with authorization' do
|
|
9
|
+
stub_authorization!
|
|
10
|
+
|
|
11
|
+
let(:order) do
|
|
12
|
+
mock_model(
|
|
13
|
+
Spree::Order,
|
|
14
|
+
completed?: true,
|
|
15
|
+
total: 100,
|
|
16
|
+
number: 'R123456789',
|
|
17
|
+
all_adjustments: adjustments,
|
|
18
|
+
ship_address: mock_model(Spree::Address)
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
let(:adjustments) do
|
|
22
|
+
instance_double('adjustments')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
before do
|
|
26
|
+
request.env['HTTP_REFERER'] = 'http://localhost:3000'
|
|
27
|
+
allow(Spree::Order).to receive_message_chain(:includes, find_by!: order)
|
|
28
|
+
allow(order)
|
|
29
|
+
.to receive_messages(contents: Spree::OrderContents.new(order))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context 'with pagination' do
|
|
33
|
+
it 'can page through the orders' do
|
|
34
|
+
get :index, params: { page: 1, per_page: 10 }
|
|
35
|
+
expect(assigns[:pagy].page).to eq(1)
|
|
36
|
+
expect(assigns[:pagy].items).to eq(10)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Test for https://github.com/spree/spree/issues/3919
|
|
41
|
+
context 'search' do
|
|
42
|
+
let(:user) { create(:user) }
|
|
43
|
+
|
|
44
|
+
before do
|
|
45
|
+
allow(controller).to receive(:try_spree_current_user) { user }
|
|
46
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
|
47
|
+
create_list(:completed_order_with_totals, 2)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context 'by line_items_variant_id_in' do
|
|
51
|
+
it 'does not display duplicated results' do
|
|
52
|
+
get :index,
|
|
53
|
+
params: {
|
|
54
|
+
q: {
|
|
55
|
+
line_items_variant_id_in: Spree::Order.first.variants.map(&:id)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
expect(assigns[:orders].size).to eq 1
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context 'by email' do
|
|
63
|
+
it 'does not display duplicated results' do
|
|
64
|
+
get :index,
|
|
65
|
+
params: {
|
|
66
|
+
q: {
|
|
67
|
+
email_start: Spree::Order.first.email
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
expect(assigns[:orders].size).to eq 1
|
|
71
|
+
expect(assigns[:orders][0].email).to eq(Spree::Order.first.email)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context 'by created_at_gt' do
|
|
76
|
+
it 'does display item results' do
|
|
77
|
+
get :index,
|
|
78
|
+
params: {
|
|
79
|
+
q: {
|
|
80
|
+
created_at_gt: DateTime.now - 1.day
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
expect(assigns[:orders].size).to eq(2)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context 'by created_at_lt' do
|
|
88
|
+
it 'does display item results' do
|
|
89
|
+
get :index,
|
|
90
|
+
params: {
|
|
91
|
+
q: {
|
|
92
|
+
created_at_lt: DateTime.now
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
expect(assigns[:orders].size).to eq(2)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Spree::Admin::PricesController, type: :controller do
|
|
6
|
+
stub_authorization!
|
|
7
|
+
|
|
8
|
+
let(:product) { create(:product) }
|
|
9
|
+
|
|
10
|
+
context 'with pagination' do
|
|
11
|
+
it 'can page through the product master prices' do
|
|
12
|
+
get :index, params: { product_id: product.slug, page: 1 }
|
|
13
|
+
expect(assigns[:pagy_master_prices].page).to eq(1)
|
|
14
|
+
expect(assigns[:pagy_master_prices].items).to eq(20)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'can page through the product variant prices' do
|
|
18
|
+
get :index, params: { product_id: product.slug, variants_page: 1 }
|
|
19
|
+
expect(assigns[:pagy_variant_prices].page).to eq(1)
|
|
20
|
+
expect(assigns[:pagy_variant_prices].items).to eq(20)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#index' do
|
|
25
|
+
context 'when only given a product' do
|
|
26
|
+
let(:product) { create(:product) }
|
|
27
|
+
|
|
28
|
+
subject { get :index, params: { product_id: product.slug } }
|
|
29
|
+
|
|
30
|
+
it { is_expected.to be_successful }
|
|
31
|
+
|
|
32
|
+
it 'assigns usable instance variables' do
|
|
33
|
+
subject
|
|
34
|
+
|
|
35
|
+
expect(assigns(:search)).to be_a(Ransack::Search)
|
|
36
|
+
expect(assigns(:variant_prices)).to eq(product.prices.for_variant)
|
|
37
|
+
expect(assigns(:master_prices)).to eq(product.prices.for_master)
|
|
38
|
+
expect(assigns(:product)).to eq(product)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context 'when given a product and a variant' do
|
|
43
|
+
let(:variant) { create(:variant) }
|
|
44
|
+
let(:product) { variant.product }
|
|
45
|
+
|
|
46
|
+
subject do
|
|
47
|
+
get :index,
|
|
48
|
+
params: {
|
|
49
|
+
product_id: product.slug,
|
|
50
|
+
variant_id: variant.id
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it { is_expected.to be_successful }
|
|
55
|
+
|
|
56
|
+
it 'assigns usable instance variables' do
|
|
57
|
+
subject
|
|
58
|
+
|
|
59
|
+
expect(assigns(:search)).to be_a(Ransack::Search)
|
|
60
|
+
expect(assigns(:variant_prices)).to eq(product.prices.for_variant)
|
|
61
|
+
expect(assigns(:master_prices)).to eq(product.prices.for_master)
|
|
62
|
+
expect(assigns(:variant_prices)).to include(variant.default_price)
|
|
63
|
+
expect(assigns(:product)).to eq(product)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'existent product id not given' do
|
|
68
|
+
subject do
|
|
69
|
+
get :index, params: { product_id: 'non-existent-product' }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'cannot find non-existent product' do
|
|
73
|
+
subject
|
|
74
|
+
|
|
75
|
+
expect(response).to redirect_to(spree.admin_products_path)
|
|
76
|
+
expect(flash[:error]).to eql('Product is not found')
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Spree::Admin::ProductsController, type: :controller do
|
|
6
|
+
stub_authorization!
|
|
7
|
+
|
|
8
|
+
let(:product) { create(:product) }
|
|
9
|
+
|
|
10
|
+
context 'with pagination' do
|
|
11
|
+
it 'can page through the products' do
|
|
12
|
+
get :index, params: { page: 1, per_page: 10 }
|
|
13
|
+
expect(assigns[:pagy].page).to eq(1)
|
|
14
|
+
expect(assigns[:pagy].items).to eq(10)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#index' do
|
|
19
|
+
let(:ability_user) do
|
|
20
|
+
stub_model(Spree::LegacyUser, has_spree_role?: true)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Regression test for https://github.com/spree/spree/issues/1259
|
|
24
|
+
it 'can find a product by SKU' do
|
|
25
|
+
product = create(:product, sku: 'ABC123')
|
|
26
|
+
|
|
27
|
+
get :index, params: { q: { sku_start: 'ABC123' } }
|
|
28
|
+
expect(assigns[:collection]).not_to be_empty
|
|
29
|
+
expect(assigns[:collection]).to include(product)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Regression test for https://github.com/spree/spree/issues/1903
|
|
33
|
+
context 'when soft deleted products exist' do
|
|
34
|
+
let(:soft_deleted_product) { create(:product, sku: 'ABC123') }
|
|
35
|
+
|
|
36
|
+
before { soft_deleted_product.discard }
|
|
37
|
+
|
|
38
|
+
context 'when params[:q][:with_discarded] is not set' do
|
|
39
|
+
let(:params) { { q: {} } }
|
|
40
|
+
|
|
41
|
+
it 'filters out soft-deleted products by default' do
|
|
42
|
+
get :index, params: params
|
|
43
|
+
expect(assigns[:collection]).not_to include(soft_deleted_product)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "when params[:q][:with_discarded] is set to 'true'" do
|
|
48
|
+
let(:params) { { q: { with_discarded: 'true' } } }
|
|
49
|
+
|
|
50
|
+
it 'includes soft-deleted products' do
|
|
51
|
+
get :index, params: params
|
|
52
|
+
expect(assigns[:collection]).to include(soft_deleted_product)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Spree::Admin::PromotionCodesController, type: :controller do
|
|
6
|
+
stub_authorization!
|
|
7
|
+
|
|
8
|
+
let(:promotion) { create(:promotion) }
|
|
9
|
+
let(:code1) { create(:promotion_code, promotion: promotion) }
|
|
10
|
+
let(:code2) { create(:promotion_code, promotion: promotion) }
|
|
11
|
+
let(:code3) { create(:promotion_code, promotion: promotion) }
|
|
12
|
+
|
|
13
|
+
context 'with pagination' do
|
|
14
|
+
it 'can page through the products' do
|
|
15
|
+
get :index,
|
|
16
|
+
params: {
|
|
17
|
+
promotion_id: promotion.id,
|
|
18
|
+
page: 1
|
|
19
|
+
}
|
|
20
|
+
expect(assigns[:pagy].page).to eq(1)
|
|
21
|
+
expect(assigns[:pagy].items).to eq(50)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '#index' do
|
|
26
|
+
it 'returns 200 as HTML' do
|
|
27
|
+
get :index, params: { promotion_id: promotion.id }
|
|
28
|
+
|
|
29
|
+
expect(response.status).to be(200)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'returns 200 as CSV' do
|
|
33
|
+
get :index, params: { promotion_id: promotion.id, format: :csv }
|
|
34
|
+
|
|
35
|
+
expect(response.status).to be(200)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|