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-09-18 17:25:04 +00:00
|
|
|
module KnowledgeBaseTopBarHelper
|
|
|
|
def kb_top_bar_color(object)
|
|
|
|
case object
|
|
|
|
when KnowledgeBase::Answer
|
|
|
|
kb_answer_top_bar_color(object)
|
|
|
|
when KnowledgeBase::Category
|
|
|
|
kb_locale = object&.translation&.kb_locale
|
|
|
|
object.public_content?(kb_locale) ? 'green' : 'yellow'
|
|
|
|
when KnowledgeBase
|
|
|
|
'green'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def kb_answer_top_bar_color(answer)
|
2020-07-13 12:46:08 +00:00
|
|
|
state_color_map = {
|
|
|
|
draft: 'yellow',
|
|
|
|
internal: 'blue',
|
|
|
|
published: 'green',
|
|
|
|
archived: 'grey',
|
|
|
|
}
|
|
|
|
state_color_map[answer.can_be_published_aasm.current_state]
|
2019-09-18 17:25:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def kb_top_bar_tag(object)
|
|
|
|
case object
|
|
|
|
when KnowledgeBase::Answer
|
|
|
|
object.can_be_published_aasm.current_state
|
|
|
|
when KnowledgeBase::Category
|
|
|
|
kb_locale = object&.translation&.kb_locale
|
|
|
|
object.public_content?(kb_locale) ? 'Visible' : 'Invisible'
|
|
|
|
when KnowledgeBase
|
|
|
|
'Published'
|
|
|
|
end
|
|
|
|
end
|
2021-08-16 08:20:07 +00:00
|
|
|
|
|
|
|
def render_top_bar_if_needed(object, knowledge_base)
|
2022-02-24 11:15:19 +00:00
|
|
|
return if !can_preview?
|
2021-08-16 08:20:07 +00:00
|
|
|
|
|
|
|
editable = object || knowledge_base
|
|
|
|
|
|
|
|
return if !editable.is_a? HasTranslations
|
|
|
|
|
|
|
|
render 'knowledge_base/public/top_banner', object: editable
|
|
|
|
end
|
2019-09-18 17:25:04 +00:00
|
|
|
end
|