Skip to content

Commit

Permalink
added function get_order_string in tags_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhbir-singh committed Apr 3, 2018
1 parent 05f4d65 commit fc46cce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
24 changes: 11 additions & 13 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ def index

@title = I18n.t('tag_controller.tags')
@paginated = true

order_string = "count DESC"
if params[:order] == "asc"
order_string = "count ASC"
end
@order_type = params[:order] == "desc" ? "asc" : "desc"

if params[:search]
prefix = params[:search]
Expand All @@ -36,10 +32,6 @@ def index
.order(order_string)
.paginate(page: params[:page], per_page: 24)
elsif @toggle == "name"
order_string = "name DESC"
if params[:order] == "asc"
order_string = "name ASC"
end
@tags = Tag.joins(:node_tag, :node)
.select('node.nid, node.status, term_data.*, community_tags.*')
.where('node.status = ?', 1)
Expand All @@ -48,10 +40,6 @@ def index
.order(order_string)
.paginate(page: params[:page], per_page: 24)
else
order_string = "name DESC"
if params[:order] == "asc"
order_string = "name ASC"
end
tags = Tag.joins(:node_tag, :node)
.select('node.nid, node.status, term_data.*, community_tags.*')
.where('node.status = ?', 1)
Expand Down Expand Up @@ -450,4 +438,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
8 changes: 2 additions & 6 deletions app/views/tag/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@

<table class="table">
<tr>
<% order_type = "desc" %>
<% if params[:order] == "desc" %>
<% order_type = "asc" %>
<% end %>
<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><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-arrows-v"></i></th>
Expand Down

0 comments on commit fc46cce

Please sign in to comment.