]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: hide max-vz and max-root inputs if product isn't PVE
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 26 Jun 2023 19:37:54 +0000 (21:37 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 26 Jun 2023 19:38:50 +0000 (21:38 +0200)
like we do in the GTK based installer

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-tui-installer/src/setup.rs
proxmox-tui-installer/src/views/bootdisk.rs
proxmox-tui-installer/src/views/mod.rs

index fb941ebfc9dc0903d47e2a537b06d487eb74c690..68207c816f783fb5f113cd59df8da7f2576f3a49 100644 (file)
@@ -11,7 +11,7 @@ use crate::{
 };
 
 #[allow(clippy::upper_case_acronyms)]
-#[derive(Clone, Copy, Deserialize)]
+#[derive(Clone, Copy, Deserialize, PartialEq)]
 #[serde(rename_all = "lowercase")]
 pub enum ProxmoxProduct {
     PVE,
index 72a0d3e828988d4864ba7372c301cae5cf2c5d26..75f70a11617f4a52535f570c2b0db224f96f5981 100644 (file)
@@ -13,6 +13,7 @@ use crate::options::{
     AdvancedBootdiskOptions, BootdiskOptions, BtrfsBootdiskOptions, Disk, FsType,
     LvmBootdiskOptions, ZfsBootdiskOptions, FS_TYPES, ZFS_CHECKSUM_OPTIONS, ZFS_COMPRESS_OPTIONS,
 };
+use crate::setup::ProxmoxProduct;
 
 pub struct BootdiskOptionsView {
     view: LinearLayout,
@@ -209,6 +210,7 @@ struct LvmBootdiskOptionsView {
 
 impl LvmBootdiskOptionsView {
     fn new(options: &LvmBootdiskOptions) -> Self {
+        let is_pve = crate::setup_info().config.product == ProxmoxProduct::PVE;
         // TODO: Set maximum accordingly to disk size
         let view = FormView::new()
             .child(
@@ -221,11 +223,13 @@ impl LvmBootdiskOptionsView {
                 "Swap size",
                 DiskSizeEditView::new_emptyable().content_maybe(options.swap_size),
             )
-            .child(
+            .child_conditional(
+                is_pve,
                 "Maximum root volume size",
                 DiskSizeEditView::new_emptyable().content_maybe(options.max_root_size),
             )
-            .child(
+            .child_conditional(
+                is_pve,
                 "Maximum data volume size",
                 DiskSizeEditView::new_emptyable().content_maybe(options.max_data_size),
             )
@@ -238,12 +242,24 @@ impl LvmBootdiskOptionsView {
     }
 
     fn get_values(&mut self) -> Option<LvmBootdiskOptions> {
+        let is_pve = crate::setup_info().config.product == ProxmoxProduct::PVE;
+        let min_lvm_free_id = if is_pve { 4 } else { 2 };
+        let max_root_size = if is_pve {
+            self.view.get_value::<DiskSizeEditView, _>(2)
+        } else {
+            None
+        };
+        let max_data_size = if is_pve {
+            self.view.get_value::<DiskSizeEditView, _>(3)
+        } else {
+            None
+        };
         Some(LvmBootdiskOptions {
             total_size: self.view.get_value::<DiskSizeEditView, _>(0)?,
             swap_size: self.view.get_value::<DiskSizeEditView, _>(1),
-            max_root_size: self.view.get_value::<DiskSizeEditView, _>(2),
-            max_data_size: self.view.get_value::<DiskSizeEditView, _>(3),
-            min_lvm_free: self.view.get_value::<DiskSizeEditView, _>(4),
+            max_root_size,
+            max_data_size,
+            min_lvm_free: self.view.get_value::<DiskSizeEditView, _>(min_lvm_free_id),
         })
     }
 }
index 5df00011249d56c647325a27532a5104fd17dc28..b1a1a138ff4cbf6ada25b9d49c9591b85493cb52 100644 (file)
@@ -310,6 +310,13 @@ impl FormView {
         self
     }
 
+    pub fn child_conditional(mut self, condition: bool, label: &str, view: impl View) -> Self {
+        if condition {
+            self.add_child(label, view);
+        }
+        self
+    }
+
     pub fn get_child<T: View>(&self, index: usize) -> Option<&T> {
         self.view
             .get_child(1)?