You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2017/06/22 20:21:09 UTC
[16/17] incubator-trafficcontrol git commit: clean it up so its pretty
clean it up so its pretty
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/104e88a2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/104e88a2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/104e88a2
Branch: refs/heads/master
Commit: 104e88a28fb3d960218a26fa4944730838bb0dae
Parents: 88f171c
Author: Derek Gelinas <de...@cable.comcast.com>
Authored: Tue Jun 20 23:37:41 2017 +0000
Committer: Jeff Elsloo <je...@cable.comcast.com>
Committed: Thu Jun 22 14:18:17 2017 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/UI/Steering.pm | 29 ++-
.../app/templates/steering/index.html.ep | 197 +++++++++----------
2 files changed, 114 insertions(+), 112 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/104e88a2/traffic_ops/app/lib/UI/Steering.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/UI/Steering.pm b/traffic_ops/app/lib/UI/Steering.pm
index 5bca3d5..d15a193 100644
--- a/traffic_ops/app/lib/UI/Steering.pm
+++ b/traffic_ops/app/lib/UI/Steering.pm
@@ -36,13 +36,20 @@ sub index {
my @steering = $self->get_target_data($ds_id, $type_ids);
+ my @targets;
+ foreach my $i ( keys @steering ) {
+ push ( @targets, $steering[$i]->{'target_id'} );
+ }
+
+ my %ds_data = $self->get_deliveryservices($ds_id, \@targets);
+
&navbarpage($self);
$self->stash(
ds_id => $ds_id,
ds_name => $self->get_ds_name($ds_id),
steering => \@steering,
- ds_data => $self->get_deliveryservices($ds_id),
+ ds_data => \%ds_data,
types => $type_names,
fbox_layout => 1
);
@@ -72,8 +79,6 @@ sub get_target_data {
my @steering;
my @positive_order_steering;
-
-
my $neg_order_rs = $self->db->resultset('SteeringTarget')->search( { deliveryservice => $ds_id, type => $type_ids->{'STEERING_ORDER'}, value => { '<', 0 } }, { order_by => 'value ASC' } );
if ( $neg_order_rs > 0 ) {
@@ -140,17 +145,22 @@ sub get_cdn {
sub get_deliveryservices {
my $self = shift;
my $ds_id = shift;
+ my @targets = @{$_[0]};
+
my $cdn_id = $self->get_cdn($ds_id);
my %ds_data;
#search for only the delivery services that match the CDN ID of the supplied delivery service.
my $rs = $self->db->resultset('Deliveryservice')->search({ cdn_id => $cdn_id } , { prefetch => [ 'type' ] });
while ( my $row = $rs->next ) {
+ my $ds = $row->id;
if ( $row->type->name =~ m/^HTTP/ ) {
- $ds_data{ $row->id } = $row->xml_id;
+ if (!grep( /$ds/, @targets )) {
+ $ds_data{ $row->id } = $row->xml_id;
+ }
}
}
- return \%ds_data;
+ return %ds_data;
}
sub update {
@@ -203,13 +213,20 @@ sub update {
my ($type_names, $type_ids) = $self->get_types();
my @steering = $self->get_target_data($ds_id, $type_ids);
+
+ my @targets;
+ foreach my $i ( keys @steering ) {
+ push ( @targets, $steering[$i]->{'target_id'} );
+ }
+
+ my %ds_data = $self->get_deliveryservices($ds_id, \@targets);
&stash_role($self);
$self->stash(
ds_id => $ds_id,
ds_name => $self->get_ds_name($ds_id),
steering => \@steering,
- ds_data => $self->get_deliveryservices(),
+ ds_data => \%ds_data,
types => $type_names,
fbox_layout => 1
);
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/104e88a2/traffic_ops/app/templates/steering/index.html.ep
----------------------------------------------------------------------
diff --git a/traffic_ops/app/templates/steering/index.html.ep b/traffic_ops/app/templates/steering/index.html.ep
index ebc140f..d421044 100644
--- a/traffic_ops/app/templates/steering/index.html.ep
+++ b/traffic_ops/app/templates/steering/index.html.ep
@@ -26,15 +26,14 @@
function togglevis() {
- var ele = document.getElementById("toggleText");
+ var ele = document.getElementById("st_row_new");
var button = document.getElementById("addTarget");
- if (ele.style.visibility == "visible") {
-
+ if (ele.style.visibility == 'visible') {
}
else {
- ele.style.visibility = "visible";
+ ele.style.visibility = 'visible';
button.style.visibility = "hidden";
}
}
@@ -49,19 +48,9 @@
var ele = document.getElementById(divId);
var text = document.getElementById(divId);
- if (ele.style.visibility == "visible") {
- ele.style.visibility = "hidden";
- }
- else {
-
- ele.style.visibility = "visible";
- }
- document.getElementById("submit_button").click();
- } else {
+ document.getElementById("submit_button").click();
}
-
-
}
</script>
@@ -77,104 +66,100 @@
<div class="main">
<h1>Steering Assignment: <%= $ds_name %></h1>
<form method="post" action="/ds/<%= $ds_id %>/steering/update" id="steering_form">
-
- <% my $i = 0; %>
- <% foreach my $st (@{$steering}) { %>
- <div id="target_<%= $i %>" style="visibility: visible">
- <div style="margin-left: 0px;">
- <h4>Target # <%= $i+1; %></h4>
- </div>
- <div style="margin-left: 2px;">
- <% unless (field('st.target_id')->valid) { %>
- <span class="field-with-error"><%= field('st.target_id')->error %></span><br>
- <% } %>
- %= label_for 'st.target_name' => 'Delivery Service:', class => 'label', style=>"width:150px;"
- <select style="max-width:250px" name="st.target_id" id="st.target_id_<%=$i%>">
- <option value="">Delete Target</option>
- <% if (defined($st->{target_id})) { %>
- <option value="<%=$st->{target_id}%>" selected><%=$st->{target_name}%></option>
- <% } else { %>
+ <table id="target_table" width=100% cellpadding="10">
+ <% my $i = 0; %>
+ <% foreach my $st (@{$steering}) { %>
+ <tr id="st_row_<%= $st->{id} %>">
+ <td width="160">
+ <span id="target_<%= $i %>" style="visibility: visible">
+ <% unless (field('st.target_id')->valid) { %>
+ <span class="field-with-error"><%= field('st.target_id')->error %></span><br>
+ <% } %>
+ <select style="display:none" style="max-width:250px" name="st.target_id" id="st.target_id_<%=$i%>">
+ <option value="">Delete Target</option>
+ <% if (defined($st->{target_id})) { %>
+ <option value="<%=$st->{target_id}%>" selected><%=$st->{target_name}%></option>
+ <% } else { %>
+ <option value="" selected></option>
+ <% } %>
+ </select>
+ <%=$st->{target_name}%>
+ </td>
+ <td style="text-align:center;" width="160">
+ <% unless (field('st.target_type')->valid) { %>
+ <span class="field-with-error"><%= field('st.target_type')->error %></span><br><br>
+ <% } %>
+ %= label_for 'st.target_type' => ' Type: ', class => 'label'
+ <select style="max-width:140px" name="st.target_type">
+ <% foreach my $type (keys $types) { %>
+ <% if ( $type == $st->{target_type} ) { %>
+ <option value="<%= $type %>" selected><%= $types->{$type} %></option>
+ <% } else { %>
+ <option value="<%= $type %>"><%= $types->{$type} %></option>
+ <% } %>
+ <% } %>
+ </select>
+ </td>
+ <td width="75" style="text-align:center;">
+ <% unless (field('st.target_value')->valid) { %>
+ <span class="field-with-error"><%= field('st.target_value')->error %></span><br><br>
+ <% } %>
+ %= label_for 'st.target_value' => 'Value: ', class => 'label'
+ <input type="text" style="max-width:25px; text-align:right" name="st.target_value" value = "<%= $st->{target_value} %>">
+ </td>
+ <td width="50" style="text-align:center;">
+ <!-- <a id="deleteTarget" href="">Delete Target</a> -->
+ <input type="button" onclick="changeText('st.target_id_<%= $i %>', 'target_<%= $i %>', '<%=$st->{target_name}%>')" value="Delete">
+ </td>
+ </tr>
+ <% $i++; %>
+ <% } %>
+ <tr id="st_row_new" style="visibility: hidden;">
+ <td width="160">
+ <% unless (field('st.target_id')->valid) { %>
+ <span class="field-with-error"><%= field('st.target_id')->error %></span><br>
+ <% } %>
+ <select style="max-width:150px" name="st.target_id">
<option value="" selected></option>
+ <% foreach my $id (sort{$ds_data->{$a} cmp $ds_data->{$b}} keys %$ds_data) { %>
+ <option value="<%=$id%>"><%=$ds_data->{$id}%></option>
+ <% } %>
+ </select>
+ </td>
+ <td width="160" style="text-align:center;">
+ <% unless (field('st.target_type')->valid) { %>
+ <span class="field-with-error"><%= field('st.target_type')->error %></span><br><br>
<% } %>
- <% foreach my $id (sort{$ds_data->{$a} cmp $ds_data->{$b}} keys %$ds_data) { %>
- <option value="<%=$id%>"><%=$ds_data->{$id}%></option>
+ %= label_for 'st.target_type' => ' Type: ', class => 'label'
+ <select style="max-width:150px" name="st.target_type">
+ <% foreach my $type (keys $types) { %>
+ <option value="<%= $type %>"><%= $types->{$type} %></option>
<% } %>
- </select>
- <span style="display:inline-block; width: 5px;"></span>
- <% unless (field('st.target_type')->valid) { %>
- <span class="field-with-error"><%= field('st.target_type')->error %></span><br><br>
- <% } %>
- %= label_for 'st.target_type' => ' Type: ', class => 'label'
- <select style="max-width:250px" name="st.target_type">
- <option value="<%=$st->{target_type}%>" selected><%=$types->{$st->{target_type}}%></option>
- <% foreach my $type (keys $types) { %>
- <% if ( $type != $st->{target_type} ) { %>
- <option value="<%= $type %>"><%= $types->{$type} %></option>
+ </select>
+ </td>
+ <td width="75" style="text-align:center;">
+ <% unless (field('st.target_value')->valid) { %>
+ <span class="field-with-error"><%= field('st.target_value')->error %></span><br><br>
+ <% } %>
+ %= label_for 'st.target_value' => 'Value: ', class => 'label'
+ <input type="text" style="max-width:25px; text-align:right" name="st.target_value" value = "0">
+ </td>
+ </tr>
+ </table>
+
+ <div class="buttons-section" style="margin-bottom: 20px;">
+ <div style="margin-top: 25px; margin-left: 15px; position: relative; display: inline-block; float: left;">
+ <% if ($priv_level >= 20) { %> <!-- operations and admins only!! -->
+ <button class="button" id="submit_button">Save</button>
<% } %>
- <% } %>
- </select>
- <span style="display:inline-block; width: 5px;"></span>
- <% unless (field('st.target_value')->valid) { %>
- <span class="field-with-error"><%= field('st.target_value')->error %></span><br><br>
- <% } %>
- %= label_for 'st.target_value' => 'Value: ', class => 'label'
- <input type="text" style="max-width:25px; text-align:right" name="st.target_value" value = "<%= $st->{target_value} %>">
- <span style="display:inline-block; width: 5px;"></span>
- <!-- <a id="deleteTarget" href="">Delete Target</a> -->
- <input type="button" onclick="changeText('st.target_id_<%= $i %>', 'target_<%= $i %>', '<%=$st->{target_name}%>')" value="Delete">
- <br>
- <% $i++; %>
+ <span style="display:inline-block; width: 10px;"></span>
+ <input type="button" class="button" id="addTarget" onclick="togglevis();" value="Add Target">
</div>
- </div><br>
- <% } %>
- <div id="toggleText" style="visibility: hidden">
- <div style="margin-left: 0px;">
- <h4>New Target</h4>
- </div>
- <div style="margin-left: 2px;">
- <% unless (field('st.target_id')->valid) { %>
- <span class="field-with-error"><%= field('st.target_id')->error %></span><br>
- <% } %>
- %= label_for 'st.target_name' => 'Delivery Service:', class => 'label', style=>"width:150px;"
- <select style="max-width:250px" name="st.target_id">
- <option value="" selected></option>
- <% foreach my $id (sort{$ds_data->{$a} cmp $ds_data->{$b}} keys %$ds_data) { %>
- <option value="<%=$id%>"><%=$ds_data->{$id}%></option><% } %>
- </select>
- <span style="display:inline-block; width: 5px;"></span>
- <% unless (field('st.target_type')->valid) { %>
- <span class="field-with-error"><%= field('st.target_type')->error %></span><br><br>
- <% } %>
- %= label_for 'st.target_type' => ' Type: ', class => 'label'
- <select style="max-width:250px" name="st.target_type">
- <% foreach my $type (keys $types) { %>
- <option value="<%= $type %>"><%= $types->{$type} %></option>
- <% } %>
- </select>
- <span style="display:inline-block; width: 5px;"></span>
- <% unless (field('st.target_value')->valid) { %>
- <span class="field-with-error"><%= field('st.target_value')->error %></span><br><br>
- <% } %>
- %= label_for 'st.target_value' => 'Value: ', class => 'label'
- <input type="text" style="max-width:25px; text-align:right" name="st.target_value" value = "0">
+ <div style="margin-top: 25px; float:right; margin-right: 15px">
+ <button class="button" id="close_button">Close</button>
</div>
- </div>
-
-
- <div class="buttons-section" style="margin-bottom: 20px;">
- <div style="margin-top: 25px; margin-left: 10px; position: relative; display: inline-block; float: left;">
- <% if ($priv_level >= 20) { %> <!-- operations and admins only!! -->
- <button class="button" id="submit_button">Save</button>
- <% } %>
- <span style="display:inline-block; width: 10px;"></span>
- <input type="button" class="button" id="addTarget" onclick="togglevis();" value="Add Target">
- </div>
+ </div>
</form>
- <div style="margin-top: 25px; float:center; margin-right: 50px">
- </div>
- <div style="margin-top: 25px; float:right; margin-right: 50px">
- <button class="button" id="close_button">Close</button>
- </div>
</div>
</div>
</div>