Skip to content

Commit

Permalink
bsc#1060172: improve dialog to add devices in bootloader order
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilson Souza committed Nov 21, 2017
1 parent 2c6b9d9 commit 22b2502
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
7 changes: 4 additions & 3 deletions package/yast2-bootloader.changes
@@ -1,8 +1,9 @@
-------------------------------------------------------------------
Thu Oct 26 12:51:47 UTC 2017 - gsouza@suse.com
Tue Nov 21 13:14:50 UTC 2017 - gsouza@suse.com

- bsc#1059757: use correct function to detect devices
- 4.0.3
- use correct function to detect devices (bsc#1059757)
- improve dialog to add devices in bootloader order (bsc#1060172)
- 4.0.5

-------------------------------------------------------------------
Fri Sep 15 11:54:25 UTC 2017 - jreidinger@suse.com
Expand Down
2 changes: 1 addition & 1 deletion package/yast2-bootloader.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-bootloader
Version: 4.0.3
Version: 4.0.5
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
39 changes: 35 additions & 4 deletions src/lib/bootloader/device_map_dialog.rb
@@ -1,8 +1,10 @@
require "yast"
require "y2storage"

Yast.import "BootStorage"
Yast.import "Label"
Yast.import "Popup"
Yast.import "Mode"

require "bootloader/device_map"

Expand Down Expand Up @@ -86,8 +88,12 @@ def handle_buttons(action, pos)
disks.delete_at(pos)
pos = pos == disks.size ? pos - 1 : pos
when :add
disk = add_device_popup
disks << disk if disk
if Yast::Mode.config || Yast::Mode.auto
disks_to_add = add_device_popup_ay_mode
else
disks_to_add = add_devices_popup
end
disks.concat disks_to_add
pos = disks.size - 1
end

Expand Down Expand Up @@ -145,6 +151,11 @@ def refresh_disks
Yast::UI.ChangeWidget(Id(:disks), :Items, disks)
end

def available_devices
staging = Y2Storage::StorageManager.instance.staging
staging.disk_devices.map(&:name)
end

def store_order
Yast::BootStorage.assign_mbr_disk_by_name(disks.first)

Expand All @@ -154,7 +165,7 @@ def store_order
end
end

def add_device_popup
def add_device_popup_ay_mode
popup = VBox(
VSpacing(1),
# textentry header
Expand All @@ -172,7 +183,27 @@ def add_device_popup
new_dev = Yast::UI.QueryWidget(Id(:devname), :Value)
Yast::UI.CloseDialog

pushed == :ok ? new_dev : nil
pushed == :ok ? [new_dev] : []
end

def add_devices_popup
devices = available_devices - disks
popup = VBox(
MultiSelectionBox(
Id(:devnames),
"&Devices:",
devices
),
ending_buttons,
VSpacing(1)
)
Yast::UI.OpenDialog(popup)
Yast::UI.SetFocus(:devnames)
pushed = Yast::UI.UserInput
new_devs = Yast::UI.QueryWidget(Id(:devnames), :SelectedItems)
Yast::UI.CloseDialog

pushed == :ok ? new_devs : []
end

def selected_disk_index
Expand Down
18 changes: 18 additions & 0 deletions test/device_map_dialog_test.rb
Expand Up @@ -39,6 +39,24 @@ def mock_ui_events(*events)
it "allows adding disks after clicking on button" do
# need additional ok for adding dialog
mock_ui_events(:add, :ok, :ok)
allow(Yast::UI).to receive(:QueryWidget).with(anything, :SelectedItems)
.and_return(["/dev/sda", "/dev/sda", "/dev/sdb"])

expect(subject.run).to eq :back
end

it "allows adding disks in config mode after clicking on button" do
# need additional ok for adding dialog
mock_ui_events(:add, :ok, :ok)
allow(Yast::Mode).to receive(:config).and_return(true)

expect(subject.run).to eq :back
end

it "allows adding disks in auto mode after clicking on button" do
# need additional ok for adding dialog
mock_ui_events(:add, :ok, :ok)
allow(Yast::Mode).to receive(:auto).and_return(true)

expect(subject.run).to eq :back
end
Expand Down

0 comments on commit 22b2502

Please sign in to comment.