manage 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +7 -10
  3. data/app/assets/javascripts/manage/application.js +1 -2
  4. data/app/assets/stylesheets/manage/application.css.scss +1 -1
  5. data/app/controllers/manage/admin_users_controller.rb +12 -0
  6. data/app/controllers/manage/application_controller.rb +4 -10
  7. data/app/controllers/manage/resource_controller.rb +74 -0
  8. data/app/controllers/manage/sessions_controller.rb +8 -3
  9. data/app/helpers/manage/form_helper.rb +1 -1
  10. data/app/helpers/manage/resource_helper.rb +56 -0
  11. data/app/models/admin_user.rb +4 -0
  12. data/app/views/layouts/manage/_main_menu.html.slim +1 -5
  13. data/app/views/layouts/manage/sign_in.html.slim +13 -13
  14. data/app/views/manage/resource/_form.html.slim +3 -3
  15. data/app/views/manage/resource/index/_count.html.slim +6 -0
  16. data/app/views/manage/resource/index/_filters.html.slim +18 -7
  17. data/app/views/manage/resource/index/_table.html.slim +7 -5
  18. data/app/views/manage/resource/index.html.slim +3 -2
  19. data/app/views/{sessions → manage/sessions}/new.html.slim +2 -3
  20. data/config/initializers/devise.rb +247 -0
  21. data/config/initializers/session_store.rb +3 -0
  22. data/config/initializers/simple_form_foundation.rb +2 -0
  23. data/config/locales/devise.en.yml +59 -0
  24. data/config/routes.rb +6 -4
  25. data/db/migrate/20131204142720_create_admin_users.rb +24 -0
  26. data/lib/manage/engine.rb +16 -5
  27. data/lib/manage/fields/reader.rb +57 -0
  28. data/lib/manage/fields/searcher.rb +48 -0
  29. data/lib/manage/fields.rb +6 -0
  30. data/lib/manage/version.rb +1 -1
  31. data/lib/manage.rb +2 -0
  32. data/lib/tasks/manage_tasks.rake +11 -0
  33. data/lib/templates/erb/scaffold/_form.html.erb +1 -1
  34. data/spec/controllers/manage/resource_controller_spec.rb +29 -0
  35. data/spec/dummy/app/controllers/manage/posts_controller.rb +4 -0
  36. data/spec/dummy/app/models/post.rb +3 -0
  37. data/spec/dummy/app/models/user.rb +5 -0
  38. data/{test → spec}/dummy/config/application.rb +1 -0
  39. data/{test → spec}/dummy/config/database.yml +1 -1
  40. data/spec/dummy/config/routes.rb +10 -0
  41. data/spec/dummy/db/migrate/20130716083410_init_migration.rb +21 -0
  42. data/spec/dummy/db/schema.rb +53 -0
  43. data/spec/fields/reader_spec.rb +79 -0
  44. data/spec/spec_helper.rb +24 -0
  45. metadata +163 -104
  46. data/test/controllers/manage/resource_controller_test.rb +0 -9
  47. data/test/dummy/config/routes.rb +0 -4
  48. data/test/helpers/manage/resource_helper_test.rb +0 -6
  49. data/test/integration/navigation_test.rb +0 -10
  50. data/test/manage_test.rb +0 -7
  51. data/test/test_helper.rb +0 -15
  52. /data/{test → spec}/dummy/README.rdoc +0 -0
  53. /data/{test → spec}/dummy/Rakefile +0 -0
  54. /data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
  55. /data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
  56. /data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
  57. /data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
  58. /data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
  59. /data/{test → spec}/dummy/bin/bundle +0 -0
  60. /data/{test → spec}/dummy/bin/rails +0 -0
  61. /data/{test → spec}/dummy/bin/rake +0 -0
  62. /data/{test → spec}/dummy/config/boot.rb +0 -0
  63. /data/{test → spec}/dummy/config/environment.rb +0 -0
  64. /data/{test → spec}/dummy/config/environments/development.rb +0 -0
  65. /data/{test → spec}/dummy/config/environments/production.rb +0 -0
  66. /data/{test → spec}/dummy/config/environments/test.rb +0 -0
  67. /data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  68. /data/{test → spec}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
  69. /data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  70. /data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
  71. /data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
  72. /data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
  73. /data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
  74. /data/{test → spec}/dummy/config/locales/en.yml +0 -0
  75. /data/{test → spec}/dummy/config.ru +0 -0
  76. /data/{test → spec}/dummy/public/404.html +0 -0
  77. /data/{test → spec}/dummy/public/422.html +0 -0
  78. /data/{test → spec}/dummy/public/500.html +0 -0
  79. /data/{test → spec}/dummy/public/favicon.ico +0 -0
