sortable_skima 0.2.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +192 -0
  3. data/app/assets/javascripts/jquery-ui.min.js +12 -0
  4. data/app/assets/javascripts/jquery.ba-bbq.js +1137 -0
  5. data/app/assets/javascripts/skima-sortable-tables_2_0_10.js +450 -0
  6. data/app/assets/stylesheets/images/animated-overlay.gif +0 -0
  7. data/app/assets/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  8. data/app/assets/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  9. data/app/assets/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  10. data/app/assets/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  11. data/app/assets/stylesheets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  12. data/app/assets/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  13. data/app/assets/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  14. data/app/assets/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  15. data/app/assets/stylesheets/images/ui-icons_222222_256x240.png +0 -0
  16. data/app/assets/stylesheets/images/ui-icons_2e83ff_256x240.png +0 -0
  17. data/app/assets/stylesheets/images/ui-icons_454545_256x240.png +0 -0
  18. data/app/assets/stylesheets/images/ui-icons_888888_256x240.png +0 -0
  19. data/app/assets/stylesheets/images/ui-icons_cd0a0a_256x240.png +0 -0
  20. data/app/assets/stylesheets/jquery-ui.css +1183 -0
  21. data/app/controllers/sortables_controller.rb +75 -0
  22. data/app/models/sortable.rb +82 -0
  23. data/config/routes.rb +5 -0
  24. data/doc/Backtrace.html +493 -0
  25. data/doc/README_rdoc.html +329 -0
  26. data/doc/SortableHelper.html +364 -0
  27. data/doc/SortableSkima.html +343 -0
  28. data/doc/SortableSkima/Engine.html +131 -0
  29. data/doc/created.rid +7 -0
  30. data/doc/images/add.png +0 -0
  31. data/doc/images/brick.png +0 -0
  32. data/doc/images/brick_link.png +0 -0
  33. data/doc/images/bug.png +0 -0
  34. data/doc/images/bullet_black.png +0 -0
  35. data/doc/images/bullet_toggle_minus.png +0 -0
  36. data/doc/images/bullet_toggle_plus.png +0 -0
  37. data/doc/images/date.png +0 -0
  38. data/doc/images/delete.png +0 -0
  39. data/doc/images/find.png +0 -0
  40. data/doc/images/loadingAnimation.gif +0 -0
  41. data/doc/images/macFFBgHack.png +0 -0
  42. data/doc/images/package.png +0 -0
  43. data/doc/images/page_green.png +0 -0
  44. data/doc/images/page_white_text.png +0 -0
  45. data/doc/images/page_white_width.png +0 -0
  46. data/doc/images/plugin.png +0 -0
  47. data/doc/images/ruby.png +0 -0
  48. data/doc/images/tag_blue.png +0 -0
  49. data/doc/images/tag_green.png +0 -0
  50. data/doc/images/transparent.png +0 -0
  51. data/doc/images/wrench.png +0 -0
  52. data/doc/images/wrench_orange.png +0 -0
  53. data/doc/images/zoom.png +0 -0
  54. data/doc/index.html +347 -0
  55. data/doc/js/darkfish.js +155 -0
  56. data/doc/js/jquery.js +18 -0
  57. data/doc/js/navigation.js +142 -0
  58. data/doc/js/search.js +94 -0
  59. data/doc/js/search_index.js +1 -0
  60. data/doc/js/searcher.js +228 -0
  61. data/doc/rdoc.css +543 -0
  62. data/doc/sortable_parser.html +78 -0
  63. data/doc/table_of_contents.html +114 -0
  64. data/lib/sortable_skima.rb +122 -0
  65. data/lib/sortable_skima/active_record.rb +36 -0
  66. data/lib/sortable_skima/backtrace.rb +53 -0
  67. data/lib/sortable_skima/engine.rb +63 -0
  68. data/lib/sortable_skima/helpers/sortable_helper.rb +188 -0
  69. metadata +142 -0
