public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid
@ 2023-07-10 13:26 Christoph Heiss
  2023-07-10 13:26 ` [pve-devel] [PATCH installer 1/2] tui: fix clippy warnings Christoph Heiss
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Heiss @ 2023-07-10 13:26 UTC (permalink / raw)
  To: pve-devel

Pretty much as it says on the tin.

pve-installer:

Christoph Heiss (2):
  tui: fix clippy warnings
  tui: add "Deselect all" button to zfs/btrfs raid disk select

 proxmox-tui-installer/src/options.rs        |  6 +--
 proxmox-tui-installer/src/setup.rs          |  8 +---
 proxmox-tui-installer/src/views/bootdisk.rs | 50 ++++++++++++++++-----
 proxmox-tui-installer/src/views/mod.rs      | 17 +++++++
 4 files changed, 58 insertions(+), 23 deletions(-)

--
2.41.0





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH installer 1/2] tui: fix clippy warnings
  2023-07-10 13:26 [pve-devel] [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Christoph Heiss
@ 2023-07-10 13:26 ` Christoph Heiss
  2023-07-10 13:26 ` [pve-devel] [PATCH installer 2/2] tui: add "Deselect all" button to zfs/btrfs raid disk select Christoph Heiss
  2023-07-13 14:10 ` [pve-devel] applied: [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Heiss @ 2023-07-10 13:26 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-tui-installer/src/options.rs        | 6 +-----
 proxmox-tui-installer/src/setup.rs          | 8 ++------
 proxmox-tui-installer/src/views/bootdisk.rs | 4 ++--
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/proxmox-tui-installer/src/options.rs b/proxmox-tui-installer/src/options.rs
index 62804c2..c8e8215 100644
--- a/proxmox-tui-installer/src/options.rs
+++ b/proxmox-tui-installer/src/options.rs
@@ -57,11 +57,7 @@ pub enum FsType {
 
 impl FsType {
     pub fn is_btrfs(&self) -> bool {
-        use FsType::Btrfs;
-        match self {
-            Btrfs(_) => true,
-            _ => false,
-        }
+        matches!(self, FsType::Btrfs(_))
     }
 }
 
diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs
index 68207c8..e8ee7f3 100644
--- a/proxmox-tui-installer/src/setup.rs
+++ b/proxmox-tui-installer/src/setup.rs
@@ -206,23 +206,19 @@ impl From<InstallerOptions> for InstallConfig {
                 config.hdsize = zfs.disk_size;
                 config.zfs_opts = Some(zfs.clone().into());
 
-                let mut i = 0;
-                for disk in &options.bootdisk.disks {
+                for (i, disk) in options.bootdisk.disks.iter().enumerate() {
                     config
                         .disk_selection
                         .insert(i.to_string(), disk.index.clone());
-                    i = i + 1;
                 }
             }
             AdvancedBootdiskOptions::Btrfs(btrfs) => {
                 config.hdsize = btrfs.disk_size;
 
-                let mut i = 0;
-                for disk in &options.bootdisk.disks {
+                for (i, disk) in options.bootdisk.disks.iter().enumerate() {
                     config
                         .disk_selection
                         .insert(i.to_string(), disk.index.clone());
-                    i = i + 1;
                 }
             }
         }
diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs
index 602e1da..4970655 100644
--- a/proxmox-tui-installer/src/views/bootdisk.rs
+++ b/proxmox-tui-installer/src/views/bootdisk.rs
@@ -274,7 +274,7 @@ struct MultiDiskOptionsView<T> {
 }
 
 impl<T: View> MultiDiskOptionsView<T> {
-    fn new(avail_disks: &[Disk], selected_disks: &Vec<usize>, options_view: T) -> Self {
+    fn new(avail_disks: &[Disk], selected_disks: &[usize], options_view: T) -> Self {
         let mut selectable_disks = avail_disks
             .iter()
             .map(|d| (d.to_string(), Some(d.clone())))
@@ -283,7 +283,7 @@ impl<T: View> MultiDiskOptionsView<T> {
         selectable_disks.push(("-- do not use --".to_owned(), None));
 
         let mut disk_form = FormView::new();
-        for i in 0..avail_disks.len() {
+        for (i, _) in avail_disks.iter().enumerate() {
             disk_form.add_child(
                 &format!("Harddisk {i}"),
                 SelectView::new()
-- 
2.41.0





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH installer 2/2] tui: add "Deselect all" button to zfs/btrfs raid disk select
  2023-07-10 13:26 [pve-devel] [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Christoph Heiss
  2023-07-10 13:26 ` [pve-devel] [PATCH installer 1/2] tui: fix clippy warnings Christoph Heiss
@ 2023-07-10 13:26 ` Christoph Heiss
  2023-07-13 14:10 ` [pve-devel] applied: [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Heiss @ 2023-07-10 13:26 UTC (permalink / raw)
  To: pve-devel

Another puzzle piece in the quest to align the TUI installer more to
its GUI counterpart.

Like the GUI installer, it will only be shown if >3 disks are
detected on the system.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-tui-installer/src/views/bootdisk.rs | 46 ++++++++++++++++-----
 proxmox-tui-installer/src/views/mod.rs      | 17 ++++++++
 2 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs
index 4970655..552cbc4 100644
--- a/proxmox-tui-installer/src/views/bootdisk.rs
+++ b/proxmox-tui-installer/src/views/bootdisk.rs
@@ -3,7 +3,8 @@ use std::{cell::RefCell, marker::PhantomData, rc::Rc};
 use cursive::{
     view::{Nameable, Resizable, ViewWrapper},
     views::{
-        Button, Dialog, DummyView, LinearLayout, NamedView, Panel, ScrollView, SelectView, TextView,
+        Button, Dialog, DummyView, LinearLayout, NamedView, PaddedView, Panel, ScrollView,
+        SelectView, TextView,
     },
     Cursive, View,
 };
@@ -293,10 +294,34 @@ impl<T: View> MultiDiskOptionsView<T> {
             );
         }

-        let disk_select_view = LinearLayout::vertical()
+        let mut disk_select_view = LinearLayout::vertical()
             .child(TextView::new("Disk setup").center())
             .child(DummyView)
-            .child(ScrollView::new(disk_form));
+            .child(ScrollView::new(disk_form.with_name("multidisk-disk-form")));
+
+        if avail_disks.len() > 3 {
+            let do_not_use_index = selectable_disks.len() - 1;
+            let deselect_all_button = Button::new("Deselect all", move |siv| {
+                siv.call_on_name("multidisk-disk-form", |view: &mut FormView| {
+                    view.call_on_childs(&|v: &mut SelectView<Option<Disk>>| {
+                        // As there is no .on_select() callback defined on the
+                        // SelectView's, the returned callback here can be safely
+                        // ignored.
+                        v.set_selection(do_not_use_index);
+                    });
+                });
+            });
+
+            disk_select_view.add_child(PaddedView::lrtb(
+                0,
+                0,
+                1,
+                0,
+                LinearLayout::horizontal()
+                    .child(DummyView.full_width())
+                    .child(deselect_all_button),
+            ));
+        }

         let options_view = LinearLayout::vertical()
             .child(TextView::new("Advanced options").center())
@@ -335,13 +360,14 @@ impl<T: View> MultiDiskOptionsView<T> {

         let disk_form = self
             .view
-            .get_child(view_top_index)?
-            .downcast_ref::<LinearLayout>()?
-            .get_child(0)?
-            .downcast_ref::<LinearLayout>()?
-            .get_child(2)?
-            .downcast_ref::<ScrollView<FormView>>()?
-            .get_inner();
+            .get_child_mut(view_top_index)?
+            .downcast_mut::<LinearLayout>()?
+            .get_child_mut(0)?
+            .downcast_mut::<LinearLayout>()?
+            .get_child_mut(2)?
+            .downcast_mut::<ScrollView<NamedView<FormView>>>()?
+            .get_inner_mut()
+            .get_mut();

         let mut selected_disks = Vec::new();

diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs
index b1a1a13..aa78289 100644
--- a/proxmox-tui-installer/src/views/mod.rs
+++ b/proxmox-tui-installer/src/views/mod.rs
@@ -326,6 +326,15 @@ impl FormView {
             .downcast_ref::<T>()
     }

+    pub fn get_child_mut<T: View>(&mut self, index: usize) -> Option<&mut T> {
+        self.view
+            .get_child_mut(1)?
+            .downcast_mut::<ResizedView<LinearLayout>>()?
+            .get_inner_mut()
+            .get_child_mut(index)?
+            .downcast_mut::<T>()
+    }
+
     pub fn get_value<T, R>(&self, index: usize) -> Option<R>
     where
         T: View + FormViewGetValue<R>,
@@ -346,6 +355,14 @@ impl FormView {
         }
     }

+    pub fn call_on_childs<T: View>(&mut self, callback: &dyn Fn(&mut T)) {
+        for i in 0..self.len() {
+            if let Some(v) = self.get_child_mut::<T>(i) {
+                callback(v);
+            }
+        }
+    }
+
     pub fn len(&self) -> usize {
         self.view
             .get_child(1)
--
2.41.0





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied: [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid
  2023-07-10 13:26 [pve-devel] [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Christoph Heiss
  2023-07-10 13:26 ` [pve-devel] [PATCH installer 1/2] tui: fix clippy warnings Christoph Heiss
  2023-07-10 13:26 ` [pve-devel] [PATCH installer 2/2] tui: add "Deselect all" button to zfs/btrfs raid disk select Christoph Heiss
@ 2023-07-13 14:10 ` Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2023-07-13 14:10 UTC (permalink / raw)
  To: Proxmox VE development discussion, Christoph Heiss

Am 10/07/2023 um 15:26 schrieb Christoph Heiss:
> Pretty much as it says on the tin.
> 
> pve-installer:
> 
> Christoph Heiss (2):
>   tui: fix clippy warnings
>   tui: add "Deselect all" button to zfs/btrfs raid disk select
> 
>  proxmox-tui-installer/src/options.rs        |  6 +--
>  proxmox-tui-installer/src/setup.rs          |  8 +---
>  proxmox-tui-installer/src/views/bootdisk.rs | 50 ++++++++++++++++-----
>  proxmox-tui-installer/src/views/mod.rs      | 17 +++++++
>  4 files changed, 58 insertions(+), 23 deletions(-)
> 

applied series, thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-13 14:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-10 13:26 [pve-devel] [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Christoph Heiss
2023-07-10 13:26 ` [pve-devel] [PATCH installer 1/2] tui: fix clippy warnings Christoph Heiss
2023-07-10 13:26 ` [pve-devel] [PATCH installer 2/2] tui: add "Deselect all" button to zfs/btrfs raid disk select Christoph Heiss
2023-07-13 14:10 ` [pve-devel] applied: [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal