Skip to content

Commit

Permalink
Fixed first part of Issue publiclab#2352 Sorting headers added in wik…
Browse files Browse the repository at this point in the history
…i index page (publiclab#2353)

* sorting headers added in wiki index page

* replaced sorting header icon
  • Loading branch information
sukhbir-singh authored and SidharthBansal committed Jun 19, 2018
1 parent 3e57596 commit 0e21a70
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 45 deletions.
18 changes: 13 additions & 5 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,19 @@ def diff

def index
@title = I18n.t('wiki_controller.wiki')

order_string = if params[:order] == 'alphabetic'
'node_revisions.title ASC'
else
'node_revisions.timestamp DESC'
sort_param = params[:sort]
order_string = 'node_revisions.timestamp DESC'

if sort_param == 'title'
order_string = 'node_revisions.title ASC'
elsif sort_param == 'last_edited'
order_string = 'node_revisions.timestamp DESC'
elsif sort_param == 'edits'
order_string = 'drupal_node_revisions_count DESC'
elsif sort_param == 'page_views'
order_string = 'views DESC'
elsif sort_param == 'likes'
order_string = 'cached_likes DESC'
end

@wikis = Node.includes(:revision)
Expand Down
6 changes: 3 additions & 3 deletions app/views/tag/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

<table class="table">
<tr>
<th><a href = "<%= tags_path %>?sort=name"><%= t('tag.index.tag') %></a> <i class="fa fa-arrows-v"></i></th>
<th><a href = "<%= tags_path %>?sort=uses"><%= t('tag.index.number_of_uses') %></a> <i class="fa fa-arrows-v"></i></th>
<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><%= 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>
<th><a href = "<%= tags_path %>?sort=subscribers"><%= t('tag.index.subscriptions') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
<% end %>
</tr>
<% @tags.each do |tag| %>
Expand Down
7 changes: 5 additions & 2 deletions app/views/wiki/_wikis.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<table class="table">
<tr>
<%= raw t('wiki._wikis.table_content') %>
<th> <%= t('wiki._wikis.likes') %></th>
<th><a href = "<%= wiki_path %>?sort=title"> <%= t('wiki._wikis.title') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
<th><a href = "<%= wiki_path %>?sort=last_edited"> <%= t('wiki._wikis.last_edited') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
<th><a href = "<%= wiki_path %>?sort=edits"> <%= t('wiki._wikis.edits') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
<th><a href = "<%= wiki_path %>?sort=page_views"> <%= t('wiki._wikis.page_views') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
<th><a href = "<%= wiki_path %>?sort=likes"> <%= t('wiki._wikis.likes') %></a> <i class="fa fa-sort" aria-hidden="true"></i></th>
</tr>
<% @wikis.each do |wiki| %>
<tr>
Expand Down
31 changes: 1 addition & 30 deletions app/views/wiki/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,11 @@
<a style="margin-bottom:4px;" href="/wiki/new" class="btn btn-default">
<i class="fa fa-plus-circle"></i> <%= t('wiki.index.create_wiki_page') %>
</a>
<span style="margin-top:4px;" class="pull-right"> <%= t('wiki.index.sort_by') %>

<% if params[:action] == "index" && params[:order] !="alphabetic" %>
<span style="color:#aaa"><%= t('wiki.index.by_recency') %></span> |
<% else %>
<a href="/wiki/"><%= t('wiki.index.by_recency') %></a> |
<% end %>

<% if params[:order] == "alphabetic" %>
<span style="color:#aaa"><%= t('wiki.index.by_alphabetic') %></span> |
<% else %>
<a href="/wiki/?order=alphabetic"><%= t('wiki.index.by_alphabetic') %></a> |
<% end %>

<% if params[:action] == "liked" %>
<span style="color:#aaa"><%= t('wiki.index.by_number_of_likes') %></span> |
<% else %>
<a href="/wiki/liked"><%= t('wiki.index.by_number_of_likes') %></a> |
<% end %>


<% if params[:action] == "popular" %>
<span style="color:#aaa"><%= t('wiki.index.by_popularity') %></span>
<% else %>
<a href="/wiki/popular"><%= t('wiki.index.by_popularity') %></a>
<% end %>

</span>
</p>


<%= render :partial => "wiki/wikis" %>

<hr />

</div>

</div><!--/span-->
9 changes: 4 additions & 5 deletions config/locales/views/wiki/_wikis/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
en:
wiki:
_wikis:
table_content: |
<th>Title</th>
<th>Last edited</th>
<th>Edits</th>
<th class="hidden-xs">Pageviews</th>
title: 'Title'
last_edited: 'Last edited'
edits: 'Edits'
page_views: 'Page Views'
likes: 'Likes'
by: 'by'

0 comments on commit 0e21a70

Please sign in to comment.