@@ -0,0 +1,247 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ # The secret key used by Devise. Devise uses this key to generate
5
+ # random tokens. Changing this key will render invalid all existing
6
+ # confirmation, reset password and unlock tokens in the database.
7
+ config.secret_key = 'cfd1236b63220546d94fbed7e953a984a6491f3a8bc1130c423439102bf1affb8ef64f5df5e36b9bd181c304204fe6c2e532982f0f359a068af9aa127e2cb064'
8
+
9
+ # ==> Mailer Configuration
10
+ # Configure the e-mail address which will be shown in Devise::Mailer,
11
+ # note that it will be overwritten if you use your own mailer class
12
+ # with default "from" parameter.
13
+ config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
14
+
15
+ # Configure the class responsible to send e-mails.
16
+ # config.mailer = 'Devise::Mailer'
17
+
18
+ # ==> ORM configuration
19
+ # Load and configure the ORM. Supports :active_record (default) and
20
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
21
+ # available as additional gems.
22
+ require 'devise/orm/active_record'
23
+
24
+ # ==> Configuration for any authentication mechanism
25
+ # Configure which keys are used when authenticating a user. The default is
26
+ # just :email. You can configure it to use [:username, :subdomain], so for
27
+ # authenticating a user, both parameters are required. Remember that those
28
+ # parameters are used only when authenticating and not when retrieving from
29
+ # session. If you need permissions, you should implement that in a before filter.
30
+ # You can also supply a hash where the value is a boolean determining whether
31
+ # or not authentication should be aborted when the value is not present.
32
+ # config.authentication_keys = [ :email ]
33
+
34
+ # Configure parameters from the request object used for authentication. Each entry
35
+ # given should be a request method and it will automatically be passed to the
36
+ # find_for_authentication method and considered in your model lookup. For instance,
37
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
38
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
39
+ # config.request_keys = []
40
+
41
+ # Configure which authentication keys should be case-insensitive.
42
+ # These keys will be downcased upon creating or modifying a user and when used
43
+ # to authenticate or find a user. Default is :email.
44
+ config.case_insensitive_keys = [ :email ]
45
+
46
+ # Configure which authentication keys should have whitespace stripped.
47
+ # These keys will have whitespace before and after removed upon creating or
48
+ # modifying a user and when used to authenticate or find a user. Default is :email.
49
+ config.strip_whitespace_keys = [ :email ]
50
+
51
+ # Tell if authentication through request.params is enabled. True by default.
52
+ # It can be set to an array that will enable params authentication only for the
53
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
54
+ # enable it only for database (email + password) authentication.
55
+ # config.params_authenticatable = true
56
+
57
+ # Tell if authentication through HTTP Auth is enabled. False by default.
58
+ # It can be set to an array that will enable http authentication only for the
59
+ # given strategies, for example, `config.http_authenticatable = [:database]` will
60
+ # enable it only for database authentication. The supported strategies are:
61
+ # :database = Support basic authentication with authentication key + password
62
+ # config.http_authenticatable = false
63
+
64
+ # If http headers should be returned for AJAX requests. True by default.
65
+ # config.http_authenticatable_on_xhr = true
66
+
67
+ # The realm used in Http Basic Authentication. 'Application' by default.
68
+ # config.http_authentication_realm = 'Application'
69
+
70
+ # It will change confirmation, password recovery and other workflows
71
+ # to behave the same regardless if the e-mail provided was right or wrong.
72
+ # Does not affect registerable.
73
+ # config.paranoid = true
74
+
75
+ # By default Devise will store the user in session. You can skip storage for
76
+ # particular strategies by setting this option.
77
+ # Notice that if you are skipping storage for all authentication paths, you
78
+ # may want to disable generating routes to Devise's sessions controller by
79
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
80
+ config.skip_session_storage = [:http_auth]
81
+
82
+ # By default, Devise cleans up the CSRF token on authentication to
83
+ # avoid CSRF token fixation attacks. This means that, when using AJAX
84
+ # requests for sign in and sign up, you need to get a new CSRF token
85
+ # from the server. You can disable this option at your own risk.
86
+ # config.clean_up_csrf_token_on_authentication = true
87
+
88
+ # ==> Configuration for :database_authenticatable
89
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
90
+ # using other encryptors, it sets how many times you want the password re-encrypted.
91
+ #
92
+ # Limiting the stretches to just one in testing will increase the performance of
93
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
94
+ # a value less than 10 in other environments.
95
+ config.stretches = Rails.env.test? ? 1 : 10
96
+
97
+ # Setup a pepper to generate the encrypted password.
98
+ # config.pepper = '7c21a253b30401590aa2948d35eb4fa6d0f1017e825c14a1ab1878f57c70e23a5b3b88126fda5dec2fbf7ec3298cf3f2e80a38fd4aa9527bdee53b636265011e'
99
+
100
+ # ==> Configuration for :confirmable
101
+ # A period that the user is allowed to access the website even without
102
+ # confirming his account. For instance, if set to 2.days, the user will be
103
+ # able to access the website for two days without confirming his account,
104
+ # access will be blocked just in the third day. Default is 0.days, meaning
105
+ # the user cannot access the website without confirming his account.
106
+ # config.allow_unconfirmed_access_for = 2.days
107
+
108
+ # A period that the user is allowed to confirm their account before their
109
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
110
+ # their account within 3 days after the mail was sent, but on the fourth day
111
+ # their account can't be confirmed with the token any more.
112
+ # Default is nil, meaning there is no restriction on how long a user can take
113
+ # before confirming their account.
114
+ # config.confirm_within = 3.days
115
+
116
+ # If true, requires any email changes to be confirmed (exactly the same way as
117
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
118
+ # db field (see migrations). Until confirmed new email is stored in
119
+ # unconfirmed email column, and copied to email column on successful confirmation.
120
+ config.reconfirmable = true
121
+
122
+ # Defines which key will be used when confirming an account
123
+ # config.confirmation_keys = [ :email ]
124
+
125
+ # ==> Configuration for :rememberable
126
+ # The time the user will be remembered without asking for credentials again.
127
+ # config.remember_for = 2.weeks
128
+
129
+ # If true, extends the user's remember period when remembered via cookie.
130
+ # config.extend_remember_period = false
131
+
132
+ # Options to be passed to the created cookie. For instance, you can set
133
+ # :secure => true in order to force SSL only cookies.
134
+ # config.rememberable_options = {}
135
+
136
+ # ==> Configuration for :validatable
137
+ # Range for password length. Default is 8..128.
138
+ config.password_length = 8..128
139
+
140
+ # Email regex used to validate email formats. It simply asserts that
141
+ # one (and only one) @ exists in the given string. This is mainly
142
+ # to give user feedback and not to assert the e-mail validity.
143
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
144
+
145
+ # ==> Configuration for :timeoutable
146
+ # The time you want to timeout the user session without activity. After this
147
+ # time the user will be asked for credentials again. Default is 30 minutes.
148
+ # config.timeout_in = 30.minutes
149
+
150
+ # If true, expires auth token on session timeout.
151
+ # config.expire_auth_token_on_timeout = false
152
+
153
+ # ==> Configuration for :lockable
154
+ # Defines which strategy will be used to lock an account.
155
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
156
+ # :none = No lock strategy. You should handle locking by yourself.
157
+ # config.lock_strategy = :failed_attempts
158
+
159
+ # Defines which key will be used when locking and unlocking an account
160
+ # config.unlock_keys = [ :email ]
161
+
162
+ # Defines which strategy will be used to unlock an account.
163
+ # :email = Sends an unlock link to the user email
164
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
165
+ # :both = Enables both strategies
166
+ # :none = No unlock strategy. You should handle unlocking by yourself.
167
+ # config.unlock_strategy = :both
168
+
169
+ # Number of authentication tries before locking an account if lock_strategy
170
+ # is failed attempts.
171
+ # config.maximum_attempts = 20
172
+
173
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
174
+ # config.unlock_in = 1.hour
175
+
176
+ # Warn on the last attempt before the account is locked.
177
+ # config.last_attempt_warning = false
178
+
179
+ # ==> Configuration for :recoverable
180
+ #
181
+ # Defines which key will be used when recovering the password for an account
182
+ # config.reset_password_keys = [ :email ]
183
+
184
+ # Time interval you can reset your password with a reset password key.
185
+ # Don't put a too small interval or your users won't have the time to
186
+ # change their passwords.
187
+ config.reset_password_within = 6.hours
188
+
189
+ # ==> Configuration for :encryptable
190
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
191
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
192
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
193
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
194
+ # REST_AUTH_SITE_KEY to pepper).
195
+ #
196
+ # Require the `devise-encryptable` gem when using anything other than bcrypt
197
+ # config.encryptor = :sha512
198
+
199
+ # ==> Scopes configuration
200
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
201
+ # "users/sessions/new". It's turned off by default because it's slower if you
202
+ # are using only default views.
203
+ config.scoped_views = true
204
+
205
+ # Configure the default scope given to Warden. By default it's the first
206
+ # devise role declared in your routes (usually :user).
207
+ # config.default_scope = :admin_user
208
+
209
+ # Set this configuration to false if you want /users/sign_out to sign out
210
+ # only the current scope. By default, Devise signs out all scopes.
211
+ # config.sign_out_all_scopes = true
212
+
213
+ # ==> Navigation configuration
214
+ # Lists the formats that should be treated as navigational. Formats like
215
+ # :html, should redirect to the sign in page when the user does not have
216
+ # access, but formats like :xml or :json, should return 401.
217
+ #
218
+ # If you have any extra navigational formats, like :iphone or :mobile, you
219
+ # should add them to the navigational formats lists.
220
+ #
221
+ # The "*/*" below is required to match Internet Explorer requests.
222
+ # config.navigational_formats = ['*/*', :html]
223
+
224
+ # The default HTTP method used to sign out a resource. Default is :delete.
225
+ config.sign_out_via = :delete
226
+
227
+ # ==> OmniAuth
228
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
229
+ # up on your models and hooks.
230
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
231
+
232
+ # ==> Warden configuration
233
+ # If you want to use other strategies, that are not supported by Devise, or
234
+ # change the failure app, you can configure them inside the config.warden block.
235
+ #
236
+ # config.warden do |manager|
237
+ # manager.intercept_401 = false
238
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
239
+ # end
240
+
241
+ #config.router_name = :manage
242
+
243
+ #
244
+ # When using omniauth, Devise cannot automatically set Omniauth path,
245
+ # so you need to do it manually. For the users scope, it would be:
246
+ # config.omniauth_path_prefix = '/my_engine/users/auth'
247
+ end
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Yatoto::Application.config.session_store :cookie_store, key: '_YatotoManage_session'
@@ -14,4 +14,6 @@ SimpleForm.setup do |config|
14
14
  # does't provide styles for hints. You will need to provide your own CSS styles for hints.