@@ -0,0 +1,188 @@
1
+ module SortableHelper
2
+
3
+ DEFAULT_GROUP = 'default'
4
+ @sortable_groups = {}
5
+
6
+ def sortable_filter_tag(column_name, options_list, opts = {})
7
+ opts = {:raw_sql=>false, :group=>DEFAULT_GROUP}.merge(opts)
8
+
9
+ srtbl = get_sortable opts
10
+
11
+ sel_val = opts.delete(:selected)
12
+ sel_val_id = nil
13
+
14
+ opts[:class] = "#{opts[:class]} sortable-filter"
15
+ filter_id = srtbl.filters.length
16
+ options = []
17
+ new_options_list = []
18
+ options_list.each_with_index do |val,key|
19
+ unless val.is_a?(Array)
20
+ val = [val,val]
21
+ end
22
+ key_val = val[1]
23
+ sel_val_id = options.length if( !sel_val.nil? && sel_val == key_val)
24
+ new_options_list<<[val[0],options.length]
25
+ options<<key_val
26
+ end
27
+ options_list = new_options_list
28
+
29
+ filter = {:id=>filter_id,:column_name=>column_name,:options=>options,:raw_sql=>opts.delete(:raw_sql)}
30
+ srtbl.add_filter filter
31
+
32
+ opts['data-filter-key'] = filter_id
33
+ opts['data-group-id'] = opts.delete(:group);
34
+ name = "filters[#{column_name}]"
35
+
36
+
37
+ option_tags = options_for_select(options_list, sel_val_id) #TODO build default list from column maybe ...IE User.all.map{username, id}
38
+ select_tag(name, option_tags, opts)
39
+ end
40
+
41
+
42
+ ##
43
+ # table options
44
+ # - items_per_page
45
+ # - disable_backtrace
46
+ # - group
47
+ # - external_filters
48
+ #
49
+ # col options
50
+ # - sort_field
51
+ # - display_method
52
+ # - path_method
53
+ # - title
54
+ # - no_display
55
+ # - td_class
56
+ # - link_item
57
+ # - disabled
58
+ ##
59
+ def sortable_table_tag base_query, columns=[], opts={}
60
+
61
+ default_opts = {
62
+ :default_order=>nil,
63
+ :class =>'sortable-list',
64
+ :items_per_page=>10,
65
+ :disable_backtrace=>false,
66
+ :paginate=>true,
67
+ :group=>DEFAULT_GROUP,
68
+ :external_filters=>nil #query conditions that should not affect the table id
69
+ }
70
+ opts ||= {}
71
+ default_opts[:class] = "#{opts[:class]} #{default_opts[:class]}" #any parameter added classes plus 'sortableList'
72
+ opts = default_opts.merge opts
73
+
74
+ do_paginate = opts.delete(:paginate) #opts[:items_per_page]
75
+ disable_backtrace = opts.delete(:disable_backtrace)
76
+
77
+ srtbl = get_sortable opts
78
+ srtbl.base_query = base_query
79
+ srtbl.external_filters = opts.delete(:external_filters)
80
+ srtbl.add_option :default_order, opts.delete(:default_order)
81
+ srtbl.add_option :per_page, opts[:items_per_page] if opts[:items_per_page]
82
+ srtbl.add_option :disable_backtrace, disable_backtrace
83
+ srtbl.add_option :paginate, do_paginate
84
+
85
+ out = ''
86
+ thead = process_columns columns, srtbl
87
+ tbody = content_tag('tbody','')
88
+ out = ( thead + tbody).html_safe
89
+
90
+ srtbl.save
91
+
92
+ opts['data-sortable-query'] = srtbl.id
93
+
94
+ opts['data-per-page'] = opts.delete(:items_per_page)
95
+ opts['data-table-token'] = srtbl.token
96
+ opts['data-group-id'] = opts.delete(:group)
97
+ opts['data-initialize-on-client'] = disable_backtrace
98
+
99
+ out = content_tag 'table', out, opts
100
+ if do_paginate
101
+ out += content_tag 'div','',:class=>'paginate-container','data-group-id'=>opts['data-group-id']
102
+ end
103
+ out
104
+ end
105
+
106
+ private
107
+ def get_sortable opts
108
+ @sortable_groups ||= {}
109
+ srtbl = @sortable_groups[opts[:group]]
110
+ unless srtbl
111
+ srtbl = Sortable.new
112
+ srtbl.token = "#{controller_name}_#{action_name}"
113
+ @sortable_groups[opts[:group]] = srtbl
114
+ end
115
+ srtbl
116
+ end
117
+
118
+ def process_columns columns, srtbl
119
+ num_head_rows, num_sub_cols = get_subcols_depth(columns)
120
+
121
+ save_columns columns, srtbl
122
+ thead = build_headers columns, num_head_rows
123
+
124
+ content_tag('thead',thead.html_safe)
125
+ end
126
+
127
+ def save_columns columns, srtbl
128
+ new_sub_cols = []
129
+ columns.each do |col|
130
+ sort_field = col.delete(:sort_field)
131
+ display_method = col.delete(:display_method) || sort_field
132
+ col_title = (col.delete(:title) || sort_field).html_safe
133
+ path_method = col.delete(:path_method)
134
+ col['col-title']=col_title
135
+ if col[:sub_columns].blank?
136
+ col['sort-field'] = srtbl.add_column(sort_field,display_method, path_method)
137
+ unless col[:no_display] #column is not shown on front table but is still passed to js
138
+ col['data-class']=col.delete(:td_class)
139
+ col['data-link-item']=col.delete(:link_item)
140
+ end
141
+ else
142
+ new_sub_cols += col[:sub_columns]
143
+ end
144
+ end
145
+ save_columns(new_sub_cols, srtbl) unless new_sub_cols.empty?
146
+ end
147
+
148
+ def build_headers columns, num_subcols
149
+ thead = ''
150
+ sub_cols = []
151
+ columns.each do |col|
152
+ col_depth = col.delete(:depth)
153
+ if col[:sub_columns].blank?
154
+ unless col[:no_display] #column is not shown on front table but is still passed to js
155
+ col['rowspan'] = num_subcols if num_subcols > 1
156
+ thead += content_tag( 'th', col['col-title'], col).html_safe
157
+ end
158
+ else
159
+ new_sub_cols = col.delete :sub_columns
160
+ master_col_opts = {'rowspan'=> num_subcols - col_depth + 1 }.merge(col)
161
+ thead += content_tag( 'th', col['col-title'], master_col_opts).html_safe
162
+ sub_cols += new_sub_cols
163
+ end
164
+
165
+ end
166
+ sub_head = ''
167
+ sub_head = build_headers(sub_cols, num_subcols - 1) unless sub_cols.blank?
168
+ content_tag('tr',thead.html_safe) + sub_head
169
+ end
170
+
171
+ def get_subcols_depth columns, depth = 0
172
+ depth += 1
173
+ num_cols = 0
174
+ columns.each do |col|
175
+ unless col[:sub_columns].blank?
176
+ col_depth, num_sub_cols = get_subcols_depth(col[:sub_columns],depth)
177
+ col[:depth] = col_depth
178
+ col[:colspan] = num_sub_cols
179
+ num_cols += num_sub_cols
180
+ depth = [depth, col_depth].max
181
+ else
182
+ num_cols += 1
183
+ end
184
+
185
+ end
186
+ return depth, num_cols
187
+ end
188
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sortable_skima
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.25
5
+ platform: ruby
6
+ authors:
7
+ - xbits
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2015-07-20 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - &id002
20
+ - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ version_requirements: *id001
25
+ description: Adds sorting, filters and pagination to html tables. TESTING
26
+ email:
27
+ - joao.costaxl@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.md
34
+ files:
35
+ - README.md
36
+ - lib/sortable_skima.rb
37
+ - lib/sortable_skima/engine.rb
38
+ - lib/sortable_skima/active_record.rb
39
+ - lib/sortable_skima/backtrace.rb
40
+ - lib/sortable_skima/helpers/sortable_helper.rb
41
+ - config/routes.rb
42
+ - app/models/sortable.rb
43
+ - app/controllers/sortables_controller.rb
44
+ - app/assets/javascripts/skima-sortable-tables_2_0_10.js
45
+ - app/assets/javascripts/jquery.ba-bbq.js
46
+ - app/assets/javascripts/jquery-ui.min.js
47
+ - app/assets/stylesheets/jquery-ui.css
48
+ - app/assets/stylesheets/images/animated-overlay.gif
49
+ - app/assets/stylesheets/images/ui-icons_454545_256x240.png
50
+ - app/assets/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png
51
+ - app/assets/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png
52
+ - app/assets/stylesheets/images/ui-icons_2e83ff_256x240.png
53
+ - app/assets/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png
54
+ - app/assets/stylesheets/images/ui-icons_cd0a0a_256x240.png
55
+ - app/assets/stylesheets/images/ui-bg_glass_75_dadada_1x400.png
56
+ - app/assets/stylesheets/images/ui-icons_888888_256x240.png
57
+ - app/assets/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png
58
+ - app/assets/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png
59
+ - app/assets/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png
60
+ - app/assets/stylesheets/images/ui-icons_222222_256x240.png
61
+ - app/assets/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png
62
+ - doc/created.rid
63
+ - doc/images/delete.png
64
+ - doc/images/page_green.png
65
+ - doc/images/wrench.png
66
+ - doc/images/ruby.png
67
+ - doc/images/add.png
68
+ - doc/images/brick.png
69
+ - doc/images/zoom.png
70
+ - doc/images/tag_blue.png
71
+ - doc/images/bullet_black.png
72
+ - doc/images/bullet_toggle_minus.png
73
+ - doc/images/page_white_width.png
74
+ - doc/images/wrench_orange.png
75
+ - doc/images/loadingAnimation.gif
76
+ - doc/images/bug.png
77
+ - doc/images/brick_link.png
78
+ - doc/images/package.png
79
+ - doc/images/bullet_toggle_plus.png
80
+ - doc/images/date.png
81
+ - doc/images/page_white_text.png
82
+ - doc/images/transparent.png
83
+ - doc/images/tag_green.png
84
+ - doc/images/find.png
85
+ - doc/images/macFFBgHack.png
86
+ - doc/images/plugin.png
87
+ - doc/README_rdoc.html
88
+ - doc/SortableSkima/Engine.html
89
+ - doc/rdoc.css
90
+ - doc/table_of_contents.html
91
+ - doc/js/darkfish.js
92
+ - doc/js/jquery.js
93
+ - doc/js/search.js
94
+ - doc/js/navigation.js
95
+ - doc/js/search_index.js
96
+ - doc/js/searcher.js
97
+ - doc/Backtrace.html
98
+ - doc/index.html
99
+ - doc/SortableHelper.html
100
+ - doc/sortable_parser.html
101
+ - doc/SortableSkima.html
102
+ homepage: https://github.com/xbits/sortable_skima
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+
107
+ post_install_message: |-
108
+ sortable: Skima.net is da bomb!!
109
+ ---->REMEMBER TO CREATE BOTH MIGRATIONS Sortable AND Backtrace <---
110
+ Ex: =========================================
111
+ create_table :sortables do |t|
112
+ t.text :query
113
+ t.timestamps
114
+ end
115
+ create_table :backtraces do |t|
116
+ t.integer :user_id
117
+ t.string :action
118
+ t.string :value
119
+ t.timestamps
120
+ end
121
+ =============================================
122
+ rdoc_options:
123
+ - --main
124
+ - README.md
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - *id002
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - *id002
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.14
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Skima.net sortable tables
140
+ test_files: []
141
+
142
+ has_rdoc: true