From 5fc7545c0189ac81d14b976c562cb18070e92c73 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 17 Jul 2015 15:53:48 +0530 Subject: [PATCH] UX: include more details on Permalinks page --- .../admin/templates/permalinks_list_item.hbs | 26 ++++++++++++++++--- .../stylesheets/common/admin/admin_base.scss | 18 ++++++++++--- .../admin/permalinks_controller.rb | 8 ++---- app/models/permalink.rb | 10 +++++++ app/serializers/permalink_serializer.rb | 22 +++++++++++++++- 5 files changed, 69 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/admin/templates/permalinks_list_item.hbs b/app/assets/javascripts/admin/templates/permalinks_list_item.hbs index 4fbf2db55e2..63d7ed839f1 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 topic_id}} + {{topic_id}} + ({{topic_title}}) + {{/if}} +
+
+ {{#if post_id}} + {{post_id}} + {{/if}} +
+
+ {{#if category_id}} + {{category_id}} + ({{category_name}}) + {{/if}} +
+
+ {{#if external_url}} + {{external_url}} + {{/if}} +
diff --git a/app/assets/stylesheets/common/admin/admin_base.scss b/app/assets/stylesheets/common/admin/admin_base.scss index 05891ad3446..fa689540537 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 9c2eb47fb2e..875110e87a6 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 c7c7d567e37..086df294406 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 2d621ed72de..3a7440888ec 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