activeadmin_dynamic_table 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: ec7d176dc20e3cb34be2eae984bf87e6c790a3fa79bc61fde512e27b67ce15c9
4
- data.tar.gz: bcc2afb91378be40321f206d2ac9d8d284ed22ad213864d1540f542f090e25f1
3
+ metadata.gz: 537aa432d0b52c8cf60622622c7893ccfb26094b9da6b48d3b529812266358e7
4
+ data.tar.gz: 5b7fdde7f367a01c537a3134e6db65c6e62478005bcc297db0dba9f13bea24a7
5
5
  SHA512:
6
- metadata.gz: ab184ef277fda19e363634353292983632793e88009ebdd08a071b9f92c226d1bce53461dc43f9c1f42fa19c4a8f1ef954befcd0370b2723b8c6d73b4667f1cf
7
- data.tar.gz: e550f74ca22cd8099454e7790c0119803f8a07bb823282c42b9b7aa6d1249a24e4e4f87e6acc0315e39c7acd06a5e0c08f40920e76337750fd2f44c80ef36436
6
+ metadata.gz: f1153e6d83dcea9a7a21607cda3dc34d72e6775bf3a0c5237135bcdbe9c8e01abce4bd97628578d876f025849f6f9c03071db31455cc594d667ccd64b08242a7
7
+ data.tar.gz: e0fed908ba563f7513d675136094f4b7a6acb649ef55697c75c0e9e7deb4474f0e921bf8e339ca129600e4a4a42bc32f129477bef59a6d55b392259d6a312ed5
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activeadmin_dynamic_table (0.1.0)
5
- activeadmin (~> 2.9)
4
+ activeadmin_dynamic_table (0.2.0)
5
+ activeadmin (>= 2.9, < 4.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # ActiveadminDynamicTable
2
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/activeadmin_dynamic_table`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This is an [ActiveAdmin](https://github.com/activeadmin/activeadmin) extension that allows managing index table columns from the activeadmin UI.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Goals
6
+ - Show/hide table columns from UI
7
+ - Resize columns
8
+ - Reorder columns
9
+
10
+ <img src="demo.gif" width="800" height="600">
6
11
 
7
12
  ## Installation
8
13
 
@@ -20,19 +25,77 @@ Or install it yourself as:
20
25
 
21
26
  $ gem install activeadmin_dynamic_table
22
27
 
28
+ Add at the end of your ActiveAdmin styles (app/assets/stylesheets/active_admin.scss):
29
+
30
+ ```scss
31
+ @import 'activeadmin_dynamic_table/all';
32
+ ```
33
+
34
+ Add at the end of your ActiveAdmin javascripts (app/assets/javascripts/active_admin.js):
35
+
36
+ ```
37
+ //= require activeadmin_dynamic_table/config
38
+ ```
39
+
23
40
  ## Usage
24
41
 
25
- TODO: Write usage instructions here
42
+ For `index` block specify `dynamic_table` to be used instead of default `table`
43
+
44
+ ```ruby
45
+ index as: :dynamic_table do
46
+ # ...
47
+ end
48
+ ```
49
+
50
+ Inside configuration block register columns that will be configurable through UI
51
+
52
+ ### register_column
26
53
 
27
- ## Development
54
+ Method follows standard `column` dsl but also requires to provide at least `key` among options. This is key of the column in the provided URL params to detect whether or not column should be rendered.
28
55
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+ `default: true` - specify column should be rendered by default (when columns are not specified in url params)
57
+ `width: 100` - default width of the column if it's not specified in the url params
30
58
 
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+ ### register_id_column
60
+
61
+ Method follows standard `id_column` dsl but also requires to provide at least `key` among options.
62
+ All other options are the same as for `register_column`
63
+
64
+ ### register_actions
65
+
66
+ Method follows standard `column` dsl but also requires to provide at least `key` among options.
67
+ All other options are the same as for `register_column`
68
+
69
+ Example:
70
+
71
+ ```ruby
72
+ index as: :dynamic_table do
73
+ selectable_column
74
+
75
+ register_id_column 'Student ID', key: :id, default: true, width: 30
76
+
77
+ register_column :name, key: :name, default: true, width: 200, &:full_name
78
+ register_column :user_phone, key: :phone, default: true, width: 200, &proc { |st| link_to st.phone, user_path(st.user) }
79
+
80
+ register_column :teacher, key: :teacher, default: true, width: 200
81
+ register_column :country, key: :country, width: 150
82
+ register_column :updated_at, key: :updated_at, width: 100
83
+
84
+ register_column 'LPD', key: :lpd, &proc { |st| st.last_payment_date&.strftime('%d.%m.%y %H:%M') }
85
+
86
+ register_column 'SC', key: :sc, width: 200, default: true do |student|
87
+ student.schedule_slots.map do |slot|
88
+ "#{slot.day_of_week.capitalize}: #{slot.time_slot.utc.strftime('%H:%M')}"
89
+ end.join(', ')
90
+ end
91
+
92
+ register_actions 'Actions', key: :actions, default: true, width: 130
93
+ end
94
+ ```
32
95
 
33
96
  ## Contributing
34
97
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activeadmin_dynamic_table.
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/amdj15/activeadmin_dynamic_table.
36
99
 
37
100
  ## License
38
101
 
@@ -8,16 +8,14 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Anton Biliaiev"]
9
9
  spec.email = ["amdj15@gmail.com"]
10
10
 
11
- spec.summary = ""
12
- spec.description = ""
13
- spec.homepage = ""
11
+ spec.summary = "Config activeadmin index tables on demand"
12
+ spec.description = "Allow to controll activeadmin table columns from the UI. (Show/hide/resize/reorder table columns)"
13
+ spec.homepage = "https://github.com/amdj15/activeadmin_dynamic_table"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
16
16
 
17
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
- # spec.metadata["homepage_uri"] = spec.homepage
19
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
21
19
 
22
20
  # Specify which files should be added to the gem when it is released.
23
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -31,7 +29,7 @@ Gem::Specification.new do |spec|
31
29
  spec.require_paths = ["lib"]
32
30
 
33
31
  # Uncomment to register a new dependency of your gem
34
- spec.add_dependency "activeadmin", "~> 2.9"
32
+ spec.add_dependency "activeadmin", ">= 2.9", "< 4.0"
35
33
 
36
34
  # For more information and examples about making a new gem, check out our
37
35
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -7,7 +7,9 @@
7
7
  }
8
8
 
9
9
  .col-table-preferences {
10
- cursor: pointer;
10
+ span {
11
+ cursor: pointer;
12
+ }
11
13
  }
12
14
 
13
15
  .dynamic_table_configuration {
data/demo.gif ADDED
Binary file
@@ -0,0 +1,34 @@
1
+ module ActiveAdmin
2
+ class DynamicCSVBuilder < CSVBuilder
3
+ def exec_columns(view_context = nil)
4
+ @view_context = view_context
5
+ settings = ActiveadminDynamicTable::SettingStringParser.new(@view_context.params[:columns])
6
+
7
+ @configurator = ActiveadminDynamicTable::Configurator.new(self, settings.parse)
8
+ @columns = [] # we want to re-render these every instance
9
+
10
+ instance_exec &@block
11
+ @configurator.columns
12
+
13
+ columns
14
+ end
15
+
16
+ def build_row(resource, columns, options)
17
+ columns.map do |column|
18
+ content = call_method_or_proc_on(resource, column.data)
19
+ encode view_context.strip_tags(content.to_s), options
20
+ end
21
+ end
22
+
23
+ def register_column(*args, &block)
24
+ @configurator.register_column(:column, *args, &block)
25
+ end
26
+
27
+ def register_id_column(*args, &block)
28
+ @configurator.register_column(:column, :id, key: :id)
29
+ end
30
+
31
+ def register_actions(*args, &block); end
32
+ def selectable_column; end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveAdmin
2
+ class ResourceDSL
3
+ def use_dynamic_csv(options = {})
4
+ options[:resource] = config
5
+
6
+ presenter = config.page_presenters[:index][:table]
7
+
8
+ config.csv_builder = DynamicCSVBuilder.new(options, &presenter.block)
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveadminDynamicTable
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -5,6 +5,8 @@ require_relative "activeadmin_dynamic_table/version"
5
5
  require_relative "activeadmin_dynamic_table/configurator"
6
6
  require_relative "activeadmin_dynamic_table/setting_string_parser"
7
7
  require_relative "activeadmin_dynamic_table/column_settings"
8
+ require_relative "activeadmin_dynamic_table/resource_dsl"
9
+ require_relative "activeadmin_dynamic_table/dynamic_csv_builder"
8
10
  require_relative "activeadmin_dynamic_table/views/index_as_dynamic_table"
9
11
 
10
12
  module ActiveadminDynamicTable
metadata CHANGED
@@ -1,30 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_dynamic_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Biliaiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-28 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2.9'
27
- description: ''
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
33
+ description: Allow to controll activeadmin table columns from the UI. (Show/hide/resize/reorder
34
+ table columns)
28
35
  email:
29
36
  - amdj15@gmail.com
30
37
  executables: []
@@ -42,17 +49,22 @@ files:
42
49
  - app/assets/stylesheets/activeadmin_dynamic_table/all.scss
43
50
  - bin/console
44
51
  - bin/setup
52
+ - demo.gif
45
53
  - lib/activeadmin_dynamic_table.rb
46
54
  - lib/activeadmin_dynamic_table/column_settings.rb
47
55
  - lib/activeadmin_dynamic_table/configurator.rb
56
+ - lib/activeadmin_dynamic_table/dynamic_csv_builder.rb
57
+ - lib/activeadmin_dynamic_table/resource_dsl.rb
48
58
  - lib/activeadmin_dynamic_table/setting_string_parser.rb
49
59
  - lib/activeadmin_dynamic_table/version.rb
50
60
  - lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb
51
61
  - sig/activeadmin_dynamic_table.rbs
52
- homepage: ''
62
+ homepage: https://github.com/amdj15/activeadmin_dynamic_table
53
63
  licenses:
54
64
  - MIT
55
- metadata: {}
65
+ metadata:
66
+ homepage_uri: https://github.com/amdj15/activeadmin_dynamic_table
67
+ source_code_uri: https://github.com/amdj15/activeadmin_dynamic_table
56
68
  post_install_message:
57
69
  rdoc_options: []
58
70
  require_paths:
@@ -71,5 +83,5 @@ requirements: []
71
83
  rubygems_version: 3.1.4
72
84
  signing_key:
73
85
  specification_version: 4
74
- summary: ''
86
+ summary: Config activeadmin index tables on demand
75
87
  test_files: []