Commit cd080069 authored by Leigh Stoller's avatar Leigh Stoller

Add warnings to confirm modal when the user is about to delete an entire

image (all versions) or the most recent version of an image. Also rework
the internal data structures so that when the user does delete the most
recent version, the next most recent version gets that warning.
parent 9fe85faf
......@@ -228,7 +228,7 @@ sub DoListImages()
# Default to version zero, for old sites not reporting version.
my $vers = (defined($osvers) ? $osvers : 0);
# Put it into the object so that PHP/JS code can find it easy.
$image->{'version'} = $vers;
$image->{'version'} = int($vers);
# Try and set a local project, but use remote pid otherwise.
$image->{'pid'} = $ospid;
......@@ -290,6 +290,8 @@ sub DoListImages()
$ref->{'candelete'} = (@nakedusing ? 0 : 1);
# How many of the children are inactive (can be deleted).
$ref->{'inactive'} = 0;
# Marker.
$ref->{'deleted'} = 0;
#
# List of profiles, with a list of versions of each.
......@@ -310,7 +312,7 @@ sub DoListImages()
}
push(@{$tmp{$profile_uuid}->{'versions'}},
{"uuid" => $profile->uuid(),
"version" => $profile->version(),
"version" => int($profile->version()),
"created" => $profile->created(),
"iscurrent"=> ($profile->version() == $headversion ? 1 : 0),
});
......@@ -320,31 +322,16 @@ sub DoListImages()
#
# And for each version of the image.
#
# The last version of the image is special; it gets any profile
# references for the naked image, since that is what a naked image
# means; use the most recent image. So if we have naked references,
# mark the last image for the loop below so we can extend the list
#
if (@nakedusing) {
$versions[scalar(@versions) - 1]->{'islast'} = 1;
}
foreach my $image (@versions) {
my $urn = $image->{'urn'};
my @using = ();
$image->{'using'} = [];
$image->{'candelete'} = 0;
$image->{'deleted'} = 0;
next
if (APT_Profile::ImageInfo::FindProfilesUsing($urn, \@using));
# Combine the lists.
if ($image->{'islast'}) {
foreach my $p (@nakedusing) {
push(@using, $p)
if (!grep {$_->profileid() == $p->profileid()} @using);
}
}
#
# No references *currently* means we can delete the image.
#
......@@ -372,7 +359,7 @@ sub DoListImages()
}
push(@{$tmp{$profile_uuid}->{'versions'}},
{"uuid" => $profile->uuid(),
"version" => $profile->version(),
"version" => int($profile->version()),
"created" => $profile->created(),
"iscurrent"=> ($profile->version() ==
$headversion ? 1 :0),
......
......@@ -201,8 +201,9 @@ $(function ()
*/
function DeleteImage(cluster, row) {
var urn = $(row).attr('data-urn');
var index = parseInt($(row).attr('data-index'));
var table = $(row).closest("table");
console.info(cluster, urn);
console.info(cluster, urn, index);
// Callback for the delete request.
var callback = function (json) {
......@@ -214,6 +215,8 @@ $(function ()
}
// Now to delete the row. This has a little trickiness.
if ($(row).hasClass("image-version")) {
var imageindex = parseInt($(row).attr('data-imageindex'));
//
// Individual version, delete the row. There should not be
// a following profile versions row, but watch for it
......@@ -236,16 +239,23 @@ $(function ()
$(prev).remove();
}
$(row).remove();
// Mark the image version as deleted in the data object.
imagelist[cluster][imageindex]
.versions[index]["deleted"] = true;
}
else {
//
// Entire image delete (all versions). Need to delete the
// main row and all rows up to the next image.
//
/*
* Entire image delete (all versions). Need to delete the
* main row and all rows up to the next image.
*/
$(row).closest('tr')
.nextUntil('tr.tablesorter-hasChildRow', '.image-version')
.remove();
$(row).remove();
// Mark the entire image as deleted in the data object.
imagelist[cluster][index]["deleted"] = true;
}
table.trigger('update');
};
......@@ -277,8 +287,39 @@ $(function ()
});
});
}
/*
* Some extra text for the title of the confirm modal.
*/
var titletext = "";
if ($(row).hasClass("naked-image")) {
// Extra warn about deleting the entire image.
titletext = " all versions of ";
}
else if ($(row).hasClass("image-version")) {
/*
* Warn about deleting highest numbered (most recent) version.
* Need to check the version list to see if this is the case,
* keeping in mind that versions might already have been marked
* as deleted.
*/
var imageindex = parseInt($(row).attr('data-imageindex'));
var version = parseInt($(row).attr('data-version'));
var max = 0;
_.each(imagelist[cluster][imageindex].versions,
function(image, index) {
if (!image.deleted && image.version > max) {
max = image.version;
}
});
if (version >= max) {
titletext = " the most recent version of ";
}
}
var html = confirmTemplate({
"profiles" : profiles,
"profiles" : profiles,
"titletext" : titletext,
});
$('#confirm_div').html(html);
// Format dates with moment before display.
......
......@@ -5,7 +5,9 @@
<div class='modal-body'>
<button type='button' class='close' data-dismiss='modal'
aria-hidden='true'>&times;</button>
<center><h4>Are you sure want to delete this image?</h4></center>
<center><h4>Are you sure want to delete
<span class="text-warning"><em><%- titletext %></em></span>
this image?</h4></center>
<center>
<button class='btn btn-danger btn-sm'
id='confirm-delete-image'
......@@ -19,7 +21,7 @@
</center>
<br>
<% var warn = 0; %>
Note: This operation is not reversible, your image will be
Note: This operation is not reversible, your image(s) will be
permanently deleted, freeing up the disk space it using.
<div id="profile-list"
<% if (profiles == null) { %>class="hidden"<% } %>>
......@@ -66,7 +68,7 @@
<span class="text-danger
glyphicon glyphicon-asterisk"></span>
<span class="text-danger">
This is the most recent version of profile. Are you sure
This is the most recent version of the profile. Are you sure
you want to delete it?</span>
<% } %>
</div>
......
......@@ -58,9 +58,10 @@
</tr>
</thead>
<tbody>
<% _.each(images, function(image, index) { %>
<% _.each(images, function(image, imageindex) { %>
<% if (! (image.candelete || image.inactive)) { return; } %>
<tr data-urn="<%- image.urn %>">
<tr data-urn="<%- image.urn %>" class="naked-image"
data-index="<%- imageindex %>">
<td>
<a href="" class="toggle-image">
<span class="glyphicon glyphicon-chevron-right"></span></a>
......@@ -74,10 +75,13 @@
<td class="format-date"><%- image.versions[0].created %></td>
<td class="image-filesize"></td>
</tr>
<% _.each(image.versions, function(version, index) { %>
<% _.each(image.versions, function(version, versionindex) { %>
<% if (! version.candelete) { return; } %>
<tr class="hidden tablesorter-childRow-versions image-version"
data-urn="<%- version.urn %>">
data-urn="<%- version.urn %>"
data-version="<%- version.version %>"
data-index="<%- versionindex %>"
data-imageindex="<%- imageindex %>">
<td>
<span style="padding-left: 15px"><%- version.urn %></span>
<% if (version.candelete) { %>
......@@ -125,7 +129,7 @@
</tr>
</thead>
<tbody>
<% _.each(images, function(image, index) { %>
<% _.each(images, function(image, imageindex) { %>
<% if (image.candelete) { return; } %>
<%
var skip = 1;
......@@ -134,7 +138,8 @@
}
if (skip) { return; }
%>
<tr data-urn="<%- image.urn %>">
<tr data-urn="<%- image.urn %>" class="naked-image"
data-index="<%- imageindex %>">
<td>
<a href="" class="toggle-image">
<span class="glyphicon glyphicon-chevron-right"></span></a>
......@@ -144,11 +149,14 @@
<td class="image-filesize"></td>
<td></td>
</tr>
<% _.each(image.versions, function(version, index) { %>
<% _.each(image.versions, function(version, versionindex) { %>
<% if (version.candelete) { return; } %>
<% if (version.using.length != 1) { return; } %>
<tr class="hidden tablesorter-childRow-versions image-version"
data-urn="<%- version.urn %>">
data-urn="<%- version.urn %>"
data-version="<%- version.version %>"
data-index="<%- versionindex %>"
data-imageindex="<%- imageindex %>">
<td>
<span style="padding-left: 15px"><%- version.urn %></span>
<a href="" class="delete-button pull-right">
......@@ -201,7 +209,7 @@
</tr>
</thead>
<tbody>
<% _.each(images, function(image, index) { %>
<% _.each(images, function(image, imageindex) { %>
<% if (image.candelete) { return; } %>
<%
var skip = 1;
......@@ -219,7 +227,7 @@
<td class="format-date"><%- image.versions[0].created %></td>
<td class="image-filesize"></td>
</tr>
<% _.each(image.versions, function(version, index) { %>
<% _.each(image.versions, function(version, versionindex) { %>
<% if (version.candelete) { return; } %>
<% if (version.using.length <= 1) { return; } %>
<tr class="hidden tablesorter-childRow-versions image-version"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment