public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer v2 2/3] tui: bootdisk: rename `disks` parameter to `avail_disks`
Date: Tue, 25 Jul 2023 17:02:47 +0200	[thread overview]
Message-ID: <20230725150300.1389135-3-c.heiss@proxmox.com> (raw)
In-Reply-To: <20230725150300.1389135-1-c.heiss@proxmox.com>

This better conveys its role/contents to the reader, as `disks` might be
ambiguous.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v1 -> v2:
  * No changes

 proxmox-tui-installer/src/views/bootdisk.rs | 45 ++++++++++++---------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs
index 0b0a9f8..d74322a 100644
--- a/proxmox-tui-installer/src/views/bootdisk.rs
+++ b/proxmox-tui-installer/src/views/bootdisk.rs
@@ -30,13 +30,13 @@ pub struct BootdiskOptionsView {
 }

 impl BootdiskOptionsView {
-    pub fn new(disks: &[Disk], options: &BootdiskOptions) -> Self {
+    pub fn new(avail_disks: &[Disk], options: &BootdiskOptions) -> Self {
         let bootdisk_form = FormView::new()
             .child(
                 "Target harddisk",
                 SelectView::new()
                     .popup()
-                    .with_all(disks.iter().map(|d| (d.to_string(), d.clone()))),
+                    .with_all(avail_disks.iter().map(|d| (d.to_string(), d.clone()))),
             )
             .with_name("bootdisk-options-target-disk");

@@ -45,10 +45,10 @@ impl BootdiskOptionsView {
         let advanced_button = LinearLayout::horizontal()
             .child(DummyView.full_width())
             .child(Button::new("Advanced options", {
-                let disks = disks.to_owned();
+                let avail_disks = avail_disks.to_owned();
                 let options = advanced_options.clone();
                 move |siv| {
-                    siv.add_layer(advanced_options_view(&disks, options.clone()));
+                    siv.add_layer(advanced_options_view(&avail_disks, options.clone()));
                 }
             }));

@@ -91,7 +91,7 @@ struct AdvancedBootdiskOptionsView {
 }

 impl AdvancedBootdiskOptionsView {
-    fn new(disks: &[Disk], options: &BootdiskOptions) -> Self {
+    fn new(avail_disks: &[Disk], options: &BootdiskOptions) -> Self {
         let enable_btrfs = crate::setup_info().config.enable_btrfs;

         let filter_btrfs = |fstype: &&FsType| -> bool { enable_btrfs || !fstype.is_btrfs() };
@@ -112,8 +112,8 @@ impl AdvancedBootdiskOptionsView {
                     .unwrap_or_default(),
             )
             .on_submit({
-                let disks = disks.to_owned();
-                move |siv, fstype| Self::fstype_on_submit(siv, &disks, fstype)
+                let avail_disks = avail_disks.to_owned();
+                move |siv, fstype| Self::fstype_on_submit(siv, &avail_disks, fstype)
             });

         let mut view = LinearLayout::vertical()
@@ -124,17 +124,17 @@ impl AdvancedBootdiskOptionsView {
         match &options.advanced {
             AdvancedBootdiskOptions::Lvm(lvm) => view.add_child(LvmBootdiskOptionsView::new(lvm)),
             AdvancedBootdiskOptions::Zfs(zfs) => {
-                view.add_child(ZfsBootdiskOptionsView::new(disks, zfs))
+                view.add_child(ZfsBootdiskOptionsView::new(avail_disks, zfs))
             }
             AdvancedBootdiskOptions::Btrfs(btrfs) => {
-                view.add_child(BtrfsBootdiskOptionsView::new(disks, btrfs))
+                view.add_child(BtrfsBootdiskOptionsView::new(avail_disks, btrfs))
             }
         };

         Self { view }
     }

-    fn fstype_on_submit(siv: &mut Cursive, disks: &[Disk], fstype: &FsType) {
+    fn fstype_on_submit(siv: &mut Cursive, avail_disks: &[Disk], fstype: &FsType) {
         siv.call_on_name("advanced-bootdisk-options-dialog", |view: &mut Dialog| {
             if let Some(AdvancedBootdiskOptionsView { view }) =
                 view.get_content_mut().downcast_mut()
@@ -142,15 +142,15 @@ impl AdvancedBootdiskOptionsView {
                 view.remove_child(3);
                 match fstype {
                     FsType::Ext4 | FsType::Xfs => view.add_child(LvmBootdiskOptionsView::new(
-                        &LvmBootdiskOptions::defaults_from(&disks[0]),
+                        &LvmBootdiskOptions::defaults_from(&avail_disks[0]),
                     )),
                     FsType::Zfs(_) => view.add_child(ZfsBootdiskOptionsView::new(
-                        disks,
-                        &ZfsBootdiskOptions::defaults_from(disks),
+                        avail_disks,
+                        &ZfsBootdiskOptions::defaults_from(avail_disks),
                     )),
                     FsType::Btrfs(_) => view.add_child(BtrfsBootdiskOptionsView::new(
-                        disks,
-                        &BtrfsBootdiskOptions::defaults_from(disks),
+                        avail_disks,
+                        &BtrfsBootdiskOptions::defaults_from(avail_disks),
                     )),
                 }
             }
@@ -164,7 +164,7 @@ impl AdvancedBootdiskOptionsView {
                         0,
                         SelectView::new()
                             .popup()
-                            .with_all(disks.iter().map(|d| (d.to_string(), d.clone()))),
+                            .with_all(avail_disks.iter().map(|d| (d.to_string(), d.clone()))),
                     );
                 }
                 other => view.replace_child(0, TextView::new(other.to_string())),
@@ -549,9 +549,18 @@ impl ViewWrapper for ZfsBootdiskOptionsView {
     cursive::wrap_impl!(self.view: MultiDiskOptionsView<FormView>);
 }

-fn advanced_options_view(disks: &[Disk], options_ref: BootdiskOptionsRef) -> impl View {
+/// Creates a dialog containing a [`AdvancedBootdiskOptionsView`] and handling confirmation of the
+/// dialog by saving the selected configuration in `options_ref`.
+///
+/// # Arguments
+///
+/// * `avail_disks` - Available disks for the user to select, with their usage depending on the
+///                   selected filesystem type
+/// * `options_ref` - A `BootdiskOptionsRef`, which is used to save the filesystem/RAID
+///                   configuration in after confirming the dialog.
+fn advanced_options_view(avail_disks: &[Disk], options_ref: BootdiskOptionsRef) -> impl View {
     Dialog::around(AdvancedBootdiskOptionsView::new(
-        disks,
+        avail_disks,
         &(*options_ref).borrow(),
     ))
     .title("Advanced bootdisk options")
--
2.41.0





  parent reply	other threads:[~2023-07-25 15:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 15:02 [pve-devel] [PATCH installer v2 0/3] fix #4856: tui: bootdisk: use correct defaults in advanced dialog Christoph Heiss
2023-07-25 15:02 ` [pve-devel] [PATCH installer v2 1/3] tui: bootdisk: refactor Rc<RefCell<..>> type into custom type Christoph Heiss
2023-07-25 15:02 ` Christoph Heiss [this message]
2023-07-25 15:02 ` [pve-devel] [PATCH installer v2 3/3] fix #4856: tui: bootdisk: use correct defaults in advanced dialog Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230725150300.1389135-3-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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