Skip to content

Commit

Permalink
Use a base class for partition sections tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed May 19, 2020
1 parent 373b0d5 commit c40d0da
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 236 deletions.
58 changes: 13 additions & 45 deletions src/lib/autoinstall/widgets/storage/partition_general_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require "cwm/tabs"
require "cwm/replace_point"
require "cwm/common_widgets"
require "autoinstall/widgets/storage/partition_tab"
require "autoinstall/widgets/storage/common_partition_attrs"
require "autoinstall/widgets/storage/lvm_partition_attrs"
require "autoinstall/widgets/storage/not_lvm_partition_attrs"
Expand All @@ -30,59 +31,24 @@ module Y2Autoinstallation
module Widgets
module Storage
# The tab used to present the general and common options for a partition section
class PartitionGeneralTab < ::CWM::Tab
# Constructor
#
# @param partition [Presenters::Partition] presenter for a partition section of the profile
def initialize(partition)
textdomain "autoinst"

@partition = partition
end

class PartitionGeneralTab < PartitionTab
# @macro seeAbstractWidget
def label
# TRANSLATORS: name of the tab to display common options
_("General")
end

def contents
MarginBox(
0.4,
0.4,
VBox(
common_partition_attrs,
VSpacing(0.5),
section_related_attrs,
VSpacing(0.5),
encryption_attrs,
VStretch()
)
)
end

# @macro seeAbstractWidget
def values
relevant_widgets.reduce({}) do |hsh, widget|
hsh.merge(widget.values)
end
end

# @macro seeAbstractWidget
def store
partition.update(values)
nil
# @see PartitionTab#visible_widgets
def visible_widgets
[
common_partition_attrs,
section_related_attrs,
encryption_attrs
]
end

private

# @return [Presenters::Partition] presenter for the partition section
attr_reader :partition

# Convenience method to retrieve all widgets holding profile attributes
#
# @return [Array<CWW::CustomWidget>]
def relevant_widgets
# @see PartitionTab#widgets
def widgets
[
common_partition_attrs,
lvm_partition_attrs,
Expand All @@ -91,6 +57,8 @@ def relevant_widgets
]
end

private

# Convenience method to display attributes related to the drive type
def section_related_attrs
if partition.logical_volume?
Expand Down
90 changes: 90 additions & 0 deletions src/lib/autoinstall/widgets/storage/partition_tab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# 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/tabs"
require "cwm/replace_point"
require "cwm/common_widgets"

module Y2Autoinstallation
module Widgets
module Storage
# Base class to create tabs for organizing the partition section attributes
class PartitionTab < ::CWM::Tab
# Constructor
#
# @param partition [Presenters::Partition] presenter for a partition section of the profile
def initialize(partition)
textdomain "autoinst"

@partition = partition
end

# @macro seeAbstractWidget
def label
""
end

def contents
MarginBox(
0.4,
0.4,
VBox(
*visible_widgets.flat_map { |widget| [Left(widget), VSpacing(0.5)] }.tap(&:pop),
VStretch()
)
)
end

# @macro seeAbstractWidget
def store
attrs = widgets.reduce({}) { |result, widget| result.merge(widget.values) }
partition.update(attrs)
nil
end

# Return widgets to be shown
#
# This method must be defined by derived tabs
#
# @return [Array<Yast::Term, CWM::AbstractWidget]
def visible_widgets
[]
end

# Returns all widgets managed by the tab
#
# This method must be defined by derived tabs since it is needed by the #store method to
# properly update the partition section setting only relevant attributes.
#
# @see Presenters::Section#update
#
# @return [Array<Yast::Term, CWM::AbstractWidget]
def widgets
[]
end

private

# @return [Presenters::Partition] presenter for the partition section
attr_reader :partition
end
end
end
end
50 changes: 13 additions & 37 deletions src/lib/autoinstall/widgets/storage/partition_usage_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require "cwm/tabs"
require "cwm/replace_point"
require "cwm/common_widgets"
require "autoinstall/widgets/storage/partition_tab"
require "autoinstall/widgets/storage/filesystem_attrs"
require "autoinstall/widgets/storage/raid_attrs"
require "autoinstall/widgets/storage/lvm_pv_attrs"
Expand All @@ -33,14 +34,12 @@ module Widgets
module Storage
# Tab to manage the partition section options that depend on its usage (file system, LVM PV,
# RAID member, etc).
class PartitionUsageTab < ::CWM::Tab
class PartitionUsageTab < PartitionTab
# Constructor
#
# @param partition [Presenters::Partition] presenter for a partition section of the profile
def initialize(partition)
textdomain "autoinst"

@partition = partition
super
self.handle_all_events = true
end

Expand All @@ -50,19 +49,6 @@ def label
_("Used As")
end

def contents
MarginBox(
0.4,
0.4,
VBox(
Left(used_as_widget),
VSpacing(0.5),
replace_point,
VStretch()
)
)
end

# @macro seeAbstractWidget
def init
used_as_widget.value = partition.usage
Expand All @@ -76,28 +62,16 @@ def handle(event)
nil
end

# @macro seeAbstractWidget
def values
relevant_widgets.reduce({}) do |hsh, widget|
hsh.merge(widget.values)
end
end

# @macro seeAbstractWidget
def store
partition.update(values)
nil
# @see PartitionTab#visible_widgets
def visible_widgets
[
Left(used_as_widget),
replace_point
]
end

private

# @return [Presenters::Partition] presenter for the partition section
attr_reader :partition

# Convenience method to retrieve all widgets holding profile attributes
#
# @return [Array<CWW::CustomWidget>]
def relevant_widgets
# @see PartitionTab#widgets
def widgets
[
filesystem_widget,
raid_widget,
Expand All @@ -107,6 +81,8 @@ def relevant_widgets
]
end

private

# Widget grouping related file system attributes
def filesystem_widget
@filesystem_widget ||= FilesystemAttrs.new(partition)
Expand Down
Loading

0 comments on commit c40d0da

Please sign in to comment.