From fd2beca67ecc2d87a8e2a917a14f8ff032ebdbc1 Mon Sep 17 00:00:00 2001 From: Kenneth Date: Wed, 25 Jun 2025 12:46:46 +0200 Subject: [PATCH 1/6] fix: new machines can not be created with negative swap values When an iso image is selected, do not try to insert negatives values in the swap field. issue #1831 --- lib/Ravada/Front.pm | 1 + templates/ng-templates/new_machine_template.html.ep | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Ravada/Front.pm b/lib/Ravada/Front.pm index 59a23b568..62fba02a7 100644 --- a/lib/Ravada/Front.pm +++ b/lib/Ravada/Front.pm @@ -778,6 +778,7 @@ sub list_iso_images { $row->{options} = decode_json($row->{options}) if $row->{options}; $row->{min_ram} = 0.2 if !$row->{min_ram}; + $row->{min_swap_size} = 0 if !$row->{min_swap_size}; push @iso,($row); } $sth->finish; diff --git a/templates/ng-templates/new_machine_template.html.ep b/templates/ng-templates/new_machine_template.html.ep index 9d0354e28..32f6216ba 100644 --- a/templates/ng-templates/new_machine_template.html.ep +++ b/templates/ng-templates/new_machine_template.html.ep @@ -168,7 +168,7 @@
- +
Date: Fri, 18 Jul 2025 15:30:24 +0200 Subject: [PATCH 2/6] wip: Displays the autostart attribute for machines in the list_bases_ng.html.ep controller. Adds a popup for shutdown confirmation on the list_bases_ng.html.ep page. issue #2185 --- lib/Ravada/Front.pm | 1 + public/js/ravada.js | 108 +++++++++++++++++++++++++-- script/rvd_front | 1 + templates/main/list_bases_ng.html.ep | 25 ++++++- 4 files changed, 129 insertions(+), 6 deletions(-) diff --git a/lib/Ravada/Front.pm b/lib/Ravada/Front.pm index 62fba02a7..9263e4443 100644 --- a/lib/Ravada/Front.pm +++ b/lib/Ravada/Front.pm @@ -212,6 +212,7 @@ sub _get_clone_info($user, $base, $clone = Ravada::Front::Domain->open($base->{i ,is_active => $clone->is_active ,screenshot => $clone->_data('screenshot') ,date_changed => $clone->_data('date_changed') + ,autostart=> $clone->_data('autostart') }; $c->{can_hibernate} = ($clone->is_active && !$clone->is_volatile); diff --git a/public/js/ravada.js b/public/js/ravada.js index 408913582..ff73fb1c4 100644 --- a/public/js/ravada.js +++ b/public/js/ravada.js @@ -31,6 +31,7 @@ .controller("notifCrtl", notifCrtl) .controller("run_domain_req",run_domain_req_ctrl) .controller("login",login_ctrl) + .controller("manage_nodes",manage_nodes) function newMachineCtrl($scope, $http) { @@ -47,6 +48,80 @@ }; + function manage_nodes($scope, $http, $interval, $timeout) { + $scope.list_nodes = function() { + if (!$scope.modal_open) { + $http.get('/list_nodes.json').then(function(response) { + $scope.nodes = response.data; + }); + } + }; + $scope.node_enable=function(id) { + $scope.modal_open = false; + $http.get('/node/enable/'+id+'.json').then(function() { + $scope.list_nodes(); + }); + + }; + $scope.node_disable=function(id) { + $scope.modal_open = false; + $http.get('/node/disable/'+id+'.json').then(function() { + $scope.list_nodes(); + }); + }; + $scope.node_remove=function(id) { + $http.get('/v1/node/remove/'+id); + $scope.list_nodes(); + }; + $scope.confirm_disable_node = function(id , n_machines) { + if (n_machines > 0 ) { + $scope.modal_open = true; + $('#confirm_disable_'+id).modal({show:true}) + } else { + $scope.node_disable(id); + } + }; + $scope.node_start=function(id) { + $scope.modal_open = false; + $http.get('/node/start/'+id+'.json').then(function() { + $scope.list_nodes(); + }); + + }; + $scope.node_shutdown=function(id) { + $scope.modal_open = false; + $http.get('/node/shutdown/'+id+'.json').then(function() { + $scope.list_nodes(); + }); + }; + $scope.node_connect = function(id) { + $scope.id_req = undefined; + $scope.request = undefined; + $http.get('/node/connect/'+id).then(function(response) { + $scope.id_req= response.data.id_req; + $timeout(function() { + $scope.fetch_request($scope.id_req); + }, 2 * 1000 ); + }); + }; + $scope.fetch_request = function(id_req) { + $http.get('/request/'+id_req+'.json').then(function(response) { + $scope.request = response.data; + if ($scope.request.status != "done") { + $timeout(function() { + $scope.fetch_request(id_req); + }, 3 * 1000 ); + } else { + $scope.list_nodes() + } + }); + }; + + $scope.modal_open = false; + $scope.list_nodes(); + $interval($scope.list_nodes,30 * 1000); + }; + function suppFormCtrl($scope){ this.user = {}; $scope.showErr = false; @@ -174,6 +249,20 @@ } } }; + $scope.open_modal=function(prefix,machine){ + $scope.modalOpened=true; + $('#'+prefix+machine.id).modal({show:true}) + } + $scope.cancel_modal=function(machine,field){ + $scope.modalOpened=false; + if (typeof(machine)!='undefined' && typeof(field)!='undefined') { + if (machine[field]) { + machine[field]=0; + } else { + machine[field]=1; + } + } + } $scope.action = function(machine, action, confirmed) { machine.action = false; @@ -200,12 +289,19 @@ $scope.host_shutdown = 0; $scope.host_force_shutdown = 0; } else if (action == 'shutdown' || action == 'hibernate' || action == 'force_shutdown' || action == 'reboot') { - $scope.host_restore = 0; - var id=machine.id; - if (machine.clone) { - id=machine.clone.id; + // si machine.autostart == 1 + if (!confirmed && machine.autostart == 1) { + $scope.modalOpened=true; + $('#'+'afc_'+machine.id).modal({show:true}) + } + else { + $scope.host_restore = 0; + var id=machine.id; + if (machine.clone) { + id=machine.clone.id; + } + $http.get( '/machine/'+action+'/'+id+'.json'); } - $http.get( '/machine/'+action+'/'+id+'.json'); } else { alert("unknown action "+action); } @@ -332,11 +428,13 @@ subscribe_list_bookings(url); } }; + $scope.modalOpened = false; $scope.only_public = false; $scope.toggle_only_public=function() { $scope.only_public = !$scope.only_public; }; $scope.startIntro = startIntro; + }; function singleMachinePageC($scope, $http, $interval, request, $location) { diff --git a/script/rvd_front b/script/rvd_front index 8449f5132..61d7a51ac 100644 --- a/script/rvd_front +++ b/script/rvd_front @@ -1116,6 +1116,7 @@ get '/machine/info/(:id).(:type)' => sub { if ($domain->is_active && ( !exists $info->{ip} || !$info->{ip})) { Ravada::Request->refresh_machine(id_domain => $domain->id, uid => $USER->id); } + print("info: $info"); return $c->render(json => $info); }; diff --git a/templates/main/list_bases_ng.html.ep b/templates/main/list_bases_ng.html.ep index 2571c49e2..130f18c42 100644 --- a/templates/main/list_bases_ng.html.ep +++ b/templates/main/list_bases_ng.html.ep @@ -74,7 +74,7 @@
+ + + Date: Fri, 18 Jul 2025 15:47:43 +0200 Subject: [PATCH 3/6] wip: Prevents the popup from being displayed when the action is a reset. issue #2185 --- public/js/ravada.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/public/js/ravada.js b/public/js/ravada.js index ff73fb1c4..45829197c 100644 --- a/public/js/ravada.js +++ b/public/js/ravada.js @@ -253,16 +253,6 @@ $scope.modalOpened=true; $('#'+prefix+machine.id).modal({show:true}) } - $scope.cancel_modal=function(machine,field){ - $scope.modalOpened=false; - if (typeof(machine)!='undefined' && typeof(field)!='undefined') { - if (machine[field]) { - machine[field]=0; - } else { - machine[field]=1; - } - } - } $scope.action = function(machine, action, confirmed) { machine.action = false; @@ -290,7 +280,7 @@ $scope.host_force_shutdown = 0; } else if (action == 'shutdown' || action == 'hibernate' || action == 'force_shutdown' || action == 'reboot') { // si machine.autostart == 1 - if (!confirmed && machine.autostart == 1) { + if (!confirmed && (action == 'shutdown' || action == 'force_shutdown') && machine.autostart == 1) { $scope.modalOpened=true; $('#'+'afc_'+machine.id).modal({show:true}) } From 8537b8194bc0332ec83a134b36c11fab46c2b17e Mon Sep 17 00:00:00 2001 From: Kenneth Date: Tue, 22 Jul 2025 15:04:07 +0200 Subject: [PATCH 4/6] wip: Added a temporary variable to distinguish between shutdown and force shutdown actions when the modal is confirmed. issue #2185 --- public/js/ravada.js | 14 ++++++-------- templates/main/list_bases_ng.html.ep | 5 +++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/public/js/ravada.js b/public/js/ravada.js index 45829197c..f037e6bb5 100644 --- a/public/js/ravada.js +++ b/public/js/ravada.js @@ -249,10 +249,6 @@ } } }; - $scope.open_modal=function(prefix,machine){ - $scope.modalOpened=true; - $('#'+prefix+machine.id).modal({show:true}) - } $scope.action = function(machine, action, confirmed) { machine.action = false; @@ -279,10 +275,12 @@ $scope.host_shutdown = 0; $scope.host_force_shutdown = 0; } else if (action == 'shutdown' || action == 'hibernate' || action == 'force_shutdown' || action == 'reboot') { - // si machine.autostart == 1 - if (!confirmed && (action == 'shutdown' || action == 'force_shutdown') && machine.autostart == 1) { - $scope.modalOpened=true; + if (machine.autostart == 1 && confirmed && (action == 'shutdown' || action == 'force_shutdown')) { + action = tmp_action; + } + if (machine.autostart == 1 && (action == 'shutdown' || action == 'force_shutdown') && !confirmed) { $('#'+'afc_'+machine.id).modal({show:true}) + tmp_action = action; } else { $scope.host_restore = 0; @@ -418,7 +416,7 @@ subscribe_list_bookings(url); } }; - $scope.modalOpened = false; + $scope.tmp_action = null; $scope.only_public = false; $scope.toggle_only_public=function() { $scope.only_public = !$scope.only_public; diff --git a/templates/main/list_bases_ng.html.ep b/templates/main/list_bases_ng.html.ep index 130f18c42..4a3cc6996 100644 --- a/templates/main/list_bases_ng.html.ep +++ b/templates/main/list_bases_ng.html.ep @@ -83,7 +83,7 @@ ng-click="machine.action=false;action(machine,'hibernate')">  <%=l 'Hibernate' %> + ng-click="machine.action=false;action(machine,'force_shutdown', false)">  <%=l 'Poweroff' %> @@ -104,9 +104,10 @@

