Skip to content

Commit

Permalink
Merge pull request #592 from yast/new-storage-ui-initial
Browse files Browse the repository at this point in the history
Storage UI: initial steps
  • Loading branch information
imobachgs committed Apr 14, 2020
2 parents c80e6d7 + 368bd97 commit 6fd809d
Show file tree
Hide file tree
Showing 28 changed files with 1,587 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -43,3 +43,4 @@ package/autoyast2-*.bz2
/.yardoc
/coverage
/test-driver

2 changes: 2 additions & 0 deletions package/autoyast2.spec
Expand Up @@ -281,6 +281,8 @@ done
%dir %{yast_libdir}/autoinstall/dialogs
%{yast_libdir}/autoinstall/dialogs/*.rb

%{yast_libdir}/autoinstall/widgets

%dir %{yast_libdir}/autoinstall/clients
%{yast_libdir}/autoinstall/clients/*.rb

Expand Down
29 changes: 25 additions & 4 deletions src/clients/storage_auto.rb
Expand Up @@ -2,8 +2,11 @@
# Package: Autoinstallation Configuration System
# Summary: Storage
# Authors: Anas Nashif<nashif@suse.de>
#
# $Id$

require "autoinstall/dialogs/storage"
require "y2storage/storage_manager"
require "y2storage/autoinst_profile/partitioning_section"

module Yast
class StorageAutoClient < Client
include Yast::Logger
Expand Down Expand Up @@ -60,8 +63,11 @@ def main
@ret = []
# Change configuration (run AutoSequence)
elsif @func == "Change"
@ret = StorageDialog()
UI.CloseDialog
storage_dialog = build_storage_dialog
@ret = storage_dialog.run
# After succesfully editing the storage settings, import the result as
# the new partition plan.
AutoinstPartPlan.Import(storage_dialog.partitioning.to_hashes) if @ret == :next
# Return actual state
elsif @func == "Export"
@ret = AutoinstPartPlan.Export
Expand All @@ -83,6 +89,21 @@ def main

# EOF
end

private

# Returns a dialog to edit the storage
#
# It uses the current partition plan.
#
# @return [Y2Storage::Dialogs::Storage] Storage dialog
def build_storage_dialog
part_plan = AutoinstPartPlan.Export
# FIXME: workaround to avoid crashing the dialog
part_plan = [{ "type" => :CT_DISK }] if part_plan.empty?
partitioning = Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes(part_plan)
Y2Autoinstallation::Dialogs::Storage.new(partitioning)
end
end
end

Expand Down
108 changes: 108 additions & 0 deletions src/lib/autoinstall/dialogs/storage.rb
@@ -0,0 +1,108 @@
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "cwm"
require "cwm/dialog"
require "autoinstall/widgets/storage/overview_tree_pager"
require "autoinstall/storage_controller"

Yast.import "Label"
Yast.import "Popup"

module Y2Autoinstallation
module Dialogs
# Dialog to set up the partition plan
#
# @example Edit a partitioning section
# devicegraph = devicegraph = Y2Storage::StorageManager.instance.probed
# partitioning = Y2Storage::Autoinst::PartitioningSection.new_from_storage(devicegraph)
# result = Y2Autoinstallation::Dialogs::Storage.new.run
#
# @example Start with an empty section
# result = Y2Autoinstallation::Dialogs::Storage.new
class Storage < CWM::Dialog
# @return [Y2Storage::AutoinstProfile::PartitioningSection]
# Partitioning section of the profile
attr_reader :partitioning

# Constructor
#
# @param partitioning [Y2Storage::AutoinstProfile::PartitioningSection]
# Partitioning section of the profile
def initialize(partitioning = Y2Storage::AutoinstProfile::PartitioningSection.new)
textdomain "autoinst"
@controller = Y2Autoinstallation::StorageController.new(partitioning)
end

# @macro seeDialog
def contents
MarginBox(
0.5,
0.5,
Y2Autoinstallation::Widgets::Storage::OverviewTreePager.new(controller)
)
end

# @macro seeDialog
def next_button
Yast::Label.FinishButton
end

# @macro seeDialog
def abort_button
""
end

# @macro seeDialog
def back_button
Yast::Label.CancelButton
end

# @macro seeDialog
def next_handler
@partitioning = controller.partitioning
true
end

# @macro seeDialog
def back_handler
Yast::Popup.ReallyAbort(controller.modified?)
end

def should_open_dialog?
true
end

private

attr_reader :controller

# CWM show loop
#
# This method is redefined to keep the dialog in a loop if a
# `redraw` is needed.
def cwm_show
loop do
result = super
return result if result != :redraw
end
end
end
end
end
69 changes: 69 additions & 0 deletions src/lib/autoinstall/storage_controller.rb
@@ -0,0 +1,69 @@
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "y2storage"

module Y2Autoinstallation
# Controller for the editing the partitioning section of a profile
#
# It is supposed to be used internally by
# {Y2Autoinstallation::Dialogs::Storage}.
class StorageController
# @return [Y2Storage::AutoinstProfile::PartitioningSection]
# Partition section
attr_reader :partitioning

# Constructor
#
# @param partitioning [Y2Storage::AutoinstProfile::PartitioningSection]
# Partitioning section of the profile
def initialize(partitioning)
@partitioning = partitioning
@modified = false
end

TYPES_MAP = {
disk: :CT_DISK
}.freeze

# Adds a new drive section of the given type
#
# @param type [Symbol]
def add_drive(type)
section = Y2Storage::AutoinstProfile::DriveSection.new_from_hashes(type: TYPES_MAP[type])
partitioning.drives << section
end

# Adds a new partition section under the given section
#
# @param parent [Y2Storage::AutoinstProfile::DriveSection] Parent section
def add_partition(parent)
parent.partitions << Y2Storage::AutoinstProfile::PartitionSection.new
end

# It determines whether the profile was modified
#
# @todo Implement logic to detect whether the partitioning
# was modified or not.
def modified?
true
end
end
end
33 changes: 33 additions & 0 deletions src/lib/autoinstall/ui_state.rb
@@ -0,0 +1,33 @@
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "cwm/ui_state"

module Y2Autoinstallation
# Singleton class to keep the position of the user in the UI and other similar
# information that needs to be rememberd across UI redraws to give the user a
# sense of continuity.
class UIState < CWM::UIState
# @see CWM::UIState#textdomain_name
def textdomain_name
"autoinst"
end
end
end
28 changes: 28 additions & 0 deletions src/lib/autoinstall/widgets.rb
@@ -0,0 +1,28 @@
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

# Work around YARD inability to link across repos/gems:
# @!macro [new] seeAbstractWidget
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM%2FAbstractWidget:${0}
# @!macro [new] seeCustomWidget
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM%2FCustomWidget:${0}
# @!macro [new] seeDialog
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM%2FDialog:${0}
# @!macro [new] seeComboBox
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM%2FComboBox:${0}
69 changes: 69 additions & 0 deletions src/lib/autoinstall/widgets/storage/add_children_button.rb
@@ -0,0 +1,69 @@
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "cwm/common_widgets"

module Y2Autoinstallation
module Widgets
module Storage
# This class provides a button to add 'partition' sections
#
# In an AutoYaST profile, a 'partition' section is used to define a
# partition, a logical volume, a RAID member, etc.
class AddChildrenButton < CWM::PushButton
extend Yast::I18n

# Constructor
#
# @param controller [Y2Autoinstallation::StorageController] UI controller
# @param section [Y2Storage::AutoinstProfile::DriveSection] Drive section of the profile
def initialize(controller, section)
textdomain "autoinst"
@controller = controller
@section = section
end

TYPE_LABELS = {
CT_DISK: N_("Partition")
}.freeze

def label
type_label = _(TYPE_LABELS[section.type])
format(_("Add %{type_label}"), type_label: type_label)
end

# @macro seeAbstractWidget
def handle
# FIXME: the controller could keep track of the current section
controller.add_partition(section)
:redraw
end

private

# @return [Y2Autoinstallation::StorageController]
attr_reader :controller

# @return [Y2Storage::AutoinstProfile::DriveSection]
attr_reader :section
end
end
end
end

0 comments on commit 6fd809d

Please sign in to comment.