cm-admin 0.7.4 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +24 -22
- data/README.md +1 -1
- data/app/controllers/cm_admin/application_controller.rb +1 -2
- data/app/controllers/cm_admin/resource_controller.rb +194 -0
- data/app/javascript/packs/cm_admin/application.js +2 -0
- data/app/views/cm_admin/main/_actions_dropdown.html.slim +52 -0
- data/app/views/cm_admin/main/_associated_table.html.slim +2 -35
- data/app/views/cm_admin/main/_table.html.slim +3 -34
- data/cm_admin.gemspec +4 -3
- data/lib/cm_admin/model.rb +13 -67
- data/lib/cm_admin/models/action.rb +10 -0
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/action_dropdown_helper.rb +21 -0
- data/lib/cm_admin/view_helpers/field_display_helper.rb +2 -2
- data/lib/cm_admin/view_helpers.rb +6 -3
- data/lib/generators/cm_admin/add_authentication_generator.rb +31 -0
- data/lib/generators/cm_admin/templates/application_controller.rb +8 -0
- data/lib/generators/cm_admin/templates/authentication.rb +14 -0
- data/lib/generators/cm_admin/templates/cm_admin_initializer.rb +2 -0
- data/lib/generators/cm_admin/templates/current.rb +9 -0
- data/package-lock.json +20255 -0
- data/package.json +3 -2
- data/tmp/cache/webpacker/last-compilation-digest-development +1 -1
- data/yarn.lock +6284 -6148
- metadata +46 -25
- data/lib/cm_admin/models/controller_method.rb +0 -99
@@ -0,0 +1,21 @@
|
|
1
|
+
module CmAdmin
|
2
|
+
module ViewHelpers
|
3
|
+
module ActionDropdownHelper
|
4
|
+
def available_actions(cm_model, action_type)
|
5
|
+
if action_type.eql?('custom_actions')
|
6
|
+
cm_model.available_actions.select {
|
7
|
+
|act| act if act.route_type.eql?('member') &&
|
8
|
+
[:button, :modal].include?(act.display_type) &&
|
9
|
+
act.name.present? &&
|
10
|
+
has_valid_policy(cm_model.name, act.name)
|
11
|
+
}
|
12
|
+
else
|
13
|
+
cm_model.available_actions.select {
|
14
|
+
|act| act if act.action_type.eql?(:default) &&
|
15
|
+
act.name.eql?(action_type)
|
16
|
+
} if has_valid_policy(cm_model.name, action_type)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module CmAdmin
|
2
2
|
module ViewHelpers
|
3
3
|
module FieldDisplayHelper
|
4
|
-
|
5
4
|
def show_field(ar_object, field)
|
6
5
|
content_tag(:div, class: "info-split") do
|
7
6
|
concat show_field_label(ar_object, field)
|
@@ -33,7 +32,8 @@ module CmAdmin
|
|
33
32
|
when :string
|
34
33
|
ar_object.send(field.field_name).to_s
|
35
34
|
when :datetime
|
36
|
-
|
35
|
+
self.extend LocalTimeHelper
|
36
|
+
local_time(ar_object.send(field.field_name).strftime(field.format || "%d/%m/%Y").to_s) if ar_object.send(field.field_name)
|
37
37
|
when :text
|
38
38
|
ar_object.send(field.field_name)
|
39
39
|
when :custom
|
@@ -2,12 +2,15 @@ module CmAdmin
|
|
2
2
|
module ViewHelpers
|
3
3
|
Dir[File.expand_path("view_helpers", __dir__) + "/*.rb"].each { |f| require f }
|
4
4
|
|
5
|
-
include
|
6
|
-
include NavigationHelper
|
7
|
-
include FormHelper
|
5
|
+
include ActionDropdownHelper
|
8
6
|
include FieldDisplayHelper
|
9
7
|
include FilterHelper
|
8
|
+
include FormHelper
|
10
9
|
include ManageColumnPopupHelper
|
10
|
+
include NavigationHelper
|
11
|
+
include PageInfoHelper
|
12
|
+
|
13
|
+
# Included Rails view helper
|
11
14
|
include ActionView::Helpers::FormTagHelper
|
12
15
|
include ActionView::Helpers::TagHelper
|
13
16
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module CmAdmin
|
4
|
+
module Generators
|
5
|
+
class AddAuthenticationGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
# This generator is used to add authentication, if no auth system is present.
|
9
|
+
# Adds authentication through devise and sets up the current user.
|
10
|
+
def add_authentication
|
11
|
+
gem "devise"
|
12
|
+
generate "devise:install"
|
13
|
+
model_name = ask("What would you like the user model to be called? [user]")
|
14
|
+
generate "devise", model_name
|
15
|
+
rake "db:migrate"
|
16
|
+
copy_file 'application_controller.rb', 'app/controllers/cm_admin/application_controller.rb'
|
17
|
+
gsub_file 'app/controllers/cm_admin/application_controller.rb', 'authenticate_user', "authenticate_#{model_name}"
|
18
|
+
copy_file 'authentication.rb', 'app/controllers/concerns/authentication.rb'
|
19
|
+
gsub_file 'app/controllers/concerns/authentication.rb', 'current_user', "current_#{model_name}"
|
20
|
+
copy_file 'current.rb', 'app/models/current.rb'
|
21
|
+
inject_into_file "app/models/#{model_name.underscore}.rb", before: "end\n" do <<-'RUBY'
|
22
|
+
# Remove this once role is setup and mentioned in zcm_admin.rb
|
23
|
+
def super_admin?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
RUBY
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|