15
15
  # b.use :hint, wrap_with: { tag: :span, class: :hint }
16
16
  end
17
+
18
+ config.form_class = 'simple_form custom'
17
19
  end
@@ -0,0 +1,59 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ devise:
5
+ confirmations:
6
+ confirmed: "Your account was successfully confirmed."
7
+ send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
8
+ send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
9
+ failure:
10
+ already_authenticated: "You are already signed in."
11
+ inactive: "Your account is not activated yet."
12
+ invalid: "Invalid email or password."
13
+ locked: "Your account is locked."
14
+ last_attempt: "You have one more attempt before your account will be locked."
15
+ not_found_in_database: "Invalid email or password."
16
+ timeout: "Your session expired. Please sign in again to continue."
17
+ unauthenticated: "You need to sign in or sign up before continuing."
18
+ unconfirmed: "You have to confirm your account before continuing."
19
+ mailer:
20
+ confirmation_instructions:
21
+ subject: "Confirmation instructions"
22
+ reset_password_instructions:
23
+ subject: "Reset password instructions"
24
+ unlock_instructions:
25
+ subject: "Unlock Instructions"
26
+ omniauth_callbacks:
27
+ failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
28
+ success: "Successfully authenticated from %{kind} account."
29
+ passwords:
30
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
31
+ send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes."
32
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
33
+ updated: "Your password was changed successfully. You are now signed in."
34
+ updated_not_active: "Your password was changed successfully."
35
+ registrations:
36
+ destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
37
+ signed_up: "Welcome! You have signed up successfully."
38
+ signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
39
+ signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
40
+ signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
41
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
42
+ updated: "You updated your account successfully."
43
+ sessions:
44
+ signed_in: "Signed in successfully."
45
+ signed_out: "Signed out successfully."
46
+ unlocks:
47
+ send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
48
+ send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
49
+ unlocked: "Your account has been unlocked successfully. Please sign in to continue."
50
+ errors:
51
+ messages:
52
+ already_confirmed: "was already confirmed, please try signing in"
53
+ confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
54
+ expired: "has expired, please request a new one"
55
+ not_found: "not found"
56
+ not_locked: "was not locked"
57
+ not_saved:
58
+ one: "1 error prohibited this %{resource} from being saved:"
59
+ other: "%{count} errors prohibited this %{resource} from being saved:"
data/config/routes.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  Manage::Engine.routes.draw do
2
+ devise_for :admin_users, :class_name => "AdminUser", skip: :registrations, controllers: {
3
+ sessions: "manage/sessions"
4
+ }
5
+
2
6
  resources :dashboards
