tramway-admin 2.1.3 → 3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -2
- data/app/controllers/tramway/admin/application_controller.rb +2 -2
- data/app/controllers/tramway/admin/records_controller.rb +6 -6
- data/app/controllers/tramway/admin/sessions_controller.rb +1 -1
- data/app/controllers/tramway/admin/singletons_controller.rb +4 -4
- data/app/views/tramway/admin/records/_search.html.haml +1 -1
- data/app/views/tramway/admin/shared/show/associations/_habtm_row.html.haml +5 -2
- data/app/views/tramway/admin/shared/show/associations/_list.html.haml +21 -0
- data/lib/tramway/admin/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a386a68e9e5d73e44283c9afbc5607e23a6dc39c059510eb039e4480c059694
|
4
|
+
data.tar.gz: b8e50c30673e2ac8f4f4448a099a84334b2c8d6656a08cd8b8cc715ece2dfbeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0075433e4129c8f0369b243c1dc8be32b0f4a6cb7808551d3e134649b432ff4c1e64596caa7b943643dd08a6b10fd27dc2bd32607d0bed7045a18283abdaf9b6
|
7
|
+
data.tar.gz: a5a8a08c04c108544845ef70895c71027ecaff90a7b164192b1294d3f5b758144a25d3390983b542bffc6fc8854466127dd0b4539b5a157741bba060e89692e3
|
data/README.md
CHANGED
@@ -192,6 +192,9 @@ en:
|
|
192
192
|
class Admin::YourModelForm < Tramway::Core::ApplicationForm
|
193
193
|
properties :title, :description, :text, :date, :logo
|
194
194
|
|
195
|
+
association :associated
|
196
|
+
association :another_polymorphic_associated
|
197
|
+
|
195
198
|
def initialize(object)
|
196
199
|
super(object).tap do
|
197
200
|
form_properties title: :string,
|
@@ -199,6 +202,8 @@ class Admin::YourModelForm < Tramway::Core::ApplicationForm
|
|
199
202
|
description: :ckeditor,
|
200
203
|
date: :date_picker,
|
201
204
|
text: :text,
|
205
|
+
associated: :association,
|
206
|
+
another_polymorphic_association: :polymorphic_association,
|
202
207
|
birth_date: {
|
203
208
|
type: :default,
|
204
209
|
input_options: {
|
@@ -210,6 +215,22 @@ class Admin::YourModelForm < Tramway::Core::ApplicationForm
|
|
210
215
|
end
|
211
216
|
```
|
212
217
|
|
218
|
+
**NOTE**
|
219
|
+
If you want fill inputs of this form, just send query params
|
220
|
+
|
221
|
+
```
|
222
|
+
params = {
|
223
|
+
your_model: {
|
224
|
+
logo: '/file/url',
|
225
|
+
description: 'some text',
|
226
|
+
text: 'some another text',
|
227
|
+
associated_id: 5,
|
228
|
+
another_polymorphic_associated: 56,
|
229
|
+
another_polymorphic_associated_type: 'AnotherModel'
|
230
|
+
}
|
231
|
+
}
|
232
|
+
```
|
233
|
+
|
213
234
|
#### 10. Add inheritance to YourModel
|
214
235
|
|
215
236
|
*app/models/your_model.rb*
|
@@ -465,7 +486,7 @@ To add notification to application, you need just set queries in initializers.
|
|
465
486
|
# Example from tramway-event gem (you also can push context variables here)
|
466
487
|
|
467
488
|
::Tramway::Admin.set_notificable_queries new_participants: -> (current_user) do
|
468
|
-
::Tramway::Event::Participant.
|
489
|
+
::Tramway::Event::Participant.where(participation_state: :requested).send "#{current_user}_scope", current_user.id
|
469
490
|
end
|
470
491
|
```
|
471
492
|
|
@@ -541,7 +562,8 @@ class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
|
541
562
|
inner: lambda do # inner HTML you want to see in the button
|
542
563
|
fa_icon 'file-excel'
|
543
564
|
end,
|
544
|
-
color: :success # bootstrap button color
|
565
|
+
color: :success, # bootstrap button color
|
566
|
+
method: :get # HTTP method. get method is a default. Available: :post, :patch: delete
|
545
567
|
}
|
546
568
|
]
|
547
569
|
}
|
@@ -21,7 +21,7 @@ module Tramway
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def check_available!
|
24
|
-
raise 'Tramway::Admin - Model or Form is not available' if !model_given? && !form_given?
|
24
|
+
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
25
|
end
|
26
26
|
|
27
27
|
def check_available_scope!
|
@@ -30,7 +30,7 @@ module Tramway
|
|
30
30
|
|
31
31
|
def collections_counts
|
32
32
|
@counts = decorator_class.collections.reduce({}) do |hash, collection|
|
33
|
-
records = model_class.
|
33
|
+
records = model_class.send(collection)
|
34
34
|
records = records.send "#{current_admin.role}_scope", current_admin.id
|
35
35
|
records = records.ransack(params[:filter]).result if params[:filter].present?
|
36
36
|
params[:list_filters]&.each do |filter, value|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationController
|
4
4
|
def index
|
5
5
|
scope = params[:scope].present? ? params[:scope] : :all
|
6
|
-
records = model_class.
|
6
|
+
records = model_class.order(id: :desc).send scope
|
7
7
|
records = records.full_text_search params[:search] if params[:search].present?
|
8
8
|
if params[:filter].present?
|
9
9
|
if params[:filter].is_a? String
|
@@ -30,7 +30,7 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def show
|
33
|
-
@record = decorator_class.decorate model_class.
|
33
|
+
@record = decorator_class.decorate model_class.find params[:id]
|
34
34
|
end
|
35
35
|
|
36
36
|
def new
|
@@ -47,11 +47,11 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def edit
|
50
|
-
@record_form = admin_form_class.new model_class.
|
50
|
+
@record_form = admin_form_class.new model_class.find params[:id]
|
51
51
|
end
|
52
52
|
|
53
53
|
def update
|
54
|
-
@record_form = admin_form_class.new model_class.
|
54
|
+
@record_form = admin_form_class.new model_class.find params[:id]
|
55
55
|
if params[:record][:aasm_event].present?
|
56
56
|
if @record_form.model.send("may_#{params[:record][:aasm_event]}?")
|
57
57
|
@record_form.model.send("#{params[:record][:aasm_event]}!")
|
@@ -67,8 +67,8 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def destroy
|
70
|
-
record = model_class.
|
71
|
-
record.
|
70
|
+
record = model_class.find params[:id]
|
71
|
+
record.destroy
|
72
72
|
redirect_to params[:redirect].present? ? params[:redirect] : records_path
|
73
73
|
end
|
74
74
|
end
|
@@ -10,7 +10,7 @@ class Tramway::Admin::SessionsController < ::Tramway::Admin::ApplicationControll
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def create
|
13
|
-
@session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.
|
13
|
+
@session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.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
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module Tramway::Admin
|
4
4
|
class SingletonsController < ApplicationController
|
5
5
|
def show
|
6
|
-
if model_class.
|
7
|
-
@singleton = decorator_class.decorate model_class.
|
6
|
+
if model_class.first.present?
|
7
|
+
@singleton = decorator_class.decorate model_class.first
|
8
8
|
else
|
9
9
|
@singleton_form = admin_form_class.new model_class.new
|
10
10
|
render :new
|
@@ -13,7 +13,7 @@ module Tramway::Admin
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def edit
|
16
|
-
@singleton_form = admin_form_class.new model_class.
|
16
|
+
@singleton_form = admin_form_class.new model_class.first
|
17
17
|
end
|
18
18
|
|
19
19
|
def create
|
@@ -26,7 +26,7 @@ module Tramway::Admin
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def update
|
29
|
-
@singleton_form = admin_form_class.new model_class.
|
29
|
+
@singleton_form = admin_form_class.new model_class.first
|
30
30
|
if @singleton_form.submit params[:singleton]
|
31
31
|
redirect_to params[:redirect] || singleton_path(model: params[:model])
|
32
32
|
else
|
@@ -8,7 +8,7 @@
|
|
8
8
|
= hidden_field_tag :model, params[:model]
|
9
9
|
= hidden_field_tag :scope, params[:scope]
|
10
10
|
= hidden_field_tag :filter, (params[:filter].is_a?(ActionController::Parameters) ? params[:filter].permit!.to_h.to_json : params[:filter])
|
11
|
-
- decorator_class(model_class).list_filters
|
11
|
+
- decorator_class(model_class).list_filters&.each_slice(3) do |slice|
|
12
12
|
.row-fluid.filters
|
13
13
|
- slice.each do |filter|
|
14
14
|
- case filter[1][:type]
|
@@ -5,7 +5,10 @@
|
|
5
5
|
%hr
|
6
6
|
- association_form = object.send("add_#{association.name}_form")
|
7
7
|
= simple_form_for association_form, url: { controller: :has_and_belongs_to_many_records, action: :create, form: association_form.class, model_class: model_class, object_id: object.id }, method: :post do |f|
|
8
|
-
|
9
|
-
|
8
|
+
- association_form.associations.each do |association_name|
|
9
|
+
- associations = association_form.model.class.reflect_on_all_associations.map(&:name)
|
10
|
+
- if associations.include? association_name
|
11
|
+
= f.association association_name, label: false
|
12
|
+
= f.button :submit, "#{I18n.t('helpers.actions.add')} #{model_class.human_attribute_name(association.name).singularize.downcase}", class: 'btn-success'
|
10
13
|
%td{ colspan: 2 }
|
11
14
|
= render 'tramway/admin/shared/show/associations/list', object: object, association: association
|
@@ -0,0 +1,21 @@
|
|
1
|
+
- association_state_machines = object.send("#{association.name}_state_machines")
|
2
|
+
%table.table.table-striped.table-bordered
|
3
|
+
- object.send(association.name)&.each do |association_object|
|
4
|
+
%tr{ id: "#{association.name}_#{association_object.id}" }
|
5
|
+
%td
|
6
|
+
= association_object.id
|
7
|
+
%td
|
8
|
+
= link_to association_object.name, record_path(association_object.id, model: association.options[:class_name])
|
9
|
+
%td
|
10
|
+
- association_state_machines.each do |state_method|
|
11
|
+
= state_events_buttons association_object, state_method: state_method, model_param_name: :record, controller: 'tramway/admin/records', action: :update, parameters: { redirect: current_model_record_path(object.id), model: association_object.class.model_name }, button_options: { class: :smart_button }
|
12
|
+
%td
|
13
|
+
- if update_is_available? association_object, object
|
14
|
+
= edit_button url: edit_record_path(association_object.id, model: association.options[:class_name], redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-warning edit' } do
|
15
|
+
= fa_icon 'pencil-alt'
|
16
|
+
- if destroy_is_available? association_object, object
|
17
|
+
= delete_button url: record_path(association_object.id, model: association.options[:class_name], redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-danger delete' } do
|
18
|
+
= fa_icon 'trash-alt'
|
19
|
+
- if habtm_destroy_is_available? association_object, object
|
20
|
+
= delete_button url: has_and_belongs_to_many_record_path(association_object.id, model_class: object.model.class, object_id: object.id, form: "Admin::#{object.model.class.to_s.pluralize}::Remove#{association_object.model.class.to_s}Form", redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-danger delete' } do
|
21
|
+
= fa_icon 'trash-alt'
|
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
|
+
version: '3.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tramway-core
|
@@ -70,20 +70,20 @@ dependencies:
|
|
70
70
|
name: copyright_mafa
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.1.2
|
76
|
-
- - "
|
76
|
+
- - "~>"
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: 0.1.2
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- - "
|
83
|
+
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: 0.1.2
|
86
|
-
- - "
|
86
|
+
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 0.1.2
|
89
89
|
- !ruby/object:Gem::Dependency
|
@@ -278,6 +278,7 @@ files:
|
|
278
278
|
- app/views/tramway/admin/shared/errors/server_error.html.haml
|
279
279
|
- app/views/tramway/admin/shared/show/_attribute_tr.html.haml
|
280
280
|
- app/views/tramway/admin/shared/show/associations/_habtm_row.html.haml
|
281
|
+
- app/views/tramway/admin/shared/show/associations/_list.html.haml
|
281
282
|
- app/views/tramway/admin/shared/show/associations/_row.html.haml
|
282
283
|
- app/views/tramway/admin/shared/show/associations/_table_row.html.haml
|
283
284
|
- app/views/tramway/admin/singletons/_form.html.haml
|
@@ -329,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
329
330
|
- !ruby/object:Gem::Version
|
330
331
|
version: '0'
|
331
332
|
requirements: []
|
332
|
-
rubygems_version: 3.
|
333
|
+
rubygems_version: 3.0.3.1
|
333
334
|
signing_key:
|
334
335
|
specification_version: 4
|
335
336
|
summary: Engine for admin
|