express_admin 1.7.26 → 1.7.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/express_admin/components/_image.sass +4 -0
- data/app/assets/stylesheets/express_admin/components/_label.sass +8 -0
- data/app/assets/stylesheets/express_admin/components/_smart_table.sass +3 -1
- data/app/assets/stylesheets/express_admin/screen.sass +2 -0
- data/app/assets/stylesheets/express_admin/shared/_forms.sass +1 -1
- data/app/components/express_admin/definition_list.rb +3 -14
- data/app/components/express_admin/error_message.rb +29 -0
- data/app/components/express_admin/helpers/presenters_helper.rb +68 -0
- data/app/components/express_admin/smart_table.rb +39 -50
- data/lib/express_admin/engine.rb +4 -1
- data/lib/express_admin/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/test/components/error_message_test.rb +24 -0
- data/test/dummy/test/components/smart_table_test.rb +10 -0
- metadata +9 -4
- data/config/initializers/request_store_current_user.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a10bf410c0e2d08756531f963dd722c22b328f
|
4
|
+
data.tar.gz: 15b6feeef65c8452edf48d4d9b60386556b40ebc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7d81d053ca6c36ef11dd11396fc2c2309c192278377a1f57a838d788d0fa9bcff49ad216743ca944e9be22459c24f5dc8ada0ace2f6e280d667daa72117c83a
|
7
|
+
data.tar.gz: 4c67126e638192e99a320e6bd153d0286c8952dd8e1a6289e4993c6f72efd8c2b17ecb2bc7259a8deda51c620ba185aec44d9aff823ce7fce1ee503429ffac41
|
@@ -3,10 +3,7 @@ module ExpressAdmin
|
|
3
3
|
module Presenters
|
4
4
|
class DefinitionList < ExpressTemplates::Components::Configurable
|
5
5
|
include ExpressTemplates::Components::Capabilities::Resourceful
|
6
|
-
|
7
|
-
COLUMN_REGEX_LIST = {
|
8
|
-
in_words: /(\w+)_in_words/
|
9
|
-
}
|
6
|
+
include ExpressAdmin::Components::Presenters::Helper
|
10
7
|
|
11
8
|
tag :dl
|
12
9
|
|
@@ -36,16 +33,8 @@ module ExpressAdmin
|
|
36
33
|
def definitions_from_hash(hash)
|
37
34
|
processed = hash.map do |k,v|
|
38
35
|
value =
|
39
|
-
if
|
40
|
-
|
41
|
-
if resource.send(attrib) < DateTime.now
|
42
|
-
"#{helpers.time_ago_in_words(resource.send(attrib))} ago"
|
43
|
-
else
|
44
|
-
"in #{helpers.time_ago_in_words(resource.send(attrib))}"
|
45
|
-
end
|
46
|
-
else
|
47
|
-
'never'
|
48
|
-
end
|
36
|
+
if words?(v)
|
37
|
+
make_in_words(resource, v)
|
49
38
|
elsif v.kind_of? Symbol
|
50
39
|
resource.send(v)
|
51
40
|
elsif v.respond_to?(:call)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ExpressAdmin
|
2
|
+
class ErrorMessage < ExpressTemplates::Components::Configurable
|
3
|
+
|
4
|
+
has_option :display, 'Display the error message, by default it is hidden', type: :boolean, default: false
|
5
|
+
has_option :title, 'Title of the error message component', type: :string
|
6
|
+
has_option :messages, 'List of error messages', type: :array
|
7
|
+
has_option :status, type: :string
|
8
|
+
|
9
|
+
contains -> {
|
10
|
+
if config[:display]
|
11
|
+
div(class: "card #{config[:status]}") {
|
12
|
+
div(class: 'card-divider') {
|
13
|
+
strong {
|
14
|
+
text_node config[:title]
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
div(class: 'card-section') {
|
19
|
+
ul {
|
20
|
+
config[:messages].each do |message|
|
21
|
+
li { text_node message }
|
22
|
+
end
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module ExpressAdmin
|
2
|
+
module Components
|
3
|
+
module Presenters
|
4
|
+
module Helper
|
5
|
+
COLUMN_REGEX_LIST = {
|
6
|
+
link: /(\w+)_link$/,
|
7
|
+
checkmark: /(\w+)_checkmark/,
|
8
|
+
in_words: /(\w+)_in_words/
|
9
|
+
}
|
10
|
+
|
11
|
+
def link(accessor)
|
12
|
+
accessor_match(accessor, COLUMN_REGEX_LIST[:link])
|
13
|
+
end
|
14
|
+
|
15
|
+
def checkmark(accessor)
|
16
|
+
accessor_match(accessor, COLUMN_REGEX_LIST[:checkmark])
|
17
|
+
end
|
18
|
+
|
19
|
+
def words(accessor)
|
20
|
+
accessor_match(accessor, COLUMN_REGEX_LIST[:in_words])
|
21
|
+
end
|
22
|
+
|
23
|
+
def accessor_match(accessor, regex)
|
24
|
+
accessor.to_s.match(regex).try(:[], 1)
|
25
|
+
end
|
26
|
+
|
27
|
+
def link?(accessor)
|
28
|
+
link(accessor).present?
|
29
|
+
end
|
30
|
+
|
31
|
+
def checkmark?(accessor)
|
32
|
+
checkmark(accessor).present?
|
33
|
+
end
|
34
|
+
|
35
|
+
def words?(accessor)
|
36
|
+
words(accessor).present?
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_link(item, accessor)
|
40
|
+
# TODO: only works with non-namespaced routes
|
41
|
+
attrib = link(accessor)
|
42
|
+
if item.send(attrib).present?
|
43
|
+
helpers.link_to item.send(attrib), resource_path(item)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def make_checkmark(item, accessor)
|
48
|
+
attrib = checkmark(accessor)
|
49
|
+
"<i class='ion-checkmark-round'></i>".html_safe if item.send(attrib)
|
50
|
+
end
|
51
|
+
|
52
|
+
def make_in_words(item, accessor)
|
53
|
+
attrib = words(accessor)
|
54
|
+
if item.send(attrib)
|
55
|
+
if item.send(attrib) < DateTime.now
|
56
|
+
"#{helpers.time_ago_in_words(item.send(attrib))} ago"
|
57
|
+
else
|
58
|
+
"in #{helpers.time_ago_in_words(item.send(attrib))}"
|
59
|
+
end
|
60
|
+
else
|
61
|
+
'never'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -3,21 +3,18 @@ module ExpressAdmin
|
|
3
3
|
module Presenters
|
4
4
|
class SmartTable < ExpressTemplates::Components::Configurable
|
5
5
|
include ExpressTemplates::Components::Capabilities::Resourceful
|
6
|
+
include ExpressAdmin::Components::Presenters::Helper
|
6
7
|
|
7
8
|
tag :div
|
8
9
|
|
9
10
|
MAX_COLS_TO_SHOW_IDX = 5
|
10
11
|
MAX_ROWS_TO_SHOW_IDX = 10
|
11
|
-
COLUMN_REGEX_LIST = {
|
12
|
-
link: /(\w+)_link$/,
|
13
|
-
checkmark: /(\w+)_checkmark/,
|
14
|
-
in_words: /(\w+)_in_words/
|
15
|
-
}
|
16
12
|
|
17
13
|
attr :columns
|
18
14
|
|
19
15
|
has_option :scrollable, 'Set to true if the table should be scrollable', type: :boolean, default: false
|
20
16
|
has_option :show_actions, 'Set to true if table has actions for each row'
|
17
|
+
has_option :show_search, 'Show search form of smart table, it is true by default', type: :boolean, default: true
|
21
18
|
has_option :search_action, 'The search form action containing the resource path or url.'
|
22
19
|
has_option :row_class, 'Add a class to each table row'
|
23
20
|
|
@@ -47,13 +44,18 @@ module ExpressAdmin
|
|
47
44
|
has_option :pagination, 'Add pagination to the bottom of the table', type: :string, default: 'bottom'
|
48
45
|
|
49
46
|
contains -> {
|
47
|
+
|
50
48
|
pagination if config[:pagination] == 'top'
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
|
50
|
+
if config[:show_search]
|
51
|
+
express_form(config[:id], method: :get, action: config[:search_action]) {
|
52
|
+
span(class: 'inline-label') {
|
53
|
+
input type: 'text', name: 'search_string', placeholder: 'Type here...', value: helpers.params[:search_string]
|
54
|
+
submit class: 'button search', value: 'Search'
|
55
|
+
}
|
55
56
|
}
|
56
|
-
|
57
|
+
end
|
58
|
+
|
57
59
|
table(class: table_classes) {
|
58
60
|
thead {
|
59
61
|
tr {
|
@@ -182,41 +184,31 @@ module ExpressAdmin
|
|
182
184
|
end
|
183
185
|
|
184
186
|
def cell_value(item, accessor)
|
185
|
-
value =
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
reflection = resource_class.reflect_on_association(relation_name.to_sym)
|
211
|
-
end
|
212
|
-
|
213
|
-
if reflection
|
214
|
-
relation = item.send(relation_name)
|
215
|
-
relation.try(:name) || relation.to_s
|
216
|
-
else
|
217
|
-
item.send(accessor)
|
218
|
-
end
|
219
|
-
end
|
187
|
+
value =
|
188
|
+
if accessor.respond_to?(:call)
|
189
|
+
begin
|
190
|
+
accessor.call(item).to_s.html_safe
|
191
|
+
rescue
|
192
|
+
'Error: '+$!.to_s
|
193
|
+
end
|
194
|
+
elsif link?(accessor)
|
195
|
+
make_link(item, accessor)
|
196
|
+
elsif checkmark?(accessor)
|
197
|
+
make_checkmark(item, accessor)
|
198
|
+
elsif words?(accessor)
|
199
|
+
make_in_words(item, accessor)
|
200
|
+
else
|
201
|
+
if relation_name = accessor.to_s.match(/(.*)_id$/).try(:[], 1)
|
202
|
+
reflection = resource_class.reflect_on_association(relation_name.to_sym)
|
203
|
+
end
|
204
|
+
|
205
|
+
if reflection
|
206
|
+
relation = item.send(relation_name)
|
207
|
+
relation.try(:name) || relation.to_s
|
208
|
+
else
|
209
|
+
item.send(accessor)
|
210
|
+
end
|
211
|
+
end
|
220
212
|
current_arbre_element.add_child value
|
221
213
|
end
|
222
214
|
|
@@ -229,6 +221,7 @@ module ExpressAdmin
|
|
229
221
|
end
|
230
222
|
|
231
223
|
class Column
|
224
|
+
include ExpressAdmin::Components::Presenters::Helper
|
232
225
|
attr :name, :title, :accessor, :table_column
|
233
226
|
def initialize(accessor, title = nil)
|
234
227
|
@name = accessor.kind_of?(Symbol) ? accessor.to_s.underscore : title.titleize.gsub(/\s+/,'').underscore
|
@@ -240,14 +233,10 @@ module ExpressAdmin
|
|
240
233
|
def table_column
|
241
234
|
if accessor.kind_of?(Symbol)
|
242
235
|
COLUMN_REGEX_LIST.map do |key, value|
|
243
|
-
accessor_match(COLUMN_REGEX_LIST[key])
|
236
|
+
accessor_match(accessor, COLUMN_REGEX_LIST[key])
|
244
237
|
end.compact.first
|
245
238
|
end
|
246
239
|
end
|
247
|
-
|
248
|
-
def accessor_match(regex)
|
249
|
-
accessor.to_s.match(regex).try(:[], 1)
|
250
|
-
end
|
251
240
|
end
|
252
241
|
|
253
242
|
def specified_columns?
|
data/lib/express_admin/engine.rb
CHANGED
@@ -15,8 +15,11 @@ require 'responders'
|
|
15
15
|
require 'tinymce-rails'
|
16
16
|
require 'textacular'
|
17
17
|
|
18
|
-
|
18
|
+
# helpers for the components
|
19
|
+
helpers = Dir.glob(File.join(File.dirname(__FILE__), '..', '..', 'app', 'components', 'express_admin', 'helpers', '*.rb'))
|
20
|
+
helpers.each {|helper| require helper }
|
19
21
|
|
22
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'app', 'components', 'express_admin', 'definition_list')
|
20
23
|
# should be a way to add this folder to rails' autoload paths
|
21
24
|
components = Dir.glob(File.join(File.dirname(__FILE__), '..', '..', 'app', 'components', '**', '*.rb'))
|
22
25
|
components.sort!
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
module Components
|
5
|
+
class ErrorMessageTest < ActiveSupport::TestCase
|
6
|
+
def render_error_message
|
7
|
+
arbre {
|
8
|
+
error_message(
|
9
|
+
display: true,
|
10
|
+
title: 'Sample Title',
|
11
|
+
messages: ["An error message", "Another error message"],
|
12
|
+
status: 'alert'
|
13
|
+
)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
test "render error message" do
|
18
|
+
assert_match '<strong>Sample Title</strong>', render_error_message
|
19
|
+
assert_match '<div class="card alert">', render_error_message
|
20
|
+
assert_match '<li>An error message</li>', render_error_message
|
21
|
+
assert_match '<li>Another error message</li>', render_error_message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -109,6 +109,16 @@ module Components
|
|
109
109
|
assert_match /class="created_at.*less than a minute ago/, fragment
|
110
110
|
end
|
111
111
|
|
112
|
+
test 'set show_search to false to hide the search form' do
|
113
|
+
fragment = arbre(widget: Widget.first, widgets: Widget.all){
|
114
|
+
smart_table(:widgets, show_search: false, columns: {
|
115
|
+
'Created' => :created_at_in_words
|
116
|
+
})
|
117
|
+
}
|
118
|
+
|
119
|
+
assert_no_match '<input type="submit" name="commit" value="Search" class="button search">', fragment
|
120
|
+
end
|
121
|
+
|
112
122
|
test 'assign column to be sortable which generates a header link' do
|
113
123
|
fragment = arbre(widget: Widget.first, widgets: Widget.all){
|
114
124
|
smart_table(:widgets,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: express_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Talcott Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: express_templates
|
@@ -400,6 +400,8 @@ files:
|
|
400
400
|
- app/assets/stylesheets/express_admin/components/_definition.sass
|
401
401
|
- app/assets/stylesheets/express_admin/components/_empty_state.sass
|
402
402
|
- app/assets/stylesheets/express_admin/components/_h_box.sass
|
403
|
+
- app/assets/stylesheets/express_admin/components/_image.sass
|
404
|
+
- app/assets/stylesheets/express_admin/components/_label.sass
|
403
405
|
- app/assets/stylesheets/express_admin/components/_main_menu.sass
|
404
406
|
- app/assets/stylesheets/express_admin/components/_module_sidebar.sass
|
405
407
|
- app/assets/stylesheets/express_admin/components/_oauth_sign_in_links.sass
|
@@ -441,8 +443,10 @@ files:
|
|
441
443
|
- app/components/express_admin/country_select.rb
|
442
444
|
- app/components/express_admin/definition_list.rb
|
443
445
|
- app/components/express_admin/definition_table.rb
|
446
|
+
- app/components/express_admin/error_message.rb
|
444
447
|
- app/components/express_admin/file_upload.rb
|
445
448
|
- app/components/express_admin/flash_messages.rb
|
449
|
+
- app/components/express_admin/helpers/presenters_helper.rb
|
446
450
|
- app/components/express_admin/icon.rb
|
447
451
|
- app/components/express_admin/icon_link.rb
|
448
452
|
- app/components/express_admin/layout_component.rb
|
@@ -477,7 +481,6 @@ files:
|
|
477
481
|
- config/initializers/gravatar_image_tag.rb
|
478
482
|
- config/initializers/kaminari.rb
|
479
483
|
- config/initializers/postgresql_trigram.rb
|
480
|
-
- config/initializers/request_store_current_user.rb
|
481
484
|
- config/initializers/tinymce-rails.rb
|
482
485
|
- config/tinymce.yml
|
483
486
|
- db/migrate/20150928044202_install_trigram.rb
|
@@ -576,6 +579,7 @@ files:
|
|
576
579
|
- test/dummy/test/components/country_select_test.rb
|
577
580
|
- test/dummy/test/components/definition_list_test.rb
|
578
581
|
- test/dummy/test/components/definition_table_test.rb
|
582
|
+
- test/dummy/test/components/error_message_test.rb
|
579
583
|
- test/dummy/test/components/flash_messages_test.rb
|
580
584
|
- test/dummy/test/components/icon_link_test.rb
|
581
585
|
- test/dummy/test/components/icon_test.rb
|
@@ -643,7 +647,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
643
647
|
version: '0'
|
644
648
|
requirements: []
|
645
649
|
rubyforge_project:
|
646
|
-
rubygems_version: 2.
|
650
|
+
rubygems_version: 2.5.1
|
647
651
|
signing_key:
|
648
652
|
specification_version: 4
|
649
653
|
summary: ExpressAdmin provides an admin menu framework based on Foundation.
|
@@ -717,6 +721,7 @@ test_files:
|
|
717
721
|
- test/dummy/test/components/country_select_test.rb
|
718
722
|
- test/dummy/test/components/definition_list_test.rb
|
719
723
|
- test/dummy/test/components/definition_table_test.rb
|
724
|
+
- test/dummy/test/components/error_message_test.rb
|
720
725
|
- test/dummy/test/components/flash_messages_test.rb
|
721
726
|
- test/dummy/test/components/icon_link_test.rb
|
722
727
|
- test/dummy/test/components/icon_test.rb
|