<%=l 'Are you sure you want to shutdown the machine ' %> {{machine.name}} <%=l '?' %>

From bf34bc3647e3d6823ef4d35f56dcfe711d30103d Mon Sep 17 00:00:00 2001 From: Kenneth Date: Fri, 25 Jul 2025 13:51:39 +0200 Subject: [PATCH 5/6] wip: Removed unnecessary code. Added shutdown confirmation to the admin page. issue #2185 --- public/js/admin.js | 11 ++-- public/js/ravada.js | 75 --------------------------- script/rvd_front | 1 - templates/main/admin_machines.html.ep | 31 +++++++++-- templates/main/list_bases_ng.html.ep | 5 +- 5 files changed, 34 insertions(+), 89 deletions(-) diff --git a/public/js/admin.js b/public/js/admin.js index 83d80fd11..c7f1f0ff3 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -556,15 +556,18 @@ ravadaApp.directive("solShowMachine", swMach) }); }; - $scope.action = function(target,action,machineId){ + $scope.action = function(target,action,machine, confirmed){ if (action === 'view-new-tab') { - window.open('/machine/view/' + machineId + '.html'); + window.open('/machine/view/' + machine.id + '.html'); } else if (action === 'view') { - window.location.assign('/machine/view/' + machineId + '.html'); + window.location.assign('/machine/view/' + machine.id + '.html'); + } + else if ((action === 'shutdown' || action === 'force_shutdown') && machine.autostart == 1 && !confirmed) { + $scope.open_modal('afc_', machine); } else { - $http.get('/'+target+'/'+action+'/'+machineId+'.json') + $http.get('/'+target+'/'+action+'/'+machine.id +'.json') .then(function(response) { if(response.status == 300 || response.status == 403) { console.error('Reponse error', response.status); diff --git a/public/js/ravada.js b/public/js/ravada.js index f037e6bb5..a85f12af2 100644 --- a/public/js/ravada.js +++ b/public/js/ravada.js @@ -31,7 +31,6 @@ .controller("notifCrtl", notifCrtl) .controller("run_domain_req",run_domain_req_ctrl) .controller("login",login_ctrl) - .controller("manage_nodes",manage_nodes) function newMachineCtrl($scope, $http) { @@ -48,80 +47,6 @@ }; - function manage_nodes($scope, $http, $interval, $timeout) { - $scope.list_nodes = function() { - if (!$scope.modal_open) { - $http.get('/list_nodes.json').then(function(response) { - $scope.nodes = response.data; - }); - } - }; - $scope.node_enable=function(id) { - $scope.modal_open = false; - $http.get('/node/enable/'+id+'.json').then(function() { - $scope.list_nodes(); - }); - - }; - $scope.node_disable=function(id) { - $scope.modal_open = false; - $http.get('/node/disable/'+id+'.json').then(function() { - $scope.list_nodes(); - }); - }; - $scope.node_remove=function(id) { - $http.get('/v1/node/remove/'+id); - $scope.list_nodes(); - }; - $scope.confirm_disable_node = function(id , n_machines) { - if (n_machines > 0 ) { - $scope.modal_open = true; - $('#confirm_disable_'+id).modal({show:true}) - } else { - $scope.node_disable(id); - } - }; - $scope.node_start=function(id) { - $scope.modal_open = false; - $http.get('/node/start/'+id+'.json').then(function() { - $scope.list_nodes(); - }); - - }; - $scope.node_shutdown=function(id) { - $scope.modal_open = false; - $http.get('/node/shutdown/'+id+'.json').then(function() { - $scope.list_nodes(); - }); - }; - $scope.node_connect = function(id) { - $scope.id_req = undefined; - $scope.request = undefined; - $http.get('/node/connect/'+id).then(function(response) { - $scope.id_req= response.data.id_req; - $timeout(function() { - $scope.fetch_request($scope.id_req); - }, 2 * 1000 ); - }); - }; - $scope.fetch_request = function(id_req) { - $http.get('/request/'+id_req+'.json').then(function(response) { - $scope.request = response.data; - if ($scope.request.status != "done") { - $timeout(function() { - $scope.fetch_request(id_req); - }, 3 * 1000 ); - } else { - $scope.list_nodes() - } - }); - }; - - $scope.modal_open = false; - $scope.list_nodes(); - $interval($scope.list_nodes,30 * 1000); - }; - function suppFormCtrl($scope){ this.user = {}; $scope.showErr = false; diff --git a/script/rvd_front b/script/rvd_front index 61d7a51ac..8449f5132 100644 --- a/script/rvd_front +++ b/script/rvd_front @@ -1116,7 +1116,6 @@ get '/machine/info/(:id).(:type)' => sub { if ($domain->is_active && ( !exists $info->{ip} || !$info->{ip})) { Ravada::Request->refresh_machine(id_domain => $domain->id, uid => $USER->id); } - print("info: $info"); return $c->render(json => $info); }; diff --git a/templates/main/admin_machines.html.ep b/templates/main/admin_machines.html.ep index 8f1670d96..48bb71ab6 100644 --- a/templates/main/admin_machines.html.ep +++ b/templates/main/admin_machines.html.ep @@ -199,7 +199,7 @@ @@ -279,7 +279,7 @@
+ +
- +