Pagination complete

This commit is contained in:
mcmac 2018-02-22 14:28:22 +00:00
parent 0a0c6b7bfc
commit c2aab96494
2 changed files with 12 additions and 14 deletions

19
.idea/workspace.xml generated
View file

@ -2,11 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="42443dfa-4405-4cad-b0d1-6c57eb86e644" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/Gemfile" afterPath="$PROJECT_DIR$/Gemfile" />
<change beforePath="$PROJECT_DIR$/Gemfile.lock" afterPath="$PROJECT_DIR$/Gemfile.lock" />
<change beforePath="$PROJECT_DIR$/app/controllers/v1/articles_controller.rb" afterPath="$PROJECT_DIR$/app/controllers/v1/articles_controller.rb" />
<change beforePath="$PROJECT_DIR$/app/serializers/article_serializer.rb" afterPath="" />
</list>
<ignored path="$PROJECT_DIR$/.bundle/" />
<ignored path="$PROJECT_DIR$/components/" />
@ -38,8 +34,8 @@
<file leaf-file-name="articles_controller.rb" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/app/controllers/v1/articles_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="17" column="61" lean-forward="false" selection-start-line="17" selection-start-column="61" selection-end-line="17" selection-end-column="61" />
<state relative-caret-position="288">
<caret line="16" column="85" lean-forward="false" selection-start-line="16" selection-start-column="85" selection-end-line="16" selection-end-column="85" />
<folding />
</state>
</provider>
@ -337,15 +333,16 @@
<workItem from="1519029876792" duration="13672000" />
<workItem from="1519112531617" duration="11606000" />
<workItem from="1519202717236" duration="9748000" />
<workItem from="1519290005411" duration="6701000" />
<workItem from="1519290005411" duration="11256000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="58239000" />
<option name="totallyTimeSpent" value="62794000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="28" width="1920" height="1026" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.19497864" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
@ -354,7 +351,7 @@
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32959402" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.37782562" sideWeight="0.704594" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.37782562" sideWeight="0.704594" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
@ -714,8 +711,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/app/controllers/v1/articles_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="17" column="61" lean-forward="false" selection-start-line="17" selection-start-column="61" selection-end-line="17" selection-end-column="61" />
<state relative-caret-position="288">
<caret line="16" column="85" lean-forward="false" selection-start-line="16" selection-start-column="85" selection-end-line="16" selection-end-column="85" />
<folding />
</state>
</provider>

View file

@ -9,11 +9,12 @@ class V1::ArticlesController < ApplicationController
@article = Article.all.order(created_at: :desc).paginate(page: current_page, per_page: 10)
total_pages = (@article.count / posts_per_page).ceil
pagination = {
"current_page": current_page,
"current_page": current_page.to_i == 0 ? 1 : current_page,
"last_page": total_pages,
"next_page": "/articles?page=#{(current_page.to_i + 1).to_s}",
"prev_page": "/articles?page=#{(current_page.to_i - 1).to_s}"
"next_page": "#{current_page.to_i < total_pages.to_i ? (current_page.to_i+1) : (current_page)}",
"prev_page": "#{current_page.to_i > 1 ? (current_page.to_i-1) : (current_page)}"
}
json_response({articles: @article.as_json(include: [:user]), pagination: pagination})
end