fix bug with pagination + add _permalink property for content instances
This commit is contained in:
parent
b4d3aae46f
commit
7cb26a74d4
@ -28,6 +28,7 @@ class ContentInstance
|
|||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
alias :visible? :_visible?
|
alias :visible? :_visible?
|
||||||
|
alias :_permalink :_slug
|
||||||
|
|
||||||
def site_id # needed by the uploader of custom fields
|
def site_id # needed by the uploader of custom fields
|
||||||
self.content_type.site_id
|
self.content_type.site_id
|
||||||
|
3
doc/TODO
3
doc/TODO
@ -16,6 +16,9 @@ BOARD:
|
|||||||
- increase the input field for domain names
|
- increase the input field for domain names
|
||||||
- drag&drop for assets ('last' class issue)
|
- drag&drop for assets ('last' class issue)
|
||||||
|
|
||||||
|
- api
|
||||||
|
- handle html request (for now, it's just json)
|
||||||
|
|
||||||
- refactor slugify method (use parameterize + create a module)
|
- refactor slugify method (use parameterize + create a module)
|
||||||
- [content types] the "display column" selector should not include file types
|
- [content types] the "display column" selector should not include file types
|
||||||
|
|
||||||
|
@ -18,29 +18,15 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def first
|
def first
|
||||||
content = @content_type.ordered_contents(@context['with_scope']).first
|
self.collection.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def last
|
def last
|
||||||
content = @content_type.ordered_contents(@context['with_scope']).last
|
self.collection.last
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@collection ||= @content_type.ordered_contents(@context['with_scope'])
|
self.collection.each(&block)
|
||||||
@collection.each(&block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def paginate(options = {})
|
|
||||||
@collection ||= @content_type.ordered_contents(@context['with_scope']).paginate(options)
|
|
||||||
{
|
|
||||||
:collection => @collection,
|
|
||||||
:current_page => @collection.current_page,
|
|
||||||
:previous_page => @collection.previous_page,
|
|
||||||
:next_page => @collection.next_page,
|
|
||||||
:total_entries => @collection.total_entries,
|
|
||||||
:total_pages => @collection.total_pages,
|
|
||||||
:per_page => @collection.per_page
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def api
|
def api
|
||||||
@ -55,6 +41,25 @@ module Locomotive
|
|||||||
klass.send(meth)
|
klass.send(meth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def paginate(options = {})
|
||||||
|
@collection ||= self.collection.paginate(options)
|
||||||
|
{
|
||||||
|
:collection => @collection,
|
||||||
|
:current_page => @collection.current_page,
|
||||||
|
:previous_page => @collection.previous_page,
|
||||||
|
:next_page => @collection.next_page,
|
||||||
|
:total_entries => @collection.total_entries,
|
||||||
|
:total_pages => @collection.total_pages,
|
||||||
|
:per_page => @collection.per_page
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection
|
||||||
|
@collection ||= @content_type.ordered_contents(@context['with_scope']) # remove per_page, page keys
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,13 +36,13 @@ module Locomotive
|
|||||||
|
|
||||||
raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil?
|
raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil?
|
||||||
|
|
||||||
pagination = collection.paginate({
|
pagination = collection.send(:paginate, {
|
||||||
:page => context['current_page'],
|
:page => context['current_page'],
|
||||||
:per_page => @per_page }).stringify_keys!
|
:per_page => @per_page }).stringify_keys
|
||||||
|
|
||||||
page_count, current_page = pagination['total_pages'], pagination['current_page']
|
page_count, current_page = pagination['total_pages'], pagination['current_page']
|
||||||
|
|
||||||
path = context['page'].path rescue '/'
|
path = context.registers[:page].fullpath
|
||||||
|
|
||||||
pagination['previous'] = link(I18n.t('pagination.previous'), current_page - 1, path) if pagination['previous_page']
|
pagination['previous'] = link(I18n.t('pagination.previous'), current_page - 1, path) if pagination['previous_page']
|
||||||
pagination['next'] = link(I18n.t('pagination.next'), current_page + 1, path) if pagination['next_page']
|
pagination['next'] = link(I18n.t('pagination.next'), current_page + 1, path) if pagination['next_page']
|
||||||
|
Loading…
Reference in New Issue
Block a user