Skip to content
Permalink
Browse files

Show Agents assigned to Environments from Config Repos (#5796)

* Fetch all the agents so that Environments defined in Config Repos are displayed on the Environments page
* Disable checkbox for agents associated with an environment via Config Repo
* Add tooltip to disabled checkbox
  • Loading branch information...
akshaydewan committed Feb 12, 2019
1 parent 2e80540 commit 2665b54a93898b8f7421e91185ca9deec6675f27
@@ -43,7 +43,7 @@ public EnvironmentConfig getEnvironmentConfig() {
}

public void setAgentViewModels(AgentService agentService) {
this.agentViewModels = agentService.filter(environmentConfig.getLocalAgents().getUuids());
this.agentViewModels = agentService.filter(environmentConfig.getAgents().getUuids());
}

public AgentsViewModel getAgentViewModels() {
@@ -40,7 +40,7 @@

.agent_header th.selector {
padding: 0 2px 0 5px;
text-align: center;
text-align: right;
}

.agent_header th.hostname {
@@ -57,5 +57,11 @@
margin-bottom: -3px;
}

.agent_selector {
text-align: right;
}


span.contextual_help.agent_tooltip {
margin: 0;
padding: 0;
}
@@ -42,7 +42,7 @@ def new
end

def show
@agent_details = agent_service.filter(@environment.getLocalAgents().map(&:uuid))
@agent_details = agent_service.filter(@environment.getAgents().map(&:uuid))
end

def create
@@ -18,12 +18,17 @@ module AgentsHelper

AgentStatus = com.thoughtworks.go.domain.AgentStatus

def agent_selector uuid, selector_name, selected_uuids
"<td class='selector'>#{agent_selector_without_cell(uuid, selector_name, selected_uuids)}</td>".html_safe
def agent_selector uuid, selector_name, selected_uuids, is_associated_through_config_repo=false
"<td class='agent_selector'>#{agent_selector_without_cell(uuid, selector_name, selected_uuids, is_associated_through_config_repo)}</td>".html_safe
end

def agent_selector_without_cell uuid, selector_name, selected_uuids
"<input type='checkbox' name='#{ERB::Util.h(selector_name)}' value='#{ERB::Util.h(uuid)}' class='agent_select' #{(selected_uuids && selected_uuids.include?(uuid)) ? "checked='true'" : ""}/>".html_safe
def agent_selector_without_cell uuid, selector_name, selected_uuids, is_associated_through_config_repo
disabled_attr, tooltip = "", ""
if is_associated_through_config_repo
disabled_attr = "disabled"
tooltip = "<span class='contextual_help has_go_tip_right agent_tooltip' title='Agent is associated in a Config Repository, cannot edit'></span>"
end
"#{tooltip}<input #{disabled_attr} type='checkbox' name='#{ERB::Util.h(selector_name)}' value='#{ERB::Util.h(uuid)}' class='agent_select' #{(selected_uuids && selected_uuids.include?(uuid)) ? "checked='true'" : ""}/>".squish.html_safe
end

def cell_with_title value, klass, title = value
@@ -9,7 +9,7 @@
<script type="text/javascript">
Util.on_load(function() {
jQuery('#select_all_agents').change(function(){
jQuery('.agent_select').prop("checked", $(this).checked);
jQuery('.agent_select:not([disabled])').prop("checked", $(this).checked);
});
var lastChecked = null;
@@ -37,11 +37,17 @@ Util.on_load(function() {
lastChecked = $this;
});
});
jQuery(".has_go_tip_right").tipTip({
activation: "click",
maxWidth: "auto",
edgeOffset: 10,
defaultPosition: "right",
keepAlive: false
});
})
</script>


