2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
module KnowledgeBaseHelper
|
2019-09-18 17:25:04 +00:00
|
|
|
def effective_layout_name(knowledge_base, object)
|
|
|
|
layout_prefix = object.present? ? :category : :homepage
|
2019-06-04 03:40:48 +00:00
|
|
|
|
2019-09-18 17:25:04 +00:00
|
|
|
knowledge_base.send("#{layout_prefix}_layout")
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
|
2020-02-18 14:36:47 +00:00
|
|
|
def custom_path_if_needed(path, knowledge_base, full: false)
|
2020-08-18 13:01:18 +00:00
|
|
|
return path if !knowledge_base.custom_address_matches?(request)
|
2019-06-04 03:40:48 +00:00
|
|
|
|
2020-02-18 14:36:47 +00:00
|
|
|
custom_address = knowledge_base.custom_address_uri
|
2020-08-18 13:01:18 +00:00
|
|
|
return path if !custom_address
|
2019-06-04 03:40:48 +00:00
|
|
|
|
2021-03-30 15:56:26 +00:00
|
|
|
custom_path = knowledge_base.custom_address_path(path)
|
2020-10-06 18:05:07 +00:00
|
|
|
prefix = full ? knowledge_base.custom_address_prefix(request) : ''
|
2020-02-18 14:36:47 +00:00
|
|
|
|
2020-08-18 13:01:18 +00:00
|
|
|
"#{prefix}#{custom_path}"
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def translation_locale_code(translation)
|
|
|
|
translation.kb_locale.system_locale.locale
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_kb_link_label(object)
|
|
|
|
suffix = case object
|
|
|
|
when KnowledgeBase::Answer
|
|
|
|
'answer'
|
|
|
|
when KnowledgeBase::Category
|
|
|
|
'category'
|
|
|
|
when KnowledgeBase
|
|
|
|
'knowledge base'
|
|
|
|
end
|
|
|
|
|
|
|
|
"edit #{suffix}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_kb_link(object)
|
2019-06-13 09:20:29 +00:00
|
|
|
locale = params.fetch(:locale, object.translation.kb_locale)
|
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
path = case object
|
|
|
|
when KnowledgeBase::Answer
|
2019-06-13 09:20:29 +00:00
|
|
|
"knowledge_base/#{object.category.knowledge_base.id}/locale/#{locale}/answer/#{object.id}/edit"
|
2019-06-04 03:40:48 +00:00
|
|
|
when KnowledgeBase::Category
|
2019-06-13 09:20:29 +00:00
|
|
|
"knowledge_base/#{object.knowledge_base.id}/locale/#{locale}/category/#{object.id}/edit"
|
2019-06-04 03:40:48 +00:00
|
|
|
when KnowledgeBase
|
2019-06-13 09:20:29 +00:00
|
|
|
"knowledge_base/#{object.id}/locale/#{locale}/edit"
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
build_zammad_link path
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_zammad_link(path)
|
|
|
|
host, port = Setting.get('fqdn').split ':'
|
|
|
|
scheme = Setting.get('http_type')
|
|
|
|
|
|
|
|
URI::Generic
|
|
|
|
.build(host: host, scheme: scheme, port: port, fragment: path)
|
|
|
|
.to_s
|
|
|
|
end
|
2020-04-20 11:28:53 +00:00
|
|
|
|
|
|
|
def dropdown_menu_direction
|
|
|
|
system_locale_via_uri.dir == 'ltr' ? 'right' : 'left'
|
|
|
|
end
|
2021-03-30 15:56:26 +00:00
|
|
|
|
|
|
|
def canonical_link_tag(knowledge_base, *objects)
|
|
|
|
path = kb_public_system_path(*objects)
|
|
|
|
|
2021-09-10 08:03:59 +00:00
|
|
|
tag.link(rel: 'canonical', href: knowledge_base.canonical_url(path))
|
2021-03-30 15:56:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def kb_public_system_path(*objects)
|
|
|
|
objects
|
|
|
|
.compact
|
2021-08-16 08:20:07 +00:00
|
|
|
.map { |elem| elem.is_a?(HasTranslations) ? elem.translation.to_param : elem }
|
2021-03-30 15:56:26 +00:00
|
|
|
.unshift(help_root_path)
|
|
|
|
.join('/')
|
|
|
|
end
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|