Skip to content

Commit

Permalink
Refactor hostgroup / app definition selection
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard committed Nov 21, 2019
1 parent 5cec89b commit 76c5a5b
Show file tree
Hide file tree
Showing 25 changed files with 278 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def index
@app_definitions = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
end

def read_hostgroups
@hostgroups = Hostgroup.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
end

def new
read_hostgroups
@app_definition = AppDefinition.new
end

Expand All @@ -25,7 +30,9 @@ def create
end
end

def edit; end
def edit
read_hostgroups
end

def update
if @app_definition.update(app_definition_params)
Expand Down
10 changes: 0 additions & 10 deletions app/controllers/ui_app_definitions_controller.rb

This file was deleted.

29 changes: 29 additions & 0 deletions app/controllers/ui_appcendep_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class UiAppcendepController < ::Api::V2::BaseController

def app
@app_data = {}
app_definition = ForemanAppcendep::AppDefinition.find(params[:id])
@app_data['app_definition'] = app_definition
@app_data['fdata'] = collect_fdata(app_definition.hostgroup_id)
end

def fdata
@fdata = collect_fdata(params['id'])
end

private
def collect_fdata(hostgroup_id)
hg = Hostgroup.find(hostgroup_id)
fdata = OpenStruct.new({
:environments => Environment.all,
:domains => Domain.all,
:computeprofiles => ComputeProfile.all,
:hostgroup_id => hg.id,
:ptables => hg.operatingsystem.ptables,
})

#:lifecycle_environments => Katello::KTEnvironment.all

fdata
end
end

This file was deleted.

17 changes: 10 additions & 7 deletions app/views/foreman_appcendep/app_definitions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

<%
json = {
"puppetEnvUrl": api_environments_path,
"lifecycleEnvUrl": api_environments_path,
"lifecycleEnvOrganization": 'ATIX',
"organization": current_organization,
"location": current_location,
"hostgroups": @hostgroups,
"loadForemanDataUrl": ui_appcendep_fdata_path("__id__")
}

if @app_definition.name.empty?
json["mode"] = "newDefinition"
else
json["mode"] = "editDefinition"
json["appDefinition"] = {
"id": @app_definition.id,
"name": @app_definition.name,
"hostgroup_id": @app_definition.hostgroup_id,
}
json["parameters"] = JSON.parse(@app_definition.parameters)
end

Expand All @@ -26,9 +32,6 @@
<div class="tab-pane active" id="primary">
<%= text_f f, :name %>
<%= text_f f, :description %>
<%= select_f f, :hostgroup_id, accessible_resource(@app_definition, :hostgroup, :title), :id, :to_label,
{ :include_blank => false},
{:label => _("Host Group"), :help_inline => :indicator } %>

<div id='param-selection'></div>
<%= mount_react_component('ParameterSelection', "#param-selection", json.to_json) %>
Expand Down
18 changes: 9 additions & 9 deletions app/views/foreman_appcendep/app_instances/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
if @app_instance.app_definition_id.blank?
json = {
"mode": "newInstance",
"organization": current_organization,
"location": current_location,
"applications": @applications,
"puppetEnvUrl": api_environments_path,
"lifecycleEnvUrl": api_environments_path,
"lifecycleEnvOrganization": 'ATIX',
"loadParameterSelectionUrl": ui_app_definition_path("__id__")
"loadParameterSelectionUrl": ui_appcendep_app_path("__id__"),
"loadForemanDataUrl": ui_appcendep_fdata_path("__id__"),
}
else
json = {
"mode": "editInstance",
"organization": current_organization,
"location": current_location,
"appDefinition": {
"id": @app_instance.app_definition_id,
"name": @applications[@app_instance.app_definition_id],
"id": @app_instance.app_definition.id,
"name": @app_instance.app_definition.name,
"hostgroup_id": @app_instance.app_definition.hostgroup_id,
},
"parameters": JSON.parse(@app_instance.parameters),
"puppetEnvUrl": api_environments_path,
"lifecycleEnvUrl": api_environments_path,
"lifecycleEnvOrganization": 'ATIX',
}
end
%>
Expand Down
3 changes: 0 additions & 3 deletions app/views/ui_app_definitions/index.json.rabl

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/ui_app_definitions/main.json.rabl

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/ui_app_definitions/show.json.rabl

This file was deleted.

9 changes: 9 additions & 0 deletions app/views/ui_appcendep/app.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

child @app_data["app_definition"] => :app_definition do
extends "ui_appcendep/app_definition"
end

child @app_data["fdata"] => :fdata do
extends "ui_appcendep/fdata"
end
2 changes: 2 additions & 0 deletions app/views/ui_appcendep/computeprofile.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collection @computeprofiles
attributes :id, :name
2 changes: 2 additions & 0 deletions app/views/ui_appcendep/domain.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collection @domains
attributes :id, :name
2 changes: 2 additions & 0 deletions app/views/ui_appcendep/environment.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collection @environments
attributes :id, :name
24 changes: 24 additions & 0 deletions app/views/ui_appcendep/fdata.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

object @fdata
attribute :hostgroup_id

child :environments => :environments do
extends "ui_appcendep/environment"
end

#child :lifecycle_environments => :lifecycle_environments do
# extends "ui_appcendep/lifecycle_environment"
#end

child :domains => :domains do
extends "ui_appcendep/domain"
end

child :computeprofiles => :computeprofiles do
extends "ui_appcendep/computeprofile"
end

child :ptables => :ptables do
extends "ui_appcendep/ptable"
end
2 changes: 2 additions & 0 deletions app/views/ui_appcendep/lifecycle_environment.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collection @Katello::KTEnvironments
attributes :id, :name
2 changes: 2 additions & 0 deletions app/views/ui_appcendep/ptable.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collection @ptables
attributes :id, :name
13 changes: 2 additions & 11 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,8 @@
end
end

constraints(:id => /[\w\.-]+/) do
resources :ui_app_definitions, :only => [:show]
end
get 'ui_appcendep_app/:id', to: 'ui_appcendep#app', constraints: { id: /[\w\.-]+/ }, as: :ui_appcendep_app
get 'ui_appcendep_fdata/:id', to: 'ui_appcendep#fdata', constraints: { id: /[\w\.-]+/ }, as: :ui_appcendep_fdata

scope :api, :path => '/api', :defaults => { :format => 'json' } do
scope '(:apiv)', :defaults => { :apiv => 'v2' }, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2) do
constraints(:id => /[\w\.-]+/) do
resources :app_definitions, :only => [:show, :index, :create, :update, :destroy], :controller => 'foreman_appcendep/api/v2/app_definitions'
resources :app_instances, :only => [:show, :index, :create, :update, :destroy], :controller => 'foreman_appcendep/api/v2/app_instances'
end
end
end
end
end
Loading

0 comments on commit 76c5a5b

Please sign in to comment.