tramway 0.1.2 → 0.1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +24 -885
- data/Rakefile +8 -8
- data/app/components/tailwind_component.html.haml +0 -0
- data/app/components/tailwind_component.rb +6 -0
- data/app/components/tailwinds/navbar/button_component.html.haml +6 -0
- data/app/components/tailwinds/navbar/button_component.rb +20 -0
- data/config/routes.rb +0 -9
- data/lib/tasks/tramway_tasks.rake +5 -0
- data/lib/tramway/engine.rb +5 -10
- data/lib/tramway/version.rb +1 -1
- data/lib/tramway.rb +5 -140
- metadata +16 -545
- data/app/assets/config/tramway_core_manifest.js +0 -2
- 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 +0 -2035
- data/app/assets/javascripts/bootstrap-datepicker-1.8.0.ru.min.js +0 -64
- data/app/assets/javascripts/ckeditor/config.js +0 -30
- data/app/assets/javascripts/ckeditor/plugins/image/dialogs/image.js +0 -1259
- 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 +0 -25
- data/app/assets/javascripts/ckeditor/plugins/image/lang/ru.js +0 -25
- data/app/assets/javascripts/ckeditor/plugins/image/plugin.js +0 -184
- 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 +0 -25
- data/app/assets/javascripts/ckeditor/plugins/youtube/lang/ru.js +0 -25
- data/app/assets/javascripts/ckeditor/plugins/youtube/plugin.js +0 -449
- data/app/assets/javascripts/tramway/application.js +0 -61
- data/app/assets/stylesheets/tramway/application.sass +0 -59
- data/app/controllers/tramway/application_controller.rb +0 -142
- data/app/controllers/tramway/concerns/auth_management.rb +0 -26
- data/app/controllers/tramway/concerns/filtering.rb +0 -43
- data/app/controllers/tramway/export/application_controller.rb +0 -5
- data/app/controllers/tramway/has_and_belongs_to_many_records_controller.rb +0 -26
- data/app/controllers/tramway/records_controller.rb +0 -86
- data/app/controllers/tramway/sessions_controller.rb +0 -49
- data/app/controllers/tramway/singletons_controller.rb +0 -48
- data/app/controllers/tramway/welcome_controller.rb +0 -17
- data/app/decorators/tramway/application_decorated_collection.rb +0 -15
- data/app/decorators/tramway/application_decorator.rb +0 -124
- data/app/decorators/tramway/associations/class_helper.rb +0 -45
- data/app/decorators/tramway/associations/object_helper.rb +0 -58
- data/app/decorators/tramway/attributes/view_helper.rb +0 -30
- data/app/decorators/tramway/concerns/attributes_decorator_helper.rb +0 -97
- data/app/decorators/tramway/concerns/table_builder.rb +0 -33
- data/app/decorators/tramway/default/values_helper.rb +0 -23
- data/app/decorators/tramway/delegating/class_helper.rb +0 -9
- data/app/decorators/tramway/user_decorator.rb +0 -49
- data/app/forms/admin/tramway/user_form.rb +0 -24
- data/app/forms/tramway/application_form.rb +0 -124
- data/app/forms/tramway/application_forms/association_class_helpers.rb +0 -7
- data/app/forms/tramway/application_forms/association_object_helpers.rb +0 -36
- data/app/forms/tramway/application_forms/constant_class_actions.rb +0 -7
- data/app/forms/tramway/application_forms/constant_object_actions.rb +0 -20
- data/app/forms/tramway/application_forms/frontend.rb +0 -12
- data/app/forms/tramway/application_forms/object_helpers.rb +0 -15
- data/app/forms/tramway/application_forms/properties_object_helper.rb +0 -16
- data/app/forms/tramway/application_forms/submit_helper.rb +0 -26
- data/app/forms/tramway/extendable_form.rb +0 -15
- data/app/forms/tramway/extendable_forms_helpers/class_builder.rb +0 -34
- data/app/forms/tramway/extendable_forms_helpers/ignored_properties_helper.rb +0 -11
- data/app/forms/tramway/extendable_forms_helpers/more_properties_helper.rb +0 -31
- data/app/forms/tramway/extendable_forms_helpers/properties_helper.rb +0 -16
- data/app/forms/tramway/extendable_forms_helpers/submit/class_helpers.rb +0 -18
- data/app/forms/tramway/extendable_forms_helpers/submit/object_helpers.rb +0 -21
- data/app/forms/tramway/extendable_forms_helpers/validators.rb +0 -40
- data/app/forms/tramway/extended_application_form.rb +0 -23
- data/app/forms/tramway/form_creator.rb +0 -7
- data/app/forms/tramway/session_form.rb +0 -26
- data/app/helpers/tramway/actions_helper.rb +0 -45
- data/app/helpers/tramway/additional_buttons_builder.rb +0 -12
- data/app/helpers/tramway/application_helper.rb +0 -27
- data/app/helpers/tramway/cases_helper.rb +0 -13
- data/app/helpers/tramway/copy_to_clipboard_helper.rb +0 -11
- data/app/helpers/tramway/focus_generator_helper.rb +0 -10
- data/app/helpers/tramway/frontend_helper.rb +0 -26
- data/app/helpers/tramway/inputs/associations_helper.rb +0 -30
- data/app/helpers/tramway/inputs/polymorphic_associations_helper.rb +0 -24
- data/app/helpers/tramway/inputs_helper.rb +0 -96
- data/app/helpers/tramway/model_helper.rb +0 -7
- data/app/helpers/tramway/navbar_helper.rb +0 -11
- data/app/helpers/tramway/records_helper.rb +0 -120
- data/app/helpers/tramway/russian_cases_helper.rb +0 -26
- data/app/helpers/tramway/singleton_helper.rb +0 -12
- data/app/helpers/tramway/state_machine_buttons_helper.rb +0 -61
- data/app/helpers/tramway/title_helper.rb +0 -25
- data/app/inputs/date_picker_input.rb +0 -4
- data/app/inputs/multiple_file_input.rb +0 -7
- data/app/models/tramway/application_record.rb +0 -62
- data/app/models/tramway/user.rb +0 -18
- data/app/uploaders/application_uploader.rb +0 -22
- data/app/uploaders/file_uploader.rb +0 -4
- data/app/uploaders/ico_uploader.rb +0 -7
- data/app/uploaders/image_defaults.rb +0 -14
- data/app/uploaders/photo_uploader.rb +0 -54
- data/app/views/layouts/tramway/application.html.haml +0 -32
- data/app/views/layouts/tramway/shared/_navbar.html.haml +0 -46
- data/app/views/tramway/404.haml +0 -1
- data/app/views/tramway/records/_form.html.haml +0 -22
- data/app/views/tramway/records/_list.html.haml +0 -38
- data/app/views/tramway/records/_search.html.haml +0 -34
- data/app/views/tramway/records/edit.html.haml +0 -1
- data/app/views/tramway/records/index.html.haml +0 -31
- data/app/views/tramway/records/new.html.haml +0 -1
- data/app/views/tramway/records/show.html.haml +0 -1
- data/app/views/tramway/sessions/new.html.haml +0 -9
- data/app/views/tramway/shared/_input.html.haml +0 -34
- data/app/views/tramway/shared/_input_extended.html.haml +0 -14
- data/app/views/tramway/shared/_messages.html.haml +0 -10
- data/app/views/tramway/shared/_show.html.haml +0 -35
- data/app/views/tramway/shared/errors/server_error.html.haml +0 -12
- data/app/views/tramway/shared/input_extended_types/_checkbox.html.haml +0 -1
- data/app/views/tramway/shared/input_extended_types/_select.html.haml +0 -16
- data/app/views/tramway/shared/input_extended_types/_simple.html.haml +0 -4
- data/app/views/tramway/shared/input_extended_types/_yes_no.html.haml +0 -4
- data/app/views/tramway/shared/show/_attribute_tr.html.haml +0 -9
- data/app/views/tramway/shared/show/associations/_habtm_row.html.haml +0 -14
- data/app/views/tramway/shared/show/associations/_list.html.haml +0 -21
- data/app/views/tramway/shared/show/associations/_row.html.haml +0 -19
- data/app/views/tramway/shared/show/associations/_table_row.html.haml +0 -21
- data/app/views/tramway/singletons/_form.html.haml +0 -15
- data/app/views/tramway/singletons/edit.html.haml +0 -1
- data/app/views/tramway/singletons/new.html.haml +0 -1
- data/app/views/tramway/singletons/show.html.haml +0 -1
- data/app/views/tramway/welcome/index.html.haml +0 -4
- data/config/initializers/assets.rb +0 -7
- data/config/initializers/ckeditor.rb +0 -9
- data/config/initializers/plurals.rb +0 -25
- data/config/locales/en/collections.yml +0 -4
- data/config/locales/en/date.yml +0 -16
- data/config/locales/en/dates.yml +0 -10
- data/config/locales/en/helpers.yml +0 -26
- data/config/locales/en/locale.yml +0 -11
- data/config/locales/en/messages.yml +0 -7
- data/config/locales/en/models.yml +0 -9
- data/config/locales/en/simple_form_extension.yml +0 -8
- data/config/locales/en/state_machines.yml +0 -8
- data/config/locales/ru/collections.yml +0 -4
- data/config/locales/ru/date.yml +0 -16
- data/config/locales/ru/dates.yml +0 -10
- data/config/locales/ru/helpers.yml +0 -30
- data/config/locales/ru/locale.yml +0 -6
- data/config/locales/ru/messages.yml +0 -7
- data/config/locales/ru/models.yml +0 -21
- data/config/locales/ru/simple_form_extension.yml +0 -8
- data/config/locales/ru/state_machines.yml +0 -8
- data/lib/string.rb +0 -18
- data/lib/tramway/application.rb +0 -10
- data/lib/tramway/class_name_helpers.rb +0 -15
- data/lib/tramway/collection.rb +0 -9
- data/lib/tramway/collections/helper.rb +0 -21
- data/lib/tramway/collections.rb +0 -4
- data/lib/tramway/error.rb +0 -32
- data/lib/tramway/forms.rb +0 -5
- data/lib/tramway/generators/install_generator.rb +0 -49
- data/lib/tramway/generators/model_generator.rb +0 -105
- data/lib/tramway/generators/templates/create_tramway_users.rb +0 -18
- data/lib/tramway/generators/templates/decorator.rb.erb +0 -56
- data/lib/tramway/generators/templates/form.rb.erb +0 -22
- data/lib/tramway/generators/templates/initializers/simple_form.rb +0 -23
- data/lib/tramway/generators/templates/initializers/simple_form_bootstrap.rb +0 -133
- data/lib/tramway/generators.rb +0 -6
- data/lib/tramway/navbar.rb +0 -44
- data/lib/tramway/notifications.rb +0 -12
- data/lib/tramway/record_routes_helper.rb +0 -23
- data/lib/tramway/records_models.rb +0 -60
- data/lib/tramway/singleton_models.rb +0 -32
- data/lib/tramway/spec/helpers/navbar_helper.rb +0 -7
- data/lib/tramway/spec/helpers/tramway_helpers.rb +0 -47
- data/lib/tramway/welcome_page_actions.rb +0 -5
- data/lib/tramway/yaml/errors.yml +0 -50
- data/lib/validators/presence_validator.rb +0 -9
data/README.md
CHANGED
@@ -1,909 +1,48 @@
|
|
1
|
-
#
|
1
|
+
# Tramway
|
2
|
+
Unite Ruby on Rails brilliance. Streamline development with Tramway.
|
2
3
|
|
3
|
-
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
4
6
|
|
5
|
-
*Gemfile*
|
6
7
|
```ruby
|
7
|
-
gem
|
8
|
-
gem
|
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'
|
8
|
+
gem "tramway"
|
9
|
+
gem "view_component"
|
24
10
|
```
|
25
11
|
|
26
|
-
*config/initializers/tramway.rb*
|
27
|
-
```ruby
|
28
|
-
# Initialize application with name
|
29
|
-
Tramway.initialize_application name: :your_application_name
|
30
|
-
|
31
|
-
# Initialize application name with model_class. Model class must be a singlethon
|
32
|
-
Tramway.initialize_application model_class: MyApplication
|
33
|
-
```
|
34
|
-
|
35
|
-
```shell
|
36
|
-
rails g tramway:install
|
37
|
-
```
|
38
|
-
|
39
|
-
*config/initializers/assets.rb*
|
40
|
-
```ruby
|
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
|
220
|
-
```
|
221
|
-
|
222
|
-
## Other helpers
|
223
|
-
|
224
|
-
### CopyToClipboardHelper
|
225
|
-
|
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)
|
227
|
-
|
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!
|
305
|
-
|
306
12
|
## 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
13
|
|
453
|
-
|
14
|
+
### Tailwind components
|
454
15
|
|
455
|
-
|
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)
|
16
|
+
Tramway use [Tailwind](https://tailwindcss.com/) by default. All UI helpers implemented with [ViewComponent](https://github.com/viewcomponent/view_component).
|
573
17
|
|
574
|
-
|
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
|
-
```
|
18
|
+
### Navbar
|
676
19
|
|
677
|
-
|
20
|
+
#### Button
|
678
21
|
|
679
|
-
|
22
|
+
Tramway provides `Tailwinds::Navbar::ButtonComponent`, that uses `button_to` or `link_to`
|
680
23
|
|
681
|
-
```
|
682
|
-
|
24
|
+
```haml
|
25
|
+
= render(Tailwinds::Navbar::ButtonComponent.new(href: "/users/sign_in")) do
|
26
|
+
Sign In
|
683
27
|
```
|
684
|
-
to the `app/assets/javascripts/admin/application.js` file
|
685
28
|
|
686
|
-
|
29
|
+
will render [this](https://play.tailwindcss.com/RT3Vvauu78)
|
687
30
|
|
688
|
-
```
|
689
|
-
|
31
|
+
```haml
|
32
|
+
= render(Tailwinds::Navbar::ButtonComponent.new(action: "/users/sign_out", method: :delete)) do
|
33
|
+
Sign Out
|
690
34
|
```
|
691
|
-
to the `app/assets/javascripts/admin/application.js.coffee` file
|
692
35
|
|
693
|
-
|
36
|
+
will render [this](https://play.tailwindcss.com/pJ8450tV21)
|
694
37
|
|
695
|
-
|
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
|
-
```
|
791
|
-
|
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
|
-
```
|
893
|
-
|
894
|
-
## Development
|
895
|
-
|
896
|
-
### Tests
|
897
|
-
|
898
|
-
```
|
899
|
-
make test
|
900
|
-
```
|
38
|
+
## Contributing
|
901
39
|
|
902
|
-
|
40
|
+
Install [lefthook](https://github.com/evilmartians/lefthook)
|
903
41
|
|
904
42
|
```
|
905
|
-
|
43
|
+
bundle
|
44
|
+
lefthook install
|
906
45
|
```
|
907
46
|
|
908
47
|
## License
|
909
|
-
The gem is available as open source under the terms of the [MIT License](
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|