<table id='agent_details' class='agents list_table <%=" sortable_table" if scope[:sortable_columns]%> selectable_table'>
<thead>
<tr class='agent_header'>
@@ -89,7 +95,8 @@ Util.on_load(function() {
<tr class='agent_instance <%= get_agent_status_class(scope[:show_only_disabled],agent_in_agent_table.getStatus()) %>' id='<%= agent_in_agent_table.getUuid() %>'>
<% agent_uuid = agent_in_agent_table.getUuid()-%>
<% if has_operate_permission_for_agents? %>
<%== agent_selector(agent_uuid, scope[:selector_name], scope[:selected]) %>
<%== contains_agent_remotely = scope[:environment]&.containsAgentRemotely(agent_uuid)
agent_selector(agent_uuid, scope[:selector_name], scope[:selected], contains_agent_remotely) %>
<% end %>
<% unless scope[:exclude_columns].include?('hostname') -%>

@@ -138,4 +145,4 @@ Util.on_load(function() {
</tr>
<% end %>
</tbody>
</table>
</table>
@@ -5,7 +5,15 @@
<% if scope[:agents].empty? %>
There are no agents available
<% else %>
<%= render :partial => "environments/agents_table", :locals => {:scope => {:agents => scope[:agents], :exclude_columns => ["status", "usable_space"], :sortable_columns => false, :show_only_disabled => true, :selector_name => 'environment[agents][][uuid]', :selected => scope[:environment].agents.map(&:uuid)}} %>
<%= render :partial => "environments/agents_table",
:locals => {:scope => {
:agents => scope[:agents],
:exclude_columns => ["status", "usable_space"],
:sortable_columns => false,
:show_only_disabled => true,
:selector_name => 'environment[agents][][uuid]',
:environment => scope[:environment],
:selected => scope[:environment].agents.map(&:uuid)}} %>
<% end %>
</div>
</div>
@@ -420,6 +420,31 @@ def md5
expect(response.body).to have_selector("form input[type='checkbox'][name='environment[agents][][uuid]'][value='out-env']")
end

it "should load existing agents as checked-disabled while editing an agent associated in config-repo" do
basic_environment_config = BasicEnvironmentConfig.new(CaseInsensitiveString.new(@environment_name))
basic_environment_config.origins = RepoConfigOrigin.new
basic_environment_config.addAgent("some-uuid")
env_from_config_repo = MergeEnvironmentConfig.new(basic_environment_config)
user = com.thoughtworks.go.server.domain.Username.new(CaseInsensitiveString.new('user_foo'))
@config_helper.addAgent("some-uuid", "some-uuid")
@config_helper.addAgent("out-of-env", "out-env")
in_env = AgentViewModel.new(AgentInstanceMother.localInstance(SystemEnvironment.new, "some-uuid", "some-uuid"), "foo-environment")
out_env = AgentViewModel.new(AgentInstanceMother.localInstance(SystemEnvironment.new, "out-env", "out-of-env"))
agents_view_model = AgentsViewModel.new(in_env, out_env)
expect(@environment_config_service).to receive(:getMergedEnvironmentforDisplay).with(@environment_name, an_instance_of(HttpLocalizedOperationResult)).and_return(com.thoughtworks.go.domain.ConfigElementForEdit.new(env_from_config_repo,"md5"))
expect(@environment_config_service).to receive(:getEnvironmentForEdit).with(@environment_name).and_return(env_from_config_repo)
expect(@environment_config_service).to receive(:getAllLocalPipelinesForUser).with(user).and_return([EnvironmentPipelineModel.new("foo", @environment_name), EnvironmentPipelineModel.new("bar", "another_env"), EnvironmentPipelineModel.new("baz", nil)])
expect(@environment_config_service).to receive(:getAllRemotePipelinesForUserInEnvironment).with(anything,anything).and_return([])
expect(@agent_service).to receive(:registeredAgents).and_return(agents_view_model)
get :edit_agents, params:{:name => "foo-environment", :no_layout => true}

expect(assigns[:environment]).to_not be_nil

expect(response.body).to have_selector("form input[type='checkbox'][name='environment[agents][][uuid]'][value='some-uuid'][checked='true'][disabled]")
expect(response.body).to have_selector("span[class='contextual_help has_go_tip_right agent_tooltip'][title='Agent is associated in a Config Repository, cannot edit']")
expect(response.body).to have_selector("form input[type='checkbox'][name='environment[agents][][uuid]'][value='out-env']")
end

it "should fail agent_edit for a non existing environment" do
allow(@environment_config_service).to receive(:getMergedEnvironmentforDisplay).with('some-non-existent-environment', an_instance_of(HttpLocalizedOperationResult)) do |env, result|
result.badRequest("Environment 'some-non-existent-environment' not found.\n")
@@ -32,16 +32,16 @@
end

it "should select agent thats selected in current request" do
expect(agent_selector('uuid', 'selected[]', @selected)).to eq("<td class='selector'><input type='checkbox' name='selected[]' value='uuid' class='agent_select' checked='true'/></td>")
expect(agent_selector('uuid', 'selected[]', @selected)).to eq("<td class='agent_selector'><input type='checkbox' name='selected[]' value='uuid' class='agent_select' checked='true'/></td>")
end

it "should not select agent thats not selected in current request" do
expect(agent_selector('uuid1', 'selected[]', @selected)).to eq("<td class='selector'><input type='checkbox' name='selected[]' value='uuid1' class='agent_select' /></td>")
expect(agent_selector('uuid1', 'selected[]', @selected)).to eq("<td class='agent_selector'><input type='checkbox' name='selected[]' value='uuid1' class='agent_select' /></td>")
end

describe "when selected is not set" do
it "should not select agent thats not selected in current request" do
expect(agent_selector('uuid1', 'selected[]', nil)).to eq("<td class='selector'><input type='checkbox' name='selected[]' value='uuid1' class='agent_select' /></td>")
expect(agent_selector('uuid1', 'selected[]', nil)).to eq("<td class='agent_selector'><input type='checkbox' name='selected[]' value='uuid1' class='agent_select' /></td>")
end
end
end

0 comments on commit 2665b54

Please sign in to comment.
You can’t perform that action at this time.