From 6c23fe9303ebc5b738ccfab1eaddc6c3fcaf4ce9 Mon Sep 17 00:00:00 2001 From: Francesc Guasch Date: Fri, 9 Feb 2024 10:56:27 +0100 Subject: [PATCH] wip: show domain in other hds --- lib/Ravada/WebSocket.pm | 25 ++++++++++++++++--------- t/device/10_templates.t | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/Ravada/WebSocket.pm b/lib/Ravada/WebSocket.pm index c39632b84..b1398df17 100644 --- a/lib/Ravada/WebSocket.pm +++ b/lib/Ravada/WebSocket.pm @@ -280,27 +280,34 @@ sub _list_domains_with_device($rvd,$row) { push @domains, ($domain); } } - push @domains,( _list_domains_with_devices_locked($rvd, values %devices) ); + for my $dev ( values %devices ) { + _get_domain_with_device($rvd, $dev); + } $row->{_domains} = \@domains; $row->{_bases} = \@bases; $row->{devices} = [values %devices]; } -sub _list_domains_with_devices_locked($rvd, @devices) { +sub _get_domain_with_device($rvd, $dev) { my $sql = "SELECT d.id, d.name, d.is_base, d.status " ." FROM host_devices_domain_locked l, domains d " ." WHERE l.id_domain = d.id " - ." AND "; + ." AND l.name=?" + ; - my $where = ''; - for (@devices ) { - $where .= " OR " if $where; - $where .= " name = ? " + my $sth = $rvd->_dbh->prepare($sql); + $sth->execute($dev->{name}); + my @domains; + while ( my ($id,$name,$is_base, $status, $is_locked, $device) = $sth->fetchrow ) { + $is_locked = 0 if !$is_locked || $status ne 'active'; + $device = '' if !$device; + my $domain = { id => $id ,name => $name, is_locked => $is_locked + ,is_base => $is_base ,device => $device + }; + $dev->{domain} = $domain;# if $is_locked; } - $sth = $rvd->_dbh->prepare($sql); - $sth->execute(@devices); } sub _list_requests($rvd, $args) { diff --git a/t/device/10_templates.t b/t/device/10_templates.t index 057705401..dfff0a881 100644 --- a/t/device/10_templates.t +++ b/t/device/10_templates.t @@ -615,7 +615,7 @@ sub test_frontend_list($vm) { } } } - is($found,2) or exit; + is($found,2) or die Dumper($front_devices); } sub _mock_hd($vm, $path) {