3
7
  resources :admin_users
4
8
 
5
- # devise_for :admin_users, skip: :registrations, controllers: {
6
- # sessions: "manage/sessions",
7
- # }
8
- end
9
+ root 'dashboards#index'
10
+ end
@@ -0,0 +1,24 @@
1
+ class CreateAdminUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table "admin_users", force: true do |t|
4
+ t.string "email", default: "", null: false
5
+ t.string "encrypted_password", default: "", null: false
6
+ t.string "reset_password_token"
7
+ t.datetime "reset_password_sent_at"
8
+ t.datetime "remember_created_at"
9
+ t.integer "sign_in_count", default: 0
10
+ t.datetime "current_sign_in_at"
11
+ t.datetime "last_sign_in_at"
12
+ t.string "current_sign_in_ip"
13
+ t.string "last_sign_in_ip"
14
+ t.integer "failed_attempts", default: 0
15
+ t.string "unlock_token"
16
+ t.datetime "locked_at"
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ end
20
+
21
+ add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree
22
+ add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree
23
+ end
24
+ end
data/lib/manage/engine.rb CHANGED
@@ -1,10 +1,21 @@
1
- require 'kaminari'
2
- require 'responders'
3
- require 'inherited_resources'
4
- require 'zurb-foundation'
1
+ require 'kaminari'
2
+ require 'responders'
3
+ require 'inherited_resources'
4
+ require 'simple_form'
5
+ require 'jquery-rails'
6
+ require 'zurb-foundation'
7
+ require 'devise'
8
+ require 'slim'
9
+ require 'search_object'
5
10
 
