trestle 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/trestle/_confirmation.js +23 -0
- data/app/assets/javascripts/trestle/_datepicker.js +22 -0
- data/app/assets/javascripts/trestle/_errors.js +11 -0
- data/app/assets/javascripts/trestle/_form.js +6 -0
- data/app/assets/javascripts/trestle/_gallery.js +27 -0
- data/app/assets/javascripts/trestle/_select.js +11 -0
- data/app/assets/javascripts/trestle/_sidebar.js +52 -0
- data/app/assets/javascripts/trestle/_table.js +21 -0
- data/app/assets/javascripts/trestle/_tabs.js +13 -0
- data/app/assets/javascripts/trestle/_tooltips.js +3 -0
- data/app/assets/javascripts/trestle/admin.js +23 -0
- data/app/assets/javascripts/trestle/custom.js +4 -0
- data/app/assets/stylesheets/trestle/components/_table.scss +6 -0
- data/app/helpers/trestle/form_helper.rb +1 -1
- data/app/helpers/trestle/format_helper.rb +48 -0
- data/app/helpers/trestle/url_helper.rb +2 -8
- data/app/views/layouts/trestle/admin.html.erb +3 -3
- data/app/views/trestle/admin/index.html.erb +1 -1
- data/app/views/trestle/dashboard/index.html.erb +2 -2
- data/app/views/trestle/resource/_form.html.erb +1 -1
- data/app/views/trestle/resource/edit.html.erb +2 -2
- data/app/views/trestle/resource/index.html.erb +1 -1
- data/app/views/trestle/resource/new.html.erb +1 -1
- data/app/views/trestle/resource/show.html.erb +2 -2
- data/app/views/trestle/shared/_sidebar.html.erb +4 -2
- data/bower.json +1 -1
- data/config/locales/en.yml +16 -2
- data/lib/generators/trestle/install/install_generator.rb +3 -3
- data/lib/generators/trestle/install/templates/custom.js +7 -0
- data/lib/generators/trestle/install/templates/trestle.rb.erb +3 -2
- data/lib/trestle/adapters.rb +7 -64
- data/lib/trestle/adapters/active_record_adapter.rb +46 -20
- data/lib/trestle/adapters/adapter.rb +176 -0
- data/lib/trestle/adapters/sequel_adapter.rb +85 -0
- data/lib/trestle/admin.rb +1 -1
- data/lib/trestle/attribute.rb +14 -37
- data/lib/trestle/breadcrumb.rb +6 -0
- data/lib/trestle/configuration.rb +1 -1
- data/lib/trestle/form/automatic.rb +29 -21
- data/lib/trestle/form/builder.rb +4 -0
- data/lib/trestle/form/field.rb +2 -2
- data/lib/trestle/form/fields/check_box.rb +1 -1
- data/lib/trestle/form/fields/collection_select.rb +1 -1
- data/lib/trestle/form/fields/date_select.rb +1 -1
- data/lib/trestle/form/fields/datetime_select.rb +1 -1
- data/lib/trestle/form/fields/grouped_collection_select.rb +1 -1
- data/lib/trestle/form/fields/select.rb +2 -2
- data/lib/trestle/form/fields/tag_select.rb +1 -2
- data/lib/trestle/form/fields/time_select.rb +1 -1
- data/lib/trestle/form/fields/time_zone_select.rb +1 -1
- data/lib/trestle/resource.rb +11 -7
- data/lib/trestle/resource/builder.rb +2 -1
- data/lib/trestle/resource/controller.rb +61 -17
- data/lib/trestle/scope.rb +1 -1
- data/lib/trestle/table/automatic.rb +5 -11
- data/lib/trestle/table/builder.rb +1 -0
- data/lib/trestle/table/column.rb +24 -43
- data/lib/trestle/version.rb +1 -1
- data/trestle.gemspec +3 -4
- data/vendor/assets/bower_components/trestle/flatpickr/dist/flatpickr.css +51 -26
- data/vendor/assets/bower_components/trestle/flatpickr/dist/flatpickr.js +349 -299
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ar.js +5 -5
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/bg.js +5 -5
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/bn.js +5 -5
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/cat.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/cs.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/cy.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/da.js +6 -6
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/de.js +10 -10
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/eo.js +11 -11
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/es.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/et.js +11 -11
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/fa.js +6 -6
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/fi.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/fr.js +11 -11
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/gr.js +13 -13
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/he.js +5 -5
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/hi.js +5 -5
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/hr.js +6 -6
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/hu.js +10 -10
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/id.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/index.js +97 -0
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/it.js +10 -10
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ja.js +5 -5
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ko.js +6 -6
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/lt.js +10 -10
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/lv.js +6 -6
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/mk.js +8 -8
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ms.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/my.js +7 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/nl.js +11 -11
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/no.js +11 -11
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/pa.js +5 -5
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/pl.js +6 -6
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/pt.js +6 -8
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ro.js +7 -9
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ru.js +6 -8
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/si.js +5 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sk.js +8 -8
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sl.js +8 -10
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sq.js +5 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sr.js +9 -10
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sv.js +8 -10
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/th.js +10 -11
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/tr.js +6 -8
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/uk.js +6 -7
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/vn.js +6 -8
- data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/zh.js +9 -11
- metadata +24 -34
- data/app/assets/javascripts/trestle/_confirmation.js.coffee +0 -18
- data/app/assets/javascripts/trestle/_datepicker.js.coffee +0 -18
- data/app/assets/javascripts/trestle/_errors.js.coffee +0 -8
- data/app/assets/javascripts/trestle/_form.js.coffee +0 -4
- data/app/assets/javascripts/trestle/_gallery.js.coffee +0 -21
- data/app/assets/javascripts/trestle/_select.js.coffee +0 -7
- data/app/assets/javascripts/trestle/_sidebar.js.coffee +0 -45
- data/app/assets/javascripts/trestle/_table.js.coffee +0 -16
- data/app/assets/javascripts/trestle/_tabs.js.coffee +0 -9
- data/app/assets/javascripts/trestle/_tooltips.js.coffee +0 -2
- data/app/assets/javascripts/trestle/admin.js.coffee +0 -22
- data/app/assets/javascripts/trestle/custom.js.coffee +0 -4
- data/lib/generators/trestle/install/templates/custom.js.coffee +0 -7
data/lib/trestle/admin.rb
CHANGED
data/lib/trestle/attribute.rb
CHANGED
@@ -1,53 +1,30 @@
|
|
1
1
|
module Trestle
|
2
2
|
class Attribute
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :name, :type, :options
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(name, type, options={})
|
6
|
+
@name, @type, @options = name.to_sym, type, options
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def boolean?
|
14
|
-
type == :boolean
|
15
|
-
end
|
16
|
-
|
17
|
-
def text?
|
18
|
-
type == :text
|
19
|
-
end
|
20
|
-
|
21
|
-
def datetime?
|
22
|
-
[:datetime, :time, :date].include?(type)
|
23
|
-
end
|
24
|
-
|
25
|
-
def primary_key?
|
26
|
-
name.to_s == admin.model.primary_key
|
27
|
-
end
|
28
|
-
|
29
|
-
def inheritance_column?
|
30
|
-
name.to_s == admin.model.inheritance_column
|
31
|
-
end
|
32
|
-
|
33
|
-
def counter_cache?
|
34
|
-
name.to_s.end_with?("_count")
|
9
|
+
def array?
|
10
|
+
options[:array] == true
|
35
11
|
end
|
36
12
|
|
37
13
|
class Association < Attribute
|
38
|
-
|
39
|
-
|
40
|
-
def initialize(admin, name, association_class)
|
41
|
-
super(admin, name, :association)
|
42
|
-
@association_class = association_class
|
14
|
+
def initialize(name, options={})
|
15
|
+
super(name, :association, options)
|
43
16
|
end
|
44
17
|
|
45
18
|
def association_name
|
46
|
-
name.to_s.sub(/_id$/, "")
|
19
|
+
options[:name] || name.to_s.sub(/_id$/, "")
|
20
|
+
end
|
21
|
+
|
22
|
+
def association_class
|
23
|
+
options[:class].respond_to?(:call) ? options[:class].call : options[:class]
|
47
24
|
end
|
48
25
|
|
49
|
-
def
|
50
|
-
|
26
|
+
def polymorphic?
|
27
|
+
options[:polymorphic] == true
|
51
28
|
end
|
52
29
|
end
|
53
30
|
end
|
data/lib/trestle/breadcrumb.rb
CHANGED
@@ -11,10 +11,16 @@ module Trestle
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Trail
|
14
|
+
include Enumerable
|
15
|
+
|
14
16
|
def initialize(breadcrumbs=[])
|
15
17
|
@breadcrumbs = Array(breadcrumbs)
|
16
18
|
end
|
17
19
|
|
20
|
+
def ==(other)
|
21
|
+
to_a == other.to_a
|
22
|
+
end
|
23
|
+
|
18
24
|
def dup
|
19
25
|
self.class.new(@breadcrumbs.dup)
|
20
26
|
end
|
@@ -67,7 +67,7 @@ module Trestle
|
|
67
67
|
option :display_methods, [:display_name, :full_name, :name, :title, :username, :login, :email, :to_s]
|
68
68
|
|
69
69
|
# Default adapter class used by all admin resources
|
70
|
-
option :default_adapter, Adapters
|
70
|
+
option :default_adapter, Adapters.compose(Adapters::ActiveRecordAdapter, Adapters::DraperAdapter)
|
71
71
|
|
72
72
|
# Register a custom form field class
|
73
73
|
def form_field(name, klass)
|
@@ -2,28 +2,36 @@ module Trestle
|
|
2
2
|
class Form
|
3
3
|
class Automatic < Form
|
4
4
|
def initialize(admin)
|
5
|
-
@block = Proc.new do
|
6
|
-
admin.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
case attribute.type
|
12
|
-
when :association
|
13
|
-
options = attribute.association_class.all.map { |instance| [display(instance), instance.id] }
|
14
|
-
prompt = "- Select #{admin.model.human_attribute_name(attribute.association_name)} -"
|
15
|
-
|
16
|
-
select attribute.name, options, include_blank: prompt
|
17
|
-
when :text
|
18
|
-
text_area attribute.name
|
19
|
-
when :date
|
20
|
-
date_field attribute.name
|
21
|
-
when :datetime
|
22
|
-
datetime_field attribute.name
|
23
|
-
when :boolean
|
24
|
-
check_box attribute.name
|
5
|
+
@block = Proc.new do |instance|
|
6
|
+
admin.default_form_attributes.each do |attribute|
|
7
|
+
if attribute.array?
|
8
|
+
if [:string, :text].include?(attribute.type)
|
9
|
+
select attribute.name, nil, {}, { multiple: true, data: { tags: true, select_on_close: true }}
|
10
|
+
end
|
25
11
|
else
|
26
|
-
|
12
|
+
case attribute.type
|
13
|
+
when :association
|
14
|
+
if attribute.polymorphic?
|
15
|
+
static_field attribute.name do
|
16
|
+
associated_instance = instance.public_send(attribute.association_name)
|
17
|
+
admin_link_to format_value(associated_instance), associated_instance
|
18
|
+
end
|
19
|
+
else
|
20
|
+
prompt = I18n.t("admin.form.select.prompt", default: "- Select %{attribute_name} -", attribute_name: admin.human_attribute_name(attribute.association_name))
|
21
|
+
|
22
|
+
select attribute.name, attribute.association_class.all, include_blank: prompt
|
23
|
+
end
|
24
|
+
when :text
|
25
|
+
text_area attribute.name
|
26
|
+
when :date
|
27
|
+
date_field attribute.name
|
28
|
+
when :datetime
|
29
|
+
datetime_field attribute.name
|
30
|
+
when :boolean
|
31
|
+
check_box attribute.name
|
32
|
+
else
|
33
|
+
text_field attribute.name
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
data/lib/trestle/form/builder.rb
CHANGED
data/lib/trestle/form/field.rb
CHANGED
@@ -13,8 +13,8 @@ module Trestle
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def errors
|
16
|
-
errors = builder.
|
17
|
-
errors += builder.
|
16
|
+
errors = builder.errors(name)
|
17
|
+
errors += builder.errors(name.to_s.sub(/_id$/, '')) if name.to_s =~ /_id$/
|
18
18
|
errors
|
19
19
|
end
|
20
20
|
|
@@ -20,7 +20,7 @@ module Trestle
|
|
20
20
|
content_tag(:label) do
|
21
21
|
safe_join([
|
22
22
|
builder.raw_check_box(name, options, checked_value, unchecked_value),
|
23
|
-
options[:label] || admin.
|
23
|
+
options[:label] || admin.human_attribute_name(name)
|
24
24
|
], " ")
|
25
25
|
end
|
26
26
|
end
|
@@ -7,7 +7,7 @@ module Trestle
|
|
7
7
|
def initialize(builder, template, name, choices=nil, options={}, html_options={}, &block)
|
8
8
|
super(builder, template, name, options, &block)
|
9
9
|
|
10
|
-
@choices = Choices.new(choices)
|
10
|
+
@choices = Choices.new(choices || builder.object.send(name))
|
11
11
|
@html_options = default_html_options.merge(html_options)
|
12
12
|
end
|
13
13
|
|
@@ -16,7 +16,7 @@ module Trestle
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def default_html_options
|
19
|
-
Trestle::Options.new(class: ["form-control"])
|
19
|
+
Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
|
20
20
|
end
|
21
21
|
|
22
22
|
# Allows an array of model instances (or a scope) to be
|
@@ -3,8 +3,7 @@ module Trestle
|
|
3
3
|
module Fields
|
4
4
|
class TagSelect < Select
|
5
5
|
def initialize(builder, template, name, options={}, html_options={})
|
6
|
-
|
7
|
-
super(builder, template, name, choices, options, html_options)
|
6
|
+
super(builder, template, name, nil, options, html_options)
|
8
7
|
end
|
9
8
|
|
10
9
|
def default_html_options
|
data/lib/trestle/resource.rb
CHANGED
@@ -39,10 +39,12 @@ module Trestle
|
|
39
39
|
adapter_method :decorate_collection
|
40
40
|
adapter_method :unscope
|
41
41
|
adapter_method :merge_scopes
|
42
|
+
adapter_method :count
|
42
43
|
adapter_method :sort
|
43
44
|
adapter_method :paginate
|
44
|
-
adapter_method :
|
45
|
-
adapter_method :
|
45
|
+
adapter_method :human_attribute_name
|
46
|
+
adapter_method :default_table_attributes
|
47
|
+
adapter_method :default_form_attributes
|
46
48
|
|
47
49
|
attr_accessor :decorator
|
48
50
|
|
@@ -95,9 +97,7 @@ module Trestle
|
|
95
97
|
return collection unless params[:sort]
|
96
98
|
|
97
99
|
field = params[:sort].to_sym
|
98
|
-
|
99
|
-
order = params[:order].downcase
|
100
|
-
order = "asc" unless %w(asc desc).include?(order)
|
100
|
+
order = params[:order].to_s.downcase == "desc" ? :desc : :asc
|
101
101
|
|
102
102
|
if column_sorts.has_key?(field)
|
103
103
|
instance_exec(collection, order, &column_sorts[field])
|
@@ -152,8 +152,12 @@ module Trestle
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def default_model_name
|
155
|
-
|
156
|
-
|
155
|
+
if model.respond_to?(:model_name)
|
156
|
+
model_name = model.model_name
|
157
|
+
model_name.respond_to?(:human) ? model_name.human : model_name.to_s.titleize
|
158
|
+
else
|
159
|
+
model.name.titleize
|
160
|
+
end
|
157
161
|
end
|
158
162
|
end
|
159
163
|
end
|
@@ -3,26 +3,52 @@ module Trestle
|
|
3
3
|
class Controller < Admin::Controller
|
4
4
|
def index
|
5
5
|
self.collection = admin.prepare_collection(params)
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html
|
9
|
+
format.json { render json: collection }
|
10
|
+
end
|
6
11
|
end
|
7
12
|
|
8
13
|
def new
|
9
|
-
self.instance = admin.build_instance
|
14
|
+
self.instance = admin.build_instance({}, params)
|
15
|
+
|
16
|
+
respond_to do |format|
|
17
|
+
format.html
|
18
|
+
format.json { render json: instance }
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
def create
|
13
|
-
self.instance = admin.build_instance(admin.permitted_params(params))
|
23
|
+
self.instance = admin.build_instance(admin.permitted_params(params), params)
|
14
24
|
|
15
25
|
if admin.save_instance(instance)
|
16
|
-
|
17
|
-
|
26
|
+
respond_to do |format|
|
27
|
+
format.html do
|
28
|
+
flash[:message] = flash_message("success.create", default: "The %{model_name} was successfully created.")
|
29
|
+
redirect_to action: :show, id: admin.to_param(instance)
|
30
|
+
end
|
31
|
+
format.json { render json: instance, status: :created, location: { action: :show, id: admin.to_param(instance) } }
|
32
|
+
format.js
|
33
|
+
end
|
18
34
|
else
|
19
|
-
|
20
|
-
|
35
|
+
respond_to do |format|
|
36
|
+
format.html do
|
37
|
+
flash.now[:error] = flash_message("failure.create", default: "Please correct the errors below.")
|
38
|
+
render "new"
|
39
|
+
end
|
40
|
+
format.json { render json: instance.errors, status: :unprocessable_entity }
|
41
|
+
end
|
21
42
|
end
|
22
43
|
end
|
23
44
|
|
24
45
|
def show
|
25
46
|
self.instance = admin.find_instance(params)
|
47
|
+
|
48
|
+
respond_to do |format|
|
49
|
+
format.html
|
50
|
+
format.json { render json: instance }
|
51
|
+
end
|
26
52
|
end
|
27
53
|
|
28
54
|
def edit
|
@@ -31,27 +57,45 @@ module Trestle
|
|
31
57
|
|
32
58
|
def update
|
33
59
|
self.instance = admin.find_instance(params)
|
34
|
-
admin.update_instance(instance, admin.permitted_params(params))
|
60
|
+
admin.update_instance(instance, admin.permitted_params(params), params)
|
35
61
|
|
36
62
|
if admin.save_instance(instance)
|
37
|
-
|
38
|
-
|
63
|
+
respond_to do |format|
|
64
|
+
format.html do
|
65
|
+
flash[:message] = flash_message("success.update", default: "The %{model_name} was successfully updated.")
|
66
|
+
redirect_to action: :show, id: admin.to_param(instance)
|
67
|
+
end
|
68
|
+
format.json { render json: instance, status: :ok }
|
69
|
+
format.js
|
70
|
+
end
|
39
71
|
else
|
40
|
-
|
41
|
-
|
72
|
+
respond_to do |format|
|
73
|
+
format.html do
|
74
|
+
flash.now[:error] = flash_message("failure.update", default: "Please correct the errors below.")
|
75
|
+
render "show"
|
76
|
+
end
|
77
|
+
format.json { render json: instance.errors, status: :unprocessable_entity }
|
78
|
+
end
|
42
79
|
end
|
43
80
|
end
|
44
81
|
|
45
82
|
def destroy
|
46
83
|
self.instance = admin.find_instance(params)
|
84
|
+
success = admin.delete_instance(instance)
|
47
85
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
86
|
+
respond_to do |format|
|
87
|
+
format.html do
|
88
|
+
if success
|
89
|
+
flash[:message] = flash_message("success.destroy", default: "The %{model_name} was successfully deleted.")
|
90
|
+
else
|
91
|
+
flash[:message] = flash_message("failure.destroy", default: "Could not delete %{model_name}.")
|
92
|
+
end
|
53
93
|
|
54
|
-
|
94
|
+
redirect_to action: :index
|
95
|
+
end
|
96
|
+
format.json { head :no_content }
|
97
|
+
format.js
|
98
|
+
end
|
55
99
|
end
|
56
100
|
|
57
101
|
protected
|