]> cat aescling's git repositories - mastodon.git/commitdiff
Togglable filter links (#4021)
authorのら <noraworld@users.noreply.github.com>
Thu, 6 Jul 2017 22:48:09 +0000 (07:48 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 6 Jul 2017 22:48:09 +0000 (00:48 +0200)
* Togglable filter links

* Rename is_selected to selected?

app/helpers/admin/filter_helper.rb
app/views/admin/accounts/index.html.haml

index 0dfa30e56df8171d8bb0ed629790e860c048a277..6a57b3d636406fee884b8085167e98d17564bc32 100644 (file)
@@ -6,15 +6,21 @@ module Admin::FilterHelper
 
   FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS
 
-  def filter_link_to(text, more_params)
-    new_url = filtered_url_for(more_params)
-    link_to text, new_url, class: filter_link_class(new_url)
+  def filter_link_to(text, link_to_params, link_class_params = link_to_params)
+    new_url = filtered_url_for(link_to_params)
+    new_class = filtered_url_for(link_class_params)
+    link_to text, new_url, class: filter_link_class(new_class)
   end
 
   def table_link_to(icon, text, path, options = {})
     link_to safe_join([fa_icon(icon), text]), path, options.merge(class: 'table-action-link')
   end
 
+  def selected?(more_params)
+    new_url = filtered_url_for(more_params)
+    filter_link_class(new_url) == 'selected' ? true : false
+  end
+
   private
 
   def filter_params(more_params)
index 6d2849c32115d701d153262a14cb1dda4945e640..07c8d16325cf61200a74535603456d0324b370d9 100644 (file)
@@ -6,14 +6,30 @@
     %strong= t('admin.accounts.location.title')
     %ul
       %li= filter_link_to t('admin.accounts.location.all'), local: nil, remote: nil
-      %li= filter_link_to t('admin.accounts.location.local'), local: '1', remote: nil
-      %li= filter_link_to t('admin.accounts.location.remote'), remote: '1', local: nil
+      %li
+        - if selected? local: '1', remote: nil
+          = filter_link_to t('admin.accounts.location.local'), {local: nil, remote: nil}, {local: '1', remote: nil}
+        - else
+          = filter_link_to t('admin.accounts.location.local'), local: '1', remote: nil
+      %li
+        - if selected? remote: '1', local: nil
+          = filter_link_to t('admin.accounts.location.remote'), {remote: nil, local: nil}, {remote: '1', local: nil}
+        - else
+          = filter_link_to t('admin.accounts.location.remote'), remote: '1', local: nil
   .filter-subset
     %strong= t('admin.accounts.moderation.title')
     %ul
       %li= filter_link_to t('admin.accounts.moderation.all'), silenced: nil, suspended: nil
-      %li= filter_link_to t('admin.accounts.moderation.silenced'), silenced: '1'
-      %li= filter_link_to t('admin.accounts.moderation.suspended'), suspended: '1'
+      %li
+        - if selected? silenced: '1'
+          = filter_link_to t('admin.accounts.moderation.silenced'), {silenced: nil}, {silenced: '1'}
+        - else
+          = filter_link_to t('admin.accounts.moderation.silenced'), silenced: '1'
+      %li
+        - if selected? suspended: '1'
+          = filter_link_to t('admin.accounts.moderation.suspended'), {suspended: nil}, {suspended: '1'}
+        - else
+          = filter_link_to t('admin.accounts.moderation.suspended'), suspended: '1'
   .filter-subset
     %strong= t('admin.accounts.order.title')
     %ul