diff --git a/app/assets/javascripts/admin/templates/permalinks_list_item.hbs b/app/assets/javascripts/admin/templates/permalinks_list_item.hbs
index 4fbf2db55..63d7ed839 100644
--- a/app/assets/javascripts/admin/templates/permalinks_list_item.hbs
+++ b/app/assets/javascripts/admin/templates/permalinks_list_item.hbs
@@ -1,7 +1,25 @@
{{url}}
-{{topic_id}}
-{{post_id}}
-{{category_id}}
-{{external_url}}
+
+
+ {{#if post_id}}
+
{{post_id}}
+ {{/if}}
+
+
+
diff --git a/app/assets/stylesheets/common/admin/admin_base.scss b/app/assets/stylesheets/common/admin/admin_base.scss
index 05891ad34..fa6895405 100644
--- a/app/assets/stylesheets/common/admin/admin_base.scss
+++ b/app/assets/stylesheets/common/admin/admin_base.scss
@@ -1473,12 +1473,22 @@ table#user-badges {
// Permalinks
.permalinks {
- .url, .external_url {
- width: 300px;
+ .url, .topic_id, .category_id, .external_url {
+ text-overflow: ellipsis;
+ white-space: nowrap;
}
- .action, .topic_id, .post_id, .category_id {
+ .url {
+ width: 200px;
+ }
+ .topic_id, .external_url {
+ width: 220px;
+ }
+ .category_id {
+ width: 160px;
+ }
+ .action, .post_id {
text-align: center;
- width: 9.9099%;
+ width: 8%;
}
}
diff --git a/app/controllers/admin/permalinks_controller.rb b/app/controllers/admin/permalinks_controller.rb
index 9c2eb47fb..875110e87 100644
--- a/app/controllers/admin/permalinks_controller.rb
+++ b/app/controllers/admin/permalinks_controller.rb
@@ -3,12 +3,8 @@ class Admin::PermalinksController < Admin::AdminController
before_filter :fetch_permalink, only: [:destroy]
def index
- filter = params[:filter]
-
- permalinks = Permalink
- permalinks = permalinks.where('url ILIKE :filter OR external_url ILIKE :filter', filter: "%#{params[:filter]}%") if filter.present?
- permalinks = permalinks.limit(100).order('created_at desc').to_a
-
+ url = params[:filter]
+ permalinks = Permalink.filter_by(url)
render_serialized(permalinks, PermalinkSerializer)
end
diff --git a/app/models/permalink.rb b/app/models/permalink.rb
index c7c7d567e..086df2944 100644
--- a/app/models/permalink.rb
+++ b/app/models/permalink.rb
@@ -80,6 +80,16 @@ class Permalink < ActiveRecord::Base
return category.url if category
nil
end
+
+ def self.filter_by(url=nil)
+ permalinks = Permalink
+ .includes(:topic, :post, :category)
+ .order('permalinks.created_at desc')
+
+ permalinks.where!('url ILIKE :url OR external_url ILIKE :url', url: "%#{url}%") if url.present?
+ permalinks.limit!(100)
+ permalinks.to_a
+ end
end
# == Schema Information
diff --git a/app/serializers/permalink_serializer.rb b/app/serializers/permalink_serializer.rb
index 2d621ed72..3a7440888 100644
--- a/app/serializers/permalink_serializer.rb
+++ b/app/serializers/permalink_serializer.rb
@@ -1,3 +1,23 @@
class PermalinkSerializer < ApplicationSerializer
- attributes :id, :url, :topic_id, :post_id, :category_id, :external_url
+ attributes :id, :url, :topic_id, :topic_title, :topic_url, :post_id, :post_url, :category_id, :category_name, :category_url, :external_url
+
+ def topic_title
+ object.try(:topic).try(:title)
+ end
+
+ def topic_url
+ object.try(:topic).try(:url)
+ end
+
+ def post_url
+ object.try(:post).try(:url)
+ end
+
+ def category_name
+ object.try(:category).try(:name)
+ end
+
+ def category_url
+ object.try(:category).try(:url)
+ end
end