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

refactor(frontend): improved list machines render

parent 1e065981
......@@ -217,7 +217,7 @@ sub list_machines($self, $user) {
sub _around_list_machines($orig, $self, $user) {
my $machines = $self->$orig($user);
for my $m (@$machines) {
$m->{can_shutdown} = $user->can_shutdown($m->{id});
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;
......
......@@ -248,6 +248,22 @@ sub BUILD {
}
sub _list_machines_fast($self, $ws, $login) {
my $user = Ravada::Auth::SQL->new(name => $login) or die "Error: uknown user $login";
my $ret0 = $self->ravada->list_domains();
my @ret;
for my $dom (@$ret0) {
next if !$user->is_admin && $dom->{id_owner} != $user->id;
$dom->{can_start} = 1;
$dom->{can_view} = 1;
$dom->{can_manage} = 1;
push @ret,($dom) if !$dom->{id_base};
}
$ws->send( { json => \@ret } );
}
sub subscribe($self, %args) {
my $ws = $args{ws};
my %args2 = %args;
......@@ -258,6 +274,9 @@ sub subscribe($self, %args) {
, %args
, ret => undef
};
if ( $args{channel} eq 'list_machines') {
$self->_list_machines_fast($ws, $args{login})
}
}
sub unsubscribe($self, $ws) {
......
......@@ -183,9 +183,9 @@ ravadaApp.directive("solShowMachine", swMach)
}
}
if ($scope.auto_hide_clones) {
$scope.hide_clones = 0;
$scope.hide_clones = false;
if ($scope.n_clones > $scope.n_clones_hide ) {
$scope.hide_clones = 1;
$scope.hide_clones = true;
}
}
for (var i = $scope.list_machines.length-1; i >= 0; i--){
......@@ -193,7 +193,10 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.list_machines.splice(i,1);
}
mach = $scope.list_machines[i];
if (!mach.id_base && typeof $scope.show_clones[mach.id] == 'undefined') {
if (!mach.id_base && typeof $scope.show_clones[mach.id] == 'undefined'
&& typeof mach.childs != 'undefined'
&& mach.childs.length > 0
) {
$scope.show_clones[mach.id] = !$scope.hide_clones;
}
}
......
......@@ -116,7 +116,8 @@
%= include 'bootstrap/requests'
<table class="table admin-cont-body" border="0">
<div ng-show="!list_machines"><%=l 'Loading ...' %> </div>
<table class="table admin-cont-body" border="0" ng-show="list_machines" ng-cloak="1">
<thead>
<tr>
<th ><div class="lgMachName machine-button" style="display:inline;float:down"
......
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