implement toggling of widgets (#227)

Co-authored-by: Meliox <na>
This commit is contained in:
Meliox 2026-07-05 15:09:51 +02:00 committed by GitHub
parent 0855a19cc3
commit 70f9790da0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 28 deletions

View File

@ -91,7 +91,13 @@ sub _get_temperature_sensors {
return $data; return $data;
} }
$data = JSON->new->pretty->encode({ "PVE MOD lm-sensors Enhanced" => $sensors_json }); $data = JSON->new->pretty->encode({
cpu => $config{lm_sensors}{enable_cpu} ? \1 : \0,
nvme => $config{lm_sensors}{enable_nvme_temp} ? \1 : \0,
fans => $config{lm_sensors}{enable_fan_speed} ? \1 : \0,
hdd => $config{lm_sensors}{enable_hdd_temp} ? \1 : \0,
data => { 'PVE MOD lm-sensors Enhanced' => $sensors_json },
});
return $data; return $data;
} }

View File

@ -10,8 +10,8 @@ use PVE::PVEMod::Collector::SystemInformation qw(get_system_information_data);
# Per-endpoint state caches (module-level, reset on worker restart) # Per-endpoint state caches (module-level, reset on worker restart)
my $graphics_cache = { data => {}, mtime => 0 }; my $graphics_cache = { data => {}, mtime => 0 };
my $sensors_cache = { data => '{}', mtime => 0 }; my $sensors_cache = { data => {}, mtime => 0 };
my $ups_cache = { data => '{}', mtime => 0 }; my $ups_cache = { data => {}, mtime => 0 };
my $system_info_cache = undef; my $system_info_cache = undef;
@ -153,7 +153,7 @@ sub get_graphics_info {
debug(__LINE__, "get_graphics_info called"); debug(__LINE__, "get_graphics_info called");
if (!($config{gpu}{intel_enabled} || !$config{gpu}{nvidia_enabled} || !$config{gpu}{amd_enabled})) { if (!($config{gpu}{intel_enabled} || !$config{gpu}{nvidia_enabled} || !$config{gpu}{amd_enabled})) {
debug(__LINE__, "GPU information collection is disabled"); debug(__LINE__, "GPU information collection is disabled");
return { }; return { disabled => \1 };
} }
# Start PVE Mod # Start PVE Mod
@ -171,13 +171,13 @@ sub get_sensors_info {
debug(__LINE__, "get_sensors_info called"); debug(__LINE__, "get_sensors_info called");
if (!$config{lm_sensors}{enabled}) { if (!$config{lm_sensors}{enabled}) {
debug(__LINE__, "LM Sensors collection is disabled"); debug(__LINE__, "LM Sensors collection is disabled");
return {}; return { disabled => \1 };
} }
# Start PVE Mod # Start PVE Mod
pve_mod_starter(); pve_mod_starter();
my $data = _read_state_file_cached($sensors_state_file, $sensors_cache, 1, '{}'); my $data = _read_state_file_cached($sensors_state_file, $sensors_cache, 0, {});
# Notify pve_mod_worker of activity # Notify pve_mod_worker of activity
notify_pve_mod_worker(); notify_pve_mod_worker();
@ -189,13 +189,13 @@ sub get_ups_info {
debug(__LINE__, "get_ups_info called"); debug(__LINE__, "get_ups_info called");
if (!$config{ups}{enabled}) { if (!$config{ups}{enabled}) {
debug(__LINE__, "UPS collection is disabled"); debug(__LINE__, "UPS collection is disabled");
return {}; return { disabled => \1 };
} }
# Start PVE Mod # Start PVE Mod
pve_mod_starter(); pve_mod_starter();
my $data = _read_state_file_cached($ups_state_file, $ups_cache, 1, '{}'); my $data = _read_state_file_cached($ups_state_file, $ups_cache, 0, {});
# Notify pve_mod_worker of activity # Notify pve_mod_worker of activity
notify_pve_mod_worker(); notify_pve_mod_worker();
@ -217,6 +217,11 @@ sub get_pve_mod_version {
sub get_system_information { sub get_system_information {
debug(__LINE__, "get_system_information called"); debug(__LINE__, "get_system_information called");
if (!$config{system_info}{enabled}) {
debug(__LINE__, "System information collection is disabled");
return { disabled => \1 };
}
if (defined $system_info_cache) { if (defined $system_info_cache) {
debug(__LINE__, "Returning cached system information"); debug(__LINE__, "Returning cached system information");
return $system_info_cache; return $system_info_cache;

View File

@ -160,7 +160,10 @@ Ext.define('PVE.node.StatusView', {
printBar: false, printBar: false,
textField: 'PveMod_graphicsInfo', textField: 'PveMod_graphicsInfo',
renderer: function(gpuStats) { renderer: function(gpuStats) {
if (!gpuStats || !gpuStats.Graphics) { if (gpuStats && gpuStats.disabled === true) {
this.hide();
return '';
} else if (!gpuStats || !gpuStats.Graphics) {
return ''; return '';
} }
@ -288,8 +291,15 @@ Ext.define('PVE.node.StatusView', {
// --- // ---
let objValue; let objValue;
try { try {
objValue = JSON.parse(value) || {}; const parsed = value || {};
objValue = objValue[Object.keys(objValue)[0]] || {}; if (parsed.disabled === true) {
this.hide();
return '';
} else if (parsed.cpu !== true) {
this.hide();
return '';
}
objValue = (parsed.data && parsed.data[Object.keys(parsed.data)[0]]) || {};
} catch(e) { } catch(e) {
objValue = {}; objValue = {};
} }
@ -456,7 +466,10 @@ Ext.define('PVE.node.StatusView', {
printBar: false, printBar: false,
textField: 'PveMod_graphicsInfo', textField: 'PveMod_graphicsInfo',
renderer: function(gpuStats) { renderer: function(gpuStats) {
if (!gpuStats || !gpuStats.Graphics) { if (gpuStats && gpuStats.disabled === true) {
this.hide();
return '';
} else if (!gpuStats || !gpuStats.Graphics) {
return ''; return '';
} }
@ -576,8 +589,15 @@ Ext.define('PVE.node.StatusView', {
// --- // ---
let objValue; let objValue;
try { try {
objValue = JSON.parse(value) || {}; const parsed = value || {};
objValue = objValue[Object.keys(objValue)[0]] || {}; if (parsed.disabled === true) {
this.hide();
return '';
} else if (parsed.nvme !== true) {
this.hide();
return '';
}
objValue = (parsed.data && parsed.data[Object.keys(parsed.data)[0]]) || {};
} catch(e) { } catch(e) {
objValue = {}; objValue = {};
} }
@ -655,8 +675,15 @@ Ext.define('PVE.node.StatusView', {
// --- // ---
let objValue; let objValue;
try { try {
objValue = JSON.parse(value) || {}; const parsed = value || {};
objValue = objValue[Object.keys(objValue)[0]] || {}; if (parsed.disabled === true) {
this.hide();
return '';
} else if (parsed.fans !== true) {
this.hide();
return '';
}
objValue = (parsed.data && parsed.data[Object.keys(parsed.data)[0]]) || {};
} catch(e) { } catch(e) {
objValue = {}; objValue = {};
} }
@ -714,7 +741,10 @@ Ext.define('PVE.node.StatusView', {
iconCls: 'fa fa-fw fa-snowflake-o', iconCls: 'fa fa-fw fa-snowflake-o',
textField: 'PveMod_graphicsInfo', textField: 'PveMod_graphicsInfo',
renderer: function(gpuStats) { renderer: function(gpuStats) {
if (!gpuStats || !gpuStats.Graphics || !gpuStats.Graphics.NVIDIA) { if (gpuStats && gpuStats.disabled === true) {
this.hide();
return '';
} else if (!gpuStats || !gpuStats.Graphics || !gpuStats.Graphics.NVIDIA) {
return ''; return '';
} }
@ -742,7 +772,7 @@ Ext.define('PVE.node.StatusView', {
}); });
if (rows.length === 0) { if (rows.length === 0) {
return 'N/A'; return '';
} }
return '<div style="padding-left: 20px; box-sizing: border-box;"><table style="width: 100%; border-collapse: collapse; table-layout: fixed;">' + rows.join('') + '</table></div>'; return '<div style="padding-left: 20px; box-sizing: border-box;"><table style="width: 100%; border-collapse: collapse; table-layout: fixed;">' + rows.join('') + '</table></div>';
@ -756,20 +786,17 @@ Ext.define('PVE.node.StatusView', {
iconCls: 'fa fa-fw fa-battery-three-quarters', iconCls: 'fa fa-fw fa-battery-three-quarters',
textField: 'PveMod_upsInfo', textField: 'PveMod_upsInfo',
renderer: function(value) { renderer: function(value) {
let objValue = {}; let objValue;
try { try {
// Parse the UPS data
if (typeof value === 'string') {
objValue = JSON.parse(value) || {};
} else if (typeof value === 'object') {
objValue = value || {}; objValue = value || {};
}
} catch(e) { } catch(e) {
objValue = {}; objValue = {};
} }
// If objValue is null or empty, return N/A if (objValue.disabled === true) {
if (!objValue || Object.keys(objValue).length === 0) { this.hide();
return '';
} else if (!objValue || Object.keys(objValue).length === 0) {
return 'N/A'; return 'N/A';
} }
@ -1000,6 +1027,9 @@ Ext.define('PVE.node.StatusView', {
renderer: function(value) { renderer: function(value) {
if (value === null || value === undefined) { if (value === null || value === undefined) {
return ''; return '';
} else if (value.disabled === true) {
this.hide();
return '';
} }
const titleMap = { const titleMap = {