Skip to content

Commit

Permalink
Ability to sort tags alphabetically #1704 (#1714)
Browse files Browse the repository at this point in the history
* Ability to sort tags alphabetically #1704

TagController changed

* Updated TagContoller

* final update Tag#controller

* Updated index.html.erb

* Updated routes.rb

* Updated de.yml

* Updated en.yml

* adding Bootstrap input class style
  • Loading branch information
sagarpreet-chadha authored and jywarren committed Oct 24, 2017
1 parent fb593f5 commit 65e072e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
26 changes: 26 additions & 0 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,41 @@ class TagController < ApplicationController
before_filter :require_user, only: %i[create delete]

def index
if params[:format]
@toggle = params[:format].to_i
else
@toggle = 1
end

@title = I18n.t('tag_controller.tags')
@paginated = true
if params[:search]
prefix = params[:search]
@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)
.where("name LIKE :prefix", prefix: "#{prefix}%")
.group(:name)
.order('count DESC')
.paginate(page: params[:page])
elsif @toggle == 1
@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')
.paginate(page: params[:page])
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')
.paginate(page: params[:page])
end
end

def show
Expand Down
29 changes: 28 additions & 1 deletion app/views/tag/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
<%= render :partial => "sidebar/featured" %>

<div class="col-md-9">
<h1 style="font-family:Junction Light;"><%= t('tag.index.popular_tags') %></h1>
<table style="width:100%">
<tr>
<th style="width: 50% ;">
<h1 style="font-family:Junction Light;"><%= t('tag.index.popular_tags') %></h1>
</th>
<th style="width: 50% ; text-align: right ;">


<a class="btn btn-default" rel="popover" data-trigger="focus" data-placement="bottom" data-html="true" data-content=" <a href = <%= tags_path(1) %> >Number of uses</a> <br> <a href = <%= tags_path(2) %> >Alphabetically</a>">
<i class="fa fa-sort"></i> <%=t('tag.index.sort_by') %>
</a>

</th>
</tr>
</table>
<p><%= t('tag.index.browse_popular_tags') %></p>
<!-- Search Bar -->
<input class="form-control" type="text" id="myInput" placeholder="Search for tags..">
<script>
$('#myInput').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
var pre = document.getElementsByTagName("input")[1].value ;

window.location.href = " <%= tags_path %>"+"/"+pre
}
});
</script>
<br><br>

<table class="table">
<tr>
Expand Down
3 changes: 2 additions & 1 deletion config/locales/views/tag/index/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ de:
tag: "Etikett"
number_of_uses: "# Einsatz"
number_of_subscriptions: "# von Menschen abonniert"
subscriptions: "Ihre Abonnements"
subscriptions: "Ihre Abonnements"
sort_by: "Sortiere nach"
1 change: 1 addition & 0 deletions config/locales/views/tag/index/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ en:
number_of_uses: "# of uses"
number_of_subscriptions: "# of people subscribed"
subscriptions: "Your subscriptions"
sort_by: "Sort By"
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
match 'contributors/:id' => 'tag#contributors'
match 'contributors' => 'tag#contributors_index'
match 'tags' => 'tag#index'
match 'tags/:search' => 'tag#index'
match 'embed/grid/:tagname' => 'tag#gridsEmbed'
match 'tag/suggested/:id' => 'tag#suggested'
match 'tag/author/:id.json' => 'tag#author'
Expand Down

0 comments on commit 65e072e

Please sign in to comment.