6
- module Manage
11
+ module Manage
7
12
  class Engine < ::Rails::Engine
8
13
  isolate_namespace Manage
14
+
15
+ config.generators do |g|
16
+ g.test_framework :rspec, :fixture => false
17
+ g.assets false
18
+ g.helper false
19
+ end
9
20
  end
10
21
  end
@@ -0,0 +1,57 @@
1
+ module Manage
2
+ module Fields
3
+ class Reader
4
+ class << self
5
+ def field_value(scope, field_data)
6
+ current_field, rest_field_parts, custom_query, custom_format = _parse_field_data(field_data)
7
+ value = scope.public_send(current_field)
8
+
9
+ if _is_field_relation?(value)
10
+ value = custom_query.present? ? custom_query.call(value) : value
11
+
12
+ value.map do |entity|
13
+ ("<a href=\"#{current_field}/#{entity.id}\">#{custom_format.present? ? custom_format.call(entity) : entity.id }</a>")
14
+ end.join(', ').html_safe
15
+ else
16
+ rest_field_parts.empty? ? value : field_value(value, rest_field_parts.join('.'))
17
+ end
18
+ end
19
+
20
+ def field_title(resource_class, field_data, prefix='')
21
+ current_field, rest_field_parts = _parse_field_data(field_data)
22
+ title = resource_class.human_attribute_name(current_field)
23
+
24
+ rest_field_parts.empty? ? prefix + title : field_title(resource_class, rest_field_parts.join('.'), prefix + title + ' ')
25
+ end
26
+
27
+ private
28
+ def _is_field_relation?(field_value)
29
+ field_value.is_a?(ActiveRecord::Associations::CollectionProxy)
30
+ end
31
+
32
+ def _parse_field_data(field_data)
33
+ custom_query = nil
34
+ custom_format = nil
35
+
36
+ if field_data.is_a?(Hash)
37
+ current_field = field_data.keys.first
38
+ rest_field_parts = field_data[current_field]
39
+
40
+ if rest_field_parts.is_a?(String)
41
+ rest_field_parts = Array(rest_field_parts)
42
+ else
43
+ custom_query = field_data[current_field][:query]
44
+ custom_format = field_data[current_field][:format]
45
+ rest_field_parts = []
46
+ end
47
+ else
48
+ current_field, *rest_field_parts = field_data.to_s.split('.')
49
+ end
50
+
51
+ return current_field, rest_field_parts, custom_query, custom_format
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,48 @@
1
+ module Manage
2
+ module Fields
3
+ class Searcher
4
+ class << self
5
+ def generate_search_object(resource_class, search_fields)
6
+ search_class = Class.new do
7
+ include SearchObject.module(:model, :sorting)
8
+
9
+ def escape_search_term(term)
10
+ "%#{term.gsub(/\s+/, '%')}%"
11
+ end
12
+
13
+ def parse_date(date)
14
+ Date.strptime(date, '%Y-%m-%d') rescue nil
15
+ end
16
+ end
17
+
18
+
19
+ search_class.scope { resource_class.all }
20
+ Object.const_set("#{resource_class.name + 'Searcher'}", search_class)
21
+
22
+ search_fields.select {|f| not f.to_s.include?('.')}.each do |field|
23
+ field_type = resource_class.columns_hash[field.to_s].type
24
+ if field_type == :text or field_type == :string
25
+ search_class.option field.to_sym do |scope, value|
26
+ scope.where "#{field.to_s} LIKE ?", escape_search_term(value)
27
+ end
28
+ elsif field_type == :datetime
29
+ search_class.option field.to_sym do |scope, value|
30
+ date = parse_date value
31
+ scope.where("DATE(#{field.to_s}) >= ?", date) if date.present?
32
+ end
33
+ elsif field_type == :integer
34
+ search_class.option field.to_sym
35
+ else
36
+ search_class.option field.to_sym do |scope, value|
37
+ scope.where "#{field.to_s} LIKE ?", escape_search_term(value)
38
+ end
39
+ end
40
+ end
41
+
42
+ search_class
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,6 @@
1
+ module Manage
2
+ module Fields
3
+ autoload :Reader, 'manage/fields/reader'
4
+ autoload :Searcher, 'manage/fields/searcher'
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Manage
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/manage.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require "manage/engine"
2
+ require "manage/fields"
3
+
2
4
  module Manage
