brainsome_typus 4.0.0.beta1
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 +60 -0
- data/Gemfile.lock +205 -0
- data/MIT-LICENSE +20 -0
- data/README.md +94 -0
- data/Rakefile +33 -0
- data/TODO.md +32 -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-1.8.3-min.js +2 -0
- data/app/assets/javascripts/typus/jquery.application.js +33 -0
- data/app/assets/stylesheets/typus/application.css +5 -0
- data/app/assets/stylesheets/typus/custom.css +4 -0
- data/app/assets/stylesheets/typus/overrides.css.scss +46 -0
- data/app/controllers/admin/account_controller.rb +47 -0
- data/app/controllers/admin/base_controller.rb +44 -0
- data/app/controllers/admin/dashboard_controller.rb +5 -0
- data/app/controllers/admin/resource_controller.rb +7 -0
- data/app/controllers/admin/resources_controller.rb +256 -0
- data/app/controllers/admin/session_controller.rb +42 -0
- data/app/controllers/concerns/admin/actions.rb +88 -0
- data/app/controllers/concerns/admin/acts_as_list.rb +26 -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 +48 -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 +26 -0
- data/app/controllers/concerns/admin/trash.rb +65 -0
- data/app/helpers/admin/base_helper.rb +59 -0
- data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +91 -0
- data/app/helpers/admin/resources/data_types/boolean_helper.rb +28 -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 +56 -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 +53 -0
- data/app/helpers/admin/resources/data_types/has_many_helper.rb +66 -0
- data/app/helpers/admin/resources/data_types/has_one_helper.rb +36 -0
- data/app/helpers/admin/resources/data_types/integer_helper.rb +10 -0
- data/app/helpers/admin/resources/data_types/paperclip_helper.rb +36 -0
- data/app/helpers/admin/resources/data_types/position_helper.rb +20 -0
- data/app/helpers/admin/resources/data_types/selector_helper.rb +11 -0
- data/app/helpers/admin/resources/data_types/string_helper.rb +32 -0
- data/app/helpers/admin/resources/data_types/text_helper.rb +7 -0
- data/app/helpers/admin/resources/data_types/transversal_helper.rb +8 -0
- data/app/helpers/admin/resources/data_types/tree_helper.rb +26 -0
- data/app/helpers/admin/resources/display_helper.rb +27 -0
- data/app/helpers/admin/resources/filters_helper.rb +28 -0
- data/app/helpers/admin/resources/form_helper.rb +84 -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 +34 -0
- data/app/helpers/admin/resources/sidebar_helper.rb +40 -0
- data/app/helpers/admin/resources/table_helper.rb +66 -0
- data/app/helpers/admin/resources_helper.rb +25 -0
- data/app/mailers/admin/mailer.rb +20 -0
- data/app/views/admin/account/_form.html.erb +11 -0
- data/app/views/admin/account/forgot_password.html.erb +19 -0
- data/app/views/admin/account/new.html.erb +13 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +14 -0
- data/app/views/admin/dashboard/index.html.erb +6 -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 +46 -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/resources/_actions.html.erb +23 -0
- data/app/views/admin/resources/_edit.html.erb +0 -0
- data/app/views/admin/resources/_form.html.erb +41 -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/edit/_actions.html.erb +7 -0
- data/app/views/admin/resources/edit/_recently_edited.html.erb +8 -0
- data/app/views/admin/resources/edit.html.erb +22 -0
- data/app/views/admin/resources/index.html.erb +81 -0
- data/app/views/admin/resources/new.html.erb +21 -0
- data/app/views/admin/resources/show.html.erb +27 -0
- data/app/views/admin/session/new.html.erb +21 -0
- data/app/views/admin/shared/_head.html.erb +15 -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 +13 -0
- data/app/views/admin/templates/_boolean.html.erb +6 -0
- data/app/views/admin/templates/_date.html.erb +6 -0
- data/app/views/admin/templates/_datetime.html.erb +7 -0
- data/app/views/admin/templates/_dragonfly.html.erb +8 -0
- data/app/views/admin/templates/_dragonfly_form_preview.html.erb +23 -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 +20 -0
- data/app/views/admin/templates/_has_one.html.erb +14 -0
- data/app/views/admin/templates/_paperclip.html.erb +7 -0
- data/app/views/admin/templates/_paperclip_preview.html.erb +3 -0
- data/app/views/admin/templates/_password.html.erb +6 -0
- data/app/views/admin/templates/_position.html.erb +6 -0
- data/app/views/admin/templates/_profile_sidebar.html.erb +4 -0
- data/app/views/admin/templates/_selector.html.erb +6 -0
- data/app/views/admin/templates/_string.html.erb +6 -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 +56 -0
- data/app/views/admin/templates/modals/_dragonfly.html.erb +9 -0
- data/app/views/admin/templates/modals/_has_and_belongs_to_many.html.erb +19 -0
- data/app/views/admin/templates/modals/_has_many.html.erb +53 -0
- data/app/views/helpers/admin/base/_apps.html.erb +38 -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 +37 -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 +14 -0
- data/app/views/helpers/admin/resources/_search.html.erb +14 -0
- data/app/views/helpers/admin/resources/_sidebar.html.erb +17 -0
- data/app/views/helpers/admin/resources/_table.html.erb +47 -0
- data/app/views/layouts/admin/base.html.erb +40 -0
- data/app/views/layouts/admin/headless.html.erb +1 -0
- data/app/views/layouts/admin/session.html.erb +44 -0
- data/config/locales/typus.ca.models.yml +17 -0
- data/config/locales/typus.ca.yml +78 -0
- data/config/locales/typus.de.models.yml +17 -0
- data/config/locales/typus.de.yml +98 -0
- data/config/locales/typus.el.models.yml +17 -0
- data/config/locales/typus.el.yml +79 -0
- data/config/locales/typus.es.models.yml +18 -0
- data/config/locales/typus.es.yml +91 -0
- data/config/locales/typus.fr.models.yml +18 -0
- data/config/locales/typus.fr.yml +83 -0
- data/config/locales/typus.hu.models.yml +17 -0
- data/config/locales/typus.hu.yml +77 -0
- data/config/locales/typus.it.models.yml +18 -0
- data/config/locales/typus.it.yml +86 -0
- data/config/locales/typus.locale.models.yml.template +17 -0
- data/config/locales/typus.locale.yml.template +78 -0
- data/config/locales/typus.pt-BR.models.yml +17 -0
- data/config/locales/typus.pt-BR.yml +77 -0
- data/config/locales/typus.pt-PT.models.yml +17 -0
- data/config/locales/typus.pt-PT.yml +85 -0
- data/config/locales/typus.ru.models.yml +17 -0
- data/config/locales/typus.ru.yml +77 -0
- data/config/locales/typus.zh-CN.models.yml +17 -0
- data/config/locales/typus.zh-CN.yml +76 -0
- data/config/routes.rb +46 -0
- data/lib/generators/templates/config/initializers/typus.rb +35 -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 +25 -0
- data/lib/generators/typus/initializers_generator.rb +20 -0
- data/lib/generators/typus/migration_generator.rb +94 -0
- data/lib/generators/typus/typus_generator.rb +52 -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 +12 -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/authentication/base.rb +24 -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 +41 -0
- data/lib/typus/engine.rb +17 -0
- data/lib/typus/i18n.rb +48 -0
- data/lib/typus/orm/active_record/admin_user.rb +84 -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 +44 -0
- data/lib/typus/orm/active_record.rb +10 -0
- data/lib/typus/orm/base/class_methods.rb +184 -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/lib/typus.rb +212 -0
- data/typus.gemspec +32 -0
- data/vendor/assets/adapt/css/1200.css +357 -0
- data/vendor/assets/adapt/css/1200.min.css +1 -0
- data/vendor/assets/adapt/css/1560.css +357 -0
- data/vendor/assets/adapt/css/1560.min.css +1 -0
- data/vendor/assets/adapt/css/720.css +357 -0
- data/vendor/assets/adapt/css/720.min.css +1 -0
- data/vendor/assets/adapt/css/960.css +357 -0
- data/vendor/assets/adapt/css/960.min.css +1 -0
- data/vendor/assets/adapt/css/fluid.css +345 -0
- data/vendor/assets/adapt/css/fluid.min.css +1 -0
- data/vendor/assets/adapt/css/master.css +120 -0
- data/vendor/assets/adapt/css/mobile.css +20 -0
- data/vendor/assets/adapt/css/mobile.min.css +1 -0
- data/vendor/assets/adapt/css/reset.css +202 -0
- data/vendor/assets/adapt/css/text.css +81 -0
- data/vendor/assets/adapt/images/h1.png +0 -0
- data/vendor/assets/adapt/js/adapt.js +135 -0
- data/vendor/assets/adapt/js/adapt.min.js +1 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap-responsive.css +1109 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap-responsive.min.css +9 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap.css +6167 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap.min.css +9 -0
- data/vendor/assets/bootstrap-2.3.2/img/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/bootstrap-2.3.2/img/glyphicons-halflings.png +0 -0
- data/vendor/assets/bootstrap-2.3.2/js/bootstrap.js +2280 -0
- data/vendor/assets/bootstrap-2.3.2/js/bootstrap.min.js +6 -0
- data/vendor/assets/chosen/LICENSE.md +24 -0
- data/vendor/assets/chosen/chosen-sprite.png +0 -0
- data/vendor/assets/chosen/chosen.css +390 -0
- data/vendor/assets/chosen/chosen.jquery.js +902 -0
- data/vendor/assets/formalize/css/formalize.css +395 -0
- data/vendor/assets/formalize/images/button.png +0 -0
- data/vendor/assets/formalize/images/select_arrow.gif +0 -0
- data/vendor/assets/formalize/js/jquery.formalize.min.js +1 -0
- metadata +329 -0
@@ -0,0 +1,184 @@
|
|
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; end
|
8
|
+
|
9
|
+
# Model relationships as an <tt>ActiveSupport::OrderedHash</tt>.
|
10
|
+
def model_relationships; end
|
11
|
+
|
12
|
+
# Model description for admin panel.
|
13
|
+
def typus_description
|
14
|
+
read_model_config['description']
|
15
|
+
end
|
16
|
+
|
17
|
+
# Form and list fields
|
18
|
+
def typus_fields_for(filter); end
|
19
|
+
|
20
|
+
def typus_filters; end
|
21
|
+
|
22
|
+
# Extended actions for this model on Typus.
|
23
|
+
def typus_actions_on(filter)
|
24
|
+
actions = read_model_config['actions']
|
25
|
+
actions && actions[filter.to_s] ? actions[filter.to_s].extract_settings : []
|
26
|
+
end
|
27
|
+
|
28
|
+
# Used for +search+, +relationships+
|
29
|
+
def typus_defaults_for(filter)
|
30
|
+
read_model_config[filter.to_s].try(:extract_settings) || []
|
31
|
+
end
|
32
|
+
|
33
|
+
def typus_scopes
|
34
|
+
typus_defaults_for(:scopes).reject { |s| !respond_to?(s) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def typus_search_fields
|
38
|
+
Hash.new.tap do |search|
|
39
|
+
typus_defaults_for(:search).each do |field|
|
40
|
+
if field.starts_with?("=")
|
41
|
+
field.slice!(0)
|
42
|
+
search[field] = "="
|
43
|
+
elsif field.starts_with?("^")
|
44
|
+
field.slice!(0)
|
45
|
+
search[field] = "^"
|
46
|
+
else
|
47
|
+
search[field] = "@"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def typus_application
|
54
|
+
name = read_model_config['application'] || 'Unknown'
|
55
|
+
name.extract_settings.first
|
56
|
+
end
|
57
|
+
|
58
|
+
def typus_field_options_for(filter)
|
59
|
+
options = read_model_config['fields']['options']
|
60
|
+
options && options[filter.to_s] ? options[filter.to_s].extract_settings.map(&:to_sym) : []
|
61
|
+
end
|
62
|
+
|
63
|
+
#--
|
64
|
+
# With +Typus::Resources.setup+ we can define application defaults.
|
65
|
+
#
|
66
|
+
# Typus::Resources.setup do |config|
|
67
|
+
# config.per_page = 25
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# If for any reason we need a better default for an specific resource we
|
71
|
+
# can override it on +application.yaml+.
|
72
|
+
#
|
73
|
+
# Post:
|
74
|
+
# ...
|
75
|
+
# options:
|
76
|
+
# per_page: 25
|
77
|
+
#++
|
78
|
+
def typus_options_for(filter)
|
79
|
+
options = read_model_config['options']
|
80
|
+
|
81
|
+
unless options.nil? || options[filter.to_s].nil?
|
82
|
+
options[filter.to_s]
|
83
|
+
else
|
84
|
+
Typus::Resources.send(filter)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def typus_order_by
|
89
|
+
typus_defaults_for(:order_by).map do |field|
|
90
|
+
field.include?('-') ? "#{field.delete('-')} DESC" : "#{field} ASC"
|
91
|
+
end.join(', ')
|
92
|
+
end
|
93
|
+
|
94
|
+
#--
|
95
|
+
# Define our own boolean mappings.
|
96
|
+
#
|
97
|
+
# Post:
|
98
|
+
# fields:
|
99
|
+
# default: title, status
|
100
|
+
# options:
|
101
|
+
# booleans:
|
102
|
+
# status: "Published", "Not published"
|
103
|
+
#
|
104
|
+
#++
|
105
|
+
def typus_boolean(attribute = :default)
|
106
|
+
options = read_model_config['fields']['options']
|
107
|
+
|
108
|
+
boolean = if options && options['booleans'] && boolean = options['booleans'][attribute.to_s]
|
109
|
+
boolean.is_a?(String) ? boolean.extract_settings : boolean
|
110
|
+
else
|
111
|
+
["True", "False"]
|
112
|
+
end
|
113
|
+
|
114
|
+
[[boolean.first, "true"], [boolean.last, "false"]]
|
115
|
+
end
|
116
|
+
|
117
|
+
#--
|
118
|
+
# Custom date formats.
|
119
|
+
#++
|
120
|
+
def typus_date_format(attribute = :default)
|
121
|
+
options = read_model_config['fields']['options']
|
122
|
+
if options && options['date_formats'] && options['date_formats'][attribute.to_s]
|
123
|
+
options['date_formats'][attribute.to_s].to_sym
|
124
|
+
else
|
125
|
+
:default
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
#--
|
130
|
+
# This is user to use custome templates for attribute:
|
131
|
+
#
|
132
|
+
# Post:
|
133
|
+
# fields:
|
134
|
+
# form: title, body, status
|
135
|
+
# options:
|
136
|
+
# templates:
|
137
|
+
# body: rich_text
|
138
|
+
#
|
139
|
+
# Templates are stored on <tt>app/views/admin/templates</tt>.
|
140
|
+
#++
|
141
|
+
def typus_template(attribute)
|
142
|
+
options = read_model_config['fields']['options']
|
143
|
+
if options && options['templates'] && options['templates'][attribute.to_s]
|
144
|
+
options['templates'][attribute.to_s]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def adapter
|
149
|
+
@adapter ||= ::ActiveRecord::Base.connection_config[:adapter]
|
150
|
+
end
|
151
|
+
|
152
|
+
def typus_user_id?; end
|
153
|
+
|
154
|
+
def read_model_config
|
155
|
+
Typus::Configuration.config[name] or raise "No typus configuration specified for #{name}"
|
156
|
+
end
|
157
|
+
|
158
|
+
#--
|
159
|
+
# >> Post.to_resource
|
160
|
+
# => "posts"
|
161
|
+
# >> Admin::User.to_resource
|
162
|
+
# => "admin/users"
|
163
|
+
#++
|
164
|
+
def to_resource
|
165
|
+
name.underscore.pluralize
|
166
|
+
end
|
167
|
+
|
168
|
+
def custom_attribute?(field)
|
169
|
+
case field.to_s
|
170
|
+
when 'parent', 'parent_id' then :tree
|
171
|
+
when /password/ then :password
|
172
|
+
when 'position' then :position
|
173
|
+
when /\./ then :transversal
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def virtual_fields
|
178
|
+
(instance_methods - model_fields.keys).map(&:to_s)
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
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, v| !model_relationships.keys.include?(k.to_sym) }
|
64
|
+
query_params.compact.map { |k, v| 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 = 25
|
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
|
data/lib/typus.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
require "support/active_record" if defined?(ActiveRecord)
|
2
|
+
require "support/hash"
|
3
|
+
require "support/object"
|
4
|
+
require "support/string"
|
5
|
+
|
6
|
+
require "typus/engine"
|
7
|
+
require "typus/regex"
|
8
|
+
require "typus/version"
|
9
|
+
|
10
|
+
require "typus/orm/base/class_methods"
|
11
|
+
require "typus/orm/base/search"
|
12
|
+
require "typus/orm/active_record"
|
13
|
+
|
14
|
+
autoload :FakeUser, "support/fake_user"
|
15
|
+
|
16
|
+
module Typus
|
17
|
+
|
18
|
+
autoload :Configuration, "typus/configuration"
|
19
|
+
autoload :I18n, "typus/i18n"
|
20
|
+
autoload :Resources, "typus/resources"
|
21
|
+
|
22
|
+
module Authentication
|
23
|
+
autoload :Base, "typus/authentication/base"
|
24
|
+
autoload :None, "typus/authentication/none"
|
25
|
+
autoload :NoneWithRole, "typus/authentication/none_with_role"
|
26
|
+
autoload :HttpBasic, "typus/authentication/http_basic"
|
27
|
+
autoload :Session, "typus/authentication/session"
|
28
|
+
|
29
|
+
autoload :Devise, "typus/authentication/devise"
|
30
|
+
end
|
31
|
+
|
32
|
+
mattr_accessor :admin_title
|
33
|
+
@@admin_title = "Typus"
|
34
|
+
|
35
|
+
mattr_accessor :admin_title_link
|
36
|
+
@@admin_title_link = nil
|
37
|
+
|
38
|
+
mattr_accessor :admin_sub_title
|
39
|
+
@@admin_sub_title = <<-CODE
|
40
|
+
<a href="http://core.typuscmf.com/">core.typuscmf.com</a>
|
41
|
+
CODE
|
42
|
+
|
43
|
+
# Set authentication (none, http_basic, session)
|
44
|
+
mattr_accessor :authentication
|
45
|
+
@@authentication = :none
|
46
|
+
|
47
|
+
mattr_accessor :config_folder
|
48
|
+
@@config_folder = "config/typus"
|
49
|
+
|
50
|
+
mattr_accessor :username
|
51
|
+
@@username = "admin"
|
52
|
+
|
53
|
+
mattr_accessor :subdomain
|
54
|
+
@@subdomain = nil
|
55
|
+
|
56
|
+
# Define a default password for http authentication.
|
57
|
+
mattr_accessor :password
|
58
|
+
@@password = "columbia"
|
59
|
+
|
60
|
+
# Configure the e-mail address which will be shown in Admin::Mailer.
|
61
|
+
# If not set `forgot_password` feature is disabled.
|
62
|
+
mattr_accessor :mailer_sender
|
63
|
+
@@mailer_sender = nil
|
64
|
+
|
65
|
+
##
|
66
|
+
# Define `paperclip` attachment styles.
|
67
|
+
#
|
68
|
+
|
69
|
+
mattr_accessor :file_preview
|
70
|
+
@@file_preview = :medium
|
71
|
+
|
72
|
+
mattr_accessor :file_thumbnail
|
73
|
+
@@file_thumbnail = :thumb
|
74
|
+
|
75
|
+
##
|
76
|
+
# Define `dragonfly` attachment styles.
|
77
|
+
#
|
78
|
+
|
79
|
+
mattr_accessor :image_preview_size
|
80
|
+
@@image_preview_size = '530x'
|
81
|
+
|
82
|
+
mattr_accessor :image_thumb_size
|
83
|
+
@@image_thumb_size = 'x100'
|
84
|
+
|
85
|
+
mattr_accessor :image_table_thumb_size
|
86
|
+
@@image_table_thumb_size = '25x25#'
|
87
|
+
|
88
|
+
# Define the default relationship table.
|
89
|
+
mattr_accessor :relationship
|
90
|
+
@@relationship = "typus_users"
|
91
|
+
|
92
|
+
mattr_accessor :master_role
|
93
|
+
@@master_role = "admin"
|
94
|
+
|
95
|
+
mattr_accessor :user_class_name
|
96
|
+
@@user_class_name = "AdminUser"
|
97
|
+
|
98
|
+
mattr_accessor :user_foreign_key
|
99
|
+
@@user_foreign_key = "admin_user_id"
|
100
|
+
|
101
|
+
mattr_accessor :quick_sidebar
|
102
|
+
@@quick_sidebar = false
|
103
|
+
|
104
|
+
mattr_accessor :ip_whitelist
|
105
|
+
@@ip_whitelist = []
|
106
|
+
|
107
|
+
mattr_accessor :link_to_view_site
|
108
|
+
@@link_to_view_site = false
|
109
|
+
|
110
|
+
mattr_accessor :link_to_help
|
111
|
+
@@link_to_help = false
|
112
|
+
|
113
|
+
class << self
|
114
|
+
|
115
|
+
# Default way to setup typus. Run `rails generate typus` to create a
|
116
|
+
# fresh initializer with all configuration values.
|
117
|
+
def setup
|
118
|
+
yield self
|
119
|
+
reload!
|
120
|
+
end
|
121
|
+
|
122
|
+
def applications
|
123
|
+
hash = {}
|
124
|
+
|
125
|
+
Typus::Configuration.config.map { |i| i.last["application"] }.compact.uniq.each do |app|
|
126
|
+
settings = app.extract_settings
|
127
|
+
hash[settings.first] = settings.size > 1 ? settings.last : 1000
|
128
|
+
end
|
129
|
+
|
130
|
+
hash.sort { |a1, a2| a1[1].to_i <=> a2[1].to_i }.map(&:first)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Lists modules of an application.
|
134
|
+
def application(name)
|
135
|
+
array = []
|
136
|
+
|
137
|
+
Typus::Configuration.config.each do |i|
|
138
|
+
settings = i.last["application"]
|
139
|
+
array << i.first if settings && settings.extract_settings.first.eql?(name)
|
140
|
+
end
|
141
|
+
|
142
|
+
array.compact.uniq
|
143
|
+
end
|
144
|
+
|
145
|
+
# Lists models from the configuration file.
|
146
|
+
def models
|
147
|
+
Typus::Configuration.config.map(&:first).sort
|
148
|
+
end
|
149
|
+
|
150
|
+
# Lists resources, which are tableless models. This is done by looking at
|
151
|
+
# the roles, which handle the permissions for this kind of data.
|
152
|
+
def resources
|
153
|
+
if roles = Typus::Configuration.roles
|
154
|
+
roles.keys.map do |key|
|
155
|
+
Typus::Configuration.roles[key].keys
|
156
|
+
end.flatten.sort.uniq.delete_if { |x| models.include?(x) }
|
157
|
+
else
|
158
|
+
[]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Lists models under <tt>app/models</tt>.
|
163
|
+
def detect_application_models
|
164
|
+
model_dir = Rails.root.join("app/models")
|
165
|
+
Dir.chdir(model_dir.to_s) { Dir["**/*.rb"].reject {|f| f["concerns/"] } }
|
166
|
+
end
|
167
|
+
|
168
|
+
def application_models
|
169
|
+
detect_application_models.map do |model|
|
170
|
+
class_name = model.sub(/\.rb$/,"").camelize
|
171
|
+
klass = class_name.split("::").inject(Object) { |klass,part| klass.const_get(part) }
|
172
|
+
class_name if is_active_record?(klass)
|
173
|
+
end.compact
|
174
|
+
end
|
175
|
+
|
176
|
+
def is_active_record?(klass)
|
177
|
+
(defined?(ActiveRecord) && klass < ActiveRecord::Base && !klass.abstract_class?)
|
178
|
+
end
|
179
|
+
private :is_active_record?
|
180
|
+
|
181
|
+
def user_class
|
182
|
+
user_class_name.constantize
|
183
|
+
end
|
184
|
+
|
185
|
+
def user_class_as_symbol
|
186
|
+
user_class_name.underscore.to_sym
|
187
|
+
end
|
188
|
+
|
189
|
+
def root
|
190
|
+
Rails.root.join(config_folder)
|
191
|
+
end
|
192
|
+
|
193
|
+
def model_configuration_files
|
194
|
+
app = Typus.root.join("**", "*.yml")
|
195
|
+
lib = Rails.root.join("lib", "*", "config", "typus", "**", "*.yml")
|
196
|
+
Dir[app.to_s, lib.to_s].reject { |f| f.match(/_roles.yml/) }.sort
|
197
|
+
end
|
198
|
+
|
199
|
+
def role_configuration_files
|
200
|
+
app = Typus.root.join("**", "*_roles.yml")
|
201
|
+
lib = Rails.root.join("lib", "*", "config", "typus", "**", "*_roles.yml")
|
202
|
+
Dir[app.to_s, lib.to_s].sort
|
203
|
+
end
|
204
|
+
|
205
|
+
def reload!
|
206
|
+
Typus::Configuration.roles!
|
207
|
+
Typus::Configuration.models!
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
data/typus.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'typus/version'
|
5
|
+
|
6
|
+
files = Dir['**/*'].keep_if{|file| File.file?(file)}
|
7
|
+
test_files = Dir['test/**/*'].keep_if{|file| File.file?(file)}
|
8
|
+
ignores = Dir['doc/**/*'].keep_if{|file| File.file?(file)} + %w(.travis.yml .gitignore)
|
9
|
+
|
10
|
+
Gem::Specification.new do |spec|
|
11
|
+
spec.name = "brainsome_typus"
|
12
|
+
spec.version = Typus::VERSION::STRING
|
13
|
+
spec.authors = ["Francesc Esplugas", "Brainsome-Developers"]
|
14
|
+
spec.email = ["support@typuscmf.com", nil]
|
15
|
+
spec.description = "Ruby on Rails Admin Panel (Engine) to allow trusted users edit structured content."
|
16
|
+
spec.summary = "Effortless backend interface for Ruby on Rails applications. (Admin scaffold generator)"
|
17
|
+
spec.homepage = "http://github.com/torial/typus"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.platform = Gem::Platform::RUBY
|
21
|
+
|
22
|
+
spec.files = files - test_files - ignores
|
23
|
+
spec.test_files = []
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.required_ruby_version = '>= 1.9.3'
|
27
|
+
spec.required_rubygems_version = '>= 1.8.11'
|
28
|
+
|
29
|
+
spec.add_dependency "bcrypt-ruby", "~> 3.1.2"
|
30
|
+
spec.add_dependency "jquery-rails"
|
31
|
+
spec.add_dependency "rails", "~> 4"
|
32
|
+
end
|