sql_search_n_sort 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afc438625d2512c3ae20d67d7f82ed5d986d5e52
4
- data.tar.gz: 88a999dfc9b2702973f2f847502e819bfc6f707f
3
+ metadata.gz: 03e83d0cfb7a3e84a681a5905cbd1fbf7a40a996
4
+ data.tar.gz: 14d29c20d503653a279e6c47dea3f82117e0a2d9
5
5
  SHA512:
6
- metadata.gz: 1f18546a8864fb5661aa16e9d8c25bb3710853c9a58f8b4ccdbc2017ddd8901830669838525370eedce880f96b42b17a3b4938ea052fa8a41cef3b2c4a4ec980
7
- data.tar.gz: 44531721f8db45913def98ed376ac437c65464dedf004c585b3faf3dbe82418a2f68fd52eb12ab0f25c958b6410762e954f30fb4883a22c6f1585665889b05a9
6
+ metadata.gz: 8c8dd28d7ef5f0d70b1f677d564450e19e8a10d77796fdccfdcc5643e1044e0567512b54868c1197cc2d865dfdd09e66241d296bc1b688a6ca03a00f07ad9b68
7
+ data.tar.gz: 11927189b6f4f2164167e527d0c0bc1d56078dae828cf76ad123d1a9ddfc199f01f0a5bee385bf2b0066bfde0dc2349f78dba21b9425fef8c503b306707da863
@@ -51,12 +51,7 @@ module SqlSearchableSortable
51
51
  end
52
52
 
53
53
  def sort_cols_for_dropdown
54
- self.sort_config ||= []
55
- return sort_config.inject([]) do |m, col_conf|
56
- m << ["#{col_conf.display_text || col_conf.column.to_s.humanize}", "#{col_conf.column.to_s}"] if col_conf.show_asc
57
- m << ["#{col_conf.display_text || col_conf.column.to_s.humanize} [desc]", "#{col_conf.column.to_s} desc"] if col_conf.show_desc
58
- m
59
- end
54
+ sort_config.select_opts
60
55
  end
61
56
 
62
57
  class ModelSortConfig < Array
@@ -83,6 +78,12 @@ module SqlSearchableSortable
83
78
  def contains_column(col)
84
79
  self.any? { |sc| sc.column == col }
85
80
  end
81
+
82
+ def select_opts
83
+ return self.inject([]) do |m, sort_col|
84
+ m + sort_col.select_opts
85
+ end
86
+ end
86
87
  end
87
88
 
88
89
  class SortColumn
@@ -93,6 +94,18 @@ module SqlSearchableSortable
93
94
  @show_asc = show_asc
94
95
  @show_desc = show_desc
95
96
  end
97
+ def name
98
+ column.to_s
99
+ end
100
+ def human_name
101
+ name.humanize
102
+ end
103
+ def select_opts
104
+ arr = []
105
+ arr << ["#{display_text || human_name}", "#{name}"] if show_asc
106
+ arr << ["#{display_text || human_name} [desc]", "#{name} desc"] if show_desc
107
+ return arr
108
+ end
96
109
  end
97
110
 
98
111
  end
@@ -3,10 +3,10 @@ module SqlSortSetup
3
3
  def setup_sql_sort
4
4
  model = controller_name.classify.constantize
5
5
  if model.is_a? SqlSearchableSortable
6
- if params[:sort_by]
7
- @sort_by = (params[:sort_by].split(' ').length > 1) ?
8
- params[:sort_by].split(' ').first.to_sym : params[:sort_by].to_sym
9
- dir = (params[:sort_by].split(' ').length > 1) ? params[:sort_by].split(' ')[1].to_sym : nil
6
+ if sort_by
7
+ @sort_by = (sort_by.split.length > 1) ?
8
+ sort_by.split.first.to_sym : sort_by.to_sym
9
+ dir = (sort_by.split.length > 1) ? sort_by.split[1].to_sym : nil
10
10
  if [:asc, :desc].include?(dir)
11
11
  @sort_dir = dir
12
12
  else
@@ -17,12 +17,18 @@ module SqlSortSetup
17
17
  end
18
18
  else
19
19
  sort_by_param = model.default_sort_col.to_s
20
- sort_by_param += " #{model.default_sort_dir}" unless model.default_sort_dir.nil?
21
- #TODO: I'm not sure its adviseable to set a params value like this
20
+ sort_by_param += " #{model.default_sort_dir}" if model.default_sort_dir
21
+ #unless model.default_sort_dir.nil?
22
22
  params[:sort_by] = sort_by_param
23
23
  end
24
24
  @sort_dropdown_opts = model.sort_cols_for_dropdown #for the view
25
25
  @sort_dir ||= :asc
26
26
  end
27
27
  end
28
- end
28
+
29
+ private
30
+ def sort_by
31
+ params[:sort_by]
32
+ end
33
+ end
34
+
@@ -1,3 +1,3 @@
1
1
  module SqlSearchNSort
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
Binary file