knowledge_base_top_bar_helper.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module KnowledgeBaseTopBarHelper
  3. def kb_top_bar_color(object)
  4. case object
  5. when KnowledgeBase::Answer
  6. kb_answer_top_bar_color(object)
  7. when KnowledgeBase::Category
  8. kb_locale = object&.translation&.kb_locale
  9. object.public_content?(kb_locale) ? 'green' : 'yellow'
  10. when KnowledgeBase
  11. 'green'
  12. end
  13. end
  14. def kb_answer_top_bar_color(answer)
  15. state_color_map = {
  16. draft: 'yellow',
  17. internal: 'blue',
  18. published: 'green',
  19. archived: 'grey',
  20. }
  21. state_color_map[answer.can_be_published_aasm.current_state]
  22. end
  23. def kb_top_bar_tag(object)
  24. case object
  25. when KnowledgeBase::Answer
  26. object.can_be_published_aasm.current_state
  27. when KnowledgeBase::Category
  28. kb_locale = object&.translation&.kb_locale
  29. object.public_content?(kb_locale) ? 'Visible' : 'Invisible'
  30. when KnowledgeBase
  31. 'Published'
  32. end
  33. end
  34. def render_top_bar_if_needed(object, knowledge_base)
  35. return if !can_preview?
  36. editable = object || knowledge_base
  37. return if !editable.is_a? HasTranslations
  38. render 'knowledge_base/public/top_banner', object: editable
  39. end
  40. end