tramway-admin 4.0.1 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/app/controllers/tramway/admin/application_controller.rb +5 -1
- data/app/controllers/tramway/admin/sessions_controller.rb +2 -2
- data/app/helpers/tramway/admin/application_helper.rb +2 -1
- data/app/helpers/tramway/admin/frontend_helper.rb +21 -0
- data/app/views/layouts/tramway/admin/application.html.haml +4 -0
- data/app/views/layouts/tramway/admin/shared/_navbar.html.haml +0 -3
- data/app/views/tramway/admin/records/_form.html.haml +9 -6
- data/app/views/tramway/admin/records/_search.html.haml +2 -3
- data/app/views/tramway/admin/records/index.html.haml +1 -1
- data/app/views/tramway/admin/shared/show/associations/_row.html.haml +1 -1
- data/lib/tramway/admin/version.rb +1 -1
- data/lib/tramway/admin.rb +30 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52f598a393f67ead5da2a67ef98a7b721edea4cda7c5968dcc5fe2224c75ba11
|
4
|
+
data.tar.gz: 4ea29fb442be1e667e843c813dd4dba340672add79d93437abd3226852e6f8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00645c93a5d1e36ad76fe059a9fd775146614cb8be7046c119f186bf9f81b00aefe636af0e56cebdebbe8abee5b4b288d3e3f0156bff8e35d336a574c13b555c
|
7
|
+
data.tar.gz: cdc9339fac651475ea6853d70096cf2ad3c7826d80668d61feb96012749e16e3f37d09310fbe4dfdedaf58a2457cae8b794ad82be98ea9b1895032d60f12fae6
|
data/README.md
CHANGED
@@ -574,6 +574,13 @@ end
|
|
574
574
|
|
575
575
|
* **Model or Form is not available** - `params[:model]` or `params[:form]` is empty **OR** current user does not have access to model or form in `params[:model]` or `params[:form]`
|
576
576
|
|
577
|
+
## Change admin user base model
|
578
|
+
|
579
|
+
*config/initializers/tramway.rb*
|
580
|
+
```ruby
|
581
|
+
::Tramway::Admin.auth_config = { user_model: User, auth_attributes: %i[email username] }
|
582
|
+
```
|
583
|
+
|
577
584
|
## Good features
|
578
585
|
|
579
586
|
### Get actions log in admin panel
|
@@ -20,6 +20,10 @@ module Tramway
|
|
20
20
|
|
21
21
|
protected
|
22
22
|
|
23
|
+
def admin_model
|
24
|
+
::Tramway::Admin.admin_model
|
25
|
+
end
|
26
|
+
|
23
27
|
def check_available!
|
24
28
|
raise 'Tramway::Admin - Model or Form is not available. Looks like current user does not have access to change this model. Update your tramway initializer file' if !model_given? && !form_given?
|
25
29
|
end
|
@@ -120,7 +124,7 @@ module Tramway
|
|
120
124
|
end
|
121
125
|
|
122
126
|
def current_admin
|
123
|
-
user =
|
127
|
+
user = admin_model.find_by id: session[:admin_id]
|
124
128
|
return false unless user
|
125
129
|
|
126
130
|
Tramway::User::UserDecorator.decorate user
|
@@ -6,11 +6,11 @@ class Tramway::Admin::SessionsController < ::Tramway::Admin::ApplicationControll
|
|
6
6
|
skip_before_action :collections_counts
|
7
7
|
|
8
8
|
def new
|
9
|
-
@session_form = ::Tramway::Auth::SessionForm.new
|
9
|
+
@session_form = ::Tramway::Auth::SessionForm.new admin_model.new
|
10
10
|
end
|
11
11
|
|
12
12
|
def create
|
13
|
-
@session_form = ::Tramway::Auth::SessionForm.new
|
13
|
+
@session_form = ::Tramway::Auth::SessionForm.new admin_model.find_or_initialize_by email: params[:user][:email]
|
14
14
|
if @session_form.validate params[:user]
|
15
15
|
admin_sign_in @session_form.model
|
16
16
|
redirect_to Tramway::Admin::Engine.routes.url_helpers.root_path
|
@@ -17,6 +17,7 @@ module Tramway
|
|
17
17
|
include ::Tramway::Collections::Helper
|
18
18
|
include ::Tramway::Core::CopyToClipboardHelper
|
19
19
|
include ::Tramway::Admin::TramwayModelHelper
|
20
|
+
include ::Tramway::Admin::FrontendHelper
|
20
21
|
|
21
22
|
def object_type(object)
|
22
23
|
object_class_name = if object.class.ancestors.include? ::Tramway::Core::ApplicationDecorator
|
@@ -28,7 +29,7 @@ module Tramway
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def current_admin
|
31
|
-
user = Tramway::
|
32
|
+
user = Tramway::Admin.admin_model.find_by id: session[:admin_id]
|
32
33
|
return false unless user
|
33
34
|
|
34
35
|
Tramway::User::UserDecorator.decorate user
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Tramway::Admin::FrontendHelper
|
2
|
+
def react_params(form, action, method)
|
3
|
+
url = case action
|
4
|
+
when :create
|
5
|
+
Tramway::Admin::Engine.routes.url_helpers.records_path(model: form.model.class)
|
6
|
+
else
|
7
|
+
Tramway::Admin::Engine.routes.url_helpers.record_path(form.model.id, model: form.model.class)
|
8
|
+
end
|
9
|
+
form.properties.reduce({ action: url, method: method, authenticity_token: form_authenticity_token }) do |hash, property|
|
10
|
+
case property[1]
|
11
|
+
when :association
|
12
|
+
hash.merge!(
|
13
|
+
property[0] => {
|
14
|
+
collection: build_collection_for_association(form, property[0])
|
15
|
+
}
|
16
|
+
)
|
17
|
+
end
|
18
|
+
hash
|
19
|
+
end.merge model: form.model.attributes
|
20
|
+
end
|
21
|
+
end
|
@@ -8,6 +8,10 @@
|
|
8
8
|
= javascript_include_tag 'tramway/admin/application'
|
9
9
|
- if File.exists?("#{Rails.root}/app/assets/javascripts/admin/application.js") || File.exists?("#{Rails.root}/app/assets/javascripts/admin/application.js.coffee")
|
10
10
|
= javascript_include_tag 'admin/application'
|
11
|
+
- if File.exists?("#{Rails.root}/app/assets/stylesheets/admin/application.css") || File.exists?("#{Rails.root}/app/assets/stylesheets/admin/application.scss")
|
12
|
+
= stylesheet_link_tag 'admin/application'
|
13
|
+
- if File.exists?("#{Rails.root}/app/javascript/packs/admin/application.js")
|
14
|
+
= javascript_pack_tag 'admin/application'
|
11
15
|
= csrf_meta_tags
|
12
16
|
- if @application.favicon.present?
|
13
17
|
= favicon_link_tag @application.favicon
|
@@ -1,5 +1,4 @@
|
|
1
1
|
%nav.navbar.navbar-expand-md.navbar-dark.bg-dark
|
2
|
-
-# FIXME use helper methods
|
3
2
|
- if ::Tramway::Admin.customized_admin_navbar.present?
|
4
3
|
= ::Tramway::Admin.customized_admin_navbar
|
5
4
|
- else
|
@@ -54,8 +53,6 @@
|
|
54
53
|
%span.badge.badge-light
|
55
54
|
= @notifications_count
|
56
55
|
%li.nav-item
|
57
|
-
-# FIXME url_helpers return with /admin for some reason
|
58
|
-
-#= link_to Tramway::Auth::Engine.routes.url_helpers.session_path(model: Tramway::User::User).sub('/admin', ''), method: :delete, class: 'nav-link' do
|
59
56
|
= link_to '/admin/sign_out', class: 'nav-link' do
|
60
57
|
= fa_icon 'sign-out-alt'
|
61
58
|
= t('helpers.links.sign_out')
|
@@ -8,12 +8,15 @@
|
|
8
8
|
= render 'tramway/core/shared/messages', object: @record_form
|
9
9
|
.row
|
10
10
|
.col-lg-12
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
=
|
15
|
-
|
16
|
-
|
11
|
+
- if @record_form.class.is_react_component?
|
12
|
+
= react_component "#{@record_form.class.name.gsub('::', '/')}", react_params(@record_form, action, method)
|
13
|
+
- else
|
14
|
+
= simple_form_for @record_form, url: { controller: :records, action: action, model: @record_form.model.class }, method: method, input_html: { class: 'form-horizontal' } do |f|
|
15
|
+
- @record_form.properties.each do |property, type|
|
16
|
+
= render 'tramway/core/shared/input', property: property, object: :record, type: type, form: f, destination: :admin, value: value_from_params(model_class: model_class, property: property, type: type)
|
17
|
+
= hidden_field_tag :redirect, params[:redirect]
|
18
|
+
= f.button :submit, t('helpers.links.save'), class: 'btn btn-success'
|
19
|
+
= link_to t('helpers.links.back'), current_model_records_path, class: 'btn btn-secondary'
|
17
20
|
|
18
21
|
-# NOTES
|
19
22
|
-# * value_from_params helper is in tramway-core gem app/helpers/inputs_helpers.rb
|
@@ -3,8 +3,9 @@
|
|
3
3
|
.d-flex.flex-row-reverse.filters
|
4
4
|
= form_tag records_path, class: 'form-inline', method: :get do |f|
|
5
5
|
- if searchable_model?(model_class)
|
6
|
-
.
|
6
|
+
.input-group
|
7
7
|
= text_field_tag :search, params[:search], class: 'text form-control'
|
8
|
+
= submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
|
8
9
|
= hidden_field_tag :model, params[:model]
|
9
10
|
= hidden_field_tag :scope, params[:scope]
|
10
11
|
= hidden_field_tag :filter, (params[:filter].is_a?(ActionController::Parameters) ? params[:filter].permit!.to_h.to_json : params[:filter])
|
@@ -31,5 +32,3 @@
|
|
31
32
|
$('#filter_datepicker_begin_date').datepicker();
|
32
33
|
$('#filter_datepicker_end_date').datepicker();
|
33
34
|
});
|
34
|
-
.col-md-4.submit
|
35
|
-
= submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
|
@@ -7,7 +7,7 @@
|
|
7
7
|
%td
|
8
8
|
= model_class.human_attribute_name association.name
|
9
9
|
%hr
|
10
|
-
- if create_is_available?(association.
|
10
|
+
- if create_is_available?(association.class_name) && (association_type != :has_one || !object.send(association.name).present?)
|
11
11
|
= link_to "#{I18n.t('helpers.actions.add')} #{model_class.human_attribute_name(association.name).singularize.downcase}", new_associated_record_path(association: association, object: object, as: object.send("#{association.name}_as")), class: 'btn btn-primary'
|
12
12
|
%td{ colspan: 2 }
|
13
13
|
- if association_type.in? [ :has_one, :belongs_to ]
|
data/lib/tramway/admin.rb
CHANGED
@@ -79,6 +79,36 @@ module Tramway
|
|
79
79
|
new_hash.merge! pair[0].to_s => pair[1]
|
80
80
|
end
|
81
81
|
end
|
82
|
+
|
83
|
+
def admin_model
|
84
|
+
@@auth_config.first[:user_model]
|
85
|
+
end
|
86
|
+
|
87
|
+
def auth_config
|
88
|
+
@@auth_config ||= [{ user_model: ::Tramway::User::User, auth_attributes: :email }]
|
89
|
+
end
|
90
|
+
|
91
|
+
def auth_config=(params)
|
92
|
+
if params.is_a? Hash
|
93
|
+
@@auth_config = [params]
|
94
|
+
elsif params.is_a? Array
|
95
|
+
@@auth_config = params
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def user_based_models
|
100
|
+
@@auth_config ||= []
|
101
|
+
@@auth_config.map do |conf|
|
102
|
+
conf[:user_model]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def auth_attributes
|
107
|
+
@@auth_config ||= []
|
108
|
+
@@auth_config.reduce({}) do |hash, conf|
|
109
|
+
hash.merge! conf[:user_model] => conf[:auth_attributes]
|
110
|
+
end
|
111
|
+
end
|
82
112
|
end
|
83
113
|
end
|
84
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tramway-core
|
@@ -256,6 +256,7 @@ files:
|
|
256
256
|
- app/helpers/tramway/admin/application_helper.rb
|
257
257
|
- app/helpers/tramway/admin/cases_helper.rb
|
258
258
|
- app/helpers/tramway/admin/focus_generator_helper.rb
|
259
|
+
- app/helpers/tramway/admin/frontend_helper.rb
|
259
260
|
- app/helpers/tramway/admin/navbar_helper.rb
|
260
261
|
- app/helpers/tramway/admin/records_helper.rb
|
261
262
|
- app/helpers/tramway/admin/russian_cases_helper.rb
|