page_wrapper 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/erubis +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/rake2thor +16 -0
- data/bin/ri +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/lib/generators/page_generator.rb +36 -0
- data/lib/page_wrapper.rb +4 -0
- data/lib/page_wrapper/engine.rb +6 -0
- data/lib/page_wrapper/model.rb +50 -0
- data/lib/page_wrapper/railtie.rb +9 -0
- data/lib/page_wrapper/version.rb +3 -0
- data/lib/templates/README +18 -0
- data/lib/templates/model_controller.rb +6 -0
- data/lib/templates/model_page.rb +15 -0
- data/lib/templates/model_serializer.rb +7 -0
- data/lib/templates/page_controller.js.coffee +15 -0
- data/lib/templates/page_model.js.coffee +3 -0
- data/lib/templates/page_template.handlebars +28 -0
- data/lib/templates/page_view.js.coffee +2 -0
- data/page_wrapper.gemspec +19 -0
- data/vendor/assets/javascripts/page-model-mixin.js.coffee +73 -0
- data/vendor/assets/javascripts/page-wrapper.js +3 -0
- data/vendor/assets/javascripts/paginated-controller-mixin.js.coffee +55 -0
- data/vendor/assets/javascripts/pagination-view.js.coffee +27 -0
- metadata +107 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 mathieul
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Page Wrapper
|
2
|
+
|
3
|
+
Pagination tools when using Ember, Ember Data and Rails / Rails-Api.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'page_wrapper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install page_wrapper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/erubis
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'erubis' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('erubis', 'erubis')
|
data/bin/rackup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rackup' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rack', 'rackup')
|
data/bin/rails
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rails' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('railties', 'rails')
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/rake2thor
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake2thor' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('thor', 'rake2thor')
|
data/bin/ri
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'ri' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rdoc', 'ri')
|
data/bin/thor
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'thor' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('thor', 'thor')
|
data/bin/tilt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'tilt' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('tilt', 'tilt')
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PageWrapper
|
2
|
+
class PageGenerator < ::Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path("../../templates", __FILE__)
|
4
|
+
|
5
|
+
desc "Creates a new page to wrap a resource collection"
|
6
|
+
|
7
|
+
def create_page_files
|
8
|
+
model_path = File.join('app/models', class_path, "#{file_name}_page.rb")
|
9
|
+
template 'model_page.rb', model_path
|
10
|
+
|
11
|
+
serializer_path = File.join('app/serializers', class_path, "#{file_name}_page_serializer.rb")
|
12
|
+
template 'model_serializer.rb', serializer_path
|
13
|
+
|
14
|
+
controller_path = File.join('app/controllers', class_path, "#{file_name}_pages_controller.rb")
|
15
|
+
template 'model_controller.rb', controller_path
|
16
|
+
|
17
|
+
route "resources :#{class_name.underscore}_pages, only: [:index]"
|
18
|
+
|
19
|
+
controller_path = File.join('app/assets/javascripts/controllers', class_path, "#{file_name}_page_controller.js.coffee")
|
20
|
+
template 'page_controller.js.coffee', controller_path
|
21
|
+
|
22
|
+
model_path = File.join('app/assets/javascripts/models', class_path, "#{file_name}_page.js.coffee")
|
23
|
+
template 'page_model.js.coffee', model_path
|
24
|
+
|
25
|
+
template_path = File.join('app/assets/javascripts/templates', class_path, "#{file_name}_page.handlebars")
|
26
|
+
template 'page_template.handlebars', template_path
|
27
|
+
|
28
|
+
view_path = File.join('app/assets/javascripts/views', class_path, "#{file_name}_page.js.coffee")
|
29
|
+
template 'page_view.js.coffee', view_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def show_readme
|
33
|
+
readme "README" if behavior == :invoke
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/page_wrapper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'active_model_serializers'
|
2
|
+
|
3
|
+
module PageWrapper
|
4
|
+
class Model
|
5
|
+
include ActiveModel::AttributeMethods
|
6
|
+
include ActiveModel::SerializerSupport
|
7
|
+
|
8
|
+
attr_reader :attributes
|
9
|
+
|
10
|
+
def self.fields
|
11
|
+
[:id, :pages, :first, :last, :total, :per_page, :query, :sort, :dir]
|
12
|
+
end
|
13
|
+
define_attribute_methods fields.map(&:to_s)
|
14
|
+
|
15
|
+
fields.each do |name|
|
16
|
+
define_method(name) { attributes[name] }
|
17
|
+
define_method(:"#{name}=") { |value| attributes[name] = value }
|
18
|
+
end
|
19
|
+
|
20
|
+
def per_page_default
|
21
|
+
10
|
22
|
+
end
|
23
|
+
|
24
|
+
def per_page_max
|
25
|
+
100
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(params)
|
29
|
+
page = params[:id].to_i
|
30
|
+
options = get_options_from(params)
|
31
|
+
records = fetch_records(page, options)
|
32
|
+
@attributes = options.merge(
|
33
|
+
id: records.current_page,
|
34
|
+
pages: records.num_pages,
|
35
|
+
first: records.first_page?,
|
36
|
+
last: records.last_page?,
|
37
|
+
total: records.total_count
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_records(page, options)
|
42
|
+
raise "Overide me"
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_options_from(params)
|
46
|
+
per_page = [params.fetch(:per_page, per_page_default).to_i, per_page_max].min
|
47
|
+
params.slice(:query, :sort, :dir).merge(per_page: per_page)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Thand you for using page_wrapper!
|
2
|
+
|
3
|
+
Please note that you should update your Ember application router with
|
4
|
+
something like below. This basic example uses "movie" as the paged
|
5
|
+
model:
|
6
|
+
|
7
|
+
# app/assets/javascripts/routes/app_router.js.coffee
|
8
|
+
App.Router = Ember.Router.extend
|
9
|
+
location: Ember.Location.create(implementation: 'hash')
|
10
|
+
|
11
|
+
root: Ember.State.extend
|
12
|
+
index: Ember.State.extend
|
13
|
+
route: '/'
|
14
|
+
connectOutlets: (router) ->
|
15
|
+
controller = router.get('applicationController')
|
16
|
+
controller.connectOutlet(App.MoviePageView, App.MoviePageController::firstPage())
|
17
|
+
moviePageController = router.get('moviePageController')
|
18
|
+
moviePageController.set('target', moviePageController)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= class_name.camelize %>Page < PageWrapper::Model
|
2
|
+
attr_reader :<%= class_name.underscore.pluralize %>
|
3
|
+
|
4
|
+
def fetch_records(page, options)
|
5
|
+
# TODO: customize the logic below and consider moving it into
|
6
|
+
# a class method <%= class_name.camelize %>.paginated_query
|
7
|
+
# and simplify this method to a one-liner:
|
8
|
+
#
|
9
|
+
# @<%= class_name.underscore.pluralize %> = <%= class_name.camelize %>.paginated_query(page, options)
|
10
|
+
|
11
|
+
result = <%= class_name.camelize %>.page(page)
|
12
|
+
result = result.per(options[:per_page]) if options[:per_page]
|
13
|
+
result
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
App.<%= class_name.camelize %>PageController = Ember.ArrayController.extend PageWrapper.PaginatedControllerMixin,
|
2
|
+
model: App.<%= class_name.camelize %>Page
|
3
|
+
|
4
|
+
#
|
5
|
+
# Properties
|
6
|
+
#
|
7
|
+
# TODO: create properties for the field titles to use in the view template
|
8
|
+
#
|
9
|
+
# i.e.: if title is a sortable field
|
10
|
+
#
|
11
|
+
# titleLabel: (->
|
12
|
+
# "Title #{@sortIndicator('title')}"
|
13
|
+
# ).property('content.isLoaded')
|
14
|
+
#
|
15
|
+
# => {{titleLable}} renders a link with sort direction in the view template
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<section>
|
2
|
+
<div class="page-header">
|
3
|
+
<h1><%= class_name.humanize.pluralize %></h1>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<div id="<%= class_name.underscore %>-list">
|
7
|
+
<table class="table table-bordered table-striped">
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<th>Field1</th>
|
11
|
+
<th>Field2</th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
|
15
|
+
<tbody>
|
16
|
+
{{#if controller.content.isLoaded}}
|
17
|
+
{{#each controller.currentPage.<%= class_name.camelize.pluralize %>}}
|
18
|
+
<tr>
|
19
|
+
<td>{{field1}}</td>
|
20
|
+
<td>{{field2}}</td>
|
21
|
+
</tr>
|
22
|
+
{{/each}}
|
23
|
+
{{/if}}
|
24
|
+
</tbody>
|
25
|
+
</table>
|
26
|
+
</div>
|
27
|
+
{{view PageWrapper.PaginationView pageBinding="controller.currentPage"}}
|
28
|
+
</section>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/page_wrapper/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mathieu Lajugie"]
|
6
|
+
gem.email = ["mathieul@gmail.com"]
|
7
|
+
gem.description = %q{Pagination tools when using Ember, Ember Data and Rails / Rails-Api.}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = "https://github.com/mathieul/page_wrapper"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "page_wrapper"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PageWrapper::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "ember-rails", ["~> 0.6.0"]
|
19
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
window.PageWrapper ?= {}
|
2
|
+
PageWrapper.PageModelMixin = Ember.Mixin.create
|
3
|
+
#
|
4
|
+
# Fields
|
5
|
+
#
|
6
|
+
pages: DS.attr('number')
|
7
|
+
first: DS.attr('boolean')
|
8
|
+
last: DS.attr('boolean')
|
9
|
+
total: DS.attr('number')
|
10
|
+
per_page: DS.attr('number')
|
11
|
+
query: DS.attr('string')
|
12
|
+
sort: DS.attr('string')
|
13
|
+
dir: DS.attr('string')
|
14
|
+
|
15
|
+
#
|
16
|
+
# Properties
|
17
|
+
#
|
18
|
+
paginated: (-> @get('pages') > 1).property('pages', 'isLoaded')
|
19
|
+
|
20
|
+
from: (->
|
21
|
+
1 + (@get('id') - 1) * @get('per_page')
|
22
|
+
).property('id', 'per_page', 'isLoaded')
|
23
|
+
|
24
|
+
to: (->
|
25
|
+
if @get('last')
|
26
|
+
@get('total')
|
27
|
+
else
|
28
|
+
@get('from') + @get('per_page') - 1
|
29
|
+
).property('last', 'total', 'from', 'per_page', 'isLoaded')
|
30
|
+
|
31
|
+
paginationItems: (->
|
32
|
+
[current, query] = [@get('id'), @get('query')]
|
33
|
+
items = @allItems(current, @get('pages'), query)
|
34
|
+
items.unshift @firstItem(current, query, @get('first'))
|
35
|
+
items.push @lastItem(current, query, @get('last'))
|
36
|
+
items
|
37
|
+
).property('id', 'pages', 'total', 'query', 'isLoaded')
|
38
|
+
|
39
|
+
#
|
40
|
+
# Other methods
|
41
|
+
#
|
42
|
+
allItems: (current, pages, query) ->
|
43
|
+
items = if pages < 9
|
44
|
+
[1..pages]
|
45
|
+
else
|
46
|
+
switch current
|
47
|
+
when 1, 2, 3, 4, 5
|
48
|
+
[1, 2, 3, 4, 5, 6, '…', pages - 1, pages]
|
49
|
+
when pages - 4, pages - 3, pages - 2, pages - 1, pages
|
50
|
+
[1, 2, '…', pages - 5, pages - 4, pages - 3, pages - 2, pages - 1, pages]
|
51
|
+
else
|
52
|
+
[1, 2, '…', current - 1, current, current + 1, '…', pages - 1, pages]
|
53
|
+
for i in items
|
54
|
+
if i is '…'
|
55
|
+
value: '…'
|
56
|
+
disabled: true
|
57
|
+
else
|
58
|
+
page: i
|
59
|
+
query: query
|
60
|
+
value: i
|
61
|
+
active: i is current
|
62
|
+
|
63
|
+
firstItem: (current, query, first) ->
|
64
|
+
page: if first then 'disabled' else current - 1
|
65
|
+
query: query
|
66
|
+
value: '«'
|
67
|
+
disabled: first
|
68
|
+
|
69
|
+
lastItem: (current, query, last) ->
|
70
|
+
page: if last then 'disabled' else current + 1
|
71
|
+
query: query
|
72
|
+
value: '»'
|
73
|
+
disabled: last
|
@@ -0,0 +1,55 @@
|
|
1
|
+
window.PageWrapper ?= {}
|
2
|
+
PageWrapper.PaginatedControllerMixin = Ember.Mixin.create
|
3
|
+
#
|
4
|
+
# Properties
|
5
|
+
#
|
6
|
+
currentPage: (->
|
7
|
+
array = @get('content')
|
8
|
+
array && array.objectAt(0)
|
9
|
+
).property('content.isLoaded')
|
10
|
+
|
11
|
+
#
|
12
|
+
# Event handlers
|
13
|
+
#
|
14
|
+
changePage: (event) ->
|
15
|
+
event.preventDefault()
|
16
|
+
page = $(event.target).data('page')
|
17
|
+
@update(id: page) unless page is 'disabled'
|
18
|
+
|
19
|
+
filter: (event) ->
|
20
|
+
event.preventDefault()
|
21
|
+
query = $(event.target).prev().val()
|
22
|
+
query = $.trim(query)
|
23
|
+
id = 1
|
24
|
+
@update(id: id, query: query)
|
25
|
+
|
26
|
+
changeSort: (event) ->
|
27
|
+
event.preventDefault()
|
28
|
+
sortType = $(event.target).data('sort')
|
29
|
+
page = @get('content').objectAt(0)
|
30
|
+
[sort, dir] = if page.get('sort') is sortType
|
31
|
+
[sortType, if page.get('dir') is 'asc' then 'desc' else 'asc']
|
32
|
+
else
|
33
|
+
[sortType, 'asc']
|
34
|
+
@update(sort: sort, dir: dir)
|
35
|
+
|
36
|
+
#
|
37
|
+
# Other methods
|
38
|
+
#
|
39
|
+
firstPage: ->
|
40
|
+
@model.find(id: 1)
|
41
|
+
|
42
|
+
sortIndicator: (column) ->
|
43
|
+
page = @get('content').objectAt(0)
|
44
|
+
return '' unless page? and column is page.get('sort')
|
45
|
+
if page.get('dir') is 'asc' then '▼' else '▲'
|
46
|
+
|
47
|
+
update: (params = {}) ->
|
48
|
+
page = @get('content').objectAt(0)
|
49
|
+
params.id ?= page.get('id')
|
50
|
+
params.query ?= page.get('query')
|
51
|
+
params.sort ?= page.get('sort')
|
52
|
+
params.dir ?= page.get('dir')
|
53
|
+
for name, value of params
|
54
|
+
delete params[name] unless value?
|
55
|
+
@set('content', @get('model').find(params))
|
@@ -0,0 +1,27 @@
|
|
1
|
+
window.PageWrapper ?= {}
|
2
|
+
PageWrapper.PaginationView = Ember.View.extend
|
3
|
+
tagName: 'div'
|
4
|
+
classNames: ['pagination pagination-right']
|
5
|
+
template: Ember.Handlebars.compile """
|
6
|
+
{{#if view.page.isLoaded}}
|
7
|
+
{{#with view.page}}
|
8
|
+
{{#if paginated}}
|
9
|
+
<ul>
|
10
|
+
{{#each paginationItems}}
|
11
|
+
<li {{bindAttr class="active disabled"}}>
|
12
|
+
{{#if disabled}}
|
13
|
+
<a href="javascript:void(0)">{{value}}</a>
|
14
|
+
{{else}}
|
15
|
+
<a href="#" {{bindAttr data-page="page"}}
|
16
|
+
{{action changePage}}>{{value}}</a>
|
17
|
+
{{/if}}
|
18
|
+
</li>
|
19
|
+
{{/each}}
|
20
|
+
</ul>
|
21
|
+
{{/if}}
|
22
|
+
<div class="pagination-info">
|
23
|
+
Showing {{itemsName}} <code>{{from}} to {{to}}</code> out of <code>{{total}}</code>
|
24
|
+
</div>
|
25
|
+
{{/with}}
|
26
|
+
{{/if}}
|
27
|
+
"""
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: page_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mathieu Lajugie
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ember-rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.6.0
|
30
|
+
description: Pagination tools when using Ember, Ember Data and Rails / Rails-Api.
|
31
|
+
email:
|
32
|
+
- mathieul@gmail.com
|
33
|
+
executables:
|
34
|
+
- erubis
|
35
|
+
- rackup
|
36
|
+
- rails
|
37
|
+
- rake
|
38
|
+
- rake2thor
|
39
|
+
- ri
|
40
|
+
- thor
|
41
|
+
- tilt
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- bin/erubis
|
51
|
+
- bin/rackup
|
52
|
+
- bin/rails
|
53
|
+
- bin/rake
|
54
|
+
- bin/rake2thor
|
55
|
+
- bin/ri
|
56
|
+
- bin/thor
|
57
|
+
- bin/tilt
|
58
|
+
- lib/generators/page_generator.rb
|
59
|
+
- lib/page_wrapper.rb
|
60
|
+
- lib/page_wrapper/engine.rb
|
61
|
+
- lib/page_wrapper/model.rb
|
62
|
+
- lib/page_wrapper/railtie.rb
|
63
|
+
- lib/page_wrapper/version.rb
|
64
|
+
- lib/templates/README
|
65
|
+
- lib/templates/model_controller.rb
|
66
|
+
- lib/templates/model_page.rb
|
67
|
+
- lib/templates/model_serializer.rb
|
68
|
+
- lib/templates/page_controller.js.coffee
|
69
|
+
- lib/templates/page_model.js.coffee
|
70
|
+
- lib/templates/page_template.handlebars
|
71
|
+
- lib/templates/page_view.js.coffee
|
72
|
+
- page_wrapper.gemspec
|
73
|
+
- vendor/assets/javascripts/page-model-mixin.js.coffee
|
74
|
+
- vendor/assets/javascripts/page-wrapper.js
|
75
|
+
- vendor/assets/javascripts/paginated-controller-mixin.js.coffee
|
76
|
+
- vendor/assets/javascripts/pagination-view.js.coffee
|
77
|
+
homepage: https://github.com/mathieul/page_wrapper
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
hash: 3175872921732100907
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: 3175872921732100907
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.23
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Pagination tools when using Ember, Ember Data and Rails / Rails-Api.
|
107
|
+
test_files: []
|