3
5
  end
@@ -2,3 +2,14 @@
2
2
  # task :manage do
3
3
  # # Task goes here
4
4
  # end
5
+
6
+ namespace :manage do
7
+ desc "Create the initial admin user for the interface"
8
+ task :create_admin => :environment do
9
+ user = Manage::AdminUser.create!(
10
+ :email => "admin@admin.com",
11
+ :password => "11223344",
12
+ :password_confirmation => "11223344"
13
+ )
14
+ end
15
+ end
@@ -2,7 +2,7 @@
2
2
  <%%= f.error_notification %>
3
3
 
4
4
  <div class="form-inputs">
5
- <%- attributes.each do |attribute| -%>
5
+ <%- edit_attributes.each do |attribute| -%>
6
6
  <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7
7
  <%- end -%>
8
8
  </div>
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Manage
4
+
5
+ describe PostsController do
6
+ render_views
7
+ routes { Manage::Engine.routes }
8
+
9
+ before do
10
+ @admin = AdminUser.create!(email: 'admin@some.gf', password: '11223344', password_confirmation: '11223344')
11
+ sign_in @admin
12
+
13
+ @user = User.create!(email: 'some@do.cd', username: 'Sandokan')
14
+ @user.posts.create(content: 'Some')
15
+ @user.save!
16
+ end
17
+
18
+ it 'Shows only index fields listed' do
19
+ get :index
20
+ body = response.body
21
+
22
+ body.should include(@user.email)
23
+ body.should include(@user.username)
24
+ body.should include(@user.posts.first.id.to_s)
25
+ body.should include(@user.posts.first.content)
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,4 @@
1
+ class Manage::PostsController < Manage::ResourceController
2
+ index_fields :id, 'content', 'user.username', 'user.email'
3
+ edit_fields :content
4
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,5 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ has_many :posts, dependent: :destroy
4
+
5
+ end
@@ -18,6 +18,7 @@ module Dummy
18
18
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
19
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
20
  # config.i18n.default_locale = :de
