rails_admin_grid 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/app/views/rails_admin/main/grid.html.haml +156 -0
- data/config/locales/grid.en.yml +9 -0
- data/lib/rails_admin_grid.rb +7 -0
- data/lib/rails_admin_grid/action.rb +50 -0
- data/lib/rails_admin_grid/engine.rb +4 -0
- data/lib/rails_admin_grid/section.rb +15 -0
- data/lib/rails_admin_grid/version.rb +3 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71e762946cdb2225a14ead81c9b1d6eee13e8722
|
4
|
+
data.tar.gz: 551a48bceeae5d9b572ce8f700662e8907ac17df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e75a2d2477b4ff1ca7ae3283d8271f8c6a894b635d6e7ea3d4312093ebe26e23e5290beae8e9f955c4e508d4060017c4996d8b491a328bd03074defd39bd0493
|
7
|
+
data.tar.gz: df3ffb6849b3914bc52bc42dc9b6c478bc8fcb38b14306142f2c2c3194c1f8548f286151f72b6827683199aa8429b58df02accbcca967bd07491bf344d2e7183
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Michael Colavita
|
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/Rakefile
ADDED
@@ -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 = 'RailsAdminGrid'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
@@ -0,0 +1,156 @@
|
|
1
|
+
:ruby
|
2
|
+
require 'rails_admin/config/fields/types/datetime.rb'
|
3
|
+
query = params[:query]
|
4
|
+
params = request.params.except(:authenticity_token, :action, :controller, :utf8, :bulk_export, :_pjax)
|
5
|
+
params.delete(:query) if params[:query].blank?
|
6
|
+
params.delete(:sort_reverse) unless params[:sort_reverse] == 'true'
|
7
|
+
sort_reverse = params[:sort_reverse]
|
8
|
+
sort = params[:sort]
|
9
|
+
params.delete(:sort) if params[:sort] == @model_config.grid.sort_by.to_s
|
10
|
+
|
11
|
+
export_action = RailsAdmin::Config::Actions.find(:export, { controller: self.controller, abstract_model: @abstract_model })
|
12
|
+
export_action = nil unless export_action && authorized?(export_action.authorization_key, @abstract_model)
|
13
|
+
|
14
|
+
description = RailsAdmin.config(@abstract_model.model_name).description
|
15
|
+
properties = @model_config.grid.with(controller: self.controller, view: self, object: @abstract_model.model.new).visible_fields
|
16
|
+
# columns paginate
|
17
|
+
@filterable_fields = @model_config.grid.fields.select(&:filterable?)
|
18
|
+
sets = get_column_sets(properties)
|
19
|
+
properties = sets[params[:set].to_i] || []
|
20
|
+
other_left = ((params[:set].to_i - 1) >= 0) && sets[params[:set].to_i - 1].present?
|
21
|
+
other_right = sets[params[:set].to_i + 1].present?
|
22
|
+
@index = 0
|
23
|
+
@ordered_filters = (params[:f] || @model_config.grid.filters).inject({}) { |memo, filter|
|
24
|
+
field_name = filter.is_a?(Array) ? filter.first : filter
|
25
|
+
(filter.is_a?(Array) ? filter.last : { (@index += 1) => { "v" => '' } }) .each do |index, filter_hash|
|
26
|
+
unless filter_hash['disabled']
|
27
|
+
memo[index] = { field_name => filter_hash }
|
28
|
+
else
|
29
|
+
params[:f].delete(field_name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
memo
|
33
|
+
}.to_a.sort_by(&:first)
|
34
|
+
|
35
|
+
@ordered_filter_string = @ordered_filters.map do |duplet|
|
36
|
+
filter_index = duplet[0]
|
37
|
+
filter_for_field = duplet[1]
|
38
|
+
filter_name = filter_for_field.keys.first
|
39
|
+
filter_hash = filter_for_field.values.first
|
40
|
+
field = @filterable_fields.find{ |field| field.name == filter_name.to_sym }
|
41
|
+
unless field
|
42
|
+
fail "#{filter_name} is not currently filterable; filterable fields are #{@filterable_fields.map(&:name).join(', ')}"
|
43
|
+
end
|
44
|
+
field_options = case field.type
|
45
|
+
when :enum
|
46
|
+
options_for_select(field.with(object: @abstract_model.model.new).enum, filter_hash['v'])
|
47
|
+
else
|
48
|
+
''
|
49
|
+
end
|
50
|
+
%{
|
51
|
+
$.filters.append(#{field.label.to_json}, #{field.name.to_json}, #{field.type.to_json}, #{filter_hash['v'].to_json}, #{filter_hash['o'].to_json}, #{field_options.to_json}, #{filter_index.to_json});
|
52
|
+
}
|
53
|
+
end.join.html_safe if @ordered_filters
|
54
|
+
|
55
|
+
|
56
|
+
= content_for :contextual_tabs do
|
57
|
+
= bulk_menu
|
58
|
+
- if @filterable_fields.present?
|
59
|
+
%li.dropdown{style: 'float:right'}
|
60
|
+
%a.dropdown-toggle{href: '#', :'data-toggle' => "dropdown"}
|
61
|
+
= t('admin.misc.add_filter')
|
62
|
+
%b.caret
|
63
|
+
%ul.dropdown-menu#filters{style: 'left:auto; right:0;'}
|
64
|
+
- @filterable_fields.each do |field|
|
65
|
+
- field_options = case field.type
|
66
|
+
- when :enum
|
67
|
+
- options_for_select(field.with(object: @abstract_model.model.new).enum)
|
68
|
+
- else
|
69
|
+
- ''
|
70
|
+
%li
|
71
|
+
%a{href: '#', :"data-field-label" => field.label, :"data-field-name" => field.name, :"data-field-options" => field_options.html_safe, :"data-field-type" => field.type, :"data-field-value" => ""}= capitalize_first_letter(field.label)
|
72
|
+
|
73
|
+
#list
|
74
|
+
%script
|
75
|
+
jQuery(function($) {
|
76
|
+
$.filters.options.regional = {
|
77
|
+
datePicker: {
|
78
|
+
dateFormat: #{raw I18n.t("admin.misc.filter_date_format", default: I18n.t("admin.misc.filter_date_format", locale: :en)).to_json},
|
79
|
+
dayNames: #{raw RailsAdmin::Config::Fields::Types::Datetime.day_names.to_json},
|
80
|
+
dayNamesShort: #{raw RailsAdmin::Config::Fields::Types::Datetime.abbr_day_names.to_json},
|
81
|
+
dayNamesMin: #{raw RailsAdmin::Config::Fields::Types::Datetime.abbr_day_names.to_json},
|
82
|
+
firstDay: "1",
|
83
|
+
monthNames: #{raw RailsAdmin::Config::Fields::Types::Datetime.month_names.to_json},
|
84
|
+
monthNamesShort: #{raw RailsAdmin::Config::Fields::Types::Datetime.abbr_month_names.to_json}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
= @ordered_filter_string
|
89
|
+
|
90
|
+
});
|
91
|
+
%style
|
92
|
+
- properties.select{ |p| p.column_width.present? }.each do |property|
|
93
|
+
= "#list th.#{property.css_class} { width: #{property.column_width}px; min-width: #{property.column_width}px; }"
|
94
|
+
= "#list td.#{property.css_class} { max-width: #{property.column_width}px; }"
|
95
|
+
:css
|
96
|
+
.center-vert {
|
97
|
+
position: relative;
|
98
|
+
top: 50%;
|
99
|
+
transform: translateY(-50%);
|
100
|
+
}
|
101
|
+
= form_tag(grid_path(params.except(*%w[page f query])), method: :get, class: "pjax-form form-inline") do
|
102
|
+
.well
|
103
|
+
%span#filters_box
|
104
|
+
%hr.filters_box{style: "display:#{@ordered_filters.empty? ? 'none' : 'block'}"}
|
105
|
+
.input-group
|
106
|
+
%input.form-control.input-small{name: "query", type: "search", value: query, placeholder: t("admin.misc.filter")}
|
107
|
+
%span.input-group-btn
|
108
|
+
%button.btn.btn-primary{type: "submit", :'data-disable-with' => "<i class='icon-white icon-refresh'></i> ".html_safe + t("admin.misc.refresh")}
|
109
|
+
%i.icon-white.icon-refresh
|
110
|
+
= t("admin.misc.refresh")
|
111
|
+
- if export_action
|
112
|
+
%span{style: 'float:right'}= link_to wording_for(:link, export_action), export_path(params.except('set').except('page')), class: 'btn btn-info'
|
113
|
+
|
114
|
+
- unless @model_config.grid.scopes.empty?
|
115
|
+
%ul.nav.nav-tabs#scope_selector
|
116
|
+
- @model_config.grid.scopes.each_with_index do |scope, index|
|
117
|
+
- scope = '_all' if scope.nil?
|
118
|
+
%li{class: "#{'active' if scope.to_s == params[:scope] || (params[:scope].blank? && index == 0)}"}
|
119
|
+
%a{href: grid_path(params.merge(scope: scope, page: nil)), class: 'pjax'}= I18n.t("admin.scopes.#{@abstract_model.to_param}.#{scope}", default: I18n.t("admin.scopes.#{scope}", default: scope.to_s.titleize))
|
120
|
+
|
121
|
+
= form_tag bulk_action_path(model_name: @abstract_model.to_param), method: :post, id: "bulk_form", class: "form" do
|
122
|
+
= hidden_field_tag :bulk_action
|
123
|
+
- if description.present?
|
124
|
+
<b>#{description}</b>
|
125
|
+
|
126
|
+
.container-fluid
|
127
|
+
- @objects.each_slice(4) do |object_row|
|
128
|
+
.row
|
129
|
+
-object_row.each do |object|
|
130
|
+
.col-md-3{class: "#{@abstract_model.param_key}_row"}
|
131
|
+
.panel.panel-default
|
132
|
+
.panel-body
|
133
|
+
%a{href: show_path(model_name: @abstract_model.to_param, id: object.try(:id))}
|
134
|
+
%div{style: "height: 200px;"}
|
135
|
+
-img_src = @model_config.grid.thumbnail_method ? object.send(@model_config.grid.thumbnail_method) : nil
|
136
|
+
%img.img-responsive.center-block.center-vert{src: img_src, alt: "View #{@abstract_model}", style: "max-height: 100%;"}
|
137
|
+
%br
|
138
|
+
.text-center= check_box_tag "bulk_ids[]", object.id, false
|
139
|
+
.panel-footer
|
140
|
+
- properties.map{ |property| property.bind(:object, object) }.each do |property|
|
141
|
+
- value = property.pretty_value
|
142
|
+
%p{class: "#{property.css_class} #{property.type_css_class}", title: strip_tags(value.to_s)}
|
143
|
+
%strong=property.label+":"
|
144
|
+
=value
|
145
|
+
.list-inline.text-center
|
146
|
+
=menu_for :member, @abstract_model, object, true
|
147
|
+
|
148
|
+
- if @objects.respond_to?(:total_count)
|
149
|
+
- total_count = @objects.total_count.to_i
|
150
|
+
.row
|
151
|
+
.col-md-6= paginate(@objects, theme: 'twitter-bootstrap', remote: true)
|
152
|
+
.row
|
153
|
+
.col-md-6= link_to(t("admin.misc.show_all"), grid_path(params.merge(all: true)), class: "show-all btn btn-default clearfix pjax") unless total_count > 100 || total_count <= @objects.to_a.size
|
154
|
+
.clearfix.total-count= "#{total_count} #{@model_config.pluralize(total_count).downcase}"
|
155
|
+
- else
|
156
|
+
.clearfix.total-count= "#{@objects.size} #{@model_config.pluralize(@objects.size).downcase}"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rails_admin/config/actions'
|
2
|
+
require 'rails_admin/config/actions/base'
|
3
|
+
|
4
|
+
module RailsAdmin
|
5
|
+
module Config
|
6
|
+
module Actions
|
7
|
+
class Grid < Base
|
8
|
+
RailsAdmin::Config::Actions.register(self)
|
9
|
+
|
10
|
+
register_instance_option :collection do
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
register_instance_option :http_methods do
|
15
|
+
[:get, :post]
|
16
|
+
end
|
17
|
+
|
18
|
+
register_instance_option :route_fragment do
|
19
|
+
'grid'
|
20
|
+
end
|
21
|
+
|
22
|
+
register_instance_option :controller do
|
23
|
+
proc do
|
24
|
+
@objects ||= list_entries
|
25
|
+
|
26
|
+
unless @model_config.list.scopes.empty?
|
27
|
+
if params[:scope].blank?
|
28
|
+
unless @model_config.list.scopes.first.nil?
|
29
|
+
@objects = @objects.send(@model_config.list.scopes.first)
|
30
|
+
end
|
31
|
+
elsif @model_config.list.scopes.collect(&:to_s).include?(params[:scope])
|
32
|
+
@objects = @objects.send(params[:scope].to_sym)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
render @action.template_name, status: (flash[:error].present? ? :not_found : 200)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
register_instance_option :link_icon do
|
41
|
+
'icon-th-large'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails_admin/config/sections'
|
2
|
+
require 'rails_admin/config/sections/base'
|
3
|
+
|
4
|
+
module RailsAdmin
|
5
|
+
module Config
|
6
|
+
module Sections
|
7
|
+
# Configuration of the explore view
|
8
|
+
class Grid < List
|
9
|
+
register_instance_option :thumbnail_method do
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_grid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Colavita
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails_admin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.8
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.6.8
|
41
|
+
description: RailsAdminGrid is a custom action for RailsAdmin that displays objects
|
42
|
+
in a grid with thumbnails. It provides an alternative to the default list view provided
|
43
|
+
in RailsAdmin.
|
44
|
+
email:
|
45
|
+
- colavitam@gmail.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- MIT-LICENSE
|
51
|
+
- Rakefile
|
52
|
+
- app/views/rails_admin/main/grid.html.haml
|
53
|
+
- config/locales/grid.en.yml
|
54
|
+
- lib/rails_admin_grid.rb
|
55
|
+
- lib/rails_admin_grid/action.rb
|
56
|
+
- lib/rails_admin_grid/engine.rb
|
57
|
+
- lib/rails_admin_grid/section.rb
|
58
|
+
- lib/rails_admin_grid/version.rb
|
59
|
+
homepage: https://github.com/colavitam/rails_admin_grid
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: A custom RailsAdmin action to display objects in a grid.
|
83
|
+
test_files: []
|