Skip to content

Commit

Permalink
Fixed issue#2445 added both direction sort order (publiclab#2557)
Browse files Browse the repository at this point in the history
* fixed issue#2445 added both direction sort order

* added function get_order_string in tags_controller
  • Loading branch information
sukhbir-singh authored and SidharthBansal committed Jun 19, 2018
1 parent 664d71d commit c795014
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = []
Expand Down Expand Up @@ -440,4 +442,14 @@ def location_modal
def gridsEmbed
render layout: false
end

private

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
4 changes: 2 additions & 2 deletions app/views/tag/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

<table class="table">
<tr>
<th><a href = "<%= tags_path %>?sort=name"><%= t('tag.index.tag') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
<th><a href = "<%= tags_path %>?sort=uses"><%= t('tag.index.number_of_uses') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
<th><a href = "<%= tags_path %>?sort=name&order=<%= @order_type %>"><%= t('tag.index.tag') %></a> <i class="fa fa-arrows-v"></i></th>
<th><a href = "<%= tags_path %>?sort=uses&order=<%= @order_type %>"><%= t('tag.index.number_of_uses') %></a> <i class="fa fa-arrows-v"></i></th>
<th><%= t('tag.index.number_of_subscriptions')%></th>
<% if current_user %>
<th><a href = "<%= tags_path %>?sort=subscribers"><%= t('tag.index.subscriptions') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
Expand Down

0 comments on commit c795014

Please sign in to comment.