rails_admin_extended_fields 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '085b7d09f7aa32cbb8e93d08aa76306784a6bdc6'
4
+ data.tar.gz: 00e78a725e7c1c185e580967a97383afad70f3cf
5
+ SHA512:
6
+ metadata.gz: 68345f960982eb4b272d182d001d3351fa42e4e8c0576bdfc79f8e4154274d98a013f47ae32a7a5f213aada342ab005af409b56aad35afa1aef63cdcf4b07980
7
+ data.tar.gz: 8f0a1d0f638f4f9637f557570f8c6dcb96533492e1f1cc174c5836a1c2c82750939fa8a830891b8a0138523dc2e1c9e8cefc27e83a54c1e1694327108ff16dea
@@ -0,0 +1,20 @@
1
+ Copyright 2017
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ # rails_admin_extended_fields
2
+
3
+ A [rails_admin](https://github.com/sferik/rails_admin) plugin to add more options to fields.
4
+
5
+ Features:
6
+
7
+ - nested sortable tabs
8
+
9
+ - load fields css classes from model
10
+
11
+ ## Install
12
+
13
+ - Add to the Gemfile:
14
+
15
+ `gem 'rails_admin_extended_fields'`
16
+
17
+ - Edit or create *app/assets/javascripts/rails_admin/custom/ui.js* and add:
18
+
19
+ `//= require rails_admin_extended_fields`
20
+
21
+ ## Usage
22
+
23
+ #### nested sortable tabs
24
+
25
+ Example with a parent model *Page* and a nested model *Block*
26
+
27
+ - Add a position field to your nested model (ex. an integer or float column):
28
+
29
+ `rails generate migration AddPositionToBlocks position:float`
30
+
31
+ - Optionally add a default in the migration (ex. `add_column :blocks, :position, :float, null: false, default: 0.0`)
32
+
33
+ - Add a default ordered scope to the nested model:
34
+
35
+ `default_scope { order( position: :desc ) }`
36
+
37
+ - rails_admin config:
38
+
39
+ ```ruby
40
+ config.model Block do
41
+ nested do
42
+ field :position, :hidden do
43
+ html_attributes 'data-sortable': 'true'
44
+ end
45
+ end
46
+ end
47
+
48
+ config.model Page do
49
+ edit do
50
+ field :blocks do
51
+ css_class 'nested-sortable'
52
+ end
53
+ end
54
+ end
55
+ ```
56
+
57
+ - If you edit a *Page* in rails_admin *Blocks* should be draggable
58
+
59
+ #### load fields css classes from model
60
+
61
+ It can be useful to add specific classes to some fields using Single Table Inheritance models.
62
+
63
+ - Add to a model:
64
+
65
+ ```ruby
66
+ class Block < ApplicationRecord
67
+ def type_enum
68
+ @type_enum ||= [ 'BlockImage', 'BlockText' ]
69
+ end
70
+ end
71
+
72
+ class BlockImage < Block
73
+ def css_class
74
+ @css_class ||= {
75
+ abstract: 'hide',
76
+ name: 'hide'
77
+ }
78
+ end
79
+ end
80
+ ```
81
+
82
+ - Class 'hide' is added to *abstract* and *name* fields of *BlockImage* only
83
+
84
+ ## Contributors
85
+
86
+ - [Mattia Roccoberton](http://blocknot.es) - creator, maintainer
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsAdminExtendedFields'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ require 'bundler/gem_tasks'
24
+
@@ -0,0 +1,40 @@
1
+ require "rails_admin_extended_fields/engine"
2
+
3
+ module RailsAdminExtendedFields
4
+ end
5
+
6
+ require 'rails_admin/config/fields'
7
+ require 'rails_admin/config/fields/base'
8
+
9
+ RailsAdmin::Config::Fields::Base.class_eval do
10
+ # Load field css classes from model (as hash)
11
+ #
12
+ # # Example:
13
+ # def css_class
14
+ # @css_class ||= { abstract: 'hide' }
15
+ # end
16
+ register_instance_option :css_class do
17
+ ( defined?( bindings[:object].css_class ) && bindings[:object].css_class[name] ) ? bindings[:object].css_class[name] : "#{name}_field"
18
+ end
19
+ end
20
+
21
+ # module RailsAdmin
22
+ # module Config
23
+ # module Fields
24
+ # module Types
25
+ # class ExtendedFields < RailsAdmin::Config::Fields::Base
26
+ # RailsAdmin::Config::Fields::Types::register(self)
27
+ # end
28
+ # end
29
+ # end
30
+ # end
31
+ # end
32
+
33
+ # RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
34
+ # if properties[:name] == :extended_fields
35
+ # fields << RailsAdmin::Config::Fields::Types::ExtendedFields.new(parent, properties[:name], properties)
36
+ # true
37
+ # else
38
+ # false
39
+ # end
40
+ # end
@@ -0,0 +1,4 @@
1
+ module RailsAdminExtendedFields
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminExtendedFields
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,38 @@
1
+ /* rails admin config example
2
+ # parent model:
3
+ field :blocks do
4
+ active true
5
+ css_class 'blocks_field nested-sortable'
6
+ inline_add false
7
+ end
8
+ ...
9
+ # nested model:
10
+ field :position do
11
+ html_attributes 'data-sortable': 'true'
12
+ end
13
+ */
14
+ function set_sortable( element, cnt, position ) {
15
+ element.addClass( 'nested-sortable-' + cnt );
16
+ // Add tab content reference
17
+ element.find('> .controls .nav-tabs > li').each( function( i ) {
18
+ $(this).attr( 'data-tab', i );
19
+ });
20
+ // Init sortable
21
+ element.find('> .controls .nav-tabs').attr( 'data-sortable', cnt );
22
+ element.find('> .controls .nav-tabs').sortable({
23
+ update: function( event, ui ) {
24
+ // Update each position field
25
+ var positions = $('.nested-sortable-' + $(this).attr('data-sortable') + ' input[data-sortable]');
26
+ var len = positions.length;
27
+ $(this).find('> li').each( function( i ) {
28
+ positions.eq( $(this).attr( 'data-tab' ) ).val( len-- );
29
+ });
30
+ }
31
+ });
32
+ }
33
+
34
+ $(document).on('rails_admin.dom_ready', function() {
35
+ $('.nested-sortable').each( function( i ) {
36
+ set_sortable( $(this), i + 1 );
37
+ });
38
+ });
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_extended_fields
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mattia Roccoberton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: RailsAdminExtendedFields adds more options to rails_admin fields
14
+ email:
15
+ - mat@blocknot.es
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT-LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - lib/rails_admin_extended_fields.rb
24
+ - lib/rails_admin_extended_fields/engine.rb
25
+ - lib/rails_admin_extended_fields/version.rb
26
+ - vendor/assets/javascripts/rails_admin_extended_fields.js.erb
27
+ homepage: https://github.com/blocknotes/rails_admin_extended_fields
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.6.8
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: RailsAdminExtendedFields plugin
51
+ test_files: []