Class: Katello::Api::V2::ContentViewComponentsController
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#check_katello_agent_not_disabled, #deprecate_katello_agent, #empty_search_query?, #full_result_response, #katello_agent_removal_release, #resource_class, #scoped_search, #skip_session
Methods included from Rendering
#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template
#api_version
Instance Method Details
#add_components ⇒ Object
76
77
78
79
80
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 76
def add_components
@view.add_components(authorized_components)
@view.save!
respond_for_index(:collection => index_response, :template => "index")
end
|
#index ⇒ Object
14
15
16
17
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 14
def index
sort_by, sort_order, options = sort_options
respond(:collection => scoped_search(index_relation, sort_by, sort_order, options))
end
|
#index_relation ⇒ Object
19
20
21
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 19
def index_relation
@view.content_view_components.readable
end
|
#index_response ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 23
def index_response
results = @view.content_view_components.readable
{
:results => results.uniq,
:subtotal => results.count,
:total => results.count
}
end
|
#remove_components ⇒ Object
103
104
105
106
107
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 103
def remove_components
@view.remove_components(params.require(:component_ids))
@view.save!
respond_for_index(:collection => index_response, :template => "index")
end
|
#show ⇒ Object
112
113
114
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 112
def show
respond :resource => @content_view_component
end
|
#show_all ⇒ Object
content_views/:id/components/show_all Shows all content views, added and available to add, for a content view Undocumented endpoint since the functionality exists in separate calls already. This was created for ease of pagination and search for the UI param :id, :number, desc: N_(“Content View id”), required: true param :status, [“Added”, “Not added”, “All”], :desc => N_(“Filter to show added, not added or all components”)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 38
def show_all
kc = Katello::ContentView.table_name
kcc = Katello::ContentViewComponent.table_name
join_query = " LEFT OUTER JOIN \#{kcc}\n ON \#{kc}.id = \#{kcc}.content_view_id\n AND \#{kcc}.composite_content_view_id = \#{@view.id}\n SQL\n order_query = <<-SQL\n CAST (\#{kcc}.composite_content_view_id as BOOLEAN) ASC, \#{kc}.name\n SQL\n query = Katello::ContentView.readable.in_organization(@organization)\n query = query&.non_composite&.non_default&.generated_for_none\n component_cv_ids = Katello::ContentViewComponent.where(composite_content_view_id: @view.id).select(:content_view_id)\n query = case params[:status]\n when \"Not added\"\n query.where.not(id: component_cv_ids)\n when \"Added\"\n query.where(id: component_cv_ids)\n else\n query\n end\n custom_sort = ->(sort_query) { sort_query.joins(join_query).order(Arel.sql(order_query)) }\n options = { resource_class: Katello::ContentView, custom_sort: custom_sort }\n collection = scoped_search(query, nil, nil, options)\n collection[:results] = ComponentViewPresenter.component_presenter(@view, params[:status], views: collection[:results])\n respond_for_index(:collection => collection, :template => \"index\")\nend\n"
|
#update ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/katello/api/v2/content_view_components_controller.rb', line 122
def update
cvv_id = component_params[:content_view_version_id]
if cvv_id && Katello::ContentViewVersion.readable.find_by(id: cvv_id).nil?
throw_resource_not_found(name: 'content view version', id: cvv_id)
end
if component_params.key?(:latest) && component_params.key?(:content_view_version_id)
latest = ::Foreman::Cast.to_bool(component_params[:latest])
if latest && cvv_id.present?
fail HttpErrors::UnprocessableEntity,
_(" Either select the latest content view or the content view version. Cannot set both.")
end
end
if cvv_id.present?
@content_view_component.update!(:content_view_version_id => cvv_id, :latest => false)
elsif component_params.key?(:latest)
latest = ::Foreman::Cast.to_bool(component_params[:latest])
@content_view_component.update!(:content_view_version_id => nil, :latest => latest)
end
respond :resource => @content_view_component
end
|