table_on_steroids 0.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 356f5f980f72a02b88bad18ca14819a425a03975be5c200068ea33908168deb9
4
+ data.tar.gz: 2a9ac22acbc7e06ea923226fdc0aaf8d25d646fc8b98c27b9fa00c55e07e355e
5
+ SHA512:
6
+ metadata.gz: 20a91d6db82c0ccc7231e02108d9ac4ad78cbe95bf8edabc03dfb34e2798fcb3d6c6a37ceba2ac9ea5d97ae0b6b145905d4203e22910c23be005899ddd22c918
7
+ data.tar.gz: bf625d2263fb6bcd785992d3b9a007774a1f71d5e991ff186ac4974d40c28a58084c0b40df1ea623088e764d44118042eaae9fc9e7b32928002d8b7b66177dcf
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at marieke@obvious.ly. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in table_on_steroids.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,160 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ table_on_steroids (0.1.0.1)
5
+ bootstrap-datepicker-rails (~> 1)
6
+ bootstrap-multiselect-rails (~> 0.9)
7
+ kaminari (~> 1.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (5.2.2)
13
+ actionpack (= 5.2.2)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailer (5.2.2)
17
+ actionpack (= 5.2.2)
18
+ actionview (= 5.2.2)
19
+ activejob (= 5.2.2)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ rails-dom-testing (~> 2.0)
22
+ actionpack (5.2.2)
23
+ actionview (= 5.2.2)
24
+ activesupport (= 5.2.2)
25
+ rack (~> 2.0)
26
+ rack-test (>= 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (5.2.2)
30
+ activesupport (= 5.2.2)
31
+ builder (~> 3.1)
32
+ erubi (~> 1.4)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
+ activejob (5.2.2)
36
+ activesupport (= 5.2.2)
37
+ globalid (>= 0.3.6)
38
+ activemodel (5.2.2)
39
+ activesupport (= 5.2.2)
40
+ activerecord (5.2.2)
41
+ activemodel (= 5.2.2)
42
+ activesupport (= 5.2.2)
43
+ arel (>= 9.0)
44
+ activestorage (5.2.2)
45
+ actionpack (= 5.2.2)
46
+ activerecord (= 5.2.2)
47
+ marcel (~> 0.3.1)
48
+ activesupport (5.2.2)
49
+ concurrent-ruby (~> 1.0, >= 1.0.2)
50
+ i18n (>= 0.7, < 2)
51
+ minitest (~> 5.1)
52
+ tzinfo (~> 1.1)
53
+ arel (9.0.0)
54
+ bootstrap-datepicker-rails (1.8.0.1)
55
+ railties (>= 3.0)
56
+ bootstrap-multiselect-rails (0.9.9)
57
+ rails (>= 4.0.0)
58
+ builder (3.2.3)
59
+ concurrent-ruby (1.1.4)
60
+ crass (1.0.4)
61
+ diff-lcs (1.3)
62
+ erubi (1.8.0)
63
+ globalid (0.4.2)
64
+ activesupport (>= 4.2.0)
65
+ i18n (1.5.3)
66
+ concurrent-ruby (~> 1.0)
67
+ kaminari (1.1.1)
68
+ activesupport (>= 4.1.0)
69
+ kaminari-actionview (= 1.1.1)
70
+ kaminari-activerecord (= 1.1.1)
71
+ kaminari-core (= 1.1.1)
72
+ kaminari-actionview (1.1.1)
73
+ actionview
74
+ kaminari-core (= 1.1.1)
75
+ kaminari-activerecord (1.1.1)
76
+ activerecord
77
+ kaminari-core (= 1.1.1)
78
+ kaminari-core (1.1.1)
79
+ loofah (2.2.3)
80
+ crass (~> 1.0.2)
81
+ nokogiri (>= 1.5.9)
82
+ mail (2.7.1)
83
+ mini_mime (>= 0.1.1)
84
+ marcel (0.3.3)
85
+ mimemagic (~> 0.3.2)
86
+ method_source (0.9.2)
87
+ mimemagic (0.3.3)
88
+ mini_mime (1.0.1)
89
+ mini_portile2 (2.4.0)
90
+ minitest (5.11.3)
91
+ nio4r (2.3.1)
92
+ nokogiri (1.10.1)
93
+ mini_portile2 (~> 2.4.0)
94
+ rack (2.0.6)
95
+ rack-test (1.1.0)
96
+ rack (>= 1.0, < 3)
97
+ rails (5.2.2)
98
+ actioncable (= 5.2.2)
99
+ actionmailer (= 5.2.2)
100
+ actionpack (= 5.2.2)
101
+ actionview (= 5.2.2)
102
+ activejob (= 5.2.2)
103
+ activemodel (= 5.2.2)
104
+ activerecord (= 5.2.2)
105
+ activestorage (= 5.2.2)
106
+ activesupport (= 5.2.2)
107
+ bundler (>= 1.3.0)
108
+ railties (= 5.2.2)
109
+ sprockets-rails (>= 2.0.0)
110
+ rails-dom-testing (2.0.3)
111
+ activesupport (>= 4.2.0)
112
+ nokogiri (>= 1.6)
113
+ rails-html-sanitizer (1.0.4)
114
+ loofah (~> 2.2, >= 2.2.2)
115
+ railties (5.2.2)
116
+ actionpack (= 5.2.2)
117
+ activesupport (= 5.2.2)
118
+ method_source
119
+ rake (>= 0.8.7)
120
+ thor (>= 0.19.0, < 2.0)
121
+ rake (10.5.0)
122
+ rspec (3.8.0)
123
+ rspec-core (~> 3.8.0)
124
+ rspec-expectations (~> 3.8.0)
125
+ rspec-mocks (~> 3.8.0)
126
+ rspec-core (3.8.0)
127
+ rspec-support (~> 3.8.0)
128
+ rspec-expectations (3.8.2)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.8.0)
131
+ rspec-mocks (3.8.0)
132
+ diff-lcs (>= 1.2.0, < 2.0)
133
+ rspec-support (~> 3.8.0)
134
+ rspec-support (3.8.0)
135
+ sprockets (3.7.2)
136
+ concurrent-ruby (~> 1.0)
137
+ rack (> 1, < 3)
138
+ sprockets-rails (3.2.1)
139
+ actionpack (>= 4.0)
140
+ activesupport (>= 4.0)
141
+ sprockets (>= 3.0.0)
142
+ thor (0.20.3)
143
+ thread_safe (0.3.6)
144
+ tzinfo (1.2.5)
145
+ thread_safe (~> 0.1)
146
+ websocket-driver (0.7.0)
147
+ websocket-extensions (>= 0.1.0)
148
+ websocket-extensions (0.1.3)
149
+
150
+ PLATFORMS
151
+ ruby
152
+
153
+ DEPENDENCIES
154
+ bundler (~> 1.16)
155
+ rake (~> 10.0)
156
+ rspec (~> 3.0)
157
+ table_on_steroids!
158
+
159
+ BUNDLED WITH
160
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Marieke Gueye
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # TableOnSteroids
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/table_on_steroids`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'table_on_steroids'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install table_on_steroids
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/table_on_steroids. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the TableOnSteroids project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/table_on_steroids/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,159 @@
1
+ #####
2
+ # The knowledge sharing concern permits creates a fast way to display,
3
+ # filter and order data of a specific object.
4
+ # To make it work:
5
+ # In the Object controller, include TableOnSteroid and add this private methods:
6
+
7
+ # - columns_on_steroid: a Hash defining the columns and filters:
8
+ # {
9
+ # 'key_defining_column_1' => {
10
+ # label: 'Label 1', >> the column label
11
+ # type: 'filter', >> can be 'filter', 'order' or nothing if no operations
12
+ # multiselect: true, >> OPTIONAL in case of a filter
13
+ # select_values: ['Option 1','Option 2'], >> in case of a filter, the options to select
14
+ # filter_lambda: -> (objects, value) { .. } >> A lambda defining the filter if applicable
15
+ # order_lambda: -> (objects) { .. }, >> A lambda defining the order if applicable
16
+ # value_lambda: -> (object) { .. } >> A lambda defining the value in the table
17
+ # },
18
+ # 'key_defining_column_2' => {
19
+ # ...
20
+ # },
21
+ # ...
22
+ # } >> See example in offers2_controller
23
+ #
24
+ # Add a deep_search function in your object
25
+ # Don't forget to add your route
26
+ # Create your view and add `= render partial: 'shared/table_on_steroid', locals: { objects: @offers }` to display the table
27
+ #
28
+ #####
29
+ require 'kaminari'
30
+
31
+ module TableOnSteroids
32
+ module TableConcern
33
+ extend ActiveSupport::Concern
34
+
35
+ included do
36
+ OBJECTS_PER_PAGE = 50
37
+ end
38
+
39
+ def filter_and_order(objects, columns_on_steroid, global_search=nil, include_counts=false )
40
+ # execute the global search if you have one
41
+ objects = global_search.call(objects,params[:search]) if global_search && params[:search].present?
42
+
43
+ [:activerecord, :array].each do |t|
44
+
45
+ #column search
46
+ objects = objects_where(objects, columns_on_steroid, t)
47
+
48
+ #apply filters
49
+ if params[:filters].present?
50
+ params[:filters].each_pair do | k, v |
51
+ filter = columns_on_steroid[k]
52
+ next unless filter.present? && filter[t].present?
53
+ objects = filter[t][:filter_lambda].call(objects, v)
54
+ end
55
+ end
56
+
57
+ #order
58
+ if params[:knowledge] && params[:knowledge] && params[:knowledge][:order].present? && (object_order = columns_on_steroid[params[:knowledge][:order]]).present?
59
+ if(object_order[t] && object_order[t][:order_lambda])
60
+ objects = objects.reorder(nil) if(objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation))
61
+ objects = object_order[t][:order_lambda].call(objects)
62
+ end
63
+ elsif(object_order = columns_on_steroid.select{ |c,v| v[:default_order]}.collect{ |c,v| v[:order_lambda] }).present?
64
+ objects = object_order.call(objects)
65
+ elsif(objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation))
66
+ #objects = objects.order('created_at desc')
67
+ end
68
+
69
+ end
70
+
71
+ #pagination
72
+
73
+ if(objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation))
74
+ objects = objects.page(params[:page]).per(OBJECTS_PER_PAGE)
75
+ total_pages = objects.total_pages
76
+ total_count = objects.total_count
77
+ else
78
+ total_count = objects.count
79
+ total_pages = total_count / OBJECTS_PER_PAGE.to_f
80
+ current_offset = OBJECTS_PER_PAGE * ((params[:page] || 1) - 1)
81
+ objects = objects[current_offset..(current_offset + OBJECTS_PER_PAGE)]
82
+ end
83
+ include_counts ? [objects, total_pages, total_count] : objects
84
+ end
85
+
86
+
87
+ def objects_where(objects, columns_on_steroid, t)
88
+ columns_on_steroid.select{
89
+ |c,v| v[t] && v[t][:search_lambda].present? }.each{
90
+ |c,v|
91
+ if(params["search_operator_" + c]) # (v[:datatype].present? && ['date','integer'].include?(v[:datatype]))
92
+ objects = v[t][:search_lambda].call(objects, params["search_" + c], params["search_operator_" + c]) if(params["search_" + c] && !params["search_" + c].blank?)
93
+ else
94
+ objects = v[t][:search_lambda].call(objects, params["search_" + c]) if(params["search_" + c] && !params["search_" + c].blank?)
95
+ end
96
+ }
97
+ objects
98
+ end
99
+
100
+ def objects_where_date(objects, column, value, operator)
101
+ case operator
102
+ when "<",">=" then
103
+ return objects.where((column + ' ' + operator + ' ?'), (value + " 00:00:00") )
104
+ when ">","<=" then
105
+ return objects.where((column + ' ' + operator + ' ?'), (value + " 23:59:59") )
106
+ when "=" then
107
+ return objects.where((column + ' between ? and ?'), (value + " 00:00:00"), (value + " 23:59:59") )
108
+ end
109
+ end
110
+
111
+ def objects_where_ruby_date(object, column, value, operator)
112
+ value = Date.strptime(value, '%m/%d/%Y').midnight
113
+ case operator
114
+ when "<" then
115
+ return object.send(column) < value
116
+ when ">" then
117
+ return object.send(column) > value + 1.days - 1.seconds
118
+ when "=" then
119
+ return ((object.send(column) > value) && (object.send(column) < (value + 1.days - 1.seconds)))
120
+ end
121
+ end
122
+
123
+ def object_where_integer(integer, operator, value)
124
+ case operator
125
+ when "<",">=" then
126
+ return integer.to_f < value.to_f
127
+ when "=" then
128
+ return integer.to_f == value.to_f
129
+ when ">" then
130
+ return integer.to_f > value.to_f
131
+ end
132
+ end
133
+
134
+ #save for later
135
+ def objects_where_or(objects, columns_on_steroid)
136
+ where_sql = ""
137
+ values = []
138
+
139
+ #search all columns
140
+ if(!query.blank?)
141
+ where_sql += columns_on_steroid.select{
142
+ |c,v| v[:or_where_sql].present? }.map{
143
+ |c,v| v[:or_where_sql].map{
144
+ |w| w[:where] }.join(" or ") }.join(" or ")
145
+
146
+ columns_on_steroid.select{
147
+ |c,v| v[:or_where_sql].present? }.map{
148
+ |c,v| v[:or_where_sql].each{
149
+ |w| values << ((w[:value]) ? w[:value] : ("%" + query + "%")) }}
150
+
151
+ where_sql = ("(" + where_sql + ")") if !where_sql.blank?
152
+
153
+ objects = objects.where(where_sql, *values)
154
+ end
155
+
156
+ objects
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,17 @@
1
+ <%= paginator.render do %>
2
+ <nav>
3
+ <ul class="pagination">
4
+ <%= first_page_tag unless current_page.first? %>
5
+ <%= prev_page_tag unless current_page.first? %>
6
+ <% each_page do |page| %>
7
+ <% if page.left_outer? || page.right_outer? || page.inside_window? %>
8
+ <%= page_tag page %>
9
+ <% elsif !page.was_truncated? -%>
10
+ <%= gap_tag %>
11
+ <% end %>
12
+ <% end %>
13
+ <%= next_page_tag unless current_page.last? %>
14
+ <%= last_page_tag unless current_page.last? %>
15
+ </ul>
16
+ </nav>
17
+ <% end %>
@@ -0,0 +1,102 @@
1
+ <% max_column ||= 8 %>
2
+ <% columns ||= @columns_on_steroid %>
3
+ <% omit_columns ||= [] %>
4
+ <% omit_columns.each{ |o| columns.delete(o) } %>
5
+ <% search_lambda ||= @global_search_lambda %>
6
+ <% download_csv ||= nil %>
7
+ <% table_on_steroid_id ||= "table_on_steroids" %>
8
+ <% column_param = params['columns' + table_on_steroid_id] || [] %>
9
+ <% selected_columns = ((column_param.count > 1) ? column_param : columns.keys.first(max_column)) %>
10
+ <% title ||= nil %>
11
+ <% subtext ||= nil %>
12
+ <% subtext_partial ||= nil %>
13
+ <% param_hash = CGI::parse(request.query_string) %>
14
+ <% expected_column_keys = columns.map{|col,col_values| col }+columns.map{|col,col_values|("search_" + col)}+columns.map{|col,col_values|("search_operator_" + col)} %>
15
+ <div class="table-on-steroids" id="<%= table_on_steroid_id %>">
16
+ <%= form_tag request.path, method: "get", id: ("knowledge_base_filters" + table_on_steroid_id) do %>
17
+ <% param_hash.select{ |k,v| !expected_column_keys.include?(k) && !["utf8","columns[]"].include?(k) }.each do |k,v| %>
18
+ <%= hidden_field_tag k, v[0] %>
19
+ <% end %>
20
+ <div class="row">
21
+ <div class="col-8 col-sn-12">
22
+ <div class="header-text-h1">
23
+ <% if title %>
24
+ <%= title %>
25
+ <% end %>
26
+ </div>
27
+ </div>
28
+ <div class="col-8 col-sn-12" style="text-align:right">
29
+ <% if(search_lambda) %>
30
+ <%= text_field_tag 'search', params[:search], placeholder: 'Search ..', onchange: "$('#knowledge_base_filters#{table_on_steroid_id}').submit();", class: 'form-control global-search' %>
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+ <% if(subtext_partial) %>
35
+ <div class="row">
36
+ <div class="col-12">
37
+ <div>
38
+ <%= render partial: subtext_partial, locals: local_assigns %>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ <% end %>
43
+ <div class="remove_search">
44
+ <% if(!columns.collect{ |c,v| params["search_" + c]}.reject!(&:blank?).empty?) %>
45
+ <%= link_to request.path, style: "text-decoration:none;padding-right:5px;" do %>
46
+ <i class="fa fa-window-close fa-lg"></i>
47
+ <% end %>
48
+ <%= t('shared.table_on_steroid.remove_search') %>
49
+ <% end %>
50
+ </div>
51
+ <div class="column_filter">
52
+ <%= select_tag("columns#{table_on_steroid_id}", options_for_select(columns.map{|c| [c[1][:label], c[0]]}, selected_columns), multiple: true, class: "column-selector table-on-steroids-selectpicker #{table_on_steroid_id}", data: {"none-selected-text" => "Display columns (max #{max_column})", "max-options" => max_column } ) %>
53
+ </div>
54
+ <% if(download_csv) %>
55
+ <div class="float-right">
56
+ <a href="<%= (download_csv + "?filter=#{request.query_string.to_s}") %>" style="float:right">
57
+ <%= image_tag "csv.png", :height => "25", :style => "padding-top:5px;" %>
58
+ </a>
59
+ </div>
60
+ <% end %>
61
+ <% if(objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation)) %>
62
+ <%= paginate objects, theme: 'twitter-bootstrap-4' %>
63
+ <% end %>
64
+ <table class="table table-striped table-bordered table-hover">
65
+ <thead>
66
+ <tr>
67
+ <% columns.each_pair do | k , v | %>
68
+ <th class="column column-<%= k %> <%= ' d-none ' unless selected_columns.include?(k) %> <%= v[:css_class].join(' ') if(v[:css_class]) %> <%= table_on_steroid_id %>">
69
+ <% if v[:type] == 'order' %>
70
+ <label>
71
+ <%= v[:label] %>
72
+ <%= radio_button('knowledge', 'order', k, onchange: "$('#knowledge_base_filters#{table_on_steroid_id}').submit();", checked: params[:knowledge] && params[:knowledge][:order] == k ) %>
73
+ v
74
+ </label>
75
+ <% else %>
76
+ <%= v[:label] %>
77
+ <% end %>
78
+ </th>
79
+ <% end %>
80
+ </tr>
81
+ <%= render partial: "table_on_steroids/table_on_steroids_filters", locals: {columns_on_steroid: columns, selected_columns: selected_columns, table_on_steroid_id: table_on_steroid_id} %>
82
+ </thead>
83
+ <tbody>
84
+ <% objects.each do |o| %>
85
+ <tr>
86
+ <% columns.each_pair do | k , v | %>
87
+ <% val = v[:value_lambda].call(o, self) %>
88
+ <td class="column column-<%= k %> <%= 'd-none' unless selected_columns.include?(k) %> <%= v[:css_class].join(' ') if(v[:css_class]) %> <%= table_on_steroid_id %>">
89
+ <%= val.is_a?(String) ? val.html_safe : val %>
90
+ </td>
91
+ <% end %>
92
+ </tr>
93
+ <% end %>
94
+ </tbody>
95
+ </table>
96
+ <div style="padding-top:20px">
97
+ <% if(objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation)) %>
98
+ <%= paginate objects, theme: 'twitter-bootstrap-4' %>
99
+ <% end %>
100
+ </div>
101
+ <% end %>
102
+ </div>
@@ -0,0 +1,21 @@
1
+ <% table_on_steroid_id ||= nil %>
2
+ <tr>
3
+ <% columns_on_steroid.each_pair do | k , v | %>
4
+ <td class="column column-<%= k %> <%= 'd-none' unless selected_columns.include?(k) %> filter-cell-left <%= v[:css_class].join(' ') if(v[:css_class]) %> <%= table_on_steroid_id %>">
5
+ <% if v[:type] == 'filter' %>
6
+ <%= select_tag("filters[#{k}]", options_for_select(v[:select_values], params[:filters] && params[:filters][k]), multiple: v[:multiselect], class: 'selectpicker form-control filter-control', data: { "none-selected-text" => v[:label], style: 'table-on-steroids-selectpicker ', table_on_steroid_id: table_on_steroid_id}, table_on_steroid_id: table_on_steroid_id ) %>
7
+ <% elsif((v[:activerecord].present? && v[:activerecord][:search_lambda].present?) || (v[:array].present? && v[:array][:search_lambda].present?)) %>
8
+ <% operator_present = (v[:datatype].present? && ['date','integer'].include?(v[:datatype])) %>
9
+ <% if operator_present %>
10
+ <% operator_options = ((['date'].include?(v[:datatype])) ? [["On","="],["Before","<"],["After",">"]] : ["=",">","<"]) %>
11
+ <%= select_tag 'search_operator_' + k, options_for_select(operator_options, params['search_operator_' + k]), class: 'form-control filter-control table-on-steroid-form-operator', table_on_steroid_id: table_on_steroid_id, operator_value_field: 'search_' + k %>
12
+ <% end %>
13
+ <% if(v[:datatype] == 'integer') %>
14
+ <%= number_field_tag 'search_' + k, params["search_" + k], placeholder: 'Search..', class: ('form-control filter-control filter-with-operator'), table_on_steroid_id: table_on_steroid_id %>
15
+ <% else %>
16
+ <%= text_field_tag 'search_' + k, params["search_" + k], placeholder: 'Search..', class: ('form-control filter-control' + (' date_search' if v[:datatype] == 'date').to_s + ((operator_present) ? " filter-with-operator" : " filter-without-operator")), table_on_steroid_id: table_on_steroid_id %>
17
+ <% end %>
18
+ <% end %>
19
+ </td>
20
+ <% end %>
21
+ </tr>
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "table_on_steroids"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "table_on_steroids/version"
2
+ require 'bootstrap-datepicker-rails'
3
+ require 'bootstrap-multiselect-rails'
4
+
5
+ module TableOnSteroids
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module TableOnSteroids
2
+ VERSION = "0.1.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "table_on_steroids/version"
5
+
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "table_on_steroids"
9
+ spec.version = TableOnSteroids::VERSION
10
+ spec.authors = ["Marieke Gueye", "Matt Hyatt"]
11
+ spec.email = ["marieke@obvious.ly"]
12
+
13
+ spec.summary = %q{Create awesome tables for rails}
14
+ spec.description = %q{Create tables that are sortable, filterable and much more}
15
+ spec.homepage = "http://www.github.com/mariekou"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ #if spec.respond_to?(:metadata)
21
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
22
+ #else
23
+ # raise "RubyGems 2.0 or newer is required to protect against " \
24
+ # "public gem pushes."
25
+ #end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+ spec.add_runtime_dependency 'bootstrap-datepicker-rails', '~> 1'
36
+ spec.add_runtime_dependency 'bootstrap-multiselect-rails', '~> 0.9'
37
+ spec.add_runtime_dependency 'kaminari', '~> 1.1'
38
+ spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
@@ -0,0 +1,75 @@
1
+ //= require bootstrap-multiselect
2
+ //= require bootstrap-datepicker
3
+
4
+
5
+ var TableOnSteroids = {
6
+ new: function(element) {
7
+ this.$element = $(element);
8
+ if (!this.$element[0]) return;
9
+ this.initColumnSelection();
10
+ this.initDatePicker();
11
+ this.observe();
12
+ $('.filter-cell-left select[multiple]').multiselect({inheritClass: true});
13
+ },
14
+ initColumnSelection: function(){
15
+ var _this = this;
16
+ $('.column_filter select[multiple]').multiselect({
17
+ inheritClass: true,
18
+ buttonWidth: '400px',
19
+ maxHeight: 250,
20
+ onChange: function(option, checked, select) {
21
+ var tableOnSteroidId = $(option).closest(".table-on-steroids").attr("id");
22
+ _this.$element.find('.column.' + tableOnSteroidId).addClass('d-none');
23
+ option.parent().val().forEach(function(element) {
24
+ _this.$element.find('.column-'+element).removeClass('d-none')+' .'+tableOnSteroidId
25
+ });
26
+ },
27
+ buttonText: function(options, select) {
28
+ if (options.length > 4) {
29
+ return options.length + ' columns displayed';
30
+ }
31
+ else {
32
+ var labels = [];
33
+ options.each(function() {
34
+ if ($(this).attr('label') !== undefined) {
35
+ labels.push($(this).attr('label'));
36
+ }
37
+ else {
38
+ labels.push($(this).html());
39
+ }
40
+ });
41
+ return labels.join(', ') + '';
42
+ }
43
+ }
44
+ });
45
+ },
46
+ observe: function(){
47
+ var _this = this;
48
+ this.$element.on('change', '.filter-control', function(e) { _this.filterControl(e)});
49
+ },
50
+ initDatePicker: function(){
51
+ this.$element.find('.date_search').datepicker({ });
52
+ },
53
+ filterControl: function(e){
54
+ if($(e.currentTarget).hasClass("table-on-steroid-form-operator"));
55
+ {
56
+ var operator_value_field = $(e.currentTarget).attr("operator_value_field");
57
+ if(operator_value_field != "undefined" && $("#" + operator_value_field).val() == "")
58
+ return;
59
+ }
60
+ if($(e.currentTarget).attr("data-table-on-steroid-id") || $(e.currentTarget).attr("table_on_steroid_id"))
61
+ {
62
+ var table_on_steroid_id = $(e.currentTarget).attr("data-table-on-steroid-id") || $(e.currentTarget).attr("table_on_steroid_id");
63
+ $('#page').val('');
64
+ $('#knowledge_base_filters' + table_on_steroid_id).submit();
65
+ }
66
+ }
67
+ }
68
+
69
+ $(document).ready(function() {
70
+ TableOnSteroids.new('.table-on-steroids');
71
+ });
72
+
73
+ $(document).on('turbolinks:load', function() {
74
+ TableOnSteroids.new('.table-on-steroids');
75
+ });
@@ -0,0 +1,119 @@
1
+ //= require bootstrap-multiselect
2
+
3
+
4
+ .table-on-steroids{
5
+ thead{
6
+ tr{
7
+ td:first-child {
8
+ border-left: 1px solid #cad6e0;
9
+ }
10
+ td {
11
+ border-right: 1px solid #cad6e0;
12
+ }
13
+ }
14
+ th{
15
+ padding: 5px;
16
+ label{
17
+ cursor: pointer;
18
+ }
19
+ input[type=radio]{
20
+ display: none
21
+ }
22
+ label:hover input[type=radio] ~ .checkmark {
23
+ background-color: #ccc;
24
+ color: green;
25
+ }
26
+
27
+ label input:checked ~ .checkmark {
28
+ background: white;
29
+ color: green;
30
+ }
31
+ .checkmark {
32
+ font-size: medium;
33
+ font-weight: bold;
34
+ padding: 2px 4px;
35
+ border-radius: 37%;
36
+ }
37
+ .bootstrap-select > .dropdown-toggle.bs-placeholder.btn-primary{
38
+ color: white;
39
+ text-transform: uppercase;
40
+ font-size: 100%;
41
+ font-weight: bold;
42
+ text-overflow: ellipsis;
43
+ }
44
+ .dropdown-menu li a{
45
+ color: green;
46
+ }
47
+ .bootstrap-select:not([class*="col-"]):not([class*="form-control"]):not(.input-group-btn){
48
+ width: 180px;
49
+ }
50
+ }
51
+ td{
52
+ padding: 5px;
53
+ }
54
+ }
55
+ tbody{
56
+ td{
57
+ overflow: hidden;
58
+ padding: 5px;
59
+ }
60
+ }
61
+
62
+ .table-on-steroid-cell {
63
+ max-width: 210px;
64
+ }
65
+
66
+ .table-on-steroid-cell-min-220 {
67
+ min-width: 220px;
68
+ }
69
+
70
+ .table-on-steroid-form-operator {
71
+ width:30%;
72
+ display:inline-block;
73
+ padding-left: 0px;
74
+ }
75
+
76
+ .filter-with-operator {
77
+ width:63%;
78
+ display:inline-block;
79
+ }
80
+
81
+ .filter-without-operator {
82
+ width:100%;
83
+ display:inline-block;
84
+ }
85
+
86
+ .remove_search {
87
+ float:left;
88
+ padding-top:15px;
89
+ height:50px;
90
+ }
91
+
92
+ .column_filter {
93
+ float:right;
94
+ ul{
95
+ width: 100%;
96
+ li{
97
+ padding: 5px;
98
+ }
99
+ }
100
+ }
101
+
102
+ .global-search {
103
+ width:40%;
104
+ display:inline-block;
105
+ }
106
+
107
+ .header-padding {
108
+ padding-bottom:20px;
109
+ }
110
+
111
+ .header-text-h1 {
112
+ font-weight: bold;
113
+ font-size: 30px;
114
+ color: #585858;
115
+
116
+ }
117
+
118
+
119
+ }
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: table_on_steroids
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marieke Gueye
8
+ - Matt Hyatt
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2019-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bootstrap-datepicker-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bootstrap-multiselect-rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.9'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.9'
42
+ - !ruby/object:Gem::Dependency
43
+ name: kaminari
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.16'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.16'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.0'
98
+ description: Create tables that are sortable, filterable and much more
99
+ email:
100
+ - marieke@obvious.ly
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - app/controllers/concerns/table_concern.rb
115
+ - app/views/kaminari/twitter-bootstrap-4/_paginator.html.erb
116
+ - app/views/table_on_steroids/_table_on_steroids.html.erb
117
+ - app/views/table_on_steroids/_table_on_steroids_filters.html.erb
118
+ - bin/console
119
+ - bin/setup
120
+ - lib/table_on_steroids.rb
121
+ - lib/table_on_steroids/version.rb
122
+ - table_on_steroids.gemspec
123
+ - vendor/assets/javascripts/table_on_steroids.js
124
+ - vendor/assets/stylesheets/table_on_steroids.scss
125
+ homepage: http://www.github.com/mariekou
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.7.7
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Create awesome tables for rails
149
+ test_files: []