Skip to content

Commit

Permalink
Merge pull request #15340 from lfu/projects_dynamic_method_ae
Browse files Browse the repository at this point in the history
Add project option to container template service dialog.
  • Loading branch information
gmcculloug authored Jun 19, 2017
2 parents 61190e9 + e3dd797 commit acf668b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
43 changes: 42 additions & 1 deletion app/models/dialog/container_template_service_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,54 @@ def self.create_dialog(label, parameters)
def create_dialog(label, parameters)
Dialog.new(:label => label, :buttons => "submit,cancel").tap do |dialog|
tab = dialog.dialog_tabs.build(:display => "edit", :label => "Basic Information", :position => 0)
add_parameters_group(tab, 0, parameters)
add_options_group(tab, 0)
add_parameters_group(tab, 1, parameters)
dialog.save!
end
end

private

def add_options_group(tab, position)
tab.dialog_groups.build(
:display => "edit",
:label => "Options",
:position => position
).tap do |dialog_group|
add_project_dropdown(dialog_group, 0)
add_project_textbox(dialog_group, 1)
end
end

def add_project_dropdown(group, position)
group.dialog_fields.build(
:type => "DialogFieldDropDownList",
:name => "existing_project_name",
:data_type => "string",
:dynamic => true,
:display => "edit",
:label => "Add To Existing Project",
:description => "The desired existing project for the provisioning",
:position => position,
:dialog_group => group
).tap do |dialog_field|
dialog_field.resource_action.fqname = "Container/Openshift/Operations/Methods/Available_Projects"
end
end

def add_project_textbox(group, position)
group.dialog_fields.build(
:type => "DialogFieldTextBox",
:name => "new_project_name",
:data_type => "string",
:display => "edit",
:label => "(or) Add To New Project",
:description => "The desired new project for the provisioning",
:position => position,
:dialog_group => group
)
end

def add_parameters_group(tab, position, parameters)
tab.dialog_groups.build(
:display => "edit",
Expand Down
13 changes: 11 additions & 2 deletions spec/models/dialog/container_template_service_dialog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,24 @@ def assert_main_tab(tab)
assert_tab_attributes(tab)

groups = tab.dialog_groups
expect(groups.size).to eq(1)
expect(groups.size).to eq(2)

assert_parameters_group(groups[0])
assert_options_group(groups[0])
assert_parameters_group(groups[1])
end

def assert_tab_attributes(tab)
expect(tab).to have_attributes(:label => "Basic Information", :display => "edit")
end

def assert_options_group(group)
expect(group).to have_attributes(:label => "Options", :display => "edit")
fields = group.dialog_fields
expect(fields.size).to eq(2)
assert_field(fields[0], DialogFieldDropDownList, :label => "Add To Existing Project", :name => "existing_project_name", :dynamic => true)
assert_field(fields[1], DialogFieldTextBox, :label => "(or) Add To New Project", :name => "new_project_name", :data_type => 'string')
end

def assert_field(field, clss, attributes)
expect(field).to be_kind_of clss
expect(field).to have_attributes(attributes)
Expand Down

0 comments on commit acf668b

Please sign in to comment.