biovision 0.0.200518.1 → 0.1.210414.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -18
- data/app/assets/images/biovision/icons/back.svg +19 -0
- data/app/assets/images/biovision/icons/create.svg +19 -0
- data/app/assets/images/biovision/icons/destroy.svg +12 -0
- data/app/assets/images/biovision/icons/dropdown.svg +3 -0
- data/app/assets/images/biovision/icons/edit.svg +22 -0
- data/app/assets/images/biovision/icons/gear.svg +11 -0
- data/app/assets/images/biovision/icons/return.svg +25 -0
- data/app/assets/images/biovision/icons/world.svg +11 -0
- data/app/assets/stylesheets/biovision/admin/components.scss +3 -1
- data/app/assets/stylesheets/biovision/admin/components/users.scss +16 -0
- data/app/assets/stylesheets/biovision/admin/layout.scss +6 -17
- data/app/assets/stylesheets/biovision/biovision.scss +42 -1
- data/app/assets/stylesheets/biovision/components.scss +6 -0
- data/app/assets/stylesheets/biovision/components/breadcrumbs.scss +13 -0
- data/app/assets/stylesheets/biovision/components/buttons.scss +130 -0
- data/app/assets/stylesheets/biovision/components/forms.scss +162 -1
- data/app/assets/stylesheets/biovision/components/lists.scss +6 -7
- data/app/assets/stylesheets/biovision/{biovision → components}/messages.scss +9 -0
- data/app/assets/stylesheets/biovision/components/pagination.scss +34 -0
- data/app/assets/stylesheets/biovision/components/simple_image.scss +112 -0
- data/app/assets/stylesheets/biovision/components/toggleable.scss +71 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +2 -3
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +2 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/form_tabs.scss +101 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/profile.scss +77 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +2 -16
- data/app/controllers/admin/components_controller.rb +9 -19
- data/app/controllers/admin/dynamic_blocks_controller.rb +15 -0
- data/app/controllers/admin/dynamic_pages_controller.rb +15 -0
- data/app/controllers/admin/navigation_groups_controller.rb +14 -0
- data/app/controllers/admin/users_controller.rb +70 -0
- data/app/controllers/admin_controller.rb +3 -2
- data/app/controllers/authentication_controller.rb +6 -34
- data/app/controllers/concerns/authentication.rb +12 -12
- data/app/controllers/concerns/crud_entities.rb +132 -0
- data/app/controllers/concerns/entity_priority.rb +10 -0
- data/app/controllers/concerns/toggleable_entity.rb +31 -0
- data/app/controllers/contact_controller.rb +49 -0
- data/app/controllers/fallback_controller.rb +12 -0
- data/app/controllers/index_controller.rb +1 -0
- data/app/controllers/legal_controller.rb +14 -0
- data/app/controllers/my/components_controller.rb +5 -0
- data/app/controllers/my/confirmations_controller.rb +44 -0
- data/app/controllers/my/index_controller.rb +8 -0
- data/app/controllers/my/profiles_controller.rb +31 -16
- data/app/controllers/profile_controller.rb +12 -0
- data/app/controllers/users_controller.rb +61 -0
- data/app/helpers/biovision_helper.rb +171 -0
- data/app/helpers/simple_image_helper.rb +125 -0
- data/app/jobs/application_job.rb +7 -0
- data/app/jobs/send_phone_confirmation_job.rb +16 -0
- data/app/lib/biovision/components/base/component_parameters.rb +44 -0
- data/app/lib/biovision/components/base/component_privileges.rb +65 -0
- data/app/lib/biovision/components/base/component_settings.rb +32 -0
- data/app/lib/biovision/components/base/privilege_handler.rb +79 -0
- data/app/lib/biovision/components/base_component.rb +51 -54
- data/app/lib/biovision/components/contact_component.rb +22 -0
- data/app/lib/biovision/components/content_component.rb +28 -0
- data/app/lib/biovision/components/track_component.rb +3 -0
- data/app/lib/biovision/components/users/authentication.rb +15 -7
- data/app/lib/biovision/components/users/codes.rb +104 -0
- data/app/lib/biovision/components/users/flag_helpers.rb +72 -0
- data/app/lib/biovision/components/users/profile_handler.rb +111 -1
- data/app/lib/biovision/components/users/registration_handler.rb +40 -52
- data/app/lib/biovision/components/users/validation.rb +83 -0
- data/app/lib/biovision/components/users_component.rb +82 -19
- data/app/lib/biovision/notifiers/base_notifier.rb +2 -2
- data/app/lib/biovision/notifiers/contact_notifier.rb +15 -0
- data/app/lib/canonizer.rb +38 -0
- data/app/lib/carrier_wave/image_optim.rb +32 -0
- data/app/mailers/code_sender.rb +29 -0
- data/app/models/agent.rb +4 -0
- data/app/models/biovision_component.rb +22 -2
- data/app/models/browser.rb +1 -1
- data/app/models/code.rb +32 -9
- data/app/models/concerns/has_simple_image.rb +9 -0
- data/app/models/concerns/meta_texts.rb +25 -5
- data/app/models/concerns/tree_structure.rb +72 -0
- data/app/models/contact_method.rb +47 -0
- data/app/models/contact_type.rb +27 -0
- data/app/models/dynamic_block.rb +43 -0
- data/app/models/dynamic_page.rb +71 -0
- data/app/models/feedback_message.rb +59 -0
- data/app/models/feedback_response.rb +50 -0
- data/app/models/group.rb +48 -0
- data/app/models/language.rb +4 -0
- data/app/models/navigation_group.rb +33 -0
- data/app/models/navigation_group_page.rb +23 -0
- data/app/models/role.rb +56 -0
- data/app/models/role_group.rb +13 -0
- data/app/models/simple_image.rb +22 -8
- data/app/models/simple_image_tag.rb +1 -1
- data/app/models/token.rb +4 -4
- data/app/models/user.rb +94 -26
- data/app/models/user_group.rb +20 -0
- data/app/models/user_role.rb +19 -0
- data/app/uploaders/simple_file_uploader.rb +27 -0
- data/app/uploaders/simple_image_uploader.rb +20 -0
- data/app/views/admin/agents/index.html.erb +0 -2
- data/app/views/admin/components/_image.jbuilder +18 -0
- data/app/views/admin/components/_list.html.erb +1 -1
- data/app/views/admin/components/entity/_links.html.erb +1 -1
- data/app/views/admin/components/image.jbuilder +1 -0
- data/app/views/admin/components/images.jbuilder +4 -0
- data/app/views/admin/components/links/_content.html.erb +9 -0
- data/app/views/admin/components/links/_users.html.erb +1 -8
- data/app/views/admin/components/links/extra/_content.html.erb +0 -0
- data/app/views/admin/components/privileges/_links.html.erb +0 -18
- data/app/views/admin/components/settings/_new_parameter.html.erb +4 -2
- data/app/views/admin/components/settings/_parameters.html.erb +8 -2
- data/app/views/admin/components/settings/_settings.html.erb +1 -1
- data/app/views/admin/components/update_privileges.jbuilder +21 -0
- data/app/views/admin/dynamic_blocks/_form.html.erb +16 -0
- data/app/views/admin/dynamic_blocks/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +10 -0
- data/app/views/admin/dynamic_blocks/index.html.erb +15 -0
- data/app/views/admin/dynamic_blocks/show.html.erb +23 -0
- data/app/views/admin/dynamic_pages/_form.html.erb +21 -0
- data/app/views/admin/dynamic_pages/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +15 -0
- data/app/views/admin/dynamic_pages/index.html.erb +15 -0
- data/app/views/admin/dynamic_pages/show.html.erb +28 -0
- data/app/views/admin/ip_addresses/index.html.erb +0 -2
- data/app/views/admin/navigation_groups/_form.html.erb +15 -0
- data/app/views/admin/navigation_groups/_nav_item.html.erb +6 -0
- data/app/views/admin/navigation_groups/entity/_in_list.html.erb +12 -0
- data/app/views/admin/navigation_groups/index.html.erb +15 -0
- data/app/views/admin/navigation_groups/show.html.erb +20 -0
- data/app/views/admin/unauthorized.html.erb +2 -5
- data/app/views/admin/users/_form.html.erb +81 -0
- data/app/views/admin/users/_nav_item.html.erb +6 -0
- data/app/views/admin/users/entity/_fields.html.erb +53 -0
- data/app/views/admin/users/entity/_in_list.html.erb +38 -0
- data/app/views/admin/users/entity/_profile.html.erb +26 -0
- data/app/views/admin/users/entity/in_list/_additional_data.html.erb +0 -0
- data/app/views/admin/users/index.html.erb +15 -0
- data/app/views/admin/users/show.html.erb +44 -0
- data/app/views/application/forbidden.html.erb +9 -0
- data/app/views/application/forbidden.jbuilder +4 -0
- data/app/views/application/not_found.html.erb +9 -0
- data/app/views/application/not_found.jbuilder +4 -0
- data/app/views/application/unauthorized.html.erb +16 -0
- data/app/views/application/unauthorized.jbuilder +4 -0
- data/app/views/authentication/new.html.erb +2 -8
- data/app/views/components/content/_dynamic_page.html.erb +21 -0
- data/app/views/components/users/_form_tabs.html.erb +31 -0
- data/app/views/components/users/_join_form.html.erb +192 -0
- data/app/views/components/users/_login_form.html.erb +45 -0
- data/app/views/components/users/form/_image.html.erb +17 -0
- data/app/views/components/users/form/_profile_data.html.erb +54 -0
- data/app/views/contact/_form.html.erb +108 -0
- data/app/views/contact/create_feedback_message.js.erb +1 -0
- data/app/views/contact/feedback.html.erb +13 -0
- data/app/views/contact/index.html.erb +16 -0
- data/app/views/fallback/show.html.erb +6 -0
- data/app/views/layouts/admin.html.erb +1 -1
- data/app/views/layouts/admin/_footer.html.erb +1 -1
- data/app/views/layouts/application/header/_authentication.html.erb +1 -1
- data/app/views/legal/privacy.html.erb +5 -0
- data/app/views/legal/tos.html.erb +5 -0
- data/app/views/my/confirmations/show.html.erb +62 -0
- data/app/views/my/index/index.html.erb +33 -0
- data/app/views/my/profiles/_form.html.erb +10 -0
- data/app/views/my/profiles/check.jbuilder +4 -0
- data/app/views/my/profiles/edit.html.erb +14 -0
- data/app/views/my/profiles/form/_basic_parameters.html.erb +9 -0
- data/app/views/my/profiles/form/_sensitive_parameters.html.erb +68 -0
- data/app/views/my/profiles/new.html.erb +6 -8
- data/app/views/my/profiles/show.html.erb +23 -0
- data/app/views/shared/_flash_messages.html.erb +1 -1
- data/app/views/shared/_list_of_errors.html.erb +7 -0
- data/app/views/shared/admin/_breadcrumbs.html.erb +8 -0
- data/app/views/shared/admin/_list.html.erb +4 -4
- data/app/views/shared/admin/_list_with_priority.html.erb +4 -4
- data/app/views/shared/admin/_priority.html.erb +5 -0
- data/app/views/shared/admin/_toggle.html.erb +11 -0
- data/app/views/shared/entity/_formatted_text_field.html.erb +10 -0
- data/app/views/shared/entity/_image.html.erb +31 -0
- data/app/views/shared/entity/_language.html.erb +6 -0
- data/app/views/shared/entity/_linked_entity.html.erb +6 -0
- data/app/views/shared/entity/_meta_texts.html.erb +16 -0
- data/app/views/shared/entity/_metadata.html.erb +18 -0
- data/app/views/shared/entity/_parent.html.erb +6 -0
- data/app/views/shared/entity/_priority.html.erb +4 -0
- data/app/views/shared/entity/_raw_text_field.html.erb +10 -0
- data/app/views/shared/entity/_simple_image.html.erb +10 -0
- data/app/views/shared/entity/_slug.html.erb +6 -0
- data/app/views/shared/entity/_text_field.html.erb +6 -0
- data/app/views/shared/entity/_text_fields.html.erb +9 -0
- data/app/views/shared/entity/_timestamps.html.erb +13 -0
- data/app/views/shared/entity/_tree_caches.html.erb +12 -0
- data/app/views/shared/entity/_uuid.html.erb +4 -0
- data/app/views/shared/entity/edit.html.erb +21 -0
- data/app/views/shared/entity/new.html.erb +16 -0
- data/app/views/shared/forms/_entity_flags.html.erb +15 -0
- data/app/views/shared/forms/_field.html.erb +46 -0
- data/app/views/shared/forms/_fields.html.erb +3 -0
- data/app/views/shared/forms/_language.html.erb +40 -0
- data/app/views/shared/forms/_meta_texts.html.erb +27 -0
- data/app/views/shared/forms/_priority.html.erb +13 -0
- data/app/views/shared/forms/_simple_image.html.erb +39 -0
- data/app/views/shared/forms/_state_container.html.erb +7 -0
- data/app/views/shared/forms/_text_area.html.erb +25 -0
- data/app/views/shared/forms/_text_field.html.erb +24 -0
- data/app/views/shared/forms/_text_fields.html.erb +3 -0
- data/app/views/shared/forms/check.jbuilder +4 -0
- data/app/views/shared/forms/errors.jbuilder +3 -0
- data/app/views/shared/forms/simple_image/_browse.html.erb +14 -0
- data/app/views/shared/forms/simple_image/_load_image.html.erb +38 -0
- data/app/views/shared/my/_list.html.erb +19 -0
- data/app/views/shared/my/_list_with_priority.html.erb +19 -0
- data/app/views/users/_profile.html.erb +30 -0
- data/app/views/users/profile/_data.html.erb +20 -0
- data/app/views/users/show.html.erb +21 -0
- data/config/locales/biovision-ru.yml +58 -0
- data/config/locales/components-ru.yml +30 -2
- data/config/locales/contact-ru.yml +106 -0
- data/config/locales/content-ru.yml +103 -0
- data/config/locales/users-ru.yml +117 -3
- data/config/routes.rb +70 -50
- data/db/migrate/20191228000000_create_biovision_components.rb +4 -5
- data/db/migrate/20200224000000_create_track_component.rb +7 -8
- data/db/migrate/20200224000010_create_users_component.rb +15 -43
- data/db/migrate/20200404000000_create_simple_images.rb +3 -3
- data/db/migrate/20200529000000_create_content_component.rb +74 -0
- data/db/migrate/20210401000000_create_contact_component.rb +95 -0
- data/db/migrate/20210405000000_create_acl.rb +74 -0
- data/lib/biovision/base_methods.rb +18 -10
- data/lib/biovision/engine.rb +8 -13
- data/lib/biovision/version.rb +1 -1
- metadata +186 -20
- data/app/assets/images/biovision/placeholders/user.svg +0 -15
- data/app/helpers/users_helper.rb +0 -11
- data/app/lib/biovision/components/component_settings.rb +0 -30
- data/app/lib/biovision/components/privilege_handler.rb +0 -77
- data/app/lib/biovision/components/users/code_handler.rb +0 -23
- data/app/models/foreign_site.rb +0 -34
- data/app/models/foreign_user.rb +0 -21
- data/app/uploaders/user_image_uploader.rb +0 -58
- data/app/views/admin/components/privileges/_privilege_flag.html.erb +0 -28
- data/app/views/authentication/_form.html.erb +0 -40
- data/app/views/authentication/failed.js.erb +0 -3
- data/app/views/my/profiles/new/_form.html.erb +0 -147
- data/app/views/shared/admin/_toggleable.html.erb +0 -8
@@ -9,19 +9,22 @@ class My::ProfilesController < ApplicationController
|
|
9
9
|
|
10
10
|
# post /my/profile/check
|
11
11
|
def check
|
12
|
-
|
12
|
+
code = Code.active.find_by(body: param_from_request(:code))
|
13
|
+
registration_handler.check(creation_parameters.to_h, code)
|
13
14
|
end
|
14
15
|
|
15
16
|
# get /my/profile/new
|
16
17
|
def new
|
17
18
|
@entity = User.new
|
18
19
|
|
19
|
-
render :closed unless component_handler.
|
20
|
+
render :closed unless component_handler.registration_open?
|
20
21
|
end
|
21
22
|
|
22
23
|
# post /my/profile
|
23
24
|
def create
|
24
25
|
if params[:agree]
|
26
|
+
metric = Biovision::Components::UsersComponent::METRIC_REGISTRATION_BOT
|
27
|
+
component_handler.register_metric(metric)
|
25
28
|
redirect_to root_path, alert: t('.are_you_bot')
|
26
29
|
else
|
27
30
|
create_user
|
@@ -39,7 +42,7 @@ class My::ProfilesController < ApplicationController
|
|
39
42
|
# patch /my/profile
|
40
43
|
def update
|
41
44
|
@entity = current_user
|
42
|
-
if @entity
|
45
|
+
if component_handler.update_user(@entity, user_parameters, profile_parameters)
|
43
46
|
flash[:notice] = t('.success')
|
44
47
|
form_processed_ok(my_path)
|
45
48
|
else
|
@@ -47,7 +50,7 @@ class My::ProfilesController < ApplicationController
|
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
|
-
|
53
|
+
private
|
51
54
|
|
52
55
|
def component_class
|
53
56
|
Biovision::Components::UsersComponent
|
@@ -57,17 +60,20 @@ class My::ProfilesController < ApplicationController
|
|
57
60
|
redirect_to my_path if current_user.is_a?(User)
|
58
61
|
end
|
59
62
|
|
63
|
+
def registration_handler
|
64
|
+
handler_class = Biovision::Components::Users::RegistrationHandler
|
65
|
+
@registration_handler ||= handler_class.new(component_handler)
|
66
|
+
end
|
67
|
+
|
60
68
|
def create_user
|
61
69
|
code = Code.active.find_by(body: param_from_request(:code))
|
62
|
-
|
70
|
+
registration_handler.handle(creation_parameters.to_h, code)
|
71
|
+
@entity = registration_handler.user
|
63
72
|
|
64
73
|
if @entity.persisted?
|
65
|
-
|
66
|
-
cookies.delete('r', domain: :all)
|
67
|
-
|
68
|
-
redirect_after_creation
|
74
|
+
user_created
|
69
75
|
else
|
70
|
-
form_processed_with_error(:new)
|
76
|
+
form_processed_with_error(:new, @entity.errors.full_messages)
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
@@ -85,13 +91,12 @@ class My::ProfilesController < ApplicationController
|
|
85
91
|
sensitive = sensitive_parameters
|
86
92
|
editable = User.profile_parameters + sensitive
|
87
93
|
parameters = params.require(:user).permit(editable)
|
88
|
-
new_data = @entity.data.merge(profile: profile_parameters)
|
89
94
|
|
90
|
-
filter_parameters(parameters.
|
95
|
+
filter_parameters(parameters.to_h, sensitive)
|
91
96
|
end
|
92
97
|
|
93
98
|
def sensitive_parameters
|
94
|
-
if current_user.authenticate
|
99
|
+
if current_user.authenticate param_from_request(:password)
|
95
100
|
User.sensitive_parameters
|
96
101
|
else
|
97
102
|
[]
|
@@ -99,9 +104,12 @@ class My::ProfilesController < ApplicationController
|
|
99
104
|
end
|
100
105
|
|
101
106
|
def profile_parameters
|
102
|
-
|
103
|
-
|
104
|
-
|
107
|
+
if params.key?(:profile)
|
108
|
+
list = Biovision::Components::Users::ProfileHandler.permitted_for_request
|
109
|
+
params.require(:profile).permit(list)
|
110
|
+
else
|
111
|
+
{}
|
112
|
+
end
|
105
113
|
end
|
106
114
|
|
107
115
|
# @param [Hash] parameters
|
@@ -118,6 +126,13 @@ class My::ProfilesController < ApplicationController
|
|
118
126
|
parameters
|
119
127
|
end
|
120
128
|
|
129
|
+
def user_created
|
130
|
+
create_token_for_user(@entity)
|
131
|
+
cookies.delete('r', domain: :all)
|
132
|
+
|
133
|
+
redirect_after_creation
|
134
|
+
end
|
135
|
+
|
121
136
|
def redirect_after_creation
|
122
137
|
return_path = cookies['return_path'].to_s
|
123
138
|
return_path = my_profile_path unless return_path[0] == '/'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Users for visitors
|
4
|
+
class UsersController < ApplicationController
|
5
|
+
before_action :restrict_anonymous_access, only: %i[ban follow unban unfollow]
|
6
|
+
before_action :set_socialization, only: %i[ban follow unban unfollow]
|
7
|
+
before_action :set_entity
|
8
|
+
|
9
|
+
# get /u/:slug
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# get /u/:slug/followees
|
14
|
+
def followees
|
15
|
+
@filter = params[:filter] || Hash.new
|
16
|
+
@collection = UserLink.filtered(:followee, @filter).with_follower(@entity).page_for_user(current_page)
|
17
|
+
end
|
18
|
+
|
19
|
+
# put /u/:slug/follow
|
20
|
+
def follow
|
21
|
+
@socialization.follow(@entity)
|
22
|
+
|
23
|
+
head :no_content
|
24
|
+
end
|
25
|
+
|
26
|
+
# delete /u/:slug/follow
|
27
|
+
def unfollow
|
28
|
+
@socialization.unfollow(@entity)
|
29
|
+
|
30
|
+
head :no_content
|
31
|
+
end
|
32
|
+
|
33
|
+
# put /u/:slug/ban
|
34
|
+
def ban
|
35
|
+
@socialization.ban(@entity)
|
36
|
+
|
37
|
+
head :no_content
|
38
|
+
end
|
39
|
+
|
40
|
+
# delete /u/:slug/ban
|
41
|
+
def unban
|
42
|
+
@socialization.unban(@entity)
|
43
|
+
|
44
|
+
head :no_content
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def component_class
|
50
|
+
Biovision::Components::UsersComponent
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_socialization
|
54
|
+
@socialization = Biovision::Components::SocializationComponent[current_user]
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_entity
|
58
|
+
@entity = User.find_by(slug: params[:slug].downcase, deleted: false)
|
59
|
+
handle_http_404('Cannot find user') if @entity.nil?
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Helper methods for common cases
|
4
|
+
module BiovisionHelper
|
5
|
+
# @param [ApplicationRecord] entity
|
6
|
+
# @param [String] text
|
7
|
+
# @param [Hash] options
|
8
|
+
def admin_entity_link(entity, text = nil, options = {})
|
9
|
+
return '∅' if entity.nil?
|
10
|
+
|
11
|
+
if text.nil?
|
12
|
+
text = entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
|
13
|
+
end
|
14
|
+
|
15
|
+
href = if entity.respond_to?(:admin_url)
|
16
|
+
entity.admin_url
|
17
|
+
else
|
18
|
+
"/admin/#{entity.class.table_name}/#{entity.id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
link_to(text, href, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [ApplicationRecord] entity
|
25
|
+
# @param [String] text
|
26
|
+
# @param [Hash] options
|
27
|
+
def my_entity_link(entity, text = nil, options = {})
|
28
|
+
return '∅' if entity.nil?
|
29
|
+
|
30
|
+
if text.nil?
|
31
|
+
text = entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
|
32
|
+
end
|
33
|
+
|
34
|
+
href = if entity.respond_to?(:my_url)
|
35
|
+
entity.my_url
|
36
|
+
else
|
37
|
+
"/my/#{entity.class.table_name}/#{entity.id}"
|
38
|
+
end
|
39
|
+
|
40
|
+
link_to(text, href, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param [ApplicationRecord] entity
|
44
|
+
# @param [String] text
|
45
|
+
# @param [Hash] options
|
46
|
+
def entity_link(entity, text = nil, options = {})
|
47
|
+
return '' if entity.nil?
|
48
|
+
|
49
|
+
if text.nil?
|
50
|
+
text = entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
|
51
|
+
end
|
52
|
+
|
53
|
+
href = if entity.respond_to?(:world_url)
|
54
|
+
entity.world_url
|
55
|
+
else
|
56
|
+
"/#{entity.class.table_name}/#{entity.id}"
|
57
|
+
end
|
58
|
+
|
59
|
+
link_to(text, href, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param [Hash] options
|
63
|
+
def my_home_link(options = {})
|
64
|
+
link_to(t('my.index.index.nav_text'), my_path, options)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param [String|ApplicationRecord] path
|
68
|
+
# @param [String] title
|
69
|
+
# @param [Hash] options
|
70
|
+
def world_icon(path, title = t(:view_as_visitor), options = {})
|
71
|
+
if path.is_a? ApplicationRecord
|
72
|
+
table_name = path.class.table_name
|
73
|
+
path = path.respond_to?(:world_url) ? path.world_url : "/#{table_name}/#{path.id}"
|
74
|
+
end
|
75
|
+
icon_with_link('biovision/icons/world.svg', path, title, options)
|
76
|
+
end
|
77
|
+
|
78
|
+
# @param [String|ApplicationRecord] path
|
79
|
+
# @param [String] title
|
80
|
+
# @param [Hash] options
|
81
|
+
def gear_icon(path, title = t(:view_settings), options = {})
|
82
|
+
path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord
|
83
|
+
icon_with_link('biovision/icons/gear.svg', path, title, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
# @param [String] path
|
87
|
+
# @param [String] title
|
88
|
+
# @param [Hash] options
|
89
|
+
def create_icon(path, title = t(:create), options = {})
|
90
|
+
icon_with_link('biovision/icons/create.svg', path, title, options)
|
91
|
+
end
|
92
|
+
|
93
|
+
# @param [String] path
|
94
|
+
# @param [String] title
|
95
|
+
# @param [Hash] options
|
96
|
+
def back_icon(path, title = t(:back), options = {})
|
97
|
+
icon_with_link('biovision/icons/back.svg', path, title, options)
|
98
|
+
end
|
99
|
+
|
100
|
+
# @param [String] path
|
101
|
+
# @param [String] title
|
102
|
+
# @param [Hash] options
|
103
|
+
def return_icon(path, title = t(:back), options = {})
|
104
|
+
icon_with_link('biovision/icons/return.svg', path, title, options)
|
105
|
+
end
|
106
|
+
|
107
|
+
# @param [String|ApplicationRecord] path
|
108
|
+
# @param [String] title
|
109
|
+
# @param [Hash] options
|
110
|
+
def edit_icon(path, title = t(:edit), options = {})
|
111
|
+
path = "/admin/#{path.class.table_name}/#{path.id}/edit" if path.is_a? ApplicationRecord
|
112
|
+
icon_with_link('biovision/icons/edit.svg', path, title, options)
|
113
|
+
end
|
114
|
+
|
115
|
+
# @param [String|ApplicationRecord] path
|
116
|
+
# @param [String] title
|
117
|
+
# @param [Hash] options
|
118
|
+
def destroy_icon(path, title = t(:delete), options = {})
|
119
|
+
path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord
|
120
|
+
default = {
|
121
|
+
class: 'danger',
|
122
|
+
data: { confirm: t(:are_you_sure) },
|
123
|
+
method: :delete,
|
124
|
+
}
|
125
|
+
icon_with_link('biovision/icons/destroy.svg', path, title, default.merge(options))
|
126
|
+
end
|
127
|
+
|
128
|
+
# @param [String|ApplicationRecord] path
|
129
|
+
# @param [String] title
|
130
|
+
# @param [Hash] options
|
131
|
+
def icon_with_link(source, path, title, options = {})
|
132
|
+
link_to(image_tag(source, alt: title), path, options)
|
133
|
+
end
|
134
|
+
|
135
|
+
# @param [String] path
|
136
|
+
# @param [String] text
|
137
|
+
def create_button(path, text = t(:create))
|
138
|
+
link_to(text, path, class: 'button button-save')
|
139
|
+
end
|
140
|
+
|
141
|
+
# @param [String|ApplicationRecord] path
|
142
|
+
# @param [String] text
|
143
|
+
def edit_button(path, text = t(:edit))
|
144
|
+
path = "/admin/#{path.class.table_name}/#{path.id}/edit" if path.is_a? ApplicationRecord
|
145
|
+
link_to(text, path, class: 'button button-secondary')
|
146
|
+
end
|
147
|
+
|
148
|
+
# @param [String|ApplicationRecord] path
|
149
|
+
# @param [String] text
|
150
|
+
def destroy_button(path, text = t(:delete))
|
151
|
+
path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord
|
152
|
+
options = {
|
153
|
+
class: 'button button-danger',
|
154
|
+
data: { confirm: t(:are_you_sure) },
|
155
|
+
method: :delete
|
156
|
+
}
|
157
|
+
link_to(text, path, options)
|
158
|
+
end
|
159
|
+
|
160
|
+
# @param [String] phone
|
161
|
+
# @param [Hash] options
|
162
|
+
def phone_link(phone, options = {})
|
163
|
+
link_to(phone, "tel:#{phone.gsub(/[^+0-9]/, '')}", options)
|
164
|
+
end
|
165
|
+
|
166
|
+
# @param [String] email
|
167
|
+
# @param [Hash] options
|
168
|
+
def email_link(email, options = {})
|
169
|
+
link_to(email, "mailto:#{email}", options)
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Helper methods for displaying versions for SimpleImageUploader
|
4
|
+
module SimpleImageHelper
|
5
|
+
# Tiny (48x48) version of simple image
|
6
|
+
#
|
7
|
+
# @param [ApplicationRecord|SimpleImageUploader] entity
|
8
|
+
# @param [Hash] options
|
9
|
+
def simple_image_tiny(entity, options = {})
|
10
|
+
return '' if entity.nil?
|
11
|
+
|
12
|
+
image = entity.is_a?(SimpleImageUploader) ? entity : entity.image
|
13
|
+
default_image = options.delete(:default_image).to_s
|
14
|
+
|
15
|
+
return default_image if image.blank?
|
16
|
+
|
17
|
+
default = {
|
18
|
+
alt: image.alt_text,
|
19
|
+
load: 'lazy'
|
20
|
+
}
|
21
|
+
image_tag(image.tiny_url, default.merge(options))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Preview (160x160) version of simple image
|
25
|
+
#
|
26
|
+
# @param [ApplicationRecord|SimpleImageUploader] entity
|
27
|
+
# @param [Hash] options
|
28
|
+
def simple_image_preview(entity, options = {})
|
29
|
+
return '' if entity.nil?
|
30
|
+
|
31
|
+
image = entity.is_a?(SimpleImageUploader) ? entity : entity.image
|
32
|
+
default_image = options.delete(:default_image).to_s
|
33
|
+
|
34
|
+
return default_image if image.blank?
|
35
|
+
|
36
|
+
default = {
|
37
|
+
alt: image.alt_text,
|
38
|
+
load: 'lazy'
|
39
|
+
}
|
40
|
+
image_tag(image.preview_url, default.merge(options))
|
41
|
+
end
|
42
|
+
|
43
|
+
# Small (320x320) version of simple image
|
44
|
+
#
|
45
|
+
# @param [ApplicationRecord|SimpleImageUploader] entity
|
46
|
+
# @param [Hash] options
|
47
|
+
def simple_image_small(entity, options = {})
|
48
|
+
return '' if entity.nil?
|
49
|
+
|
50
|
+
image = entity.is_a?(SimpleImageUploader) ? entity : entity.image
|
51
|
+
default_image = options.delete(:default_image).to_s
|
52
|
+
|
53
|
+
return default_image if image.blank?
|
54
|
+
|
55
|
+
default = {
|
56
|
+
alt: image.alt_text,
|
57
|
+
load: 'lazy'
|
58
|
+
}
|
59
|
+
default[:srcset] = "#{image.medium.url} 2x" if image.raster?
|
60
|
+
|
61
|
+
image_tag(image.small_url, default.merge(options))
|
62
|
+
end
|
63
|
+
|
64
|
+
# Medium (640x640) version of simple image
|
65
|
+
#
|
66
|
+
# @param [ApplicationRecord|SimpleImageUploader] entity
|
67
|
+
# @param [Hash] options
|
68
|
+
def simple_image_medium(entity, options = {})
|
69
|
+
return '' if entity.nil?
|
70
|
+
|
71
|
+
image = entity.is_a?(SimpleImageUploader) ? entity : entity.image
|
72
|
+
default_image = options.delete(:default_image).to_s
|
73
|
+
|
74
|
+
return default_image if image.blank?
|
75
|
+
|
76
|
+
default = {
|
77
|
+
alt: image.alt_text,
|
78
|
+
load: 'lazy'
|
79
|
+
}
|
80
|
+
default[:srcset] = "#{image.large.url} 2x" if image.raster?
|
81
|
+
|
82
|
+
image_tag(image.medium_url, default.merge(options))
|
83
|
+
end
|
84
|
+
|
85
|
+
# Large (1280x1280) version of simple image
|
86
|
+
#
|
87
|
+
# @param [ApplicationRecord|SimpleImageUploader] entity
|
88
|
+
# @param [Hash] options
|
89
|
+
def simple_image_large(entity, options = {})
|
90
|
+
return '' if entity.nil?
|
91
|
+
|
92
|
+
image = entity.is_a?(SimpleImageUploader) ? entity : entity.image
|
93
|
+
default_image = options.delete(:default_image).to_s
|
94
|
+
|
95
|
+
return default_image if image.blank?
|
96
|
+
|
97
|
+
default = {
|
98
|
+
alt: image.alt_text,
|
99
|
+
load: 'lazy'
|
100
|
+
}
|
101
|
+
default[:srcset] = "#{image.hd.url} 2x" if image.raster?
|
102
|
+
|
103
|
+
image_tag(image.large_url, default.merge(options))
|
104
|
+
end
|
105
|
+
|
106
|
+
# HD (1920x1920) version of simple image
|
107
|
+
#
|
108
|
+
# @param [ApplicationRecord|SimpleImageUploader] entity
|
109
|
+
# @param [Hash] options
|
110
|
+
def simple_image_hd(entity, options = {})
|
111
|
+
return '' if entity.nil?
|
112
|
+
|
113
|
+
image = entity.is_a?(SimpleImageUploader) ? entity : entity.image
|
114
|
+
default_image = options.delete(:default_image).to_s
|
115
|
+
|
116
|
+
return default_image if image.blank?
|
117
|
+
|
118
|
+
default = {
|
119
|
+
alt: image.alt_text,
|
120
|
+
load: 'lazy'
|
121
|
+
}
|
122
|
+
|
123
|
+
image_tag(image.hd_url, default.merge(options))
|
124
|
+
end
|
125
|
+
end
|