Unverified Commit aa47b1d0 authored by Fernando Verdugo's avatar Fernando Verdugo Committed by GitHub
Browse files

Refactor/1407 action buttons (#1408)



* refactor(frontend): dropdown actions
* feature(frontend): poweroff option

Issue #1407

Co-authored-by: default avatarfv3rdugo <fv3rdugo@gmail.com>
parent e121e086
......@@ -129,7 +129,7 @@ our %VALID_ARG = (
);
our %CMD_SEND_MESSAGE = map { $_ => 1 }
qw( create start shutdown prepare_base remove remove_base rename_domain screenshot download
qw( create start shutdown force_shutdown prepare_base remove remove_base rename_domain screenshot download
clone
set_base_vm remove_base_vm
domain_autostart hibernate hybernate
......
......@@ -101,7 +101,8 @@
if ( action == 'restore' ) {
$scope.host_restore = machine.id_clone;
$scope.host_shutdown = 0;
} else if (action == 'shutdown' || action == 'hibernate') {
$scope.host_force_shutdown = 0;
} else if (action == 'shutdown' || action == 'hibernate' || action == 'force_shutdown') {
$scope.host_restore = 0;
$http.get( '/machine/'+action+'/'+machine.id_clone+'.json');
} else {
......
......@@ -557,6 +557,12 @@ get '/machine/shutdown/(:id).(:type)' => sub {
return shutdown_machine($c);
};
get '/machine/force_shutdown/(:id).(:type)' => sub {
my $c = shift;
return access_denied($c) if !$USER ->can_shutdown($c->stash('id'));
return force_shutdown_machine($c);
};
any '/machine/remove/(:id).(:type)' => sub {
my $c = shift;
return access_denied($c) if !$USER->can_remove_machine($c->stash('id'));
......@@ -2210,6 +2216,17 @@ sub shutdown_machine {
return $c->render(json => { req => $req->id });
}
sub force_shutdown_machine {
my $c = shift;
return login($c) if !_logged_in($c);
my ($domain, $type) = _search_requested_machine($c);
my $req = Ravada::Request->force_shutdown_domain(id_domain => $domain->id, uid => $USER->id);
return $c->redirect_to('/machines') if $type eq 'html';
return $c->render(json => { req => $req->id });
}
sub _do_remove_machine {
my $c = shift;
return login($c) if !_logged_in($c);
......
......@@ -41,6 +41,26 @@
<div class="row">
<a type="button" class="btn btn-success mr-2" ng-hide="machine.action"
href="/machine/clone/{{machine.id}}.html"><strong><i class="fa fa-play" aria-hidden="true"></i>&nbsp;<%=l 'Start' %></strong></a>
<div class="dropdown">
<button ng-show="machine.is_active && !machine.action" class="btn btn-secondary dropdown-toggle"
ng-click="$parent.refresh=20" type="button" id="dropdownMenuButton"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><%=l 'action'%>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a ng-show="machine.can_remove" class="dropdown-item"
ng-click="host_restore=machine.id_clone">
<i class="fa fa-angle-double-left" aria-hidden="true"></i>&nbsp;<%=l 'Restore' %></a>
<a ng-show="machine.is_active" class="dropdown-item"
ng-click="machine.action=false;action(machine,'shutdown')">
<i class="fa fa-angle-double-down" aria-hidden="true"></i>&nbsp;<%=l 'Shutdown'%></a>
<a ng-show="machine.is_active && machine.can_hibernate" class="dropdown-item"
ng-click="machine.action=false;action(machine,'hibernate')">
<i class="fa fa-snowflake" aria-hidden="true"></i>&nbsp;<%=l 'Hibernate' %></a>
<a ng-show="machine.is_active" class="dropdown-item"
ng-click="machine.action=false;action(machine,'force_shutdown')">
<i class="fa fa-times" aria-hidden="true"></i>&nbsp;<%=l 'Poweroff' %></a>
</div>
</div>
<a type="button" class="btn btn-danger text-white"
ng-show="machine.id_clone && !machine.is_active && machine.can_remove && !host_restore"
ng-click="host_restore=machine.id_clone;machine.action=true "
......@@ -56,32 +76,6 @@
ng-click="restore(machine.id_clone);host_restore=0;machine.action=false"
><%=l 'Yes' %></a>
</div>
<a ng-show="machine.is_active && !machine.action"
class="btn btn-outline-secondary"
ng-click="machine.action=true;$parent.refresh=20"
type="button"><%=l 'action'%></a>
<div class="btn-group"
ng-show="machine.action && !host_restore"
>
<button type="button" class="btn btn-outline-dark btn-sm"
ng-show="machine.can_remove"
ng-click="host_restore=machine.id_clone"
><%=l 'Restore' %></button>
<button ng-show="machine.is_active" type="button"
class="btn btn-outline-dark btn-sm"
ng-click="machine.action=false;action(machine,'shutdown')"
><%=l 'Shutdown'%></button>
<button ng-show="machine.is_active && machine.can_hibernate" type="button"
class="btn btn-outline-dark"
ng-click="machine.action=false;action(machine,'hibernate')"
><%=l 'Hibernate' %></button>
<a
ng-click="machine.action=false"
><i class="align-bottom fas fa-chevron-circle-left"></i></a>
</div>
% if ($user
% && ( $user->can_change_settings || $user->can_change_settings_all)){
<a ng-show="machine.id_clone && !machine.action && host_restore != machine.id_clone"
......
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