Browse Source

integrate knu's suggestions

Andrew Cantino 10 years ago
parent
commit
933f1eb1f9

+ 11 - 3
app/controllers/concerns/sortable_table.rb

@@ -15,7 +15,7 @@ module SortableTable
   end
 
   def set_table_sort(sort_options)
-    valid_sorts = sort_options[:sorts] || raise("You must specify :sorts as an array of valid sort attributes.")
+    valid_sorts = sort_options[:sorts] or raise ArgumentError.new("You must specify :sorts as an array of valid sort attributes.")
     default = sort_options[:default] || { valid_sorts.first.to_sym => :desc }
 
     if params[:sort].present?
@@ -37,7 +37,15 @@ module SortableTable
   end
 
   module SortableTableHelper
-    def sortable_column(attribute, name = attribute.humanize, default_direction = 'desc')
+    # :call-seq:
+    #   sortable_column(attribute, default_direction = 'desc', name: attribute.humanize)
+    def sortable_column(attribute, default_direction = nil, options = nil)
+      if options.nil? && (options = Hash.try_convert(default_direction))
+        default_direction = nil
+      end
+      default_direction ||= 'desc'
+      options ||= {}
+      name = options[:name] || attribute.humanize
       selected = @table_sort_info[:attribute].to_s == attribute
       if selected
         direction = @table_sort_info[:direction]
@@ -50,4 +58,4 @@ module SortableTable
       link_to(name, url_for(sort: "#{attribute}.#{new_direction}"), class: classes)
     end
   end
-end
+end

+ 4 - 4
app/views/agents/_table.html.erb

@@ -1,11 +1,11 @@
 <div class='table-responsive'>
   <table class='table table-striped'>
     <tr>
-      <th><%= sortable_column 'name', 'Name', 'asc' %></th>
+      <th><%= sortable_column 'name', 'asc' %></th>
       <th>Schedule</th>
-      <th><%= sortable_column 'last_check_at', 'Last Check' %></th>
-      <th><%= sortable_column 'last_event_at', 'Last Event Out' %></th>
-      <th><%= sortable_column 'last_receive_at', 'Last Event In' %></th>
+      <th><%= sortable_column 'last_check_at', name: 'Last Check' %></th>
+      <th><%= sortable_column 'last_event_at', name: 'Last Event Out' %></th>
+      <th><%= sortable_column 'last_receive_at', name: 'Last Event In' %></th>
       <th>Events Created</th>
       <th>Working?</th>
       <th></th>

+ 1 - 1
app/views/scenarios/index.html.erb

@@ -12,7 +12,7 @@
 
       <table class='table table-striped'>
         <tr>
-          <th><%= sortable_column 'name', 'Name', 'asc' %></th>
+          <th><%= sortable_column 'name', 'asc' %></th>
           <th>Agents</th>
           <th><%= sortable_column 'public' %></th>
           <th></th>

+ 3 - 3
app/views/services/index.html.erb

@@ -25,9 +25,9 @@
       <div class='table-responsive'>
         <table class='table table-striped events'>
           <tr>
-            <th><%= sortable_column 'provider', 'Provider', 'asc' %></th>
-            <th><%= sortable_column 'name', 'Name', 'asc' %></th>
-            <th><%= sortable_column 'global', 'Global?' %></th>
+            <th><%= sortable_column 'provider', 'asc' %></th>
+            <th><%= sortable_column 'name', 'asc' %></th>
+            <th><%= sortable_column 'global', name: 'Global?' %></th>
             <th></th>
           </tr>
 

+ 2 - 2
app/views/user_credentials/index.html.erb

@@ -14,8 +14,8 @@
 
       <table class='table table-striped'>
         <tr>
-          <th><%= sortable_column 'credential_name', 'Name', 'asc' %></th>
-          <th><%= sortable_column 'credential_value', 'Value', 'asc' %></th>
+          <th><%= sortable_column 'credential_name', 'asc', name: 'Name'  %></th>
+          <th><%= sortable_column 'credential_value', 'asc', name: 'Value' %></th>
         </tr>
 
         <% @user_credentials.each do |user_credential| %>