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
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway::Concerns::AuthManagement
|
4
|
-
def sign_in(user)
|
5
|
-
session[:tramway_user_id] = user.id
|
6
|
-
end
|
7
|
-
|
8
|
-
def sign_out
|
9
|
-
session[:tramway_user_id] = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def signed_in?
|
13
|
-
current_user
|
14
|
-
end
|
15
|
-
|
16
|
-
def authenticate_user!
|
17
|
-
redirect_to Tramway::Engine.routes.url_helpers.new_session_path if !session_path? && !signed_in?
|
18
|
-
end
|
19
|
-
|
20
|
-
def current_user
|
21
|
-
user = Tramway::User.find_by id: session[:tramway_user_id]
|
22
|
-
return false unless user
|
23
|
-
|
24
|
-
Tramway::UserDecorator.decorate user
|
25
|
-
end
|
26
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway::Concerns::Filtering
|
4
|
-
def list_filtering(records)
|
5
|
-
params[:list_filters]&.each do |filter, _value|
|
6
|
-
case decorator_class.list_filters[filter.to_sym][:type]
|
7
|
-
when :select
|
8
|
-
records = list_filtering_select records, filter
|
9
|
-
when :dates
|
10
|
-
records = list_filtering_dates records, filter
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
records
|
15
|
-
end
|
16
|
-
|
17
|
-
def list_filtering_select(records, filter)
|
18
|
-
value.present? ? decorator_class.list_filters[filter.to_sym][:query].call(records, value) : records
|
19
|
-
end
|
20
|
-
|
21
|
-
def list_filtering_dates(records, filter)
|
22
|
-
begin_date = date_filter :begin, filter
|
23
|
-
end_date = date_filter :end, filter
|
24
|
-
if begin_date.present? && end_date.present? && value.present?
|
25
|
-
decorator_class.list_filters[filter.to_sym][:query].call(records, begin_date, end_date)
|
26
|
-
else
|
27
|
-
records
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def date_filter(type, filter)
|
32
|
-
params[:list_filters][filter.to_sym]["#{type}_date".to_sym]
|
33
|
-
end
|
34
|
-
|
35
|
-
def filtering(records)
|
36
|
-
if params[:filter].present?
|
37
|
-
params[:filter] = JSON.parse params[:filter] if params[:filter].is_a? String
|
38
|
-
records.ransack(params[:filter]).result(distinct: true)
|
39
|
-
else
|
40
|
-
records
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Tramway::HasAndBelongsToManyRecordsController < Tramway::ApplicationController
|
4
|
-
def create
|
5
|
-
base_object = model_class.find params[:object_id]
|
6
|
-
@record_form = form_class.new base_object
|
7
|
-
@sending_params = params[params[:model_class].underscore] || params[form_class.associated_as]
|
8
|
-
redirect_to path
|
9
|
-
end
|
10
|
-
|
11
|
-
def destroy
|
12
|
-
base_object = model_class.find params[:object_id]
|
13
|
-
@record_form = params[:form].constantize.new base_object
|
14
|
-
redirect_to path
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def path
|
20
|
-
params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
|
21
|
-
end
|
22
|
-
|
23
|
-
def form_class
|
24
|
-
params[:form].constantize
|
25
|
-
end
|
26
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Tramway::RecordsController < Tramway::ApplicationController
|
4
|
-
def index
|
5
|
-
records = model_class.order(id: :desc).send scope
|
6
|
-
records = full_text_search records
|
7
|
-
records = filtering records
|
8
|
-
records = list_filtering records
|
9
|
-
records = records.public_send current_user_role_scope, current_user.id
|
10
|
-
@records = decorator_class.decorate records.page params[:page]
|
11
|
-
end
|
12
|
-
|
13
|
-
def show
|
14
|
-
@record = decorator_class.decorate model_class.find params[:id]
|
15
|
-
end
|
16
|
-
|
17
|
-
def new
|
18
|
-
@record_form = admin_form_class.new model_class.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def create
|
22
|
-
@record_form = admin_form_class.new model_class.new
|
23
|
-
if @record_form.submit params[attributes_key]
|
24
|
-
redirect_to params[:redirect].present? ? params[:redirect] : record_path(@record_form.model)
|
25
|
-
else
|
26
|
-
render :new
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def edit
|
31
|
-
@record_form = admin_form_class.new model_class.find params[:id]
|
32
|
-
end
|
33
|
-
|
34
|
-
def update
|
35
|
-
@record_form = admin_form_class.new model_class.find params[:id]
|
36
|
-
if state_event.present?
|
37
|
-
if record_state_event?
|
38
|
-
record_make_state_event!
|
39
|
-
default_redirect
|
40
|
-
end
|
41
|
-
elsif @record_form.submit params[attributes_key]
|
42
|
-
default_redirect
|
43
|
-
else
|
44
|
-
render :edit
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def destroy
|
49
|
-
record = model_class.find params[:id]
|
50
|
-
record.destroy
|
51
|
-
redirect_to params[:redirect].present? ? params[:redirect] : records_path
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def default_redirect
|
57
|
-
redirect_to params[:redirect].present? ? params[:redirect] : record_path(@record_form.model)
|
58
|
-
end
|
59
|
-
|
60
|
-
def record_state_event?
|
61
|
-
@record_form.model.public_send("may_#{state_event}?")
|
62
|
-
end
|
63
|
-
|
64
|
-
def record_make_state_event!
|
65
|
-
@record_form.model.send("#{state_event}!")
|
66
|
-
end
|
67
|
-
|
68
|
-
def state_event
|
69
|
-
params[attributes_key][:aasm_event]
|
70
|
-
end
|
71
|
-
|
72
|
-
def scope
|
73
|
-
params[:scope].present? ? params[:scope] : :all
|
74
|
-
end
|
75
|
-
|
76
|
-
def full_text_search(records)
|
77
|
-
params[:search].present? ? records.full_text_search(params[:search]) : records
|
78
|
-
end
|
79
|
-
|
80
|
-
def attributes_key
|
81
|
-
old_key_name = model_class.to_s.underscore
|
82
|
-
actual_key_name = :record
|
83
|
-
|
84
|
-
params[old_key_name].present? ? old_key_name : actual_key_name
|
85
|
-
end
|
86
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# FIXME: configurate load_path
|
4
|
-
load "#{Tramway.root}/app/controllers/tramway/concerns/auth_management.rb"
|
5
|
-
|
6
|
-
class Tramway::SessionsController < Tramway::ApplicationController
|
7
|
-
before_action :redirect_if_signed_in, except: :destroy
|
8
|
-
|
9
|
-
# FIXME: should be included in Tramway::ApplicationController
|
10
|
-
include Tramway::Concerns::AuthManagement
|
11
|
-
|
12
|
-
def new
|
13
|
-
@session_form = Tramway::SessionForm.new Tramway::User.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def create
|
17
|
-
@session_form = Tramway::SessionForm.new record
|
18
|
-
|
19
|
-
if @session_form.validate params[:user]
|
20
|
-
sign_in @session_form.model
|
21
|
-
redirect_to root_path
|
22
|
-
else
|
23
|
-
render :new
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def destroy
|
28
|
-
root_path = Tramway::Engine.routes.url_helpers.root_path
|
29
|
-
sign_out
|
30
|
-
|
31
|
-
redirect_to params[:redirect] || root_path
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def redirect_if_signed_in
|
37
|
-
if params[:model].present? && signed_in? && request.env['PATH_INFO'] != Tramway.root_path_for(current_user.class)
|
38
|
-
redirect_to Tramway.root_path_for(current_user.class)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def record
|
43
|
-
@record ||= params[:model].constantize.find_by email: params[:user][:email]
|
44
|
-
end
|
45
|
-
|
46
|
-
def root_path
|
47
|
-
Tramway::Engine.routes.url_helpers.root_path[0..-2]
|
48
|
-
end
|
49
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway
|
4
|
-
class SingletonsController < ApplicationController
|
5
|
-
def show
|
6
|
-
if model_class.first.present?
|
7
|
-
@singleton = decorator_class.decorate model_class.first
|
8
|
-
else
|
9
|
-
@singleton_form = admin_form_class.new model_class.new
|
10
|
-
render :new
|
11
|
-
nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def edit
|
16
|
-
@singleton_form = admin_form_class.new model_class.first
|
17
|
-
end
|
18
|
-
|
19
|
-
def create
|
20
|
-
@singleton_form = admin_form_class.new model_class.new
|
21
|
-
if @singleton_form.submit params[:singleton]
|
22
|
-
redirect_to params[:redirect] || singleton_path(model: params[:model])
|
23
|
-
else
|
24
|
-
render :edit
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
@singleton_form = admin_form_class.new model_class.first
|
30
|
-
if @singleton_form.submit params[:singleton]
|
31
|
-
redirect_to params[:redirect] || singleton_path(model: params[:model])
|
32
|
-
else
|
33
|
-
render :edit
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# FIXME: replace to module
|
41
|
-
def singleton_path(*args, **options)
|
42
|
-
super args, options.merge(model: params[:model])
|
43
|
-
end
|
44
|
-
|
45
|
-
def edit_singleton_path(*args, **options)
|
46
|
-
super args, options.merge(model: params[:model])
|
47
|
-
end
|
48
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# FIXME: configurate load_path
|
4
|
-
load "#{Tramway.root}/app/controllers/tramway/concerns/auth_management.rb"
|
5
|
-
|
6
|
-
class Tramway::WelcomeController < Tramway::ApplicationController
|
7
|
-
skip_before_action :check_available!
|
8
|
-
|
9
|
-
# FIXME: should be included in Tramway::ApplicationController
|
10
|
-
include Tramway::Concerns::AuthManagement
|
11
|
-
|
12
|
-
before_action :authenticate_user!
|
13
|
-
|
14
|
-
def index
|
15
|
-
instance_exec(&Tramway.welcome_page_actions) if Tramway.welcome_page_actions.present?
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Tramway::ApplicationDecoratedCollection < Array
|
4
|
-
def initialize(array, original_array)
|
5
|
-
@original_array = original_array
|
6
|
-
super(array)
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :original_array
|
10
|
-
|
11
|
-
delegate :total_pages, to: :original_array
|
12
|
-
delegate :total_count, to: :original_array
|
13
|
-
delegate :current_page, to: :original_array
|
14
|
-
delegate :limit_value, to: :original_array
|
15
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tramway/error'
|
4
|
-
require 'tramway/class_name_helpers'
|
5
|
-
|
6
|
-
class Tramway::ApplicationDecorator
|
7
|
-
include ActionView::Helpers
|
8
|
-
include ActionView::Context
|
9
|
-
include FontAwesome5::Rails::IconHelper
|
10
|
-
include Tramway::CopyToClipboardHelper
|
11
|
-
include Tramway::Associations::ObjectHelper
|
12
|
-
include Tramway::Attributes::ViewHelper
|
13
|
-
include Tramway::Concerns::TableBuilder
|
14
|
-
include Tramway::ClassNameHelpers
|
15
|
-
|
16
|
-
def initialize(object)
|
17
|
-
@object = object
|
18
|
-
end
|
19
|
-
|
20
|
-
def name
|
21
|
-
object.try(:name) || object.try(:title) || title
|
22
|
-
end
|
23
|
-
|
24
|
-
def title
|
25
|
-
Tramway::Error.raise_error(
|
26
|
-
:tramway, :application_decorator, :title, :please_implement_title,
|
27
|
-
class_name: self.class, object_class: object.class
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
def present?
|
32
|
-
object.present?
|
33
|
-
end
|
34
|
-
|
35
|
-
def render(view, **locals)
|
36
|
-
view_name = view.split('/').map.with_index do |dir, index|
|
37
|
-
if index == view.split('/').length - 1
|
38
|
-
"_#{dir}"
|
39
|
-
else
|
40
|
-
dir
|
41
|
-
end
|
42
|
-
end.join('/')
|
43
|
-
Haml::Engine.new(File.read("#{Rails.root}/app/views/#{view_name}.html.haml")).render(self, locals)
|
44
|
-
end
|
45
|
-
|
46
|
-
def listed_state_machines
|
47
|
-
nil
|
48
|
-
end
|
49
|
-
|
50
|
-
delegate :id, to: :object
|
51
|
-
|
52
|
-
class << self
|
53
|
-
include Tramway::Associations::ClassHelper
|
54
|
-
include Tramway::Delegating::ClassHelper
|
55
|
-
include Tramway::Default::ValuesHelper
|
56
|
-
|
57
|
-
def decorate(object_or_array)
|
58
|
-
is_activerecord_relation = object_or_array.class.superclass == ActiveRecord::Relation
|
59
|
-
is_activerecord_association_relation = object_or_array.class.to_s.include?('ActiveRecord_AssociationRelation')
|
60
|
-
if is_activerecord_relation || is_activerecord_association_relation
|
61
|
-
decorated_array = object_or_array.map do |obj|
|
62
|
-
new obj
|
63
|
-
end
|
64
|
-
Tramway::ApplicationDecoratedCollection.new decorated_array, object_or_array
|
65
|
-
else
|
66
|
-
new object_or_array
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def model_class
|
71
|
-
to_s.sub(/Decorator$/, '').constantize
|
72
|
-
end
|
73
|
-
|
74
|
-
def model_name
|
75
|
-
model_class.try(:model_name)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def link
|
80
|
-
if object.try :file
|
81
|
-
object.file.url
|
82
|
-
else
|
83
|
-
Tramway::Error.raise_error :tramway, :application_decorator, :link, :method_link_uses_file_attribute
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def additional_buttons
|
88
|
-
{ show: [], index: [] }
|
89
|
-
end
|
90
|
-
|
91
|
-
def public_path; end
|
92
|
-
|
93
|
-
def model
|
94
|
-
object
|
95
|
-
end
|
96
|
-
|
97
|
-
def associations(associations_type)
|
98
|
-
object.class.reflect_on_all_associations(associations_type).map do |association|
|
99
|
-
association unless association.name == :versions
|
100
|
-
end.compact
|
101
|
-
end
|
102
|
-
|
103
|
-
include Tramway::Concerns::AttributesDecoratorHelper
|
104
|
-
|
105
|
-
RESERVED_WORDS = ['fields'].freeze
|
106
|
-
|
107
|
-
def attributes
|
108
|
-
object.attributes.reduce({}) do |hash, attribute|
|
109
|
-
if attribute[0].in? RESERVED_WORDS
|
110
|
-
Tramway::Error.raise_error(
|
111
|
-
:tramway, :application_decorator, :attributes, :method_is_reserved_word,
|
112
|
-
attribute_name: attribute[0], class_name: self.class.name
|
113
|
-
)
|
114
|
-
end
|
115
|
-
hash.merge! attribute[0] => build_viewable_value(object, attribute)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
protected
|
120
|
-
|
121
|
-
attr_reader :object
|
122
|
-
|
123
|
-
def association_class_name; end
|
124
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway::Associations::ClassHelper
|
4
|
-
def decorate_association(association_name, decorator: nil, as: nil, state_machines: [])
|
5
|
-
@@decorated_associations ||= []
|
6
|
-
@@decorated_associations << association_name
|
7
|
-
|
8
|
-
define_main_association_method association_name, decorator
|
9
|
-
|
10
|
-
define_method "#{association_name}_as" do
|
11
|
-
as
|
12
|
-
end
|
13
|
-
|
14
|
-
define_method "#{association_name}_state_machines" do
|
15
|
-
state_machines
|
16
|
-
end
|
17
|
-
|
18
|
-
define_method "add_#{association_name}_form" do
|
19
|
-
add_association_form_class_name(object, association_name).new object
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def decorate_associations(*association_names)
|
24
|
-
association_names.each do |association_name|
|
25
|
-
decorate_association association_name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def define_main_association_method(association_name, decorator)
|
30
|
-
define_method association_name do
|
31
|
-
association = object.class.reflect_on_association(association_name)
|
32
|
-
type = association_type(association)
|
33
|
-
return if association_has_one_without_object(object, association_name, type)
|
34
|
-
|
35
|
-
check_association object, association_name, association
|
36
|
-
decorator_class_name = decorator || decorator_class_name(class_name(association))
|
37
|
-
case type
|
38
|
-
when :has_many, :has_and_belongs_to_many
|
39
|
-
associations_collection(object, association_name, decorator_class_name)
|
40
|
-
when :belongs_to, :has_one
|
41
|
-
decorator_class_name.decorate(association_object(object, association_name))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway::Associations::ObjectHelper
|
4
|
-
def class_name(association)
|
5
|
-
if association.polymorphic?
|
6
|
-
object.send(association.name).class
|
7
|
-
else
|
8
|
-
unless association.options[:class_name]
|
9
|
-
Tramway::Error.raise_error(
|
10
|
-
:tramway, :associations, :object_helper, :please_specify_association_name,
|
11
|
-
association_name: association.name, object_class: object.class,
|
12
|
-
association_class_name: association.name.to_s.singularize.camelize
|
13
|
-
)
|
14
|
-
end
|
15
|
-
association.options[:class_name]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def check_association(object, association_name, association)
|
20
|
-
return unless association.nil?
|
21
|
-
|
22
|
-
Tramway::Error.raise_error(
|
23
|
-
:tramway, :associations, :class_helper, :model_does_not_have_association,
|
24
|
-
object_class: object.class, association_name:
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
def association_type(association)
|
29
|
-
association.class.to_s.split('::').last.sub(/Reflection$/, '').underscore.to_sym
|
30
|
-
end
|
31
|
-
|
32
|
-
def associations_collection(object, association_name, decorator_class_name)
|
33
|
-
object.send(association_name).map do |association_object|
|
34
|
-
decorator_class_name.decorate association_object
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def add_association_form_class_name(object, association_name)
|
39
|
-
form_class = "Admin::#{object.class.to_s.pluralize}::Add#{association_name.to_s.camelize.singularize}Form"
|
40
|
-
|
41
|
-
begin
|
42
|
-
form_class.constantize
|
43
|
-
rescue StandardError
|
44
|
-
Tramway::Error.raise_error(
|
45
|
-
:tramway, :associations, :object_helper, :habtm_add_class_not_defined,
|
46
|
-
class: form_class, association_name:
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def association_has_one_without_object(object, association_name, association_type)
|
52
|
-
association_type == :has_one && object.send(association_name).nil?
|
53
|
-
end
|
54
|
-
|
55
|
-
def association_object(object, association_name)
|
56
|
-
object.send association_name
|
57
|
-
end
|
58
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway::Attributes::ViewHelper
|
4
|
-
def build_viewable_value(object, attribute)
|
5
|
-
value = try(attribute[0]) ? send(attribute[0]) : object.send(attribute[0])
|
6
|
-
return state_machine_view(object, attribute[0]) if state_machine? object, attribute[0]
|
7
|
-
|
8
|
-
view_by_value object, value, attribute
|
9
|
-
end
|
10
|
-
|
11
|
-
def state_machine?(object, attribute_name)
|
12
|
-
attribute_name.to_s.in? object.class.state_machines_names.map(&:to_s)
|
13
|
-
end
|
14
|
-
|
15
|
-
def view_by_value(object, value, attribute)
|
16
|
-
if value.class.in? [ActiveSupport::TimeWithZone, DateTime, Time]
|
17
|
-
datetime_view(attribute[1])
|
18
|
-
elsif value.instance_of?(PhotoUploader)
|
19
|
-
image_view(object.send(attribute[0]))
|
20
|
-
elsif value.instance_of?(FileUploader)
|
21
|
-
file_view(object.send(attribute[0]))
|
22
|
-
elsif value.is_a? Enumerize::Value
|
23
|
-
enumerize_view(value)
|
24
|
-
elsif value.is_a? Hash
|
25
|
-
yaml_view(value)
|
26
|
-
else
|
27
|
-
value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway::Concerns::AttributesDecoratorHelper
|
4
|
-
def date_view(value)
|
5
|
-
I18n.l value.to_date if value
|
6
|
-
end
|
7
|
-
|
8
|
-
def datetime_view(value)
|
9
|
-
I18n.l value if value
|
10
|
-
end
|
11
|
-
|
12
|
-
def state_machine_view(object, attribute_name)
|
13
|
-
state = object.send(attribute_name)
|
14
|
-
I18n.t("state_machines.#{object.class.model_name.to_s.underscore}.#{attribute_name}.states.#{state}")
|
15
|
-
rescue StandardError
|
16
|
-
object.aasm.human_state
|
17
|
-
end
|
18
|
-
|
19
|
-
BASE64_REGEXP = %r{^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|
|
20
|
-
(?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))$}x
|
21
|
-
|
22
|
-
def image_view(original, thumb: nil, filename: nil)
|
23
|
-
return unless original.present?
|
24
|
-
|
25
|
-
filename ||= build_filename(original)
|
26
|
-
content_tag(:div) do
|
27
|
-
build_div_content src_original(original), src_thumb(original, thumb), filename || build_filename(original)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def file_view(original, filename: nil)
|
32
|
-
return unless original.present?
|
33
|
-
|
34
|
-
filename ||= build_filename(original)
|
35
|
-
content_tag(:div) do
|
36
|
-
concat filename
|
37
|
-
concat ' '
|
38
|
-
concat download_button(filename:, original:) if filename
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def enumerize_view(value)
|
43
|
-
value.text
|
44
|
-
end
|
45
|
-
|
46
|
-
def yaml_view(value)
|
47
|
-
content_tag(:pre) { value.to_yaml }
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def src_thumb(original, thumb)
|
53
|
-
thumb ||= original.is_a?(CarrierWave::Uploader::Base) ? original.small : nil
|
54
|
-
if thumb.is_a?(CarrierWave::Uploader::Base)
|
55
|
-
thumb.url
|
56
|
-
elsif thumb&.match(BASE64_REGEXP)
|
57
|
-
"data:image/jpeg;base64,#{thumb}"
|
58
|
-
else
|
59
|
-
thumb
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def src_original(original)
|
64
|
-
case original
|
65
|
-
when CarrierWave::Uploader::Base
|
66
|
-
original.url
|
67
|
-
when BASE64_REGEXP
|
68
|
-
"data:image/jpeg;base64,#{original}"
|
69
|
-
else
|
70
|
-
original
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def build_filename(original)
|
75
|
-
original.is_a?(CarrierWave::Uploader::Base) ? original.path&.split('/')&.last : nil
|
76
|
-
end
|
77
|
-
|
78
|
-
def build_div_content(original, thumb, filename)
|
79
|
-
begin
|
80
|
-
concat image_tag src_thumb(original, thumb) || src_original(original)
|
81
|
-
rescue NoMethodError => e
|
82
|
-
Tramway::Error.raise_error(
|
83
|
-
:tramway, :concerns, :attributes_decorator_helper, :you_should_mount_photo_uploader,
|
84
|
-
message: e.message, attribute_name:
|
85
|
-
)
|
86
|
-
end
|
87
|
-
concat download_button(filename:, original:) if filename
|
88
|
-
end
|
89
|
-
|
90
|
-
def download_button(filename:, original:)
|
91
|
-
link_to(fa_icon(:download), src_original(original), class: 'btn btn-success', download: filename)
|
92
|
-
end
|
93
|
-
|
94
|
-
def yes_no(boolean_attr)
|
95
|
-
boolean_attr.to_s == 'true' ? I18n.t('helpers.yes') : I18n.t('helpers.no')
|
96
|
-
end
|
97
|
-
end
|