Unverified Commit 5803381c authored by robertperez-upc's avatar robertperez-upc Committed by GitHub
Browse files

Add buttons tab (#1445)

Added actions tab
parent 3149cfad
......@@ -827,7 +827,7 @@ sub _pre_prepare_base($self, $user, $request = undef ) {
# TODO: if disk is not base and disks have not been modified, do not generate them
# again, just re-attach them
# again, just re-attach them
# $self->_check_disk_modified(
confess "ERROR: domain ".$self->name." is already a base" if $self->is_base();
$self->_check_has_clones();
......@@ -994,7 +994,7 @@ sub _check_cpu_usage($self, $request=undef){
chomp(my $cpu_count = `grep -c -P '^processor\\s+:' /proc/cpuinfo`);
die "Error: Too many active domains." if (scalar $self->_vm->vm->list_domains() >= $self->_vm->active_limit);
}
my @cpu;
my $msg;
for ( 1 .. 10 ) {
......@@ -1220,7 +1220,7 @@ sub _data($self, $field, $value=undef, $table='domains') {
$self->{$data} = $self->_select_domain_db( _table => $table, @field_select );
confess "No DB info for domain @field_select in $table ".$self->name
confess "No DB info for domain @field_select in $table ".$self->name
if ! exists $self->{$data};
confess "No field $field in $data ".Dumper(\@field_select)."\n".Dumper($self->{$data})
if !exists $self->{$data}->{$field};
......@@ -1630,6 +1630,8 @@ sub info($self, $user) {
$info->{cdrom} = \@cdrom;
$info->{requests} = $self->list_requests();
Ravada::Front::init_available_actions($user, $info);
return $info;
}
......@@ -2228,7 +2230,7 @@ sub _pre_remove_base {
my ($domain) = @_;
_allow_manage(@_);
_check_has_clones(@_);
if (!$domain->is_local) {
my $vm_local = $domain->_vm->new( host => 'localhost' );
confess "Error: I can't find local virtual manager ".$domain->type
......@@ -2524,7 +2526,7 @@ sub _post_shutdown {
id_domain => $self->id
,id_vm => $self->_vm->id
, uid => $arg{user}->id
, at => time+$timeout
, at => time+$timeout
);
}
if ($self->is_volatile) {
......@@ -3665,7 +3667,7 @@ sub get_controller {
my $sub = $self->get_controller_by_name($name);
# my $sub = $GET_CONTROLLER_SUB{$name};
die "I can't get controller $name for domain ".$self->name
if !$sub;
......
......@@ -211,36 +211,36 @@ sub list_machines($self, $user, @filter) {
push @list,(@{filter_base_without_clones($self->list_domains(@filter))}) if $user->can_list_clones();
push @list,(@{$self->_list_own_clones($user)}) if $user->can_list_clones_from_own_base();
push @list,(@{$self->_list_own_machines($user)}) if $user->can_list_own_machines();
return [@list] if scalar @list < 2;
my %uniq = map { $_->{name} => $_ } @list;
return [sort { $a->{name} cmp $b->{name} } values %uniq];
}
sub _around_list_machines($orig, $self, $user, @filter) {
my $machines = $self->$orig($user, @filter);
for my $m (@$machines) {
eval { $m->{can_shutdown} = $user->can_shutdown($m->{id}) };
sub init_available_actions($user, $m) {
eval { $m->{can_shutdown} = $user->can_shutdown($m->{id}) };
$m->{can_start} = 0;
$m->{can_start} = 1 if $m->{id_owner} == $user->id || $user->is_admin;
$m->{can_start} = 0;
$m->{can_start} = 1 if $m->{id_owner} == $user->id || $user->is_admin;
$m->{can_view} = 0;
$m->{can_view} = 1 if $m->{id_owner} == $user->id || $user->is_admin;
$m->{can_view} = 0;
$m->{can_view} = 1 if $m->{id_owner} == $user->id || $user->is_admin;
$m->{can_manage} = ( $user->can_manage_machine($m->{id}) or 0);
eval {
$m->{can_change_settings} = ( $user->can_change_settings($m->{id}) or 0);
};
#may have been deleted just now
next if $@ && $@ =~ /Unknown domain/;
die $@ if $@;
$m->{can_manage} = ( $user->can_manage_machine($m->{id}) or 0);
eval {
$m->{can_change_settings} = ( $user->can_change_settings($m->{id}) or 0);
};
die $@ if $@ && $@ !~ /Unknown domain/;
$m->{can_hibernate} = 0;
$m->{can_hibernate} = 1 if $user->can_shutdown($m->{id})
&& !$m->{is_volatile};
$m->{can_hibernate} = 0;
$m->{can_hibernate} = 1 if $user->can_shutdown($m->{id}) && !$m->{is_volatile};
}
sub _around_list_machines($orig, $self, $user, @filter) {
my $machines = $self->$orig($user, @filter);
for my $m (@$machines) {
init_available_actions($user, $m);
$m->{id_base} = undef if !exists $m->{id_base};
lock_hash(%$m);
}
......@@ -259,7 +259,7 @@ sub search_clone_data {
$sth->execute( map { $args{$_} } sort keys %args );
my $row = $sth->fetchrow_hashref;
return ( $row or {});
}
=cut
......@@ -294,7 +294,7 @@ sub list_domains($self, %args) {
my $sth = $CONNECTOR->dbh->prepare("$query $where ORDER BY d.id");
$sth->execute(map { $args{$_} } sort keys %args);
my @domains = ();
while ( my $row = $sth->fetchrow_hashref) {
for (qw(is_locked is_hibernated is_paused
......@@ -348,7 +348,7 @@ sub list_domains($self, %args) {
=head2 filter_base_without_clones
filters the list of domains and drops all machines that are unacessible and
filters the list of domains and drops all machines that are unacessible and
bases with 0 machines accessible
=cut
......@@ -412,7 +412,7 @@ sub _where(%args) {
sub list_clones {
my $self = shift;
my %args = @_;
my $domains = $self->list_domains();
my @clones;
for (@$domains ) {
......@@ -665,7 +665,7 @@ Returns a reference to a list of the users
sub list_users($self,$name=undef) {
my $sth = $CONNECTOR->dbh->prepare("SELECT id, name FROM users ");
$sth->execute();
my @users = ();
while ( my $row = $sth->fetchrow_hashref) {
next if defined $name && $row->{name} !~ /$name/;
......@@ -696,7 +696,7 @@ Waits for a request for some seconds.
=head3 Arguments
=over
=over
=item * request
......@@ -1080,7 +1080,7 @@ sub list_bases_anonymous {
}
=head2 disconnect_vm
=head2 disconnect_vm
Disconnects all the conneted VMs
......
......@@ -63,7 +63,7 @@
};
function swSupForm() {
return {
restrict: "E",
templateUrl: '/ng-templates/support_form.html',
......@@ -73,8 +73,8 @@
function addUserFormCrtl($scope, $http, request){
};
function swNewMach() {
......@@ -85,6 +85,7 @@
};
};
// list machines
function mainpageCrtl($scope, $http, $timeout, request, listMach) {
$scope.set_restore=function(machineId) {
......@@ -203,6 +204,15 @@
}
};
$scope.action = function(target,action,machineId){
$http.get('/'+target+'/'+action+'/'+machineId+'.json')
.then(function() {
}, function(data,status) {
console.error('Repos error', status, data);
window.location.reload();
});
};
subscribe_requests = function(url) {
var ws = new WebSocket(url);
ws.onopen = function(event) { ws.send('list_requests') };
......@@ -333,7 +343,7 @@
}, 2000);
$http.get('/machine/screenshot/'+machineId+'.json');
};
$scope.reload_page_copy_msg = false;
$scope.fail_page_copy_msg = false;
$scope.copy_done = false;
......@@ -583,7 +593,7 @@
$scope.init_domain_access();
});
};
$scope.set_access = function(id_access, allowed, last) {
$http.get('/machine/set_access/'+$scope.showmachine.id+'/'+id_access+'/'+allowed
+'/'+last)
......@@ -868,7 +878,7 @@
if (!$scope.redirect_done) {
$timeout(function() {
if(typeof $_anonymous != "undefined" && $_anonymous){
window.location.href="/anonymous";
window.location.href="/anonymous";
}
else {
window.location.href="/logout";
......@@ -925,13 +935,13 @@
$scope.add_user = function() {
$http.get('/users/register')
};
$scope.checkbox = [];
//if it is checked make the user admin, otherwise remove admin
$scope.stateChanged = function(id,userid) {
$scope.stateChanged = function(id,userid) {
if($scope.checkbox[id]) { //if it is checked
$http.get('/users/make_admin/' + userid + '.json')
location.reload();
......@@ -945,7 +955,7 @@
};
function swListUsers() {
return {
restrict: "E",
templateUrl: '/ng-templates/list_users.html',
......@@ -1015,7 +1025,7 @@
//here you should access the backend, to check if username exists
//and return a promise
//here we're using $q and $timeout to mimic a backend call
//here we're using $q and $timeout to mimic a backend call
//that will resolve after 1 sec
var defer = $q.defer();
......
......@@ -51,6 +51,11 @@
<div class="tab-pane fade" id="v-pills-hardware" role="tabpanel" aria-labelledby="v-pills-hardware-tab" >
%= include 'main/vm_hardware'
</div>
% }
% if ($USER->can_change_settings($domain->id) && !$domain->is_base) {
<div class="tab-pane fade" id="v-pills-actions" role="tabpanel" aria-labelledby="v-pills-actions-tab" >
%= include 'main/vm_actions'
</div>
% }
<div class="tab-pane fade" id="v-pills-copy" role="tabpanel" aria-labelledby="v-pills-copy-tab">
%= include 'main/vm_copy'
......
<div class="nav flex-column nav-pills bg-light" id="v-pills-tab" role="tablist" aria-orientation="vertical">
% if (($USER->can_change_settings($domain->id)) && !$domain->is_base) {
<a class="nav-link" id="v-pills-actions-tab" ng-click="refresh_machine()" href="#v-pills-actions" data-toggle="pill" role="tab" aria-controls="v-pills-icons" aria-selected="true"><%=l 'Actions' %></a>
% }
% if ($USER->can_change_settings($domain->id)) {
<a class="nav-link active" id="v-pills-description-tab" ng-click="refresh_machine()" href="#v-pills-description" data-toggle="pill" role="tab" aria-controls="v-pills-description" aria-selected="true"><%=l 'Description' %></a>
% }
......
<div class="card-body">
<div ng-show="showmachine.can_start">
<button type="button" class="btn btn-success btn-sm"
ng-click="action('machine','start',showmachine.id)"
ng-disabled="showmachine.is_active"
title="<%=l 'Start' %>">
<i class="fa fa-play"></i>
</button>
<span><%=l 'Start' %></span>
<br><br>
<div>
<div ng-show="showmachine.can_hibernate">
<button type="button" class="btn btn-warning btn-sm"
ng-click="action('machine','hibernate',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'Hibernate' %>">
<i class="fa fa-pause"></i>
</button>
<span><%=l 'Hibernate' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_shutdown">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','shutdown',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'ShutDown' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'ShutDown' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_view">
<a type="button" class="btn btn-primary btn-sm"
ng-href="/machine/view/{{showmachine.id}}.html"
title="<%=l 'View' %>">
<i class="fa fa-desktop"></i>
</a>
<span><%=l 'View' %></span>
<br><br>
</div>
</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