-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed issue#2445 added both direction sort order #2557
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ def index | |
|
||
@title = I18n.t('tag_controller.tags') | ||
@paginated = true | ||
@order_type = params[:order] == "desc" ? "asc" : "desc" | ||
|
||
if params[:search] | ||
keyword = params[:search] | ||
@tags = Tag.joins(:node_tag, :node) | ||
|
@@ -20,31 +22,31 @@ def index | |
.where('community_tags.date > ?', (DateTime.now - 1.month).to_i) | ||
.where("name LIKE :keyword", keyword: "%#{keyword}%") | ||
.group(:name) | ||
.order('count DESC') | ||
.order(order_string) | ||
.paginate(page: params[:page], per_page: 24) | ||
elsif @toggle == "uses" | ||
@tags = Tag.joins(:node_tag, :node) | ||
.select('node.nid, node.status, term_data.*, community_tags.*') | ||
.where('node.status = ?', 1) | ||
.where('community_tags.date > ?', (DateTime.now - 1.month).to_i) | ||
.group(:name) | ||
.order('count DESC') | ||
.order(order_string) | ||
.paginate(page: params[:page], per_page: 24) | ||
elsif @toggle == "name" | ||
@tags = Tag.joins(:node_tag, :node) | ||
.select('node.nid, node.status, term_data.*, community_tags.*') | ||
.where('node.status = ?', 1) | ||
.where('community_tags.date > ?', (DateTime.now - 1.month).to_i) | ||
.group(:name) | ||
.order('name') | ||
.order(order_string) | ||
.paginate(page: params[:page], per_page: 24) | ||
else | ||
tags = Tag.joins(:node_tag, :node) | ||
.select('node.nid, node.status, term_data.*, community_tags.*') | ||
.where('node.status = ?', 1) | ||
.where('community_tags.date > ?', (DateTime.now - 1.month).to_i) | ||
.group(:name) | ||
.order('name') | ||
.order(order_string) | ||
|
||
followed = [] | ||
not_followed = [] | ||
|
@@ -440,4 +442,14 @@ def location_modal | |
def gridsEmbed | ||
render layout: false | ||
end | ||
|
||
private | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But all other controllers in this project have used same pattern to specify private methods in a class. Please check out the |
||
|
||
def order_string | ||
if params[:search] || @toggle == "uses" | ||
params[:order] == "asc" ? "count ASC" : "count DESC" | ||
else | ||
params[:order] == "asc" ? "name ASC" : "name DESC" | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little bit confused... if the
order
param isdesc
, we want to set the@order_type
todesc
...?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shauncarland The logic behind this is that, we have to invert the order when a user click on sorting header again. So lets say if current shown order is according to "name descending" then we want front end to request on url with order type be ascending (opposite of descending). I hope you got my point 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🎉 🎉 🎉 🎉 🎉