Class: Katalyst::Content::Editor::StatusBarComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/katalyst/content/editor/status_bar_component.rb

Constant Summary collapse

ACTIONS =
<<~ACTIONS.gsub(/\s+/, " ").freeze
  content:change@document->#{STATUS_BAR_CONTROLLER}#change
  turbo:morph-element->#{STATUS_BAR_CONTROLLER}#morph
ACTIONS

Constants inherited from BaseComponent

BaseComponent::CONTAINER_CONTROLLER, BaseComponent::ITEM_CONTROLLER, BaseComponent::LIST_CONTROLLER, BaseComponent::NEW_ITEM_CONTROLLER, BaseComponent::STATUS_BAR_CONTROLLER

Instance Attribute Summary collapse

Attributes inherited from BaseComponent

#item

Instance Method Summary collapse

Methods inherited from BaseComponent

#attributes_scope, #container_form_id, #initialize, #inspect

Constructor Details

This class inherits a constructor from Katalyst::Content::Editor::BaseComponent

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



12
13
14
# File 'app/components/katalyst/content/editor/status_bar_component.rb', line 12

def container
  @container
end

Instance Method Details

#action(action) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'app/components/katalyst/content/editor/status_bar_component.rb', line 47

def action(action, **)
  tag.li do
    button_tag(t("views.katalyst.content.editor.#{action}"),
               name:  "commit",
               value: action,
               form:  container_form_id,
               **)
  end
end

#actionsObject



38
39
40
41
42
43
44
45
# File 'app/components/katalyst/content/editor/status_bar_component.rb', line 38

def actions
  tag.menu do
    concat action(:discard, class: "button button--text")
    concat action(:revert, class: "button button--text") if container.draft?
    concat action(:save, class: "button button--secondary")
    concat action(:publish, class: "button button--primary")
  end
end

#callObject



14
15
16
17
18
19
20
21
22
# File 'app/components/katalyst/content/editor/status_bar_component.rb', line 14

def call
  tag.div(**html_attributes) do
    concat status(:published, last_update: l(container.updated_at, format: :short))
    concat status(:unpublished)
    concat status(:draft)
    concat status(:dirty)
    concat actions
  end
end

#status(state) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/katalyst/content/editor/status_bar_component.rb', line 24

def status(state, **)
  status_text  = t("views.katalyst.content.editor.#{state}_html", **)
  html_options = { class: "status-text", data: { state => "", turbo: false } }

  case state.to_sym
  when :published
    link_to status_text, url_for(container), **html_options
  when :unpublished, :draft
    link_to status_text, "#{url_for(container)}/preview", **html_options
  else
    tag.span status_text, **html_options
  end
end