Commit c09f6ad9 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

[#48] Button to remove the clones

parent 73ef559f
......@@ -100,7 +100,14 @@
}
window.location.href = "/admin/machines";
});
}
};
$scope.remove = function(machineId) {
$http.get('/machine/remove/'+machineId+'.json');
};
$scope.remove_clones = function(machineId) {
$http.get('/machine/remove_clones/'+machineId+'.json');
};
$scope.action = function(target,action,machineId){
$http.get('/'+target+'/'+action+'/'+machineId+'.json');
};
......
......@@ -303,6 +303,12 @@ any '/machine/remove/(:id).(:type)' => sub {
my $c = shift;
return remove_machine($c);
};
any '/machine/remove_clones/(:id).(:type)' => sub {
my $c = shift;
return remove_clones($c);
};
get '/machine/prepare/(:id).(:type)' => sub {
my $c = shift;
return prepare_machine($c);
......@@ -1131,6 +1137,22 @@ sub remove_machine {
}
sub remove_clones {
my $c = shift;
my $domain = _search_requested_machine($c);
my @req;
for my $clone ( $domain->clones) {
my $req = Ravada::Request->remove_domain(
name => $clone->{name}
,uid => $USER->id
);
push @req,($req);
}
$c->render(json => { request => map { id => { $_->id } } });
}
sub remove_base {
my $c = shift;
return login($c) if !_logged_in($c);
......
......@@ -5,29 +5,53 @@
<div class="panel panel-warning" ng-show="showmachine.has_clones">
<div class="panel-heading">
This virtual machine can't be removed because it
has {{showmachine.has_clones}} clones.
</div>
</div>
<a type="button" class="btn btn-danger"
ng-hide="showmachine.has_clones > 0 || domain_remove_done"
<div ng-show="!domain_remove_done">
<a ng-show="showmachine.has_clones>0" type="button" class="btn btn-danger"
ng-click="domain_remove_clones=1"
>
<%=l 'Remove Clones' %>
</a>
<a type="button" class="btn btn-danger"
ng-hide="showmachine.has_clones > 0"
ng-click="domain_remove=1"
>
<%=l 'Remove' %>
</a>
</a>
</div>
<div ng-show="domain_remove">
<div ng-show="domain_remove">
<b>Danger</b>.
This will remove all the contents of the machine
<i><%= $domain->name %></i>. <b>This action can't be undone</b>.
<i><%= $domain->name %></i>.
<b>This action can't be undone</b>.
Are you sure ? <br/>
<a type="button" class="btn btn-danger"
ng-click="domain_remove=0"
>No</a>
<a type="button" class="btn btn-warning"
ng-click="action('machine','remove',<%= $domain->id %>);domain_remove=0;domain_remove_done=1"
>Yes</a>
ng-click="remove(<%= $domain->id %>);domain_remove=0;domain_remove_done=1;"
>Yes, remove {{showmachine.name}}</a>
</div><!-- del domain remove -->
<div ng-show="domain_remove_clones">
<b>Danger</b>.
This will remove all the {{showmachine.has_clones}} clones of the
machine <i><%= $domain->name %></i>.
<b>This action can't be undone</b>.
Are you sure ? <br/>
<a type="button" class="btn btn-danger"
ng-click="domain_remove_clones=0"
>No</a>
<a type="button" class="btn btn-warning"
ng-click="remove_clones(<%= $domain->id %>);domain_remove_clones=0;"
>Yes, remove all the clones</a>
</div><!-- del domain remove clones-->
<div ng-show="domain_remove_done">
Virtual Machine <b>{{showmachine.name}}</b> removed.
</div>
......
Supports Markdown
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