typus-rails4 4.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +488 -0
- data/Gemfile +57 -0
- data/Gemfile.lock +253 -0
- data/MIT-LICENSE +20 -0
- data/README.md +101 -0
- data/Rakefile +51 -0
- data/app/assets/javascripts/typus/application.js +11 -0
- data/app/assets/javascripts/typus/custom.js +2 -0
- data/app/assets/javascripts/typus/jquery-2.1.1.min.js +4 -0
- data/app/assets/javascripts/typus/jquery.application.js +30 -0
- data/app/assets/stylesheets/typus/application.css +6 -0
- data/app/assets/stylesheets/typus/custom.scss +4 -0
- data/app/assets/stylesheets/typus/overrides.scss +10 -0
- data/app/assets/stylesheets/typus/signin.scss +45 -0
- data/app/controllers/admin/account_controller.rb +47 -0
- data/app/controllers/admin/base_controller.rb +40 -0
- data/app/controllers/admin/dashboard_controller.rb +6 -0
- data/app/controllers/admin/resource_controller.rb +8 -0
- data/app/controllers/admin/resources_controller.rb +268 -0
- data/app/controllers/admin/session_controller.rb +43 -0
- data/app/controllers/concerns/admin/actions.rb +88 -0
- data/app/controllers/concerns/admin/acts_as_list.rb +35 -0
- data/app/controllers/concerns/admin/ancestry.rb +26 -0
- data/app/controllers/concerns/admin/autocomplete.rb +11 -0
- data/app/controllers/concerns/admin/bulk.rb +76 -0
- data/app/controllers/concerns/admin/featured_image.rb +22 -0
- data/app/controllers/concerns/admin/filters.rb +57 -0
- data/app/controllers/concerns/admin/format.rb +49 -0
- data/app/controllers/concerns/admin/headless.rb +23 -0
- data/app/controllers/concerns/admin/hooks.rb +4 -0
- data/app/controllers/concerns/admin/multisite.rb +10 -0
- data/app/controllers/concerns/admin/navigation.rb +27 -0
- data/app/controllers/concerns/admin/trash.rb +65 -0
- data/app/helpers/admin/base_helper.rb +78 -0
- data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +88 -0
- data/app/helpers/admin/resources/data_types/boolean_helper.rb +33 -0
- data/app/helpers/admin/resources/data_types/date_helper.rb +16 -0
- data/app/helpers/admin/resources/data_types/datetime_helper.rb +19 -0
- data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +49 -0
- data/app/helpers/admin/resources/data_types/float_helper.rb +2 -0
- data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +59 -0
- data/app/helpers/admin/resources/data_types/has_many_helper.rb +76 -0
- data/app/helpers/admin/resources/data_types/has_one_helper.rb +44 -0
- data/app/helpers/admin/resources/data_types/integer_helper.rb +13 -0
- data/app/helpers/admin/resources/data_types/paperclip_helper.rb +49 -0
- data/app/helpers/admin/resources/data_types/selector_helper.rb +11 -0
- data/app/helpers/admin/resources/data_types/string_helper.rb +38 -0
- data/app/helpers/admin/resources/data_types/text_helper.rb +6 -0
- data/app/helpers/admin/resources/data_types/transversal_helper.rb +8 -0
- data/app/helpers/admin/resources/data_types/tree_helper.rb +28 -0
- data/app/helpers/admin/resources/display_helper.rb +27 -0
- data/app/helpers/admin/resources/filters_helper.rb +18 -0
- data/app/helpers/admin/resources/form_helper.rb +85 -0
- data/app/helpers/admin/resources/list_helper.rb +31 -0
- data/app/helpers/admin/resources/pagination_helper.rb +28 -0
- data/app/helpers/admin/resources/relationships_helper.rb +33 -0
- data/app/helpers/admin/resources/sidebar_helper.rb +34 -0
- data/app/helpers/admin/resources/table_helper.rb +69 -0
- data/app/helpers/admin/resources_helper.rb +25 -0
- data/app/mailers/admin/mailer.rb +19 -0
- data/app/views/admin/account/_form.html.erb +17 -0
- data/app/views/admin/account/forgot_password.html.erb +16 -0
- data/app/views/admin/account/new.html.erb +10 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +14 -0
- data/app/views/admin/dashboard/index.html.erb +8 -0
- data/app/views/admin/dashboard/styles.html.erb +153 -0
- data/app/views/admin/dashboard/widgets/_applications.html.erb +44 -0
- data/app/views/admin/dashboard/widgets/_default.html.erb +43 -0
- data/app/views/admin/dashboard/widgets/_models.html.erb +23 -0
- data/app/views/admin/dashboard/widgets/_models_extended.html.erb +25 -0
- data/app/views/admin/dashboard/widgets/_resources.html.erb +23 -0
- data/app/views/admin/dashboard/widgets/_users.html.erb +23 -0
- data/app/views/admin/mailer/reset_password_instructions.html.erb +7 -0
- data/app/views/admin/mailer/reset_password_instructions.text.erb +7 -0
- data/app/views/admin/resource/_sidebar.html.erb +14 -0
- data/app/views/admin/resources/_edit.html.erb +0 -0
- data/app/views/admin/resources/_form.html.erb +28 -0
- data/app/views/admin/resources/_form_javascripts.html.erb +0 -0
- data/app/views/admin/resources/_form_modal.html.erb +13 -0
- data/app/views/admin/resources/_index.html.erb +0 -0
- data/app/views/admin/resources/_new.html.erb +0 -0
- data/app/views/admin/resources/_pagination.html.erb +15 -0
- data/app/views/admin/resources/_show.html.erb +0 -0
- data/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/app/views/admin/resources/destroy.html.erb +16 -0
- data/app/views/admin/resources/edit.html.erb +22 -0
- data/app/views/admin/resources/edit/_actions.html.erb +7 -0
- data/app/views/admin/resources/edit/_recently_edited.html.erb +8 -0
- data/app/views/admin/resources/index.html.erb +29 -0
- data/app/views/admin/resources/new.html.erb +20 -0
- data/app/views/admin/resources/show.html.erb +26 -0
- data/app/views/admin/session/new.html.erb +18 -0
- data/app/views/admin/shared/_head.html.erb +24 -0
- data/app/views/admin/shared/_modals.html.erb +3 -0
- data/app/views/admin/shared/_sidebar_placeholder.html.erb +0 -0
- data/app/views/admin/templates/README.md +5 -0
- data/app/views/admin/templates/_belongs_to.html.erb +8 -0
- data/app/views/admin/templates/_boolean.html.erb +7 -0
- data/app/views/admin/templates/_date.html.erb +6 -0
- data/app/views/admin/templates/_datetime.html.erb +8 -0
- data/app/views/admin/templates/_dragonfly.html.erb +6 -0
- data/app/views/admin/templates/_dragonfly_form_preview.html.erb +21 -0
- data/app/views/admin/templates/_dragonfly_preview.html.erb +12 -0
- data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +21 -0
- data/app/views/admin/templates/_has_many.html.erb +18 -0
- data/app/views/admin/templates/_has_one.html.erb +14 -0
- data/app/views/admin/templates/_json.html.erb +11 -0
- data/app/views/admin/templates/_paperclip.html.erb +5 -0
- data/app/views/admin/templates/_paperclip_form_preview.html.erb +21 -0
- data/app/views/admin/templates/_paperclip_preview.html.erb +12 -0
- data/app/views/admin/templates/_password.html.erb +6 -0
- data/app/views/admin/templates/_position.html.erb +5 -0
- data/app/views/admin/templates/_profile_sidebar.html.erb +4 -0
- data/app/views/admin/templates/_selector.html.erb +4 -0
- data/app/views/admin/templates/_string.html.erb +4 -0
- data/app/views/admin/templates/_string_with_preview.html.erb +11 -0
- data/app/views/admin/templates/_text.html.erb +11 -0
- data/app/views/admin/templates/_text_with_ckeditor.html.erb +24 -0
- data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +38 -0
- data/app/views/admin/templates/_time.html.erb +9 -0
- data/app/views/admin/templates/_tree.html.erb +6 -0
- data/app/views/admin/templates/modals/_belongs_to.html.erb +60 -0
- data/app/views/admin/templates/modals/_dragonfly.html.erb +13 -0
- data/app/views/admin/templates/modals/_has_and_belongs_to_many.html.erb +25 -0
- data/app/views/admin/templates/modals/_has_many.html.erb +59 -0
- data/app/views/admin/templates/modals/_paperclip.html.erb +13 -0
- data/app/views/helpers/admin/base/_apps.html.erb +86 -0
- data/app/views/helpers/admin/base/_breadcrumbs.html.erb +6 -0
- data/app/views/helpers/admin/base/_flash_message.html.erb +3 -0
- data/app/views/helpers/admin/base/_login_info.html.erb +0 -0
- data/app/views/helpers/admin/dashboard/_resources.html.erb +19 -0
- data/app/views/helpers/admin/resources/_actions.html.erb +18 -0
- data/app/views/helpers/admin/resources/_errors.html.erb +12 -0
- data/app/views/helpers/admin/resources/_filters.html.erb +16 -0
- data/app/views/helpers/admin/resources/_search.html.erb +17 -0
- data/app/views/helpers/admin/resources/_sidebar.html.erb +4 -0
- data/app/views/helpers/admin/resources/_table.html.erb +45 -0
- data/app/views/helpers/admin/resources/sidebar/_item.html.erb +26 -0
- data/app/views/helpers/admin/resources/sidebar/_items.html.erb +14 -0
- data/app/views/helpers/admin/resources/sidebar/_items_index.html.erb +57 -0
- data/app/views/layouts/admin/base.html.erb +30 -0
- data/app/views/layouts/admin/headless.html.erb +1 -0
- data/app/views/layouts/admin/session.html.erb +26 -0
- data/bin/run-tests +7 -0
- data/bin/setup +9 -0
- data/config/locales/typus.en.yml +125 -0
- data/config/routes.rb +46 -0
- data/lib/generators/templates/config/initializers/typus.rb +34 -0
- data/lib/generators/templates/config/initializers/typus_authentication.rb +18 -0
- data/lib/generators/templates/config/initializers/typus_resources.rb +24 -0
- data/lib/generators/templates/config/typus/README +58 -0
- data/lib/generators/templates/config/typus/application.yml +3 -0
- data/lib/generators/templates/config/typus/application_roles.yml +4 -0
- data/lib/generators/templates/config/typus/typus.yml +15 -0
- data/lib/generators/templates/config/typus/typus_roles.yml +4 -0
- data/lib/generators/templates/controller.erb +2 -0
- data/lib/generators/templates/migration.erb +22 -0
- data/lib/generators/templates/view.html.erb +13 -0
- data/lib/generators/typus/config_generator.rb +67 -0
- data/lib/generators/typus/controller_generator.rb +26 -0
- data/lib/generators/typus/initializers_generator.rb +20 -0
- data/lib/generators/typus/migration_generator.rb +94 -0
- data/lib/generators/typus/model_generator.rb +93 -0
- data/lib/generators/typus/typus_generator.rb +54 -0
- data/lib/generators/typus/views_generator.rb +19 -0
- data/lib/support/active_record.rb +42 -0
- data/lib/support/fake_user.rb +47 -0
- data/lib/support/hash.rb +8 -0
- data/lib/support/object.rb +9 -0
- data/lib/support/string.rb +40 -0
- data/lib/tasks/typus.rake +11 -0
- data/lib/typus.rb +215 -0
- data/lib/typus/authentication/base.rb +39 -0
- data/lib/typus/authentication/devise.rb +19 -0
- data/lib/typus/authentication/http_basic.rb +18 -0
- data/lib/typus/authentication/none.rb +15 -0
- data/lib/typus/authentication/none_with_role.rb +15 -0
- data/lib/typus/authentication/session.rb +123 -0
- data/lib/typus/configuration.rb +43 -0
- data/lib/typus/engine.rb +4 -0
- data/lib/typus/orm/active_record.rb +10 -0
- data/lib/typus/orm/active_record/admin_user.rb +65 -0
- data/lib/typus/orm/active_record/class_methods.rb +104 -0
- data/lib/typus/orm/active_record/instance_methods.rb +76 -0
- data/lib/typus/orm/active_record/search.rb +43 -0
- data/lib/typus/orm/base/class_methods.rb +188 -0
- data/lib/typus/orm/base/search.rb +70 -0
- data/lib/typus/regex.rb +11 -0
- data/lib/typus/resources.rb +55 -0
- data/lib/typus/version.rb +10 -0
- data/typus.gemspec +27 -0
- data/vendor/assets/chosen/LICENSE.md +24 -0
- data/vendor/assets/chosen/chosen-sprite.png +0 -0
- data/vendor/assets/chosen/chosen-sprite@2x.png +0 -0
- data/vendor/assets/chosen/chosen.jquery.js +1239 -0
- data/vendor/assets/chosen/chosen.scss +437 -0
- metadata +271 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
module Typus
|
2
|
+
module Orm
|
3
|
+
module ActiveRecord
|
4
|
+
module InstanceMethods
|
5
|
+
|
6
|
+
def to_label
|
7
|
+
email
|
8
|
+
end
|
9
|
+
|
10
|
+
def resources
|
11
|
+
Typus::Configuration.roles[role.to_s].compact
|
12
|
+
end
|
13
|
+
|
14
|
+
def models
|
15
|
+
Typus.models.delete_if { |m| cannot?('read', m) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def applications
|
19
|
+
Typus.applications.delete_if { |a| application(a).empty? }
|
20
|
+
end
|
21
|
+
|
22
|
+
def application(name)
|
23
|
+
Typus.application(name).delete_if { |r| !resources.keys.include?(r) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def can?(action, resource, options = {})
|
27
|
+
resource = resource.to_s
|
28
|
+
|
29
|
+
return false if !resources.include?(resource)
|
30
|
+
return true if resources[resource].include?('all')
|
31
|
+
|
32
|
+
action = options[:special] ? action : action.acl_action_mapper
|
33
|
+
|
34
|
+
resources[resource].extract_settings.include?(action)
|
35
|
+
end
|
36
|
+
|
37
|
+
def cannot?(*args)
|
38
|
+
!can?(*args)
|
39
|
+
end
|
40
|
+
|
41
|
+
def is_root?
|
42
|
+
role == Typus.master_role
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_not_root?
|
46
|
+
!is_root?
|
47
|
+
end
|
48
|
+
|
49
|
+
def active?
|
50
|
+
status && Typus::Configuration.roles.has_key?(role)
|
51
|
+
end
|
52
|
+
|
53
|
+
def locale
|
54
|
+
(preferences && preferences[:locale]) ? preferences[:locale] : ::I18n.default_locale
|
55
|
+
end
|
56
|
+
|
57
|
+
def locale=(locale)
|
58
|
+
self.preferences ||= {}
|
59
|
+
self.preferences[:locale] = locale
|
60
|
+
end
|
61
|
+
|
62
|
+
def owns?(resource)
|
63
|
+
id == resource.send(Typus.user_foreign_key)
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_token
|
67
|
+
token = "#{SecureRandom.hex(6)}-#{SecureRandom.hex(6)}"
|
68
|
+
token.encode!('UTF-8') if token.respond_to?(:encode)
|
69
|
+
self.token = token
|
70
|
+
end
|
71
|
+
protected :set_token
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Typus
|
2
|
+
module Orm
|
3
|
+
module ActiveRecord
|
4
|
+
module Search
|
5
|
+
|
6
|
+
include Typus::Orm::Base::Search
|
7
|
+
|
8
|
+
def build_search_conditions(key, value)
|
9
|
+
data = Array.new.tap do |search|
|
10
|
+
query = ::ActiveRecord::Base.connection.quote_string(value.downcase)
|
11
|
+
|
12
|
+
typus_search_fields.each do |local_key, local_value|
|
13
|
+
_query = case local_value
|
14
|
+
when '=' then query
|
15
|
+
when '^' then "#{query}%"
|
16
|
+
when '@' then "%#{query}%"
|
17
|
+
end
|
18
|
+
|
19
|
+
column_name = (local_key.match('\.') ? local_key : "#{table_name}.#{local_key}")
|
20
|
+
table_key = (adapter == 'postgresql') ? "LOWER(TEXT(#{column_name}))" : "#{column_name}"
|
21
|
+
|
22
|
+
search << "#{table_key} LIKE '#{_query}'"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
data.join(' OR ')
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO: Use Rails scopes to build the search: where(key => interval)
|
30
|
+
def build_filter_interval(interval, key)
|
31
|
+
["#{table_name}.#{key} BETWEEN ? AND ?", interval.first.to_s(:db), interval.last.to_s(:db)]
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_my_joins(params)
|
35
|
+
query_params = params.dup
|
36
|
+
query_params.reject! { |k, _| !model_relationships.keys.include?(k.to_sym) }
|
37
|
+
query_params.compact.map { |k, _| k.to_sym }
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
module Typus
|
2
|
+
module Orm
|
3
|
+
module Base
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
# Model fields as an <tt>ActiveSupport::OrderedHash</tt>.
|
7
|
+
def model_fields
|
8
|
+
end
|
9
|
+
|
10
|
+
# Model relationships as an <tt>ActiveSupport::OrderedHash</tt>.
|
11
|
+
def model_relationships
|
12
|
+
end
|
13
|
+
|
14
|
+
# Model description for admin panel.
|
15
|
+
def typus_description
|
16
|
+
read_model_config['description']
|
17
|
+
end
|
18
|
+
|
19
|
+
# Form and list fields
|
20
|
+
def typus_fields_for(filter)
|
21
|
+
end
|
22
|
+
|
23
|
+
def typus_filters
|
24
|
+
end
|
25
|
+
|
26
|
+
# Extended actions for this model on Typus.
|
27
|
+
def typus_actions_on(filter)
|
28
|
+
actions = read_model_config['actions']
|
29
|
+
actions && actions[filter.to_s] ? actions[filter.to_s].extract_settings : []
|
30
|
+
end
|
31
|
+
|
32
|
+
# Used for +search+, +relationships+
|
33
|
+
def typus_defaults_for(filter)
|
34
|
+
read_model_config[filter.to_s].try(:extract_settings) || []
|
35
|
+
end
|
36
|
+
|
37
|
+
def typus_scopes
|
38
|
+
typus_defaults_for(:scopes).reject { |s| !respond_to?(s) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def typus_search_fields
|
42
|
+
Hash.new.tap do |search|
|
43
|
+
typus_defaults_for(:search).each do |field|
|
44
|
+
if field.starts_with?('=')
|
45
|
+
field.slice!(0)
|
46
|
+
search[field] = '='
|
47
|
+
elsif field.starts_with?('^')
|
48
|
+
field.slice!(0)
|
49
|
+
search[field] = '^'
|
50
|
+
else
|
51
|
+
search[field] = '@'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def typus_application
|
58
|
+
name = read_model_config['application'] || 'Unknown'
|
59
|
+
name.extract_settings.first
|
60
|
+
end
|
61
|
+
|
62
|
+
def typus_field_options_for(filter)
|
63
|
+
options = read_model_config['fields']['options']
|
64
|
+
options && options[filter.to_s] ? options[filter.to_s].extract_settings.map(&:to_sym) : []
|
65
|
+
end
|
66
|
+
|
67
|
+
#--
|
68
|
+
# With +Typus::Resources.setup+ we can define application defaults.
|
69
|
+
#
|
70
|
+
# Typus::Resources.setup do |config|
|
71
|
+
# config.per_page = 25
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# If for any reason we need a better default for an specific resource we
|
75
|
+
# can override it on +application.yaml+.
|
76
|
+
#
|
77
|
+
# Post:
|
78
|
+
# ...
|
79
|
+
# options:
|
80
|
+
# per_page: 25
|
81
|
+
#++
|
82
|
+
def typus_options_for(filter)
|
83
|
+
options = read_model_config['options']
|
84
|
+
|
85
|
+
unless options.nil? || options[filter.to_s].nil?
|
86
|
+
options[filter.to_s]
|
87
|
+
else
|
88
|
+
Typus::Resources.send(filter)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def typus_order_by
|
93
|
+
typus_defaults_for(:order_by).map do |field|
|
94
|
+
field.include?('-') ? "#{field.delete('-')} DESC" : "#{field} ASC"
|
95
|
+
end.join(', ')
|
96
|
+
end
|
97
|
+
|
98
|
+
#--
|
99
|
+
# Define our own boolean mappings.
|
100
|
+
#
|
101
|
+
# Post:
|
102
|
+
# fields:
|
103
|
+
# default: title, status
|
104
|
+
# options:
|
105
|
+
# booleans:
|
106
|
+
# status: "Published", "Not published"
|
107
|
+
#
|
108
|
+
#++
|
109
|
+
def typus_boolean(attribute = :default)
|
110
|
+
options = read_model_config['fields']['options']
|
111
|
+
|
112
|
+
boolean = if options && options['booleans'] && boolean = options['booleans'][attribute.to_s]
|
113
|
+
boolean.is_a?(String) ? boolean.extract_settings : boolean
|
114
|
+
else
|
115
|
+
["True", "False"]
|
116
|
+
end
|
117
|
+
|
118
|
+
[[boolean.first, "true"], [boolean.last, "false"]]
|
119
|
+
end
|
120
|
+
|
121
|
+
#--
|
122
|
+
# Custom date formats.
|
123
|
+
#++
|
124
|
+
def typus_date_format(attribute = :default)
|
125
|
+
options = read_model_config['fields']['options']
|
126
|
+
if options && options['date_formats'] && options['date_formats'][attribute.to_s]
|
127
|
+
options['date_formats'][attribute.to_s].to_sym
|
128
|
+
else
|
129
|
+
:default
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
#--
|
134
|
+
# This is user to use custome templates for attribute:
|
135
|
+
#
|
136
|
+
# Post:
|
137
|
+
# fields:
|
138
|
+
# form: title, body, status
|
139
|
+
# options:
|
140
|
+
# templates:
|
141
|
+
# body: rich_text
|
142
|
+
#
|
143
|
+
# Templates are stored on <tt>app/views/admin/templates</tt>.
|
144
|
+
#++
|
145
|
+
def typus_template(attribute)
|
146
|
+
options = read_model_config['fields']['options']
|
147
|
+
if options && options['templates'] && options['templates'][attribute.to_s]
|
148
|
+
options['templates'][attribute.to_s]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def adapter
|
153
|
+
@adapter ||= ::ActiveRecord::Base.connection_config[:adapter]
|
154
|
+
end
|
155
|
+
|
156
|
+
def typus_user_id?
|
157
|
+
end
|
158
|
+
|
159
|
+
def read_model_config
|
160
|
+
Typus::Configuration.config[name] or raise "No typus configuration specified for #{name}"
|
161
|
+
end
|
162
|
+
|
163
|
+
#--
|
164
|
+
# >> Post.to_resource
|
165
|
+
# => "posts"
|
166
|
+
# >> Admin::User.to_resource
|
167
|
+
# => "admin/users"
|
168
|
+
#++
|
169
|
+
def to_resource
|
170
|
+
name.underscore.pluralize
|
171
|
+
end
|
172
|
+
|
173
|
+
def custom_attribute?(field)
|
174
|
+
case field.to_s
|
175
|
+
when 'parent', 'parent_id' then :tree
|
176
|
+
when /password/ then :password
|
177
|
+
when /\./ then :transversal
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def virtual_fields
|
182
|
+
(instance_methods - model_fields.keys).map(&:to_s)
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Typus
|
2
|
+
module Orm
|
3
|
+
module Base
|
4
|
+
module Search
|
5
|
+
|
6
|
+
def build_search_conditions(key, value)
|
7
|
+
raise 'Not implemented!'
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_boolean_conditions(key, value)
|
11
|
+
{ key => (value == 'true') ? true : false }
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_date_conditions(key, value)
|
15
|
+
if %w(all_day all_week all_month all_year).include?(value)
|
16
|
+
interval = Time.zone.now.send(value)
|
17
|
+
build_filter_interval(interval, key)
|
18
|
+
else
|
19
|
+
raise "#{value} is not allowed!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method :build_datetime_conditions, :build_date_conditions
|
24
|
+
alias_method :build_timestamp_conditions, :build_date_conditions
|
25
|
+
|
26
|
+
def build_filter_interval(interval, key)
|
27
|
+
raise 'Not implemented!'
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_string_conditions(key, value)
|
31
|
+
{ key => value }
|
32
|
+
end
|
33
|
+
|
34
|
+
alias_method :build_integer_conditions, :build_string_conditions
|
35
|
+
alias_method :build_belongs_to_conditions, :build_string_conditions
|
36
|
+
|
37
|
+
# TODO: Detect the primary_key for this object.
|
38
|
+
def build_has_many_conditions(key, value)
|
39
|
+
["#{key}.id = ?", value]
|
40
|
+
end
|
41
|
+
|
42
|
+
# To build conditions we accept only model fields and the search
|
43
|
+
# param.
|
44
|
+
def build_conditions(params)
|
45
|
+
Array.new.tap do |conditions|
|
46
|
+
query_params = params.dup
|
47
|
+
|
48
|
+
query_params.reject! do |k, v|
|
49
|
+
!model_fields.keys.include?(k.to_sym) &&
|
50
|
+
!model_relationships.keys.include?(k.to_sym) &&
|
51
|
+
!(k.to_sym == :search)
|
52
|
+
end
|
53
|
+
|
54
|
+
query_params.compact.each do |key, value|
|
55
|
+
filter_type = model_fields[key.to_sym] || model_relationships[key.to_sym] || key
|
56
|
+
conditions << send("build_#{filter_type}_conditions", key, value)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_my_joins(params)
|
62
|
+
query_params = params.dup
|
63
|
+
query_params.reject! { |k, _| !model_relationships.keys.include?(k.to_sym) }
|
64
|
+
query_params.compact.map { |k, _| k.to_sym }
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/typus/regex.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Typus
|
2
|
+
module Resources
|
3
|
+
|
4
|
+
# Usage:
|
5
|
+
#
|
6
|
+
# Typus::Resources.setup do |config|
|
7
|
+
# config.default_action_on_item = 'index'
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
def self.setup
|
11
|
+
yield self
|
12
|
+
end
|
13
|
+
|
14
|
+
mattr_accessor :default_action_on_item
|
15
|
+
@@default_action_on_item = 'edit'
|
16
|
+
|
17
|
+
mattr_accessor :end_year
|
18
|
+
@@end_year = nil
|
19
|
+
|
20
|
+
mattr_accessor :form_rows
|
21
|
+
@@form_rows = 15
|
22
|
+
|
23
|
+
mattr_accessor :minute_step
|
24
|
+
@@minute_step = nil
|
25
|
+
|
26
|
+
mattr_accessor :only_user_items
|
27
|
+
@@only_user_items = false
|
28
|
+
|
29
|
+
mattr_accessor :per_page
|
30
|
+
@@per_page = 20
|
31
|
+
|
32
|
+
mattr_accessor :sortable
|
33
|
+
@@sortable = true
|
34
|
+
|
35
|
+
mattr_accessor :start_year
|
36
|
+
@@start_year = nil
|
37
|
+
|
38
|
+
mattr_accessor :hide_from_sidebar
|
39
|
+
@@hide_from_sidebar = false
|
40
|
+
|
41
|
+
mattr_accessor :hide_from_dashboard
|
42
|
+
@@hide_from_dashboard = false
|
43
|
+
|
44
|
+
mattr_accessor :export
|
45
|
+
@@export = ''
|
46
|
+
|
47
|
+
mattr_accessor :counters
|
48
|
+
@@counters = false
|
49
|
+
|
50
|
+
def self.method_missing(*args)
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|