rao-component 0.0.2.pre
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +25 -0
- data/app/components/rao/component/base.rb +26 -0
- data/app/components/rao/component/collection_table.rb +123 -0
- data/app/components/rao/component/resource_table.rb +101 -0
- data/app/concerns/rao/component/collection_table/acts_as_list_concern.rb +18 -0
- data/app/concerns/rao/component/collection_table/acts_as_published_concern.rb +12 -0
- data/app/concerns/rao/component/collection_table/awesome_nested_set_concern.rb +12 -0
- data/app/concerns/rao/component/collection_table/batch_actions_concern.rb +18 -0
- data/app/concerns/rao/component/collection_table/boolean_concern.rb +12 -0
- data/app/concerns/rao/component/resource_table/boolean_concern.rb +12 -0
- data/app/helpers/rao/component/application_helper.rb +89 -0
- data/app/views/rao/component/_collection_table.html.haml +30 -0
- data/app/views/rao/component/_resource_table.html.haml +15 -0
- data/app/views/rao/component/table/body_cells/_acts_as_list.html.haml +11 -0
- data/app/views/rao/component/table/body_cells/_acts_as_published.html.haml +9 -0
- data/app/views/rao/component/table/body_cells/_association.html.haml +18 -0
- data/app/views/rao/component/table/body_cells/_awesome_nested_set.html.haml +9 -0
- data/app/views/rao/component/table/body_cells/_batch_actions.html.haml +1 -0
- data/app/views/rao/component/table/body_cells/_boolean.html.haml +4 -0
- data/app/views/rao/component/table/body_cells/_default.html.haml +4 -0
- data/app/views/rao/component/table/body_cells/_timestamp.html.haml +7 -0
- data/app/views/rao/component/table/header_cells/_batch_actions.html.haml +42 -0
- data/config/locales/de.yml +21 -0
- data/config/locales/en.yml +21 -0
- data/lib/generators/rao/component/install_generator.rb +15 -0
- data/lib/generators/rao/component/templates/initializer.rb +2 -0
- data/lib/rao-component.rb +2 -0
- data/lib/rao/component.rb +9 -0
- data/lib/rao/component/configuration.rb +12 -0
- data/lib/rao/component/engine.rb +7 -0
- data/lib/rao/component/version.rb +7 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3176ff3236482c18350f5a94f1e90f28218ed753
|
4
|
+
data.tar.gz: 3c517cbbfe60a18c0ea977f64579adfb02de2eb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f72dce6a27dd7bced33732b4f8b9b2e82398de0a4303599bedb212e7908a44673f3cfe0b12b46136385d788e734b45e5bef704e260dfb8d3fe7af02d07599133
|
7
|
+
data.tar.gz: 5f70ea7e847ef49e646ea204f84a63499e0d0fa815939850aef9f1c4ebd82d8480422edc8ed13cfe88ed5693eaa44ec072e1b8e503ed5f4950853ff95a3e9f53
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Roberto Vasquez Angel
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Rails Add-Ons Component
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rao-component'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install rao-component
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
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 = 'Rails Add-Ons Component'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
class Base
|
4
|
+
def initialize(view, options = {}, &block)
|
5
|
+
@view = view
|
6
|
+
@block = block
|
7
|
+
@options = options
|
8
|
+
@view_locals = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
@block_output = block_output
|
13
|
+
@view.render partial: self.class.name.underscore, locals: view_locals
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :view_locals
|
19
|
+
|
20
|
+
def block_output
|
21
|
+
return unless @block.present?
|
22
|
+
@view.capture { @block.call(self) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
# Example:
|
4
|
+
#
|
5
|
+
# = collection_table(collection: @posts, resource_class: Post) do |t|
|
6
|
+
# = t.column :id, sort: true
|
7
|
+
# = t.column :title
|
8
|
+
# = t.column :body
|
9
|
+
# = t.boolean :visible
|
10
|
+
# = t.timestamps format: :short
|
11
|
+
#
|
12
|
+
class CollectionTable < Base
|
13
|
+
include AwesomeNestedSetConcern
|
14
|
+
include ActsAsPublishedConcern
|
15
|
+
include ActsAsListConcern
|
16
|
+
include BatchActionsConcern
|
17
|
+
include BooleanConcern
|
18
|
+
|
19
|
+
SIZE_MAP = {
|
20
|
+
default: nil,
|
21
|
+
small: :sm,
|
22
|
+
extrasmall: :xs
|
23
|
+
}
|
24
|
+
|
25
|
+
def initialize(*args)
|
26
|
+
super
|
27
|
+
@options.reverse_merge!(header: true)
|
28
|
+
|
29
|
+
@columns = {}
|
30
|
+
@collection = @options.delete(:collection)
|
31
|
+
@resource_class = @options.delete(:resource_class) || @collection.first.class
|
32
|
+
end
|
33
|
+
|
34
|
+
def column(name, options = {}, &block)
|
35
|
+
options.reverse_merge!(render_as: :default)
|
36
|
+
options.reverse_merge!(block: block) if block_given?
|
37
|
+
@columns[name] = options
|
38
|
+
end
|
39
|
+
|
40
|
+
def id(options = {}, &block)
|
41
|
+
column(:id, options, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def timestamp(name, options = {}, &block)
|
45
|
+
options.reverse_merge!(render_as: :timestamp, format: Rao::Component::Configuration.table_default_timestamp_format)
|
46
|
+
column(name, options, &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def timestamps(options = {})
|
50
|
+
timestamp(:created_at, options)
|
51
|
+
timestamp(:updated_at, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Example:
|
55
|
+
#
|
56
|
+
# = table.association :category, sortable: true, label_method: :name, link_to: ->(r) { url_for(r.category) }
|
57
|
+
#
|
58
|
+
def association(name, options = {}, &block)
|
59
|
+
options.reverse_merge!(render_as: :association)
|
60
|
+
column(name, options, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def table
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def view_locals
|
70
|
+
{
|
71
|
+
columns: @columns,
|
72
|
+
collection: @collection,
|
73
|
+
resource_class: @resource_class,
|
74
|
+
table_css_classes: table_css_classes,
|
75
|
+
show_header: show_header
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def show_header
|
80
|
+
!!@options[:header]
|
81
|
+
end
|
82
|
+
|
83
|
+
def striped?
|
84
|
+
!!@options[:striped]
|
85
|
+
end
|
86
|
+
|
87
|
+
def responsive?
|
88
|
+
!!@options[:responsive]
|
89
|
+
end
|
90
|
+
|
91
|
+
def inverse?
|
92
|
+
!!@options[:inverse]
|
93
|
+
end
|
94
|
+
|
95
|
+
def bordered?
|
96
|
+
!!@options[:bordered]
|
97
|
+
end
|
98
|
+
|
99
|
+
def hover?
|
100
|
+
!!@options[:hover]
|
101
|
+
end
|
102
|
+
|
103
|
+
def size
|
104
|
+
SIZE_MAP[@options[:size] || :default]
|
105
|
+
end
|
106
|
+
|
107
|
+
def table_css_classes
|
108
|
+
classes = ['table', 'collection-table', @resource_class.name.underscore.pluralize.gsub('/', '-')]
|
109
|
+
classes << 'table-bordered' if bordered?
|
110
|
+
classes << 'table-hover' if hover?
|
111
|
+
classes << 'table-inverse' if inverse?
|
112
|
+
classes << 'table-striped' if striped?
|
113
|
+
classes << 'table-responsive' if responsive?
|
114
|
+
classes << "table-#{size}" if size.present?
|
115
|
+
classes
|
116
|
+
end
|
117
|
+
|
118
|
+
def t(key, options = {})
|
119
|
+
I18n.t("#{self.class.name.underscore.gsub('/', '.')}#{key}", options)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
# Example:
|
4
|
+
#
|
5
|
+
# = resource_table(resource: @post) do |t|
|
6
|
+
# = t.id
|
7
|
+
# = t.row :title
|
8
|
+
# = t.row :body
|
9
|
+
# = t.boolean :visible
|
10
|
+
# = t.timestamps format: :short
|
11
|
+
#
|
12
|
+
class ResourceTable < Base
|
13
|
+
include BooleanConcern
|
14
|
+
|
15
|
+
SIZE_MAP = {
|
16
|
+
default: nil,
|
17
|
+
small: :sm,
|
18
|
+
extrasmall: :xs
|
19
|
+
}
|
20
|
+
def size
|
21
|
+
SIZE_MAP[@options[:size] || :default]
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :resource
|
25
|
+
|
26
|
+
def initialize(*args)
|
27
|
+
super
|
28
|
+
@rows = {}
|
29
|
+
@resource = @options.delete(:resource)
|
30
|
+
@resource_class = @resource.class
|
31
|
+
end
|
32
|
+
|
33
|
+
def row(name, options = {}, &block)
|
34
|
+
options.reverse_merge!(render_as: :default)
|
35
|
+
options.reverse_merge!(block: block) if block_given?
|
36
|
+
@rows[name] = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def id(options = {}, &block)
|
40
|
+
row(:id, options, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def timestamp(name, options = {}, &block)
|
44
|
+
options.reverse_merge!(render_as: :timestamp, format: Rao::Component::Configuration.table_default_timestamp_format)
|
45
|
+
row(name, options, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def timestamps(options = {})
|
49
|
+
timestamp(:created_at, options)
|
50
|
+
timestamp(:updated_at, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def association(name, options = {}, &block)
|
54
|
+
options.reverse_merge!(render_as: :association)
|
55
|
+
row(name, options, &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def view_locals
|
61
|
+
{
|
62
|
+
rows: @rows,
|
63
|
+
resource: @resource,
|
64
|
+
resource_class: @resource_class,
|
65
|
+
table_css_classes: table_css_classes
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def table_css_classes
|
70
|
+
classes = ['table', 'resource-table', @resource_class.name.underscore.pluralize.gsub('/', '-')]
|
71
|
+
classes << 'table-bordered' if bordered?
|
72
|
+
classes << 'table-hover' if hover?
|
73
|
+
classes << 'table-inverse' if inverse?
|
74
|
+
classes << 'table-striped' if striped?
|
75
|
+
classes << 'table-responsive' if responsive?
|
76
|
+
classes << "table-#{size}" if size.present?
|
77
|
+
classes
|
78
|
+
end
|
79
|
+
|
80
|
+
def striped?
|
81
|
+
!!@options[:striped]
|
82
|
+
end
|
83
|
+
|
84
|
+
def responsive?
|
85
|
+
!!@options[:responsive]
|
86
|
+
end
|
87
|
+
|
88
|
+
def inverse?
|
89
|
+
!!@options[:inverse]
|
90
|
+
end
|
91
|
+
|
92
|
+
def bordered?
|
93
|
+
!!@options[:bordered]
|
94
|
+
end
|
95
|
+
|
96
|
+
def hover?
|
97
|
+
!!@options[:hover]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
module CollectionTable::ActsAsListConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def acts_as_list_actions(options = {}, &block)
|
7
|
+
options.reverse_merge!(render_as: :acts_as_list, title: t('.column_titles.acts_as_list'), scope: nil)
|
8
|
+
|
9
|
+
scope = options.delete(:scope)
|
10
|
+
scope = "#{scope}_id".intern if scope.is_a?(Symbol) && scope.to_s !~ /_id$/
|
11
|
+
|
12
|
+
options.merge(scope: scope)
|
13
|
+
|
14
|
+
column(:acts_as_list_actions, options, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
module CollectionTable::ActsAsPublishedConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def acts_as_published_actions(options = {}, &block)
|
7
|
+
options.reverse_merge!(render_as: :acts_as_published, title: t('.column_titles.acts_as_published'))
|
8
|
+
column(:acts_as_published_actions, options, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
module CollectionTable::AwesomeNestedSetConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def awesome_nested_set_actions(name, options = {}, &block)
|
7
|
+
options.reverse_merge!(render_as: :awesome_nested_set, scope: nil, title: t('.column_titles.awesome_nested_set'))
|
8
|
+
column(name, options, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
module CollectionTable::BatchActionsConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# = table.batch_actions(actions: { destroy: url_for(action: :destroy_many) })
|
9
|
+
#
|
10
|
+
def batch_actions(options = {}, &block)
|
11
|
+
@wrap_in_form = true
|
12
|
+
title = @view.render partial: 'component/table/header_cells/batch_actions', locals: { options: options }
|
13
|
+
options.reverse_merge!(render_as: :batch_actions, title: title)
|
14
|
+
column(:batch_actions, options, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
# Provides helpers to render tables for collections and single resources.
|
4
|
+
# To use it you have to add it to your controller:
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# class PostsController < ApplicationController
|
9
|
+
# #...
|
10
|
+
# helper Rao::Component::ApplicationHelper
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
module ApplicationHelper
|
14
|
+
def collection_table(options = {}, &block)
|
15
|
+
Rao::Component::CollectionTable.new(self, options, &block).perform
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_table(options = {}, &block)
|
19
|
+
Rao::Component::ResourceTable.new(self, options, &block).perform
|
20
|
+
end
|
21
|
+
|
22
|
+
def sort_link(column_name, title, options = {})
|
23
|
+
return title if options === false
|
24
|
+
SortLink.new(self, column_name, title, options).perform
|
25
|
+
end
|
26
|
+
|
27
|
+
class SortLink
|
28
|
+
ARROW_UP = '▲'
|
29
|
+
ARROW_DOWN = '▼'
|
30
|
+
|
31
|
+
def initialize(view_context, column_name, title, options)
|
32
|
+
default_options = {}
|
33
|
+
|
34
|
+
if options === true
|
35
|
+
@options = default_options
|
36
|
+
else
|
37
|
+
@options = options.reverse_merge(default_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
@view_context = view_context
|
41
|
+
@column_name = @options[:column_name] || column_name
|
42
|
+
@title = title
|
43
|
+
|
44
|
+
if h.params[:sort_direction].present?
|
45
|
+
@sort_direction = sorted_ascending? ? :desc : :asc
|
46
|
+
else
|
47
|
+
@sort_direction = :asc
|
48
|
+
end
|
49
|
+
|
50
|
+
if sorted_by_this_column?
|
51
|
+
if sorted_ascending?
|
52
|
+
@title_with_arrow = add_arrow_up(@title)
|
53
|
+
else
|
54
|
+
@title_with_arrow = add_arrow_down(@title)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@title_with_arrow = @title
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def perform
|
62
|
+
h.link_to(@title_with_arrow, h.url_for(h.request.query_parameters.merge(sort_by: @column_name, sort_direction: @sort_direction)))
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def h
|
68
|
+
@view_context
|
69
|
+
end
|
70
|
+
|
71
|
+
def sorted_by_this_column?
|
72
|
+
h.params[:sort_by] == @column_name.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
def sorted_ascending?
|
76
|
+
h.params[:sort_direction].to_sym == :asc
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_arrow_up(title)
|
80
|
+
"#{title} #{ARROW_UP}".html_safe
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_arrow_down(title)
|
84
|
+
"#{title} #{ARROW_DOWN}".html_safe
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
%table{ class: table_css_classes }
|
2
|
+
- if show_header
|
3
|
+
%thead
|
4
|
+
%tr
|
5
|
+
- columns.each do |name, options|
|
6
|
+
- title = options.delete(:title)
|
7
|
+
- if title.nil?
|
8
|
+
- if resource_class.respond_to?(:human_attribute_name)
|
9
|
+
- title = resource_class.human_attribute_name(name)
|
10
|
+
- else
|
11
|
+
- title = name
|
12
|
+
- if options.has_key?(:sort)
|
13
|
+
%td= sort_link(name, title, options[:sort])
|
14
|
+
- else
|
15
|
+
%td= title
|
16
|
+
%tbody
|
17
|
+
- collection.each do |resource|
|
18
|
+
- tr_options = { class: resource_class.name.underscore.gsub('/', '-') }
|
19
|
+
- if resource.respond_to?(:model_name)
|
20
|
+
- tr_options[:id] = dom_id(resource)
|
21
|
+
- else
|
22
|
+
- tr_options[:id] = "#{resource.class.name.underscore.gsub('/', '-')}-#{resource.object_id}"
|
23
|
+
%tr{ tr_options }
|
24
|
+
- columns.each do |name, options|
|
25
|
+
- td_options = { class: "attribute-#{name}", id: "#{tr_options[:id]}-#{name}"}
|
26
|
+
- if options[:block].present?
|
27
|
+
%td{ td_options }= options[:block].call(resource)
|
28
|
+
- else
|
29
|
+
%td{ td_options }
|
30
|
+
= render partial: "rao/component/table/body_cells/#{options[:render_as]}", locals: { resource: resource, name: name, options: options }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%table{ class: table_css_classes }
|
2
|
+
- rows.each do |name, options|
|
3
|
+
%tr
|
4
|
+
- if resource_class.respond_to? :human_attribute_name
|
5
|
+
%th
|
6
|
+
= resource_class.human_attribute_name(name)
|
7
|
+
- else
|
8
|
+
%th
|
9
|
+
= name
|
10
|
+
- if options[:block].present?
|
11
|
+
%td
|
12
|
+
= options[:block].call(resource)
|
13
|
+
- else
|
14
|
+
%td
|
15
|
+
= render partial: "rao/component/table/body_cells/#{options[:render_as]}", locals: { resource: resource, name: name, options: options }
|
@@ -0,0 +1,11 @@
|
|
1
|
+
:ruby
|
2
|
+
scope = options.delete(:scope)
|
3
|
+
data_attributes = {
|
4
|
+
'acts-as-list-item': true,
|
5
|
+
'acts-as-list-item-uid': resource.to_param,
|
6
|
+
'acts-as-list-item-on-drop-target': url_for([:reposition, resource])
|
7
|
+
}
|
8
|
+
data_attributes['acts-as-list-item-scope'] = "#{scope}-#{resource.send(scope)}" if scope.present?
|
9
|
+
|
10
|
+
%span.btn.btn-xs.btn-default.acts-as-list-item{ data: data_attributes }
|
11
|
+
%span.glyphicon.glyphicon-sort.fas.fa-sort
|
@@ -0,0 +1,9 @@
|
|
1
|
+
- link_path = controller.url_for(action: :toggle_published, id: resource.to_param)
|
2
|
+
- if resource.published?
|
3
|
+
= button_to(link_path, class: 'btn btn-xs btn-danger btn-responsive', method: :post) do
|
4
|
+
%span.glyphicon.glyphicon-eye-close
|
5
|
+
%span.btn-text= t('.unpublish', default: t('acts_as_published.actions.unpublish'))
|
6
|
+
- else
|
7
|
+
= button_to(link_path, class: 'btn btn-xs btn-success btn-responsive', method: :post) do
|
8
|
+
%span.glyphicon.glyphicon-eye-open
|
9
|
+
%span.btn-text= t('.publish', default: t('acts_as_published.actions.publish'))
|
@@ -0,0 +1,18 @@
|
|
1
|
+
- label = if options[:label_method].present?
|
2
|
+
- case options[:label_method]
|
3
|
+
- when Proc
|
4
|
+
- options[:label_method].call(resource.send(name))
|
5
|
+
- else
|
6
|
+
- resource.send(name).try(options[:label_method])
|
7
|
+
- else
|
8
|
+
- resource.send(name)
|
9
|
+
- link_to = options[:link_to]
|
10
|
+
- case link_to
|
11
|
+
- when Proc
|
12
|
+
= link_to(label, link_to.call(resource))
|
13
|
+
- when String
|
14
|
+
= link_to(label, link_to)
|
15
|
+
- when Symbol
|
16
|
+
= link_to(label, send(link_to))
|
17
|
+
- when nil
|
18
|
+
= label
|
@@ -0,0 +1,9 @@
|
|
1
|
+
:ruby
|
2
|
+
data_attributes = {
|
3
|
+
'awesome-nested-set-item': true,
|
4
|
+
'awesome-nested-set-item-uid': resource.to_param,
|
5
|
+
'awesome-nested-set-item-on-drop-target': url_for([:reposition, resource])
|
6
|
+
}
|
7
|
+
data_attributes['awesome-nested-set-item-scope'] = scope.call(model) if options[:scope].present?
|
8
|
+
%span.btn.btn-xs.btn-default.awesome-nested-set-item{ data: data_attributes }
|
9
|
+
%span.glyphicon.glyphicon-sort
|
@@ -0,0 +1 @@
|
|
1
|
+
= check_box_tag "ids[]", resource.id, false, class: 'batch-action-checkbox'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
:css
|
2
|
+
#batch-action-dropdown {
|
3
|
+
display: none;
|
4
|
+
}
|
5
|
+
|
6
|
+
%form{ method: 'post', id: 'batch-action-form' }
|
7
|
+
= hidden_field_tag :authenticity_token, form_authenticity_token
|
8
|
+
.dropdown.batch-action-dropdown
|
9
|
+
%button.btn.btn-default.dropdown-toggle{"aria-expanded" => "true", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button", id: 'batch-action-dropdown' }
|
10
|
+
= t('.title')
|
11
|
+
%span.caret
|
12
|
+
%ul.dropdown-menu{"aria-labelledby" => 'batch-action-dropdown' }
|
13
|
+
- options[:actions].each do |action, target|
|
14
|
+
%li
|
15
|
+
%a{ href: target, class: 'batch-action-form-submit-link' }= t(".#{action}")
|
16
|
+
|
17
|
+
:javascript
|
18
|
+
$(document).ready(function() {
|
19
|
+
$('.batch-action-checkbox').click(function() {
|
20
|
+
var check_count = $('.batch-action-checkbox:checked').size();
|
21
|
+
if( check_count > 0 ) {
|
22
|
+
$("#batch-action-dropdown").show();
|
23
|
+
} else {
|
24
|
+
$("#batch-action-dropdown").hide();
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
$('#batch-action-form').submit(function() {
|
29
|
+
$('#batch-action-form input:checked').remove();
|
30
|
+
var selected_items = $('.batch-action-checkbox:checked').clone();
|
31
|
+
selected_items.css('display', 'none');
|
32
|
+
$('#batch-action-form').append(selected_items);
|
33
|
+
return true;
|
34
|
+
});
|
35
|
+
|
36
|
+
$('.batch-action-form-submit-link').click(function(e) {
|
37
|
+
e.preventDefault();
|
38
|
+
var target = $(this).attr('href');
|
39
|
+
$("#batch-action-form").attr("action", target);
|
40
|
+
$('#batch-action-form').submit();
|
41
|
+
});
|
42
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
de:
|
2
|
+
rao:
|
3
|
+
component:
|
4
|
+
collection_table:
|
5
|
+
column_titles:
|
6
|
+
acts_as_list: Sortierung
|
7
|
+
acts_as_published: Veröffentlichung
|
8
|
+
awesome_nested_set: Sortierung
|
9
|
+
delete: Löschen
|
10
|
+
edit: Bearbeiten
|
11
|
+
show: Anzeigen
|
12
|
+
download: Download
|
13
|
+
table:
|
14
|
+
body_cells:
|
15
|
+
boolean:
|
16
|
+
'true': Ja
|
17
|
+
'false': Nein
|
18
|
+
header_cells:
|
19
|
+
batch_actions:
|
20
|
+
title: Stapelverarbeitung
|
21
|
+
destroy: Löschen
|
@@ -0,0 +1,21 @@
|
|
1
|
+
en:
|
2
|
+
rao:
|
3
|
+
component:
|
4
|
+
collection_table:
|
5
|
+
column_titles:
|
6
|
+
acts_as_list: Sorting
|
7
|
+
acts_as_published: Publishing
|
8
|
+
awesome_nested_set: Sorting
|
9
|
+
delete: Delete
|
10
|
+
edit: Edit
|
11
|
+
show: Show
|
12
|
+
download: Download
|
13
|
+
table:
|
14
|
+
body_cells:
|
15
|
+
boolean:
|
16
|
+
'true': Yes
|
17
|
+
'false': No
|
18
|
+
header_cells:
|
19
|
+
batch_actions:
|
20
|
+
title: Batch actions
|
21
|
+
destroy: Delete
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rao
|
2
|
+
module Component
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
desc 'Generates the initializer'
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def generate_initializer
|
10
|
+
template 'initializer.rb', 'config/initializers/rao-component.rb'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rao-component
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roberto Vasquez Angel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rao
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- roberto@vasquez-angel.de
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- app/components/rao/component/base.rb
|
108
|
+
- app/components/rao/component/collection_table.rb
|
109
|
+
- app/components/rao/component/resource_table.rb
|
110
|
+
- app/concerns/rao/component/collection_table/acts_as_list_concern.rb
|
111
|
+
- app/concerns/rao/component/collection_table/acts_as_published_concern.rb
|
112
|
+
- app/concerns/rao/component/collection_table/awesome_nested_set_concern.rb
|
113
|
+
- app/concerns/rao/component/collection_table/batch_actions_concern.rb
|
114
|
+
- app/concerns/rao/component/collection_table/boolean_concern.rb
|
115
|
+
- app/concerns/rao/component/resource_table/boolean_concern.rb
|
116
|
+
- app/helpers/rao/component/application_helper.rb
|
117
|
+
- app/views/rao/component/_collection_table.html.haml
|
118
|
+
- app/views/rao/component/_resource_table.html.haml
|
119
|
+
- app/views/rao/component/table/body_cells/_acts_as_list.html.haml
|
120
|
+
- app/views/rao/component/table/body_cells/_acts_as_published.html.haml
|
121
|
+
- app/views/rao/component/table/body_cells/_association.html.haml
|
122
|
+
- app/views/rao/component/table/body_cells/_awesome_nested_set.html.haml
|
123
|
+
- app/views/rao/component/table/body_cells/_batch_actions.html.haml
|
124
|
+
- app/views/rao/component/table/body_cells/_boolean.html.haml
|
125
|
+
- app/views/rao/component/table/body_cells/_default.html.haml
|
126
|
+
- app/views/rao/component/table/body_cells/_timestamp.html.haml
|
127
|
+
- app/views/rao/component/table/header_cells/_batch_actions.html.haml
|
128
|
+
- config/locales/de.yml
|
129
|
+
- config/locales/en.yml
|
130
|
+
- lib/generators/rao/component/install_generator.rb
|
131
|
+
- lib/generators/rao/component/templates/initializer.rb
|
132
|
+
- lib/rao-component.rb
|
133
|
+
- lib/rao/component.rb
|
134
|
+
- lib/rao/component/configuration.rb
|
135
|
+
- lib/rao/component/engine.rb
|
136
|
+
- lib/rao/component/version.rb
|
137
|
+
homepage: https://github.com/rao
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 1.3.1
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.6.14
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: View Components for Ruby on Rails.
|
161
|
+
test_files: []
|