tramway 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/MIT-LICENSE +20 -0
- data/README.md +889 -15
- data/Rakefile +8 -8
- data/app/assets/config/tramway_core_manifest.js +2 -0
- data/app/assets/images/tramway/mona_lisa_from_prado.jpg +0 -0
- data/app/assets/images/tramway/mona_lisa_from_prado_square.jpg +0 -0
- data/app/assets/javascripts/bootstrap-datepicker-1.8.0.js +2035 -0
- data/app/assets/javascripts/bootstrap-datepicker-1.8.0.ru.min.js +64 -0
- data/app/assets/javascripts/ckeditor/config.js +30 -0
- data/app/assets/javascripts/ckeditor/plugins/image/dialogs/image.js +1259 -0
- data/app/assets/javascripts/ckeditor/plugins/image/icons/hidpi/image.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/image/icons/image.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/image/images/noimage.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/image/lang/en.js +25 -0
- data/app/assets/javascripts/ckeditor/plugins/image/lang/ru.js +25 -0
- data/app/assets/javascripts/ckeditor/plugins/image/plugin.js +184 -0
- data/app/assets/javascripts/ckeditor/plugins/youtube/images/icon-hdpi.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/youtube/images/icon.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/youtube/lang/en.js +25 -0
- data/app/assets/javascripts/ckeditor/plugins/youtube/lang/ru.js +25 -0
- data/app/assets/javascripts/ckeditor/plugins/youtube/plugin.js +449 -0
- data/app/assets/javascripts/tramway/application.js +60 -0
- data/app/assets/stylesheets/tramway/application.sass +60 -0
- data/app/assets/stylesheets/tramway/bootstrap-datepicker-1.8.0.css +477 -0
- data/app/controllers/concerns/auth_management.rb +26 -0
- data/app/controllers/concerns/filtering.rb +43 -0
- data/app/controllers/tramway/application_controller.rb +142 -0
- data/app/controllers/tramway/export/application_controller.rb +5 -0
- data/app/controllers/tramway/has_and_belongs_to_many_records_controller.rb +26 -0
- data/app/controllers/tramway/records_controller.rb +86 -0
- data/app/controllers/tramway/sessions_controller.rb +49 -0
- data/app/controllers/tramway/singletons_controller.rb +48 -0
- data/app/controllers/tramway/welcome_controller.rb +17 -0
- data/app/decorators/tramway/application_decorated_collection.rb +15 -0
- data/app/decorators/tramway/application_decorator.rb +124 -0
- data/app/decorators/tramway/associations/class_helper.rb +45 -0
- data/app/decorators/tramway/associations/object_helper.rb +58 -0
- data/app/decorators/tramway/attributes/view_helper.rb +30 -0
- data/app/decorators/tramway/concerns/attributes_decorator_helper.rb +97 -0
- data/app/decorators/tramway/concerns/table_builder.rb +33 -0
- data/app/decorators/tramway/default/values_helper.rb +23 -0
- data/app/decorators/tramway/delegating/class_helper.rb +9 -0
- data/app/decorators/tramway/user_decorator.rb +49 -0
- data/app/forms/admin/tramway/user_form.rb +24 -0
- data/app/forms/tramway/application_form.rb +124 -0
- data/app/forms/tramway/application_forms/association_class_helpers.rb +7 -0
- data/app/forms/tramway/application_forms/association_object_helpers.rb +36 -0
- data/app/forms/tramway/application_forms/constant_class_actions.rb +7 -0
- data/app/forms/tramway/application_forms/constant_object_actions.rb +20 -0
- data/app/forms/tramway/application_forms/frontend.rb +12 -0
- data/app/forms/tramway/application_forms/object_helpers.rb +15 -0
- data/app/forms/tramway/application_forms/properties_object_helper.rb +16 -0
- data/app/forms/tramway/application_forms/submit_helper.rb +26 -0
- data/app/forms/tramway/extendable_form.rb +15 -0
- data/app/forms/tramway/extendable_forms_helpers/class_builder.rb +34 -0
- data/app/forms/tramway/extendable_forms_helpers/ignored_properties_helper.rb +11 -0
- data/app/forms/tramway/extendable_forms_helpers/more_properties_helper.rb +31 -0
- data/app/forms/tramway/extendable_forms_helpers/properties_helper.rb +16 -0
- data/app/forms/tramway/extendable_forms_helpers/submit/class_helpers.rb +18 -0
- data/app/forms/tramway/extendable_forms_helpers/submit/object_helpers.rb +21 -0
- data/app/forms/tramway/extendable_forms_helpers/validators.rb +40 -0
- data/app/forms/tramway/extended_application_form.rb +23 -0
- data/app/forms/tramway/form_creator.rb +7 -0
- data/app/forms/tramway/session_form.rb +26 -0
- data/app/helpers/tramway/actions_helper.rb +45 -0
- data/app/helpers/tramway/additional_buttons_builder.rb +12 -0
- data/app/helpers/tramway/application_helper.rb +27 -0
- data/app/helpers/tramway/cases_helper.rb +13 -0
- data/app/helpers/tramway/copy_to_clipboard_helper.rb +11 -0
- data/app/helpers/tramway/focus_generator_helper.rb +10 -0
- data/app/helpers/tramway/frontend_helper.rb +26 -0
- data/app/helpers/tramway/inputs/associations_helper.rb +30 -0
- data/app/helpers/tramway/inputs/polymorphic_associations_helper.rb +24 -0
- data/app/helpers/tramway/inputs_helper.rb +96 -0
- data/app/helpers/tramway/model_helper.rb +7 -0
- data/app/helpers/tramway/navbar_helper.rb +11 -0
- data/app/helpers/tramway/records_helper.rb +120 -0
- data/app/helpers/tramway/russian_cases_helper.rb +26 -0
- data/app/helpers/tramway/singleton_helper.rb +12 -0
- data/app/helpers/tramway/state_machine_buttons_helper.rb +61 -0
- data/app/helpers/tramway/title_helper.rb +25 -0
- data/app/inputs/date_picker_input.rb +4 -0
- data/app/inputs/multiple_file_input.rb +7 -0
- data/app/models/tramway/application_record.rb +60 -0
- data/app/models/tramway/user.rb +23 -0
- data/app/uploaders/application_uploader.rb +22 -0
- data/app/uploaders/file_uploader.rb +4 -0
- data/app/uploaders/ico_uploader.rb +7 -0
- data/app/uploaders/image_defaults.rb +14 -0
- data/app/uploaders/photo_uploader.rb +54 -0
- data/app/views/layouts/tramway/application.html.haml +32 -0
- data/app/views/layouts/tramway/shared/_navbar.html.haml +46 -0
- data/app/views/tramway/404.haml +1 -0
- data/app/views/tramway/records/_form.html.haml +22 -0
- data/app/views/tramway/records/_list.html.haml +38 -0
- data/app/views/tramway/records/_search.html.haml +34 -0
- data/app/views/tramway/records/edit.html.haml +1 -0
- data/app/views/tramway/records/index.html.haml +31 -0
- data/app/views/tramway/records/new.html.haml +1 -0
- data/app/views/tramway/records/show.html.haml +1 -0
- data/app/views/tramway/sessions/new.html.haml +9 -0
- data/app/views/tramway/shared/_input.html.haml +34 -0
- data/app/views/tramway/shared/_input_extended.html.haml +14 -0
- data/app/views/tramway/shared/_messages.html.haml +10 -0
- data/app/views/tramway/shared/_show.html.haml +35 -0
- data/app/views/tramway/shared/errors/server_error.html.haml +12 -0
- data/app/views/tramway/shared/input_extended_types/_checkbox.html.haml +1 -0
- data/app/views/tramway/shared/input_extended_types/_select.html.haml +16 -0
- data/app/views/tramway/shared/input_extended_types/_simple.html.haml +4 -0
- data/app/views/tramway/shared/input_extended_types/_yes_no.html.haml +4 -0
- data/app/views/tramway/shared/show/_attribute_tr.html.haml +9 -0
- data/app/views/tramway/shared/show/associations/_habtm_row.html.haml +14 -0
- data/app/views/tramway/shared/show/associations/_list.html.haml +21 -0
- data/app/views/tramway/shared/show/associations/_row.html.haml +19 -0
- data/app/views/tramway/shared/show/associations/_table_row.html.haml +21 -0
- data/app/views/tramway/singletons/_form.html.haml +15 -0
- data/app/views/tramway/singletons/edit.html.haml +1 -0
- data/app/views/tramway/singletons/new.html.haml +1 -0
- data/app/views/tramway/singletons/show.html.haml +1 -0
- data/app/views/tramway/welcome/index.html.haml +4 -0
- data/config/initializers/assets.rb +7 -0
- data/config/initializers/carrierwave.rb +5 -0
- data/config/initializers/ckeditor.rb +9 -0
- data/config/initializers/plurals.rb +25 -0
- data/config/locales/en/collections.yml +4 -0
- data/config/locales/en/date.yml +16 -0
- data/config/locales/en/dates.yml +10 -0
- data/config/locales/en/helpers.yml +26 -0
- data/config/locales/en/locale.yml +11 -0
- data/config/locales/en/messages.yml +7 -0
- data/config/locales/en/models.yml +9 -0
- data/config/locales/en/simple_form_extension.yml +8 -0
- data/config/locales/en/state_machines.yml +8 -0
- data/config/locales/ru/collections.yml +4 -0
- data/config/locales/ru/date.yml +16 -0
- data/config/locales/ru/dates.yml +10 -0
- data/config/locales/ru/helpers.yml +30 -0
- data/config/locales/ru/locale.yml +6 -0
- data/config/locales/ru/messages.yml +7 -0
- data/config/locales/ru/models.yml +21 -0
- data/config/locales/ru/simple_form_extension.yml +8 -0
- data/config/locales/ru/state_machines.yml +8 -0
- data/config/routes.rb +13 -0
- data/lib/string.rb +18 -0
- data/lib/tramway/application.rb +10 -0
- data/lib/tramway/class_name_helpers.rb +15 -0
- data/lib/tramway/collection.rb +9 -0
- data/lib/tramway/collections/helper.rb +21 -0
- data/lib/tramway/collections.rb +4 -0
- data/lib/tramway/engine.rb +14 -0
- data/lib/tramway/error.rb +32 -0
- data/lib/tramway/forms.rb +5 -0
- data/lib/tramway/generators/install_generator.rb +49 -0
- data/lib/tramway/generators/model_generator.rb +105 -0
- data/lib/tramway/generators/templates/create_tramway_users.rb +18 -0
- data/lib/tramway/generators/templates/decorator.rb.erb +56 -0
- data/lib/tramway/generators/templates/form.rb.erb +22 -0
- data/lib/tramway/generators/templates/initializers/simple_form.rb +23 -0
- data/lib/tramway/generators/templates/initializers/simple_form_bootstrap.rb +133 -0
- data/lib/tramway/generators.rb +4 -0
- data/lib/tramway/navbar.rb +44 -0
- data/lib/tramway/notifications.rb +12 -0
- data/lib/tramway/record_routes_helper.rb +23 -0
- data/lib/tramway/records_models.rb +52 -0
- data/lib/tramway/singleton_models.rb +32 -0
- data/lib/tramway/spec/helpers/navbar_helper.rb +7 -0
- data/lib/tramway/spec/helpers/tramway_helpers.rb +47 -0
- data/lib/tramway/version.rb +3 -1
- data/lib/tramway/welcome_page_actions.rb +5 -0
- data/lib/tramway/yaml/errors.yml +49 -0
- data/lib/tramway.rb +143 -2
- data/lib/validators/presence_validator.rb +9 -0
- metadata +582 -25
- data/.gitignore +0 -9
- data/.travis.yml +0 -5
- data/Gemfile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/tramway.gemspec +0 -26
data/README.md
CHANGED
@@ -1,35 +1,909 @@
|
|
1
|
-
# Tramway
|
1
|
+
# ![tramway-ico](https://raw.githubusercontent.com/kalashnikovisme/kalashnikovisme/master/%D1%82%D1%80%D1%8D%D0%BC%D0%B2%D1%8D%D0%B9%D0%B1%D0%B5%D0%B7%D1%84%D0%BE%D0%BD%D0%B0-min.png) Tramway [![Tests](https://github.com/Purple-Magic/tramway/actions/workflows/tests.yml/badge.svg)](https://github.com/Purple-Magic/tramway/actions/workflows/tests.yml) [![Rubocop](https://github.com/Purple-Magic/tramway/actions/workflows/rubocop.yml/badge.svg)](https://github.com/Purple-Magic/tramway/actions/workflows/rubocop.yml) [![Gem Version](https://badge.fury.io/rb/tramway.svg)](https://badge.fury.io/rb/tramway)
|
2
2
|
|
3
|
-
|
3
|
+
# Installation
|
4
4
|
|
5
|
-
|
5
|
+
*Gemfile*
|
6
|
+
```ruby
|
7
|
+
gem 'tramway'
|
8
|
+
gem 'audited'
|
9
|
+
gem 'clipboard-rails'
|
10
|
+
gem 'bcrypt'
|
11
|
+
gem 'haml-rails'
|
12
|
+
gem 'bootstrap'
|
13
|
+
gem 'jquery-rails'
|
14
|
+
gem 'copyright_mafa'
|
15
|
+
gem 'trap'
|
16
|
+
gem 'kaminari'
|
17
|
+
gem 'bootstrap-kaminari-views', github: 'kalashnikovisme/bootstrap-kaminari-views', branch: :master
|
18
|
+
gem 'state_machine_buttons'
|
19
|
+
gem 'ckeditor', '4.2.4'
|
20
|
+
gem 'ransack'
|
21
|
+
gem 'smart_buttons'
|
22
|
+
gem 'carrierwave'
|
23
|
+
gem 'validates'
|
24
|
+
```
|
6
25
|
|
7
|
-
|
26
|
+
*config/initializers/tramway.rb*
|
27
|
+
```ruby
|
28
|
+
# Initialize application with name
|
29
|
+
Tramway.initialize_application name: :your_application_name
|
8
30
|
|
9
|
-
|
31
|
+
# Initialize application name with model_class. Model class must be a singlethon
|
32
|
+
Tramway.initialize_application model_class: MyApplication
|
33
|
+
```
|
10
34
|
|
35
|
+
```shell
|
36
|
+
rails g tramway:install
|
37
|
+
```
|
38
|
+
|
39
|
+
*config/initializers/assets.rb*
|
11
40
|
```ruby
|
12
|
-
|
41
|
+
Rails.application.config.assets.precompile += %w( *.jpg *.png *.js )
|
42
|
+
```
|
43
|
+
|
44
|
+
#### Every Tramway application need initialized @application object (or if you create Tramway plugin, it should be @application_engine object).
|
45
|
+
|
46
|
+
You don't need to initialize this object yourself, just configurate application with Tramway. You have **2** options of this:
|
47
|
+
|
48
|
+
## Option 1. If you want to change @application object just in the code base.
|
49
|
+
|
50
|
+
```shell
|
51
|
+
rails g tramway:install
|
52
|
+
```
|
53
|
+
|
54
|
+
*config/initializers/tramway.rb*
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
Tramway::Core.initialize_application name: :your_application_name
|
58
|
+
```
|
59
|
+
|
60
|
+
## Option 2. If you want to change @application object from admin panel. How to create model that will be an Application Model for the Tramway
|
61
|
+
|
62
|
+
#### 1. Generate model that you to use. We create Organization, for example
|
63
|
+
|
64
|
+
```shell
|
65
|
+
rails g tramway:application
|
66
|
+
rails db:migrate
|
67
|
+
```
|
68
|
+
|
69
|
+
#### 2. Add model_class to Initializer
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Tramway::Core.initialize_application model_class: Organization
|
73
|
+
```
|
74
|
+
|
75
|
+
#### 3. Create 1 instance of Organization model
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
rails c
|
79
|
+
Organization.create! public_name: 'Tramway', name: :organization, tagline: 'Tramway is not buggy, LOL!', main_image: 'https://raw.githubusercontent.com/ulmic/tramway-dev/develop/logo.png'
|
80
|
+
```
|
81
|
+
|
82
|
+
#### 4. Add model to singleton to the `tramway-admin` admin panel to be able to change its data
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
Tramway::Admin.set_singleton_models Organization, project: :organization # now you should use organization.name here
|
86
|
+
```
|
87
|
+
|
88
|
+
#### 5. Then continue configuration of your model in admin panel with tramway-admin gem [instruction, starting from point 8](https://github.com/ulmic/tramway-dev/tree/develop/tramway-admin#8-configurate-navbar)
|
89
|
+
|
90
|
+
#### 6. Now you are able to change your application main info in admin panel
|
91
|
+
|
92
|
+
## How-to
|
93
|
+
|
94
|
+
### add favicon to your application
|
95
|
+
|
96
|
+
*config/initializers/tramway.rb*
|
97
|
+
```ruby
|
98
|
+
::Tramway::Core.initialize_application attribute1: value, another_attribute: another_value, favicon: `/icon.ico` # icon should be in public folder
|
99
|
+
```
|
100
|
+
|
101
|
+
# Usage
|
102
|
+
|
103
|
+
## Tramway::Core::ApplicationRecord
|
104
|
+
|
105
|
+
### uploader
|
106
|
+
|
107
|
+
Tramway use [carrierwave](https://github.com/carrierwaveuploader/carrierwave) for file uploading by default. To mount uploader you should use `uploader` method
|
108
|
+
|
109
|
+
Interface: `uploader(attribute_name, uploader_name, **options)`
|
110
|
+
|
111
|
+
* attribute_name - ActiveRecord attribute to mount uploader
|
112
|
+
* uploader_name - **short** uploader name. You need to connect uploaders which are compatible with Tramway. Available uploaders:
|
113
|
+
* :photo - you can see it [here](https://github.com/Purple-Magic/tramway/blob/develop/app/uploaders/photo_uploader.rb)
|
114
|
+
* :file - you can see it [here](https://github.com/Purple-Magic/tramway/blob/develop/app/uploaders/file_uploader.rb)
|
115
|
+
* :ico - you can see [here](https://github.com/Purple-Magic/tramway/blob/develop/app/uploaders/ico_uploader.rb)
|
116
|
+
* options - you are available to set options for uploaders exactly for this model. Available options:
|
117
|
+
* versions - **only for :photo**. Set needed versions for file to be cropped. If empty - 0 zero versions will be used. All versions you can see [here](https://github.com/Purple-Magic/tramway/blob/develop/app/uploaders/photo_uploader.rb)
|
118
|
+
* extensions - whitelist of file extensions. If empty will be used default whitelist from the uploaders (links above)
|
119
|
+
|
120
|
+
Example:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
class User < Tramway::Core::ApplicationRecord
|
124
|
+
uploader :avatar, :photo, version: [ :small, :medium ], extensions: [ :jpg, :jpeg ]
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
## Tramway::Core::ApplicationDecorator
|
129
|
+
### Associations
|
130
|
+
|
131
|
+
Your can decorate association models. Supporting all types of association
|
132
|
+
|
133
|
+
*app/decorators/your_model_decorator.rb*
|
134
|
+
```ruby
|
135
|
+
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
136
|
+
decorate_association :some_model
|
137
|
+
decorate_association :another_model, decorator: SpecificDecoratorForThisCase
|
138
|
+
decorate_association :another_one_model, as: :repeat_here_as_parameter_from_model
|
139
|
+
decorate_association :something_else_model, state_machines: [ :here_array_of_state_machines_you_want_to_see_in_YourModel_show_page ] # support from tramway-admin gem
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
You can decorate a lot of models in one line
|
144
|
+
|
145
|
+
*app/decorators/your_model_decorator.rb*
|
146
|
+
```ruby
|
147
|
+
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
148
|
+
decorate_associations :some_model, :another_model, :another_one_model, :something_else_model
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
Also, you can configurate what associations you want to see in YourModel page in admin panel *support only for [tramway-admin](https://rubygems.org/gems/tramway-admin) gem*
|
153
|
+
|
154
|
+
*app/decorators/your_model_decorator.rb*
|
155
|
+
```ruby
|
156
|
+
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
157
|
+
class << self
|
158
|
+
def show_associations
|
159
|
+
[ :some_model, :another_model, :another_one_model ]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
### Delegating attributes
|
166
|
+
|
167
|
+
*app/decorators/your_model_decorator.rb*
|
168
|
+
```ruby
|
169
|
+
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
170
|
+
delegate_attributes :title, :something_else, :another_atttribute
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
### Helper methods
|
175
|
+
|
176
|
+
#### date_view
|
177
|
+
Returns a date in the format depending on localization
|
178
|
+
|
179
|
+
*app/decorators/\*_decorator.rb*
|
180
|
+
```ruby
|
181
|
+
def created_at
|
182
|
+
date_view object.created_at
|
183
|
+
end
|
184
|
+
```
|
185
|
+
#### datetime_view
|
186
|
+
Returns a date and time in the format depending on localization
|
187
|
+
|
188
|
+
*app/decorators/*_decorator.rb*
|
189
|
+
```ruby
|
190
|
+
def created_at
|
191
|
+
datetime_view object.created_at
|
192
|
+
end
|
193
|
+
```
|
194
|
+
#### state_machine_view
|
195
|
+
Returns the state of an object according to a state machine
|
196
|
+
|
197
|
+
*app/decorators/*_decorator.rb*
|
198
|
+
```ruby
|
199
|
+
def state
|
200
|
+
state_machine_view object, :state
|
201
|
+
end
|
202
|
+
```
|
203
|
+
#### image_view
|
204
|
+
Returns an image in a particular format depending on the parameters of the original image file
|
205
|
+
|
206
|
+
*app/decorators/\*_decorator.rb*
|
207
|
+
```ruby
|
208
|
+
def avatar
|
209
|
+
image_view object.avatar
|
210
|
+
end
|
211
|
+
```
|
212
|
+
#### enumerize_view
|
213
|
+
Returns object enumerations as text
|
214
|
+
|
215
|
+
*app/decorators/\*_decorator.rb*
|
216
|
+
```ruby
|
217
|
+
def field_type
|
218
|
+
enumerize_view object.field_type
|
219
|
+
end
|
13
220
|
```
|
14
221
|
|
15
|
-
|
222
|
+
## Other helpers
|
16
223
|
|
17
|
-
|
224
|
+
### CopyToClipboardHelper
|
18
225
|
|
19
|
-
|
226
|
+
[app/helpers/tramway/copy_to_clipboard_helper.rb] (https://github.com/ulmic/tramway-dev/blob/develop/tramway/app/helpers/tramway/copy_to_clipboard_helper.rb)
|
20
227
|
|
21
|
-
|
228
|
+
#### Install
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
include ::Tramway::Core::CopyToClipboardHelper
|
232
|
+
```
|
233
|
+
|
234
|
+
#### How to use it
|
235
|
+
|
236
|
+
It will show you in the view in bootstrap styles with font-awesome `copy` icon.
|
237
|
+
|
238
|
+
Something like this:
|
239
|
+
|
240
|
+
![copy_to_clipboard_button](https://raw.githubusercontent.com/ulmic/tramway-dev/develop/tramway/docs/copy_to_clipboard_button.png)
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
copy_to_clipboard "some_id" # some_id is HTML id of element. Content of this element will be copied to the clipboard after pressing the button
|
244
|
+
```
|
245
|
+
|
246
|
+
## In Russian
|
247
|
+
|
248
|
+
# Базовые классы
|
249
|
+
|
250
|
+
* ApplicationDecorator - Базовый класс декоратора. В него по умолчанию включены `ActionView::Helpers` и `ActionView::Context` и `FontAwesome5` (версия гема FontAwesome, которая поддерживает 5 версию шрифта). `FontAwesome` считается в `Tramway` основным шрифтом для иконок.
|
251
|
+
* ApplicationForm - наследованный от Reform::Form класс форм.
|
252
|
+
* ApplicationRecord - базовый класс для AR моделей
|
253
|
+
* ApplicationUploader - базовый класс для Carrierwave аплоадеров.
|
254
|
+
* FileUploader - базовый класс для загрузки файлов
|
255
|
+
* PhotoUploader - базовый класс для загрузки фотографий
|
256
|
+
* Вьюха `_messages` - предоставляет отображение ошибок в форме. Совместима с AR и Reform
|
257
|
+
|
258
|
+
# Локализация
|
259
|
+
|
260
|
+
* dates - правила локализации даты
|
261
|
+
* helpers - часто используемые в формах слова
|
262
|
+
* models - часто используемые в моделях слова
|
263
|
+
* state_machines - локализация состояний
|
264
|
+
|
265
|
+
## Contribution
|
266
|
+
|
267
|
+
### Contributors
|
268
|
+
|
269
|
+
* [Pavel Kalashnikov](https://github.com/kalashnikovisme)
|
270
|
+
* [moshinaan](https://github.com/moshinaan)
|
271
|
+
|
272
|
+
### Run tests
|
273
|
+
|
274
|
+
```shell
|
275
|
+
make test
|
276
|
+
```
|
277
|
+
|
278
|
+
### Deployment workflow
|
279
|
+
|
280
|
+
#### If you don't have access to push gem to rubygems then
|
281
|
+
|
282
|
+
Just create PR to develop branch
|
283
|
+
|
284
|
+
#### If you have access to push gem to rubygems then
|
285
|
+
|
286
|
+
* Create PR to develop branch
|
287
|
+
* After merging PR you should create new release via git-flow this way
|
288
|
+
|
289
|
+
```shell
|
290
|
+
git release start (version which you upgraded in lib/tramway/version.rb file)
|
291
|
+
git release finish (version which you upgraded in lib/tramway/version.rb file)
|
292
|
+
git push origin develop
|
293
|
+
git push origin master
|
294
|
+
```
|
295
|
+
|
296
|
+
* Then push new version of the gem
|
297
|
+
|
298
|
+
```shell
|
299
|
+
rm -rf *.gem && gem build $(basename "$PWD").gemspec && gem push *.gem
|
300
|
+
```
|
301
|
+
|
302
|
+
# ![tramway-ico](https://raw.githubusercontent.com/kalashnikovisme/kalashnikovisme/master/%D1%82%D1%80%D1%8D%D0%BC%D0%B2%D1%8D%D0%B9%D0%B1%D0%B5%D0%B7%D1%84%D0%BE%D0%BD%D0%B0-min.png) Tramway::Admin
|
303
|
+
|
304
|
+
Create admin panel for your application FAST!
|
22
305
|
|
23
306
|
## Usage
|
307
|
+
How to use my plugin.
|
308
|
+
|
309
|
+
#### 1. Add this gems to Gemfile
|
310
|
+
|
311
|
+
#### 2. You should remove gem `turbolinks` from your application and from app/assets/javascripts/application.js
|
312
|
+
|
313
|
+
#### 3. Update your routes
|
314
|
+
|
315
|
+
*config/routes.rb*
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
Rails.application.routes.draw do
|
319
|
+
mount Tramway::Auth::Engine, at: '/auth'
|
320
|
+
mount Tramway::Admin::Engine, at: '/admin'
|
321
|
+
end
|
322
|
+
```
|
323
|
+
|
324
|
+
#### 4. Then make `tramway-core` installation. [How-to](https://github.com/Purple-Magic/tramway-core/blob/develop/README.md#installation)
|
325
|
+
|
326
|
+
|
327
|
+
#### 5. And then execute:
|
328
|
+
|
329
|
+
```bash
|
330
|
+
$ rails g tramway:user:install
|
331
|
+
$ rails db:migrate
|
332
|
+
```
|
333
|
+
|
334
|
+
#### 6. Create your first admin user
|
335
|
+
|
336
|
+
```bash
|
337
|
+
$ rails c
|
338
|
+
$> Tramway::User::User.create! email: 'your@email.com', password: '123456789', role: :admin
|
339
|
+
```
|
340
|
+
|
341
|
+
#### 7. Add models to your admin
|
342
|
+
|
343
|
+
*app/config/initializers/tramway.rb*
|
344
|
+
|
345
|
+
```ruby
|
346
|
+
# set available models for your admin
|
347
|
+
::Tramway::Admin.set_available_models YourModel, AnotherYourModel, project: #{project_name_which_you_used_in_application_name}
|
348
|
+
# set singleton models for your admin
|
349
|
+
::Tramway::Admin.set_singleton_models YourSingletonModel, AnotherYourSingletonModel, project: #{project_name_which_you_used_in_application_name}
|
350
|
+
::Tramway::Auth.root_path = '/admin' # you need it to redirect in the admin panel after admin signed_in
|
351
|
+
```
|
352
|
+
|
353
|
+
#### 8. Configurate navbar
|
354
|
+
|
355
|
+
*config/initializers/tramway.rb*
|
356
|
+
```ruby
|
357
|
+
Tramway::Admin.navbar_structure(
|
358
|
+
YourModel, # this line will create first-level link in your navbar, which will send you to the YourModel management
|
359
|
+
{
|
360
|
+
my_dropdown: [ # this line contains dropdown link name
|
361
|
+
AnotherYourModel # this line will create 2nd-level link in your navbar, which will send you to the YourModel management,
|
362
|
+
:divider # this line adds bootstrap divider to the dropdown list
|
363
|
+
]
|
364
|
+
},
|
365
|
+
project: :your_application_name
|
366
|
+
)
|
367
|
+
```
|
368
|
+
#### 9. Create decorators and forms for all available_models.
|
369
|
+
You can run generator that will create all necessary files
|
370
|
+
```bash
|
371
|
+
$ rails g tramway:admin:install
|
372
|
+
```
|
373
|
+
Or generate decorator and form for only one model
|
374
|
+
```bash
|
375
|
+
$ rails g tramway:admin:model Coworking
|
376
|
+
```
|
377
|
+
If you're using several user roles in your admin dashboard, then you can specify scope for the form(default scope is `admin`)
|
378
|
+
```bash
|
379
|
+
$ rails g tramway:admin:install --user-role=partner
|
380
|
+
```
|
381
|
+
|
382
|
+
Or you can create forms and decorators manually as it written below:
|
383
|
+
|
384
|
+
#### 9a. Create decorator for models [manual option]
|
385
|
+
|
386
|
+
*app/decorators/your_model_decorator.rb*
|
387
|
+
```ruby
|
388
|
+
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
389
|
+
decorate_associations :messages, :posts
|
390
|
+
|
391
|
+
class << self
|
392
|
+
def collections
|
393
|
+
[ :all, :scope1, :scope2 ]
|
394
|
+
end
|
395
|
+
|
396
|
+
def list_attributes
|
397
|
+
[ :begin_date, :end_date ]
|
398
|
+
end
|
399
|
+
|
400
|
+
def show_attributes
|
401
|
+
[ :begin_date, :end_date ]
|
402
|
+
end
|
403
|
+
|
404
|
+
def show_associations
|
405
|
+
[ :messages ]
|
406
|
+
end
|
407
|
+
|
408
|
+
def list_filters
|
409
|
+
{
|
410
|
+
filter_name: {
|
411
|
+
type: :select,
|
412
|
+
select_collection: filter_collection,
|
413
|
+
query: lambda do |list, value|
|
414
|
+
list.where some_attribute: value
|
415
|
+
end
|
416
|
+
},
|
417
|
+
date_filter_name: {
|
418
|
+
type: :dates,
|
419
|
+
query: lambda do |list, begin_date, end_date|
|
420
|
+
list.where 'created_at > ? AND created_at < ?', begin_date, end_date
|
421
|
+
end
|
422
|
+
}
|
423
|
+
}
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
delegate_attributes :title
|
428
|
+
end
|
429
|
+
```
|
430
|
+
|
431
|
+
**NOTES:**
|
432
|
+
* `collections` method must return array of scopes of `YourModel`. Every collection will be a tab in a list of your model in admin panel
|
433
|
+
* `list_filters` method returns hash of filters where:
|
434
|
+
* select_collection - collection which will be in the select of filter. It must be compatible with [options_for_select](https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select) method
|
435
|
+
* query - some Active Record query which be used as a filter of records
|
436
|
+
* `list_attributes` method returns array of attributes which will be shown in index page. If empty only `name` will be shown
|
437
|
+
* `show_attributes` method returns array of attributes which will be shown in show page. If empty all attributes of the model will be shown
|
438
|
+
* `show_associations` method returns array of decorated associations which will be show in show page. If empty no associations will be shown
|
439
|
+
|
440
|
+
Filters naming:
|
441
|
+
|
442
|
+
*Select filters*
|
443
|
+
|
444
|
+
```yaml
|
445
|
+
en:
|
446
|
+
tramway:
|
447
|
+
admin:
|
448
|
+
filters:
|
449
|
+
model_name:
|
450
|
+
filter_name: Your Filter
|
451
|
+
```
|
452
|
+
|
453
|
+
*Date filters*
|
454
|
+
|
455
|
+
```yaml
|
456
|
+
en:
|
457
|
+
tramway:
|
458
|
+
admin:
|
459
|
+
filters:
|
460
|
+
model_name:
|
461
|
+
date_filter_name:
|
462
|
+
begin_date: Your Begin date filter
|
463
|
+
end_date Your end date filter
|
464
|
+
```
|
465
|
+
|
466
|
+
#### 9b. Create `Admin::YourModelForm` [manual option]
|
467
|
+
|
468
|
+
*app/forms/admin/your_model_form.rb
|
469
|
+
```ruby
|
470
|
+
class Admin::YourModelForm < Tramway::Core::ApplicationForm
|
471
|
+
properties :title, :description, :text, :date, :logo
|
472
|
+
|
473
|
+
association :associated
|
474
|
+
association :another_polymorphic_associated
|
475
|
+
|
476
|
+
def initialize(object)
|
477
|
+
super(object).tap do
|
478
|
+
form_properties title: :string,
|
479
|
+
logo: :file,
|
480
|
+
description: :ckeditor,
|
481
|
+
date: :date_picker,
|
482
|
+
text: :text,
|
483
|
+
associated: :association,
|
484
|
+
another_polymorphic_association: :polymorphic_association,
|
485
|
+
birth_date: {
|
486
|
+
type: :default,
|
487
|
+
input_options: {
|
488
|
+
hint: 'It should be more than 18'
|
489
|
+
}
|
490
|
+
}
|
491
|
+
end
|
492
|
+
end
|
493
|
+
end
|
494
|
+
```
|
495
|
+
|
496
|
+
**NOTE**
|
497
|
+
If you want fill inputs of this form, just send query params
|
498
|
+
|
499
|
+
```
|
500
|
+
params = {
|
501
|
+
your_model: {
|
502
|
+
logo: '/file/url',
|
503
|
+
description: 'some text',
|
504
|
+
text: 'some another text',
|
505
|
+
associated_id: 5,
|
506
|
+
another_polymorphic_associated: 56,
|
507
|
+
another_polymorphic_associated_type: 'AnotherModel'
|
508
|
+
}
|
509
|
+
}
|
510
|
+
```
|
511
|
+
|
512
|
+
#### 10. Add inheritance to YourModel
|
513
|
+
|
514
|
+
*app/models/your_model.rb*
|
515
|
+
```ruby
|
516
|
+
class YourModel < Tramway::Core::ApplicationRecord
|
517
|
+
end
|
518
|
+
```
|
519
|
+
|
520
|
+
### 11. You can add search to your index page
|
521
|
+
|
522
|
+
Tramway use gem [PgSearch](https://github.com/Casecommons/pg_search`) as search engine
|
523
|
+
|
524
|
+
Just add `search` method to `YourModel` like this
|
525
|
+
|
526
|
+
```ruby
|
527
|
+
search_by *attributes, **associations # `attributes` and `associations` should be the same syntax as in PgSearch
|
528
|
+
```
|
529
|
+
|
530
|
+
Example:
|
531
|
+
|
532
|
+
```ruby
|
533
|
+
class YourModel < Tramway::Core::ApplicationRecord
|
534
|
+
search_by :my_attribute, :another_attribute, my_association: [ :my_association_attribute, :another_my_association_attribute ]
|
535
|
+
```
|
536
|
+
|
537
|
+
#### 12. Run server `rails s`
|
538
|
+
#### 13. Launch `localhost:3000/admin`
|
539
|
+
|
540
|
+
### CRUDs for models
|
541
|
+
|
542
|
+
By default users with role `admin` have access to all models used as arguments in method `::Tramway::Admin.set_available_models`. If you want specify models by roles, use them as keys
|
543
|
+
|
544
|
+
```ruby
|
545
|
+
::Tramway::Admin.set_available_models ::Tramway::Event::Event, ::Tramway::Event::ParticipantFormField,
|
546
|
+
::Tramway::Event::Participant, ::Tramway::Landing::Block, ::Tramway::User::User,
|
547
|
+
::Tramway::Profiles::SocialNetwork, project: #{project_name_which_you_used_in_application_name}, role: :admin
|
548
|
+
|
549
|
+
::Tramway::Admin.set_available_models ::Tramway::Event::Event, ::Tramway::Event::ParticipantFormField,
|
550
|
+
::Tramway::Event::Participant, project: #{project_name_which_you_used_in_application_name}, role: :another_role
|
551
|
+
```
|
552
|
+
|
553
|
+
You can set functions which are available by default some CRUD functions for any role:
|
554
|
+
|
555
|
+
```ruby
|
556
|
+
# this line gives access only index page to YourModel for partner role
|
557
|
+
::Tramway::Admin.set_available_models YourModel => [ :index ], role: :partner
|
558
|
+
```
|
559
|
+
|
560
|
+
You can set conditions for functions which are available for any role:
|
561
|
+
|
562
|
+
```ruby
|
563
|
+
# this line gives access to destroy only record with name `Elon Musk`
|
564
|
+
|
565
|
+
::Tramway::Admin.set_available_models YourModel => [
|
566
|
+
destroy => lambda do |record|
|
567
|
+
record.name == 'Elon Musk'
|
568
|
+
end
|
569
|
+
], role: :partner
|
570
|
+
```
|
571
|
+
|
572
|
+
Here docs about changing roles of `Tramway::User::User` model [Readme](https://github.com/ulmic/tramway-dev/tree/develop/tramway#if-you-want-to-edit-roles-to-the-tramwayuseruser-class)
|
573
|
+
|
574
|
+
## Associations management
|
575
|
+
|
576
|
+
### has_many
|
577
|
+
|
578
|
+
We have models Game and Packs.
|
579
|
+
|
580
|
+
*app/models/game.rb*
|
581
|
+
```ruby
|
582
|
+
class Game < Tramway::Core::ApplicationRecord
|
583
|
+
has_many :packs
|
584
|
+
end
|
585
|
+
```
|
586
|
+
|
587
|
+
*app/models/pack.rb*
|
588
|
+
```ruby
|
589
|
+
class Pack < Tramway::Core::ApplicationRecord
|
590
|
+
belongs_to :game
|
591
|
+
end
|
592
|
+
```
|
593
|
+
|
594
|
+
**You want to manage packs in the Game show admin page**
|
595
|
+
|
596
|
+
#### 1. Add association to PackDecorator
|
597
|
+
|
598
|
+
*app/decorators/pack_decorator.rb*
|
599
|
+
```ruby
|
600
|
+
class GameDecorator < Tramway::Core::ApplicationDecorator
|
601
|
+
decorate_association :packs, as: :game # we recommend you to add association name in Pack model. You need it if association name of Game in Pack is not `game`
|
602
|
+
end
|
603
|
+
```
|
604
|
+
|
605
|
+
### has_and_belongs_to_many
|
606
|
+
|
607
|
+
We have models Game and Packs.
|
608
|
+
|
609
|
+
*app/models/game.rb*
|
610
|
+
```ruby
|
611
|
+
class Game < Tramway::Core::ApplicationRecord
|
612
|
+
has_and_belongs_to_many :packs
|
613
|
+
end
|
614
|
+
```
|
615
|
+
|
616
|
+
*app/models/pack.rb*
|
617
|
+
```ruby
|
618
|
+
class Pack < Tramway::Core::ApplicationRecord
|
619
|
+
has_and_belongs_to_many :games
|
620
|
+
end
|
621
|
+
```
|
622
|
+
|
623
|
+
**You want to manage games in the Pack show admin page**
|
624
|
+
|
625
|
+
#### 1. Add association to PackDecorator
|
626
|
+
|
627
|
+
*app/decorators/pack_decorator.rb*
|
628
|
+
```ruby
|
629
|
+
class PackDecorator < Tramway::Core::ApplicationDecorator
|
630
|
+
decorate_association :games
|
631
|
+
end
|
632
|
+
```
|
633
|
+
|
634
|
+
#### 2. Create `Admin::Packs::AddGameForm` and `Admin::Packs::RemoveGameForm`
|
635
|
+
|
636
|
+
*app/forms/admin/packs/add_game_form.rb*
|
637
|
+
```ruby
|
638
|
+
class Admin::Packs::AddGameForm < Tramway::Core::ApplicationForm
|
639
|
+
properties :game_ids
|
640
|
+
association :games
|
641
|
+
|
642
|
+
def initialize(object)
|
643
|
+
super(object).tap do
|
644
|
+
form_properties games: :association
|
645
|
+
end
|
646
|
+
end
|
647
|
+
|
648
|
+
def submit(params)
|
649
|
+
params[:game_ids].each do |id|
|
650
|
+
model.games << Game.find(id) if id.present?
|
651
|
+
end
|
652
|
+
model.save!
|
653
|
+
end
|
654
|
+
end
|
655
|
+
```
|
656
|
+
|
657
|
+
*app/forms/admin/packs/remove_game_form.rb*
|
658
|
+
```ruby
|
659
|
+
class Admin::Packs::RemoveGameForm < Tramway::Core::ApplicationForm
|
660
|
+
properties :id
|
661
|
+
|
662
|
+
def submit(params)
|
663
|
+
model.games -= [Game.find(params)] if id.present?
|
664
|
+
model.save!
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
```
|
669
|
+
|
670
|
+
#### 3. Add this forms to initializer
|
671
|
+
|
672
|
+
*config/initializers/tramway/admin/forms.rb*
|
673
|
+
```ruby
|
674
|
+
Tramway::Admin.forms = 'packs/add_game', 'packs/remove_game'
|
675
|
+
```
|
676
|
+
|
677
|
+
## Date Picker locale
|
678
|
+
|
679
|
+
DatePicker provides `ru`, `en` locales. To set needed locale, just add
|
680
|
+
|
681
|
+
```javascript
|
682
|
+
window.current_locale = window.i18n_locale('en');
|
683
|
+
```
|
684
|
+
to the `app/assets/javascripts/admin/application.js` file
|
685
|
+
|
686
|
+
**OR**
|
687
|
+
|
688
|
+
```coffeescript
|
689
|
+
window.current_locale = window.i18n_locale 'en'
|
690
|
+
```
|
691
|
+
to the `app/assets/javascripts/admin/application.js.coffee` file
|
692
|
+
|
693
|
+
### Decorator Helper methods
|
694
|
+
|
695
|
+
#### date_view
|
696
|
+
Returns a date in the format depending on localization
|
697
|
+
|
698
|
+
*app/decorators/\*_decorator.rb*
|
699
|
+
```ruby
|
700
|
+
def created_at
|
701
|
+
date_view object.created_at
|
702
|
+
end
|
703
|
+
```
|
704
|
+
#### datetime_view
|
705
|
+
Returns a date and time in the format depending on localization
|
706
|
+
|
707
|
+
*app/decorators/*_decorator.rb*
|
708
|
+
```ruby
|
709
|
+
def created_at
|
710
|
+
datetime_view object.created_at
|
711
|
+
end
|
712
|
+
```
|
713
|
+
#### state_machine_view
|
714
|
+
Returns the state of an object according to a state machine
|
715
|
+
|
716
|
+
*app/decorators/*_decorator.rb*
|
717
|
+
```ruby
|
718
|
+
def state
|
719
|
+
state_machine_view object, :state
|
720
|
+
end
|
721
|
+
```
|
722
|
+
|
723
|
+
It takes locales from `I18n.t("state_machines.#{model_name}.#{state_machine_name}.states.#{state_value}")`
|
724
|
+
|
725
|
+
#### image_view
|
726
|
+
Returns an image in a particular format depending on the parameters of the original image file
|
727
|
+
|
728
|
+
*app/decorators/\*_decorator.rb*
|
729
|
+
```ruby
|
730
|
+
def avatar
|
731
|
+
image_view object.avatar
|
732
|
+
end
|
733
|
+
```
|
734
|
+
#### enumerize_view
|
735
|
+
Returns object enumerations as text
|
736
|
+
|
737
|
+
*app/decorators/\*_decorator.rb*
|
738
|
+
```ruby
|
739
|
+
def field_type
|
740
|
+
enumerize_view object.field_type
|
741
|
+
end
|
742
|
+
```
|
743
|
+
|
744
|
+
#### file_view
|
745
|
+
Returns file name and button to download it
|
746
|
+
|
747
|
+
*app/decorators/\*_decorator.rb*
|
748
|
+
```ruby
|
749
|
+
def file_download
|
750
|
+
file_view object.file
|
751
|
+
end
|
752
|
+
```
|
753
|
+
|
754
|
+
## Notifications
|
755
|
+
|
756
|
+
You can add notification to your admin panel to the navbar.
|
757
|
+
|
758
|
+
To add notification to application, you need just set queries in initializers.
|
759
|
+
|
760
|
+
*config/initializers/tramway.rb*
|
761
|
+
```ruby
|
762
|
+
::Tramway::Admin.set_notificable_queries :"#{your_title}" => -> { your_query }
|
763
|
+
|
764
|
+
# Example from tramway-event gem (you also can push context variables here)
|
765
|
+
|
766
|
+
::Tramway::Admin.set_notificable_queries new_participants: -> (current_user) do
|
767
|
+
::Tramway::Event::Participant.where(participation_state: :requested).send "#{current_user}_scope", current_user.id
|
768
|
+
end
|
769
|
+
```
|
770
|
+
|
771
|
+
**NOTE:** Proc with `current_user` argument is expecting. If you don't need `current_user`, just name do something like that:
|
772
|
+
|
773
|
+
```ruby
|
774
|
+
::Tramway::Admin.set_notificable_queries new_participants: -> (_current_user) do
|
775
|
+
# some code which does not need current_user
|
776
|
+
end
|
777
|
+
```
|
778
|
+
|
779
|
+
## Admin Main Page management
|
780
|
+
|
781
|
+
Start page of admin panel contains only `application.name` by default. To manage it just set `Tramway::Admin.welcome_page_actions` with some lambda and set `@content` variable with HTML.
|
782
|
+
|
783
|
+
Example:
|
784
|
+
|
785
|
+
*config/initializers/tramway/admin.rb*
|
786
|
+
```ruby
|
787
|
+
::Tramway::Admin.welcome_page_actions = lambda do
|
788
|
+
@content = '<a href="http://it-way.pro">IT Way</a>'
|
789
|
+
end
|
790
|
+
```
|
24
791
|
|
25
|
-
|
792
|
+
## Navbar management
|
793
|
+
|
794
|
+
### Navbar structure
|
795
|
+
|
796
|
+
You can manage your navbar easy
|
797
|
+
|
798
|
+
*config/initializers/tramway.rb*
|
799
|
+
```ruby
|
800
|
+
Tramway::Admin.navbar_structure(
|
801
|
+
YourModel, # this line will create first-level link in your navbar, which will send you to the YourModel management
|
802
|
+
{
|
803
|
+
my_dropdown: [ # this line contains dropdown link name
|
804
|
+
AnotherYourModel # this line will create 2nd-level link in your navbar, which will send you to the YourModel management,
|
805
|
+
:divider # this line adds bootstrap divider to the dropdown list
|
806
|
+
]
|
807
|
+
},
|
808
|
+
project: :your_application_name
|
809
|
+
)
|
810
|
+
```
|
811
|
+
|
812
|
+
**NOTE:** navbar structure is the same for all roles, but users will see only available models for them
|
813
|
+
|
814
|
+
### Dropdown localization
|
815
|
+
|
816
|
+
To set human-read name for dropdown link you can use i18n:
|
817
|
+
|
818
|
+
*config/locales/admin.yml*
|
819
|
+
|
820
|
+
```yaml
|
821
|
+
en:
|
822
|
+
admin:
|
823
|
+
navbar:
|
824
|
+
links:
|
825
|
+
my_dropdown: Very important dropdown
|
826
|
+
```
|
827
|
+
|
828
|
+
## Additional buttons to the show view
|
829
|
+
|
830
|
+
You can additional buttons to the header of show view of your model. Just add its configuration to the decorator
|
831
|
+
|
832
|
+
*app/decorators/your_model_decorator.rb*
|
833
|
+
```ruby
|
834
|
+
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
835
|
+
def additional_buttons
|
836
|
+
{
|
837
|
+
show: [ # means that this buttons will be shown on show view only
|
838
|
+
{
|
839
|
+
url: ::Tramway::Export::Engine.routes.url_helpers.export_path(object.id, model: object.class, collection: :tasks),
|
840
|
+
inner: lambda do # inner HTML you want to see in the button
|
841
|
+
fa_icon 'file-excel'
|
842
|
+
end,
|
843
|
+
color: :success, # bootstrap button color
|
844
|
+
method: :get # HTTP method. get method is a default. Available: :post, :patch: delete
|
845
|
+
}
|
846
|
+
]
|
847
|
+
}
|
848
|
+
end
|
849
|
+
end
|
850
|
+
```
|
851
|
+
|
852
|
+
## Errors
|
853
|
+
|
854
|
+
* **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]`
|
855
|
+
|
856
|
+
## Change admin user base model
|
857
|
+
|
858
|
+
*config/initializers/tramway.rb*
|
859
|
+
```ruby
|
860
|
+
::Tramway::Admin.auth_config = { user_model: User, auth_attributes: %i[email username] }
|
861
|
+
```
|
862
|
+
|
863
|
+
## Good features
|
864
|
+
|
865
|
+
### Get actions log in admin panel
|
866
|
+
|
867
|
+
Tramway uses [audited](https://github.com/collectiveidea/audited) to log actions of models. That's why all we need it's creating view for model `Audited::Audit`
|
868
|
+
|
869
|
+
#### 1. Add Audited::Audit model to available models
|
870
|
+
|
871
|
+
*config/initializers/tramway.rb*
|
872
|
+
```ruby
|
873
|
+
Tramway::Admin.set_available_models(
|
874
|
+
Audited::Audit,
|
875
|
+
project: :your_project_name
|
876
|
+
)
|
877
|
+
```
|
878
|
+
|
879
|
+
#### 2. Add this model to navbar
|
880
|
+
|
881
|
+
```ruby
|
882
|
+
Tramway::Admin.set_navbar_structure(
|
883
|
+
Audited::Audit,
|
884
|
+
project: :your_project_name
|
885
|
+
)
|
886
|
+
```
|
887
|
+
|
888
|
+
#### 3. Generate decorator for Audited::Audit
|
889
|
+
|
890
|
+
```
|
891
|
+
rails g tramway:admin:model Audited::Audit
|
892
|
+
```
|
26
893
|
|
27
894
|
## Development
|
28
895
|
|
29
|
-
|
896
|
+
### Tests
|
30
897
|
|
31
|
-
|
898
|
+
```
|
899
|
+
make test
|
900
|
+
```
|
901
|
+
|
902
|
+
### Rubocop
|
32
903
|
|
33
|
-
|
904
|
+
```
|
905
|
+
make rubocop
|
906
|
+
```
|
34
907
|
|
35
|
-
|
908
|
+
## License
|
909
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|