21
+ I18n.enforce_available_locales = false
21
22
  end
22
23
  end
23
24
 
@@ -14,7 +14,7 @@ development:
14
14
  # Do not set this db to the same as development or production.
15
15
  test:
16
16
  adapter: sqlite3
17
- database: db/test.sqlite3
17
+ database: ":memory:"
18
18
  pool: 5
19
19
  timeout: 5000
20
20
 
@@ -0,0 +1,10 @@
1
+ Rails.application.routes.draw do
2
+
3
+ mount Manage::Engine => "/manage"
4
+
5
+ Manage::Engine.routes.draw do
6
+ resources :users
7
+ resources :posts
8
+ end
9
+
10
+ end
@@ -0,0 +1,21 @@
1
+ class InitMigration < ActiveRecord::Migration
2
+ def change
3
+
4
+ create_table "posts", force: true do |t|
5
+ t.text "content"
6
+ t.datetime "created_at"
7
+ t.datetime "updated_at"
8
+ t.integer "user_id"
9
+ end
10
+
11
+ add_index "posts", ["user_id"]
12
+
13
+ create_table "users", force: true do |t|
14
+ t.string "username"
15
+ t.string "email", null: false
16
+ t.datetime "created_at"
17
+ t.datetime "updated_at"
18
+ end
19
+ end
20
+
21
+ end