Skip to content
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

Ability to sort tags alphabetically #1704 #1714

Merged
merged 8 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -152,6 +152,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