biovision 0.1.210414.0 → 0.12.211128.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 +50 -40
- data/app/assets/stylesheets/biovision/admin/components/users.scss +4 -0
- data/app/assets/stylesheets/biovision/admin/components.scss +10 -0
- data/app/assets/stylesheets/biovision/admin/layout.scss +34 -8
- data/app/assets/stylesheets/biovision/biovision.scss +64 -26
- data/app/assets/stylesheets/biovision/components/carousel.scss +24 -24
- data/app/assets/stylesheets/biovision/components/filters.scss +39 -0
- data/app/assets/stylesheets/biovision/components/forms.scss +56 -10
- data/app/assets/stylesheets/biovision/components/quick_search.scss +24 -0
- data/app/assets/stylesheets/biovision/components.scss +1 -0
- data/app/assets/stylesheets/biovision/default.scss +4 -4
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/dashboard.scss +4 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +1 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +3 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +12 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +6 -3
- data/app/assets/stylesheets/biovision/themes/default_theme.scss +0 -1
- data/app/assets/stylesheets/biovision/vars.scss +5 -0
- data/app/controllers/admin/biovision_components_controller.rb +10 -0
- data/app/controllers/admin/components_controller.rb +33 -83
- data/app/controllers/admin/dynamic_pages_controller.rb +1 -1
- data/app/controllers/admin/index_controller.rb +8 -2
- data/app/controllers/admin/navigation_groups_controller.rb +31 -0
- data/app/controllers/admin/tokens_controller.rb +15 -0
- data/app/controllers/admin/users_controller.rb +35 -4
- data/app/controllers/admin_controller.rb +2 -9
- data/app/controllers/concerns/component_stories.rb +22 -0
- data/app/controllers/concerns/crud_entities.rb +23 -15
- data/app/controllers/concerns/my_crud_entities.rb +146 -0
- data/app/controllers/concerns/processed_forms.rb +28 -0
- data/app/controllers/concerns/restricted_access.rb +37 -0
- data/app/controllers/contact_controller.rb +1 -1
- data/app/controllers/errors_controller.rb +37 -0
- data/app/controllers/my/components_controller.rb +21 -0
- data/app/controllers/my/index_controller.rb +1 -3
- data/app/controllers/my/profiles_controller.rb +2 -0
- data/app/controllers/oembed_controller.rb +12 -0
- data/app/controllers/profile_controller.rb +2 -0
- data/app/controllers/users_controller.rb +2 -0
- data/app/helpers/biovision_components_helper.rb +7 -3
- data/app/helpers/biovision_helper.rb +33 -34
- data/app/helpers/entity_helper.rb +77 -0
- data/app/helpers/my_helper.rb +34 -0
- data/app/lib/biovision/components/base/component_parameters.rb +13 -2
- data/app/lib/biovision/components/base/component_privileges.rb +28 -18
- data/app/lib/biovision/components/base/component_settings.rb +8 -0
- data/app/lib/biovision/components/base/component_stories.rb +30 -0
- data/app/lib/biovision/components/base/entity_links.rb +38 -0
- data/app/lib/biovision/components/base/image_handling.rb +33 -0
- data/app/lib/biovision/components/base_component.rb +20 -49
- data/app/lib/biovision/components/contact_component.rb +5 -1
- data/app/lib/biovision/components/content/oembed/receiver.rb +98 -0
- data/app/lib/biovision/components/content/oembed/twitter_receiver.rb +20 -0
- data/app/lib/biovision/components/content/oembed/vimeo_receiver.rb +20 -0
- data/app/lib/biovision/components/content/oembed/youtube_receiver.rb +20 -0
- data/app/lib/biovision/components/content_component.rb +46 -9
- data/app/lib/biovision/components/track_component.rb +1 -1
- data/app/lib/biovision/components/users_component.rb +34 -2
- data/app/lib/biovision/helpers/data_helper.rb +70 -0
- data/app/lib/biovision/helpers/export_helper.rb +97 -0
- data/app/lib/biovision/migrations/component_migration.rb +56 -0
- data/app/lib/biovision/stories/component_story.rb +55 -0
- data/app/mailers/feedback_mailer.rb +14 -0
- data/app/models/biovision_component.rb +17 -1
- data/app/models/browser.rb +1 -1
- data/app/models/code.rb +5 -5
- data/app/models/concerns/checkable.rb +2 -1
- data/app/models/concerns/has_uploaded_file.rb +26 -0
- data/app/models/concerns/simple_tag.rb +30 -0
- data/app/models/concerns/toggleable.rb +2 -1
- data/app/models/concerns/tree_structure.rb +4 -1
- data/app/models/contact_method.rb +1 -1
- data/app/models/contact_type.rb +1 -1
- data/app/models/dynamic_block.rb +1 -1
- data/app/models/dynamic_page.rb +3 -1
- data/app/models/feedback_message.rb +7 -1
- data/app/models/feedback_response.rb +2 -2
- data/app/models/metric.rb +4 -0
- data/app/models/navigation_group.rb +11 -1
- data/app/models/oembed_domain.rb +25 -0
- data/app/models/oembed_link.rb +19 -0
- data/app/models/oembed_receiver.rb +15 -0
- data/app/models/role.rb +42 -12
- data/app/models/simple_image.rb +30 -3
- data/app/models/simple_image_tag.rb +1 -16
- data/app/models/token.rb +6 -2
- data/app/models/uploaded_file.rb +62 -0
- data/app/models/uploaded_file_tag.rb +15 -0
- data/app/models/uploaded_file_tag_file.rb +13 -0
- data/app/models/user.rb +35 -10
- data/app/models/user_role.rb +0 -1
- data/app/uploaders/simple_file_uploader.rb +2 -6
- data/app/uploaders/simple_image_uploader.rb +10 -21
- data/app/uploaders/uploaders/path_slug.rb +22 -0
- data/app/views/admin/agents/index.html.erb +1 -1
- data/app/views/admin/biovision_components/_nav_item.html.erb +6 -0
- data/app/views/admin/biovision_components/entity/_in_list.html.erb +12 -0
- data/app/views/admin/biovision_components/index.html.erb +11 -0
- data/app/views/admin/components/_list.html.erb +1 -1
- data/app/views/admin/components/entity/_links.html.erb +31 -21
- data/app/views/admin/components/links/_base.html.erb +1 -0
- data/app/views/admin/components/settings/_settings.html.erb +3 -3
- data/app/views/admin/components/settings.html.erb +2 -1
- data/app/views/admin/dynamic_blocks/_form.html.erb +1 -1
- data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +8 -6
- data/app/views/admin/dynamic_blocks/index.html.erb +6 -4
- data/app/views/admin/dynamic_blocks/show.html.erb +9 -7
- data/app/views/admin/dynamic_pages/_dynamic_page.jbuilder +18 -0
- data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +6 -4
- data/app/views/admin/dynamic_pages/entity/_in_search.html.erb +7 -0
- data/app/views/admin/dynamic_pages/index.html.erb +6 -4
- data/app/views/admin/dynamic_pages/search.jbuilder +4 -0
- data/app/views/admin/dynamic_pages/show.html.erb +2 -2
- data/app/views/admin/index/index.html.erb +7 -5
- data/app/views/admin/ip_addresses/index.html.erb +2 -2
- data/app/views/admin/navigation_group_pages/entity/_in_list.html.erb +26 -0
- data/app/views/admin/navigation_groups/entity/_dynamic_pages.html.erb +38 -0
- data/app/views/admin/navigation_groups/entity/_in_list.html.erb +7 -5
- data/app/views/admin/navigation_groups/index.html.erb +6 -4
- data/app/views/admin/navigation_groups/show.html.erb +16 -3
- data/app/views/admin/tokens/_form.html.erb +31 -0
- data/app/views/admin/tokens/_nav_item.html.erb +6 -0
- data/app/views/admin/tokens/entity/_in_list.html.erb +27 -0
- data/app/views/admin/tokens/index.html.erb +11 -0
- data/app/views/admin/tokens/show.html.erb +26 -0
- data/app/views/admin/users/_user.jbuilder +18 -0
- data/app/views/admin/users/entity/_fields.html.erb +1 -1
- data/app/views/admin/users/entity/_in_list.html.erb +3 -3
- data/app/views/admin/users/entity/_in_search.html.erb +18 -0
- data/app/views/admin/users/index.html.erb +13 -4
- data/app/views/admin/users/roles/_component.html.erb +22 -0
- data/app/views/admin/users/roles.html.erb +23 -0
- data/app/views/admin/users/search.jbuilder +4 -0
- data/app/views/admin/users/show.html.erb +28 -10
- data/app/views/admin/widgets/_filters.html.erb +20 -0
- data/app/views/admin/widgets/_quick_search.html.erb +13 -0
- data/app/views/admin/widgets/filters/_flag.html.erb +15 -0
- data/app/views/admin/widgets/filters/_text.html.erb +7 -0
- data/app/views/application/unauthorized.html.erb +4 -1
- data/app/views/components/content/_dynamic_page.html.erb +6 -10
- data/app/views/components/content/_dynamic_page_content.html.erb +14 -0
- data/app/views/components/users/_login_form.html.erb +1 -0
- data/app/views/contact/_form.html.erb +1 -1
- data/app/views/errors/error.html.erb +1 -0
- data/app/views/feedback_mailer/new_feedback_request.html.erb +11 -0
- data/app/views/feedback_mailer/new_feedback_request.text.erb +6 -0
- data/app/views/index/index.html.erb +14 -0
- data/app/views/layouts/admin/_header.html.erb +7 -2
- data/app/views/layouts/admin.html.erb +0 -1
- data/app/views/layouts/application/_footer.html.erb +1 -1
- data/app/views/layouts/application/header/_authentication.html.erb +4 -1
- data/app/views/my/components/index.html.erb +25 -0
- data/app/views/my/components/show.html.erb +21 -0
- data/app/views/my/index/_cards.html.erb +15 -0
- data/app/views/my/index/_email.html.erb +14 -0
- data/app/views/my/index/_navigation.html.erb +33 -0
- data/app/views/my/index/index.html.erb +7 -26
- data/app/views/my/profiles/show.html.erb +13 -0
- data/app/views/{admin/components/links/extra/_content.html.erb → my/recoveries/show.html.erb} +0 -0
- data/app/views/shared/admin/_list.html.erb +10 -19
- data/app/views/shared/admin/_list_with_priority.html.erb +10 -19
- data/app/views/shared/admin/_priority.html.erb +6 -5
- data/app/views/shared/admin/_toggle.html.erb +5 -10
- data/app/views/shared/entity/_date_field.html.erb +6 -0
- data/app/views/shared/entity/_linked_entity.html.erb +2 -2
- data/app/views/shared/entity/_list.html.erb +22 -0
- data/app/views/shared/entity/_list_with_priority.html.erb +22 -0
- data/app/views/shared/entity/_parent.html.erb +1 -1
- data/app/views/shared/entity/_priority_icons.html.erb +8 -0
- data/app/views/shared/entity/_time_field.html.erb +6 -0
- data/app/views/shared/entity/_toggle.html.erb +12 -0
- data/app/views/shared/entity/_track.html.erb +12 -0
- data/app/views/shared/entity/_tree_caches.html.erb +8 -1
- data/app/views/shared/entity/edit.html.erb +10 -6
- data/app/views/shared/entity/new.html.erb +4 -2
- data/app/views/shared/forms/_field.html.erb +6 -2
- data/app/views/shared/forms/_field_with_search.html.erb +17 -0
- data/app/views/shared/forms/_meta_texts.html.erb +1 -1
- data/app/views/shared/forms/_simple_entity_link.html.erb +14 -0
- data/app/views/shared/forms/_simple_image.html.erb +12 -4
- data/app/views/shared/forms/_text_area.html.erb +1 -1
- data/app/views/shared/forms/_text_field.html.erb +1 -1
- data/app/views/shared/my/_list.html.erb +10 -19
- data/app/views/shared/my/_list_with_priority.html.erb +10 -19
- data/app/views/shared/my/entity/edit.html.erb +25 -0
- data/app/views/shared/my/entity/new.html.erb +18 -0
- data/app/views/simple_images/_simple_image.jbuilder +13 -0
- data/config/locales/biovision-ru.yml +18 -1
- data/config/locales/components-ru.yml +27 -4
- data/config/locales/contact-ru.yml +4 -0
- data/config/locales/content-ru.yml +12 -0
- data/config/locales/users-ru.yml +31 -6
- data/config/routes.rb +35 -4
- data/db/migrate/20191228000000_create_biovision_components.rb +2 -0
- data/db/migrate/20200224000000_create_track_component.rb +8 -12
- data/db/migrate/20200224000010_create_users_component.rb +8 -49
- data/db/migrate/20200404000000_create_simple_images.rb +1 -0
- data/db/migrate/20210405000000_create_acl.rb +15 -1
- data/db/migrate/{20200529000000_create_content_component.rb → 20210421000000_create_content_component.rb} +24 -18
- data/db/migrate/{20210401000000_create_contact_component.rb → 20210421000010_create_contact_component.rb} +1 -22
- data/db/migrate/20210616000000_create_uploaded_files.rb +52 -0
- data/db/migrate/amends/20210816060606_create_oembed_receivers.rb +21 -0
- data/db/migrate/amends/20210907070707_add_checksum_to_simple_images.rb +13 -0
- data/lib/biovision/base_methods.rb +8 -28
- data/lib/biovision/version.rb +1 -1
- data/lib/tasks/components.rake +51 -0
- metadata +90 -17
- data/app/lib/biovision/components/base/privilege_handler.rb +0 -79
- data/app/models/biovision_component_user.rb +0 -21
- data/app/views/admin/components/links/_content.html.erb +0 -9
- data/app/views/admin/components/links/_track.html.erb +0 -2
- data/app/views/admin/components/links/_users.html.erb +0 -4
- data/app/views/admin/components/privileges/_component_user.html.erb +0 -17
- data/app/views/admin/components/privileges/_links.html.erb +0 -17
- data/app/views/admin/components/privileges/_users.html.erb +0 -23
- data/app/views/admin/components/privileges.html.erb +0 -20
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Helpers
|
5
|
+
# Helper for receiving model data in controllers
|
6
|
+
class DataHelper
|
7
|
+
attr_reader :model_class
|
8
|
+
|
9
|
+
# @param [ApplicationRecord] model_class
|
10
|
+
# @param [Hash] filters
|
11
|
+
def initialize(model_class, filters = {})
|
12
|
+
@model_class = model_class
|
13
|
+
@filters = filters
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Integer] page
|
17
|
+
def administrative_collection(page = 1)
|
18
|
+
paginates = model_class.respond_to?(:page_for_administration)
|
19
|
+
paginates ? administrative_page(page) : administrative_list
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [User] user
|
23
|
+
# @param [Integer] page
|
24
|
+
def personal_collection(user, page = 1)
|
25
|
+
paginates = model_class.respond_to?(:page_for_owner)
|
26
|
+
paginates ? personal_page(user, page) : personal_list(user)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def administrative_list
|
32
|
+
if model_class.respond_to?(:filtered)
|
33
|
+
model_class.filtered(@filters).list_for_administration
|
34
|
+
else
|
35
|
+
model_class.list_for_administration
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [Integer] page
|
40
|
+
def administrative_page(page)
|
41
|
+
reflection = model_class.singleton_method(:page_for_administration)
|
42
|
+
if reflection.parameters.include?(%i[key filters])
|
43
|
+
model_class.page_for_administration(page, filters: @filters)
|
44
|
+
else
|
45
|
+
model_class.page_for_administration(page)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param [User] user
|
50
|
+
def personal_list(user)
|
51
|
+
if model_class.respond_to?(:filtered)
|
52
|
+
model_class.filtered(@filters).list_for_owner(user)
|
53
|
+
else
|
54
|
+
model_class.list_for_owner(user)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param [User] user
|
59
|
+
# @param [Integer] page
|
60
|
+
def personal_page(user, page)
|
61
|
+
reflection = model_class.singleton_method(:page_for_owner)
|
62
|
+
if reflection.parameters.include?(%i[key filters])
|
63
|
+
model_class.page_for_owner(user, page, filters: @filters)
|
64
|
+
else
|
65
|
+
model_class.page_for_owner(user, page)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Helpers
|
5
|
+
# Helper for exporting model data
|
6
|
+
class ExportHelper
|
7
|
+
EXPORT_DIR = "#{Rails.root}/tmp/export"
|
8
|
+
SPECIAL_FIELDS = %w[id agent_id ip_address_id image attachment].freeze
|
9
|
+
|
10
|
+
# @param [Class] model
|
11
|
+
def export_model(model)
|
12
|
+
puts "Exporting model #{model}..."
|
13
|
+
FileUtils.mkdir_p(EXPORT_DIR) unless Dir.exist?(EXPORT_DIR)
|
14
|
+
file_name = "#{EXPORT_DIR}/#{model.table_name}.yml"
|
15
|
+
File.open(file_name, 'wb') do |file|
|
16
|
+
@file = file
|
17
|
+
model.order(:id).each do |entity|
|
18
|
+
@entity = entity
|
19
|
+
export_entity
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def export_entity
|
27
|
+
print "\r#{@entity.id} "
|
28
|
+
@file.puts "#{@entity.id}:"
|
29
|
+
export_attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def export_attributes
|
33
|
+
filtered = @entity.attributes.reject { |a, v| ignored?(a) || v.nil? }
|
34
|
+
filtered.each do |attribute, value|
|
35
|
+
export_attribute(attribute, value)
|
36
|
+
end
|
37
|
+
export_track
|
38
|
+
export_media('image') if @entity.attributes.key?('image')
|
39
|
+
export_media('attachment') if @entity.attributes.key?('attachment')
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param [String] attribute
|
43
|
+
# @param value
|
44
|
+
def export_attribute(attribute, value)
|
45
|
+
@file.print " #{attribute}: "
|
46
|
+
if value.is_a?(Hash)
|
47
|
+
if value.blank?
|
48
|
+
@file.puts '{}'
|
49
|
+
else
|
50
|
+
@file.puts value.to_yaml.gsub(/\A---|\n\z/, '').gsub("\n", "\n ")
|
51
|
+
end
|
52
|
+
else
|
53
|
+
@file.puts value.inspect
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def export_track
|
58
|
+
return unless @entity.is_a?(HasTrack)
|
59
|
+
|
60
|
+
unless @entity.ip_address.nil?
|
61
|
+
@file.puts " ip_address: #{@entity.ip_address.ip.to_s.inspect}"
|
62
|
+
end
|
63
|
+
|
64
|
+
return if @entity.agent.blank?
|
65
|
+
|
66
|
+
@file.puts " agent: #{@entity.agent.name.inspect}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def media_dir
|
70
|
+
"#{EXPORT_DIR}/#{@entity.class.table_name}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def export_media(type)
|
74
|
+
media = @entity.send(type.to_sym)
|
75
|
+
|
76
|
+
return if media.blank?
|
77
|
+
|
78
|
+
media_name = File.basename(media.path)
|
79
|
+
dir_name = "#{media_dir}/#{@entity.id}"
|
80
|
+
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
81
|
+
FileUtils.copy(media.path, "#{dir_name}/#{media_name}")
|
82
|
+
@file.puts " #{type}: #{media_name.inspect}"
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param [String] attribute
|
86
|
+
def ignored?(attribute)
|
87
|
+
return true if SPECIAL_FIELDS.include?(attribute)
|
88
|
+
|
89
|
+
%w[count cache].each do |ending|
|
90
|
+
return true if attribute.end_with?("_#{ending}")
|
91
|
+
end
|
92
|
+
|
93
|
+
false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Migrations
|
5
|
+
# Mix-ins for repeated component migration parts
|
6
|
+
module ComponentMigration
|
7
|
+
# Component class
|
8
|
+
def component
|
9
|
+
@component ||= find_component
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create component tables and roles
|
13
|
+
#
|
14
|
+
# Creates new BiovisionComponent
|
15
|
+
# For each dependent model, calls "create_<table_name>" method
|
16
|
+
# Creates roles for new component
|
17
|
+
def up
|
18
|
+
component.create
|
19
|
+
component.dependent_models.each do |model|
|
20
|
+
next if model.table_exists?
|
21
|
+
|
22
|
+
message = "create_#{model.table_name}".to_sym
|
23
|
+
send(message) if respond_to?(message, true)
|
24
|
+
end
|
25
|
+
handler = component[nil]
|
26
|
+
handler.create_roles
|
27
|
+
handler.seed if handler.respond_to?(:seed)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Drops tables for each dependent model
|
31
|
+
# Removes BiovisionComponent
|
32
|
+
def down
|
33
|
+
component.dependent_models.reverse.each do |model|
|
34
|
+
drop_table model.table_name if model.table_exists?
|
35
|
+
end
|
36
|
+
BiovisionComponent[component]&.destroy
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Find component class by migration name
|
42
|
+
#
|
43
|
+
# Method relies on naming like Create<:CamelCaseSlug>Component
|
44
|
+
#
|
45
|
+
# Example:
|
46
|
+
# - Migration class is named CreateFooBarComponent
|
47
|
+
# - Component slug is "foo_bar"
|
48
|
+
# - Use base component handler to get "FooBarComponent" class
|
49
|
+
def find_component
|
50
|
+
migration = name.to_s.demodulize.to_s.underscore
|
51
|
+
slug = migration.gsub(/\Acreate_/, '').gsub(/_component\z/, '')
|
52
|
+
Biovision::Components::BaseComponent.handler_class(slug)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Stories
|
5
|
+
# Base component story
|
6
|
+
class ComponentStory
|
7
|
+
attr_accessor :component_handler, :entity
|
8
|
+
|
9
|
+
# @param [Biovision::Components::BaseComponent] handler
|
10
|
+
# @param [ApplicationRecord|String|nil] entity
|
11
|
+
def initialize(handler, entity = nil)
|
12
|
+
self.component_handler = handler
|
13
|
+
return if entity.blank?
|
14
|
+
|
15
|
+
if entity.is_a?(ApplicationRecord)
|
16
|
+
self.entity = entity
|
17
|
+
else
|
18
|
+
self.entity_id = entity.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get associated model class
|
23
|
+
#
|
24
|
+
# This method should be implemented in children if story name
|
25
|
+
# does not match model name.
|
26
|
+
# The result is used in #entity_id=
|
27
|
+
def model_class
|
28
|
+
model_name = to_s.demodulize.to_s.underscore.gsub('_story', '')
|
29
|
+
model_name.classify.safe_constantize
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param [Hash] parameters
|
33
|
+
def perform(parameters)
|
34
|
+
@parameters = parameters
|
35
|
+
# implement in children and return hash
|
36
|
+
{ result: 'Nothing was processed.' }
|
37
|
+
end
|
38
|
+
|
39
|
+
# Set entity identified by value
|
40
|
+
#
|
41
|
+
# This method can be implemented in child classes
|
42
|
+
#
|
43
|
+
# @param [String] value
|
44
|
+
def entity_id=(value)
|
45
|
+
return if model_class.nil?
|
46
|
+
|
47
|
+
if model_class.respond_to?(:[])
|
48
|
+
self.entity = model_class[value]
|
49
|
+
elsif model_class.respond_to?(:find_by)
|
50
|
+
self.entity = model_class.find_by(id: value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Mailer for sending feedback requests
|
4
|
+
class FeedbackMailer < ApplicationMailer
|
5
|
+
# @param [Integer] id
|
6
|
+
def new_feedback_request(id)
|
7
|
+
@entity = FeedbackMessage.find_by(id: id)
|
8
|
+
|
9
|
+
key = Biovision::Components::ContactComponent::SETTING_FEEDBACK_MAIL
|
10
|
+
receiver = Biovision::Components::ContactComponent[nil].settings[key]
|
11
|
+
|
12
|
+
mail to: receiver unless @entity.nil? || receiver.blank?
|
13
|
+
end
|
14
|
+
end
|
@@ -13,16 +13,22 @@
|
|
13
13
|
class BiovisionComponent < ApplicationRecord
|
14
14
|
include FlatPriority
|
15
15
|
include RequiredUniqueSlug
|
16
|
+
include Toggleable
|
16
17
|
|
17
18
|
SLUG_LIMIT = 250
|
18
19
|
SLUG_PATTERN_HTML = '^[a-zA-Z][-a-zA-Z0-9_]+[a-zA-Z0-9]$'
|
19
20
|
|
20
|
-
|
21
|
+
toggleable :active
|
22
|
+
|
21
23
|
has_many :simple_images, dependent: :destroy
|
24
|
+
has_many :uploaded_files, dependent: :destroy
|
22
25
|
has_many :codes, dependent: :delete_all
|
26
|
+
has_many :roles, dependent: :destroy
|
27
|
+
has_many :groups, dependent: :destroy
|
23
28
|
|
24
29
|
scope :active, -> { where(active: true) }
|
25
30
|
scope :list_for_administration, -> { ordered_by_priority }
|
31
|
+
scope :list_for_user, -> { active.ordered_by_priority }
|
26
32
|
|
27
33
|
# Find component by slug
|
28
34
|
#
|
@@ -39,6 +45,8 @@ class BiovisionComponent < ApplicationRecord
|
|
39
45
|
|
40
46
|
# @param [String] slug
|
41
47
|
# @param value
|
48
|
+
#
|
49
|
+
# @deprecated use parameters[slug.to_s] = value
|
42
50
|
def []=(slug, value)
|
43
51
|
parameters[slug.to_s] = value
|
44
52
|
save!
|
@@ -62,4 +70,12 @@ class BiovisionComponent < ApplicationRecord
|
|
62
70
|
|
63
71
|
code
|
64
72
|
end
|
73
|
+
|
74
|
+
def text_for_link
|
75
|
+
I18n.t("biovision.components.#{slug}.name", default: slug)
|
76
|
+
end
|
77
|
+
|
78
|
+
def admin_url
|
79
|
+
"/admin/components/#{slug}"
|
80
|
+
end
|
65
81
|
end
|
data/app/models/browser.rb
CHANGED
data/app/models/code.rb
CHANGED
@@ -17,7 +17,7 @@ class Code < ApplicationRecord
|
|
17
17
|
include HasTrack
|
18
18
|
|
19
19
|
BODY_LIMIT = 50
|
20
|
-
QUANTITY_RANGE = (0..32_767)
|
20
|
+
QUANTITY_RANGE = (0..32_767)
|
21
21
|
|
22
22
|
belongs_to :biovision_component
|
23
23
|
belongs_to :user, optional: true
|
@@ -40,11 +40,11 @@ class Code < ApplicationRecord
|
|
40
40
|
list_for_administration.page(page)
|
41
41
|
end
|
42
42
|
|
43
|
-
def self.entity_parameters
|
43
|
+
def self.entity_parameters
|
44
44
|
%i[body quantity]
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.creation_parameters
|
47
|
+
def self.creation_parameters
|
48
48
|
entity_parameters + %i[user_id biovision_component_id]
|
49
49
|
end
|
50
50
|
|
@@ -80,10 +80,10 @@ class Code < ApplicationRecord
|
|
80
80
|
return unless body.nil?
|
81
81
|
|
82
82
|
if phone?
|
83
|
+
self.body = SecureRandom.random_number(1_000_000).to_s.rjust(6, '0')
|
84
|
+
else
|
83
85
|
number = SecureRandom.random_number(0xffff_ffff_ffff_ffff)
|
84
86
|
self.body = number.to_s(36).scan(/.{4}/).join('-').upcase
|
85
|
-
else
|
86
|
-
self.body = SecureRandom.random_number(1_000_000).to_s.rjust(6, '0')
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Model references to uploaded file
|
4
|
+
module HasUploadedFile
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
belongs_to :uploaded_file, optional: true, counter_cache: :object_count
|
9
|
+
|
10
|
+
scope :included_file, -> { includes(:uploaded_file) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def attachment_name
|
14
|
+
uploaded_file&.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def attachment_size
|
18
|
+
uploaded_file&.file_size
|
19
|
+
end
|
20
|
+
|
21
|
+
def attachment_url
|
22
|
+
return if uploaded_file&.attachment.blank?
|
23
|
+
|
24
|
+
uploaded_file.attachment.url
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Adds list of toggleable attributes to model
|
4
|
+
#
|
5
|
+
# @author Maxim Khan-Magomedov <maxim.km@gmail.com>
|
6
|
+
module SimpleTag
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
|
11
|
+
before_validation :normalize_name
|
12
|
+
validates_uniqueness_of :name, case_sensitive: false
|
13
|
+
|
14
|
+
scope :list_for_administration, -> { order(:name) }
|
15
|
+
|
16
|
+
def self.entity_parameters
|
17
|
+
%i[name]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.name_limit
|
21
|
+
100
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def normalize_name
|
27
|
+
self.name = name.to_s[0..name_limit]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -14,7 +14,8 @@ module Toggleable
|
|
14
14
|
def toggle_parameter(attribute)
|
15
15
|
return unless toggleable_attributes.include? attribute.to_sym
|
16
16
|
|
17
|
-
|
17
|
+
assign_attributes(attribute => !attributes[attribute.to_s])
|
18
|
+
save!
|
18
19
|
{ attribute => self[attribute] }
|
19
20
|
end
|
20
21
|
end
|
@@ -10,7 +10,10 @@ module TreeStructure
|
|
10
10
|
|
11
11
|
before_save { children_cache.uniq! }
|
12
12
|
after_create :cache_parents!
|
13
|
-
|
13
|
+
after_destroy { parent&.cache_children! unless ENV['SKIP_CHILDREN_CACHE'] }
|
14
|
+
after_save { parent&.cache_children! unless ENV['SKIP_CHILDREN_CACHE'] }
|
15
|
+
|
16
|
+
scope :with_parent_id, ->(v) { where(parent_id: v) }
|
14
17
|
|
15
18
|
def self.tree(collection)
|
16
19
|
result = {}
|
data/app/models/contact_type.rb
CHANGED
data/app/models/dynamic_block.rb
CHANGED
data/app/models/dynamic_page.rb
CHANGED
@@ -36,14 +36,16 @@ class DynamicPage < ApplicationRecord
|
|
36
36
|
validates_length_of :slug, maximum: SLUG_LIMIT
|
37
37
|
validates_length_of :url, maximum: URL_LIMIT
|
38
38
|
|
39
|
+
scope :visible, -> { where(visible: true) }
|
39
40
|
scope :list_for_administration, -> { included_image.order('slug asc, language_id asc nulls first') }
|
41
|
+
scope :search, ->(q) { where('url ilike ? or slug ilike ?', "#{q}%", "#{q}%") unless q.blank? }
|
40
42
|
|
41
43
|
# @param [String] slug
|
42
44
|
def self.[](slug)
|
43
45
|
find_by(slug: slug)
|
44
46
|
end
|
45
47
|
|
46
|
-
def self.entity_parameters
|
48
|
+
def self.entity_parameters
|
47
49
|
%i[body language_id name simple_image_id slug url visible]
|
48
50
|
end
|
49
51
|
|
@@ -53,7 +53,13 @@ class FeedbackMessage < ApplicationRecord
|
|
53
53
|
list_for_administration.page(page)
|
54
54
|
end
|
55
55
|
|
56
|
-
def self.entity_parameters
|
56
|
+
def self.entity_parameters
|
57
57
|
%i[attachment comment email language_id name phone]
|
58
58
|
end
|
59
|
+
|
60
|
+
def attachment_name
|
61
|
+
return if attachment.blank?
|
62
|
+
|
63
|
+
File.basename(attachment.path)
|
64
|
+
end
|
59
65
|
end
|
@@ -40,11 +40,11 @@ class FeedbackResponse < ApplicationRecord
|
|
40
40
|
list_for_administration.page(page)
|
41
41
|
end
|
42
42
|
|
43
|
-
def self.entity_parameters
|
43
|
+
def self.entity_parameters
|
44
44
|
%i[body]
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.creation_parameters
|
47
|
+
def self.creation_parameters
|
48
48
|
entity_parameters + %i[feedback_message_id]
|
49
49
|
end
|
50
50
|
end
|
data/app/models/metric.rb
CHANGED
@@ -23,11 +23,21 @@ class NavigationGroup < ApplicationRecord
|
|
23
23
|
|
24
24
|
scope :list_for_administration, -> { ordered_by_name }
|
25
25
|
|
26
|
-
def self.entity_parameters
|
26
|
+
def self.entity_parameters
|
27
27
|
%i[name slug]
|
28
28
|
end
|
29
29
|
|
30
30
|
def text_for_link
|
31
31
|
name
|
32
32
|
end
|
33
|
+
|
34
|
+
# @param [DynamicPage] entity
|
35
|
+
def add_dynamic_page(entity)
|
36
|
+
navigation_group_pages.create(dynamic_page: entity)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [DynamicPage] entity
|
40
|
+
def remove_dynamic_page(entity)
|
41
|
+
navigation_group_pages.where(dynamic_page: entity).destroy_all
|
42
|
+
end
|
33
43
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain for OEmbed receiver
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# name [String]
|
7
|
+
# oembed_receiver_id [OembedReceiver]
|
8
|
+
class OembedDomain < ApplicationRecord
|
9
|
+
include RequiredUniqueName
|
10
|
+
|
11
|
+
NAME_LIMIT = 255
|
12
|
+
|
13
|
+
belongs_to :oembed_receiver
|
14
|
+
|
15
|
+
validates_length_of :name, maximum: NAME_LIMIT
|
16
|
+
|
17
|
+
# @param [String] name
|
18
|
+
def self.[](name)
|
19
|
+
find_by(name: name.to_s.downcase)
|
20
|
+
end
|
21
|
+
|
22
|
+
def receiver_slug
|
23
|
+
oembed_receiver&.slug
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Link from oembed tag
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# code [Text], optional
|
7
|
+
# created_at [DateTime]
|
8
|
+
# updated_at [DateTime]
|
9
|
+
# url [String]
|
10
|
+
class OembedLink < ApplicationRecord
|
11
|
+
URL_LIMIT = 255
|
12
|
+
|
13
|
+
validates_presence_of :url
|
14
|
+
before_save { self.url = url.to_s[0..(URL_LIMIT - 1)] }
|
15
|
+
|
16
|
+
def self.[](url)
|
17
|
+
find_or_initialize_by(url: url)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Receiver for OEmbed links
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# slug [String]
|
7
|
+
class OembedReceiver < ApplicationRecord
|
8
|
+
include RequiredUniqueSlug
|
9
|
+
|
10
|
+
SLUG_PATTERN = /\A[a-z]+(_?[a-z]+){2,49}\z/
|
11
|
+
|
12
|
+
has_many :oembed_domains, dependent: :delete_all
|
13
|
+
|
14
|
+
validates_format_of :slug, with: SLUG_PATTERN
|
15
|
+
end
|