Class: Katello::ComponentViewPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/services/katello/component_view_presenter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(composite_cv, component_content_view = nil, content_view_component = nil) ⇒ ComponentViewPresenter

Returns a new instance of ComponentViewPresenter.



5
6
7
8
9
10
# File 'app/services/katello/component_view_presenter.rb', line 5

def initialize(composite_cv, component_content_view = nil, content_view_component = nil)
  @view = component_content_view
  cv_component_record = content_view_component || Katello::ContentViewComponent.where(composite_content_view_id: composite_cv.id, content_view_id: @view.id).first
  @component_view = cv_component_record || Katello::ContentViewComponent.new(composite_content_view_id: composite_cv.id, content_view_id: @view.id, latest: true)
  super(@component_view)
end

Instance Attribute Details

#component_viewObject

Returns the value of attribute component_view.



3
4
5
# File 'app/services/katello/component_view_presenter.rb', line 3

def component_view
  @component_view
end

#viewObject

Returns the value of attribute view.



3
4
5
# File 'app/services/katello/component_view_presenter.rb', line 3

def view
  @view
end

Class Method Details

.component_presenter(composite_cv, status, views:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/katello/component_view_presenter.rb', line 12

def self.component_presenter(composite_cv, status, views:)
  case status
  when 'All'
    views.map { |component_content_view| ComponentViewPresenter.new(composite_cv, component_content_view) }
  when 'Added'
    added_cvs = views.map { |component_content_view| Katello::ContentViewComponent.where(composite_content_view_id: composite_cv.id, content_view_id: component_content_view.id).first }
    added_cvs.compact.map { |content_view| ComponentViewPresenter.new(composite_cv, nil, content_view) }
  when 'Not added'
    not_added_cvs = views.reject { |component_content_view| Katello::ContentViewComponent.where(composite_content_view_id: composite_cv.id, content_view_id: component_content_view.id).first }
    not_added_cvs.map { |component_content_view| ComponentViewPresenter.new(composite_cv, nil, Katello::ContentViewComponent.where(composite_content_view_id: composite_cv.id, content_view_id: component_content_view.id, latest: true).new) }
  else
    views.map { |component_content_view| ComponentViewPresenter.new(composite_cv, component_content_view) }
  end
end