Class: Workarea::Admin::ContentViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Admin::ContentViewModel
- Includes:
- CommentableViewModel
- Defined in:
- app/view_models/workarea/admin/content_view_model.rb
Instance Method Summary collapse
-
#area_options ⇒ Array<Array<String, String>>
Options for use in the area select tag.
-
#areas ⇒ Array<String>
The list of available areas blocks can be added to.
- #contentable ⇒ Object
- #contentable_template ⇒ Object
-
#current_area ⇒ String
The area currently editing blocks for.
-
#current_blocks ⇒ Array<Workarea::Content::Block>
The current set of blocks to display for editing.
-
#new_block ⇒ Workarea::Content::Block
An instance of the new block being created.
-
#new_block? ⇒ Boolean
Whether there is a new block being created.
- #new_block_defaults ⇒ Object
-
#new_block_draft ⇒ Workarea::Content::BlockDraft
A block draft instance that represents the supplied state of the new block.
- #open_graph_asset ⇒ Object
-
#presets ⇒ Array<Content::Preset>
List of customized content blocks available for reuse in a content area.
-
#show_advanced? ⇒ Boolean
Whether to show fields that are used in the <head> of the page on which the content is rendered, like title and meta tags.
-
#show_areas? ⇒ Boolean
Whether to show area selection for this content, not necessary if there is only one area.
- #timeline ⇒ Object
Methods included from CommentableViewModel
#comment_count, #comments, #has_comments?, #new_comments_for?
Instance Method Details
#area_options ⇒ Array<Array<String, String>>
Options for use in the area select tag.
58 59 60 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 58 def areas.map { |area| [area.titleize, area] } end |
#areas ⇒ Array<String>
The list of available areas blocks can be added to. Specific to this type of content. Intended to be configured as part of customizing the system.
30 31 32 33 34 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 30 def areas Workarea.config.content_areas[model.slug] || Workarea.config.content_areas[contentable_template] || Workarea.config.content_areas['generic'] end |
#contentable ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 6 def contentable return if system? @contentable ||= ApplicationController.wrap_in_view_model( model.contentable, ) end |
#contentable_template ⇒ Object
126 127 128 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 126 def contentable_template contentable.try(:template) end |
#current_area ⇒ String
The area currently editing blocks for.
66 67 68 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 66 def current_area [:area_id].presence || areas.first end |
#current_blocks ⇒ Array<Workarea::Content::Block>
The current set of blocks to display for editing. Matching the #current_area and active.
75 76 77 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 75 def current_blocks model.blocks_for(current_area).select(&:active?).select(&:persisted?) end |
#new_block ⇒ Workarea::Content::Block
An instance of the new block being created.
91 92 93 94 95 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 91 def new_block @new_block ||= model.blocks.build( .fetch(:new_block, {}).merge(data: new_block_defaults) ) end |
#new_block? ⇒ Boolean
Whether there is a new block being created.
83 84 85 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 83 def new_block? [:new_block].present? end |
#new_block_defaults ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 112 def new_block_defaults if [:preset_id].present? Content::Preset.find([:preset_id]).data else Content::BlockType.find( .dig(:new_block, :type_id).to_sym ).defaults end end |
#new_block_draft ⇒ Workarea::Content::BlockDraft
A block draft instance that represents the supplied state of the new block. Used for rendering the initial preview.
102 103 104 105 106 107 108 109 110 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 102 def new_block_draft @new_block_draft ||= Content::BlockDraft.create!( content_id: model.id, type_id: new_block.type_id, data: new_block.data, area: current_area ) end |
#open_graph_asset ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 130 def open_graph_asset @open_graph_asset ||= if model.open_graph_asset_id.present? Content::Asset.find(model.open_graph_asset_id) else Content::Asset.open_graph_placeholder end rescue Mongoid::Errors::DocumentNotFound @open_graph_asset = Content::Asset.open_graph_placeholder end |
#presets ⇒ Array<Content::Preset>
List of customized content blocks available for reuse in a content area.
41 42 43 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 41 def presets @presets ||= Content::Preset.all.to_a end |
#show_advanced? ⇒ Boolean
Whether to show fields that are used in the <head> of the page on which the content is rendered, like title and meta tags.
20 21 22 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 20 def show_advanced? (!system? && !contentable.is_a?(Navigation::Menu)) || home_page? end |
#show_areas? ⇒ Boolean
Whether to show area selection for this content, not necessary if there is only one area.
50 51 52 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 50 def show_areas? areas.many? end |
#timeline ⇒ Object
122 123 124 |
# File 'app/view_models/workarea/admin/content_view_model.rb', line 122 def timeline @timeline ||= TimelineViewModel.wrap(model) end |