Skip to content

Commit

Permalink
Merge ce6ff7e into 9c04bc3
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Mar 13, 2020
2 parents 9c04bc3 + ce6ff7e commit efe4ce0
Show file tree
Hide file tree
Showing 11 changed files with 938 additions and 660 deletions.
10 changes: 10 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Thu Mar 12 14:11:54 UTC 2020 - David Diaz <dgonzalez@suse.com>

- Improves the addons selection dialog:
- Avoid the scroll reset after (un)selecting and addon
(bsc#1049965).
- Avoid the need to(un)select an addon to see its description
(bsc#1161200).
- 4.2.36

-------------------------------------------------------------------
Tue Feb 18 16:34:38 UTC 2020 - Knut Anderssen <kanderssen@suse.com>

Expand Down
10 changes: 5 additions & 5 deletions package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 4.2.35
Version: 4.2.36
Release: 0
Summary: YaST2 - Registration Module
License: GPL-2.0-only
Expand All @@ -27,8 +27,8 @@ Url: https://github.com/yast/yast-registration
Source0: %{name}-%{version}.tar.bz2

BuildRequires: update-desktop-files
# Y2Packager::Product#version_version
BuildRequires: yast2 >= 4.2.59
# CWM::MultiStatusSelector
BuildRequires: yast2 >= 4.2.72
BuildRequires: yast2-devtools >= 4.2.2
BuildRequires: yast2-slp >= 3.1.9
BuildRequires: rubygem(%{rb_default_ruby_abi}:rspec)
Expand All @@ -39,8 +39,8 @@ BuildRequires: yast2-packager >= 4.2.37
BuildRequires: yast2-update >= 3.1.36


# Y2Packager::Product#version_version
Requires: yast2 >= 4.2.59
# CWM::MultiStatusSelector
Requires: yast2 >= 4.2.72
# "dupAllowVendorChange" option in Pkg.SetSolverFlags()
Requires: yast2-pkg-bindings >= 3.1.34
# N_() method
Expand Down
4 changes: 2 additions & 2 deletions src/lib/registration/clients/inst_scc.rb
Expand Up @@ -36,8 +36,8 @@
require "registration/url_helpers"
require "registration/registration"
require "registration/registration_ui"
require "registration/dialogs/addons_selection"
require "registration/ui/addon_eula_dialog"
require "registration/ui/addon_selection_registration_dialog"
require "registration/ui/addon_reg_codes_dialog"
require "registration/ui/registered_system_dialog"
require "registration/ui/base_system_registration_dialog"
Expand Down Expand Up @@ -148,7 +148,7 @@ def select_addons
# FIXME: workaround to reference between old way and new storage in Addon metaclass
@selected_addons = Registration::Addon.selected
::Registration::Storage::InstallationOptions.instance.selected_addons = @selected_addons
Registration::UI::AddonSelectionRegistrationDialog.run(@registration)
Registration::Dialogs::AddonsSelection.run(@registration)
end

# load available addons from SCC server
Expand Down
182 changes: 182 additions & 0 deletions src/lib/registration/dialogs/addons_selection.rb
@@ -0,0 +1,182 @@
# 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/dialog"
require "registration/addon"
require "registration/addon_sorter"
require "registration/ui/abort_confirmation"
require "registration/widgets/addons_selector"

module Registration
module Dialogs
# A dialog in charge to display the addons selection for registered products
class AddonsSelection < CWM::Dialog
Yast.import "Stage"

# @return [Registration::Registration] the object handling the communication with SCC
attr_reader :registration

# Constructor
#
# @param registration [Registration::Registration]
def initialize(registration)
textdomain "registration"

@available_addons = Addon.find_all(registration).sort(&::Registration::ADDON_SORTER)
@initial_addons_selection = Addon.selected.dup

preselect_recommended_addons
end

# @macro seeDialog
def title
_("Extension and Module Selection")
end

# @macro seeDialog
def contents
VBox(
Left(Heading(_("Available Extensions and Modules"))),
addons_selector_widget
)
end

# @macro seeDialog
def run
ret = super until continue_actions.include?(ret)

case ret
when :next
ret = handle_next_action
when :cancel, :abort
ret = handle_cancel_action
end

ret
end

# Handles the cancel action
#
# @return [nil, :abort] nil if user regrets about canceling; :abort otherwise
def handle_cancel_action
return nil if Yast::Stage.initial && !UI::AbortConfirmation.run

restore_selection
:abort
end

# Handles the next action
#
# This action will be canceled if there are selected too many addons requiring a registration
# code.
#
# @see #supported_addon_count
#
# @return [nil, :skip, :abort] nil if there are too many addons requiring a registration code;
# :skip when there are no selected addons;
# :next otherwise
def handle_next_action
return nil unless supported_addon_count?

selected_addons = Addon.selected

log.info "Selected addons: #{selected_addons.map(&:name)}"

return :skip if selected_addons.empty?
:next
end

# @return [Array<Symbol>]
def continue_actions
@continue_actions ||= [:next, :back, :cancel, :abort, :skip]
end

# @macro seeDialog
def help
[
_("<p>Here you can select available extensions and modules for your system.</p>"),
_("<p>Please note, that some extensions or modules might need "\
"specific registration code.</p>"),
_("<p>If you want to remove any extension or module you need to log "\
"into the SUSE Customer Center and remove them manually there.</p>"),
_("<p>The extensions and modules can have several states depending on " \
"how they were selected to be installed or not (see the legend below). Note "\
"that an extension or module can be selected by the user, pre-selected as a "\
"recommended addon, or auto selected as a dependency of another extension "\
"or module.</p>")
].join
end

private

# @return [Array<Addon>] List of available addons
attr_reader :available_addons

# @return [Array<Addon>] List of initially selected addons
attr_reader :initial_addons_selection

# Addons selector widget
#
# @return [Registration::Widgets::AddonsSelector]
def addons_selector_widget
@addons_selector_widget ||= ::Registration::Widgets::AddonsSelector.new(available_addons)
end

# Restores selected addons to the initial selection
#
# @see @initial_addons_selection
def restore_selection
Addon.selected.replace(initial_addons_selection)
end

# Max number of registration codes that can be displayed vertically in an 80x25 ncurses UI
MAX_REGCODES_PER_COLUMN = 8
private_constant :MAX_REGCODES_PER_COLUMN

# Whether the number of required registration codes are within the limit
#
# @return [Boolean] true if number of the required registration codes fits the maximum limit
def supported_addon_count?
# Maximum number or reg codes which can be displayed in two column layout
max_supported = 2 * MAX_REGCODES_PER_COLUMN
# Addons requiring a registration code
requiring_reg_codes = Addon.selected.count { |a| a.registered? && a.free }

if requiring_reg_codes > max_supported
Report.Error(_("YaST allows to select at most %s extensions or modules.") % max_supported)
return false
end

true
end

# Pre-selects recommended addons if there is none selected/registered yet
def preselect_recommended_addons
return if Addon.selected.any? || Addon.registered.any?

available_addons.each do |a|
next unless a.recommended
log.info("Preselecting a default addon: #{a.friendly_name}")
a.selected
end
end
end
end
end

0 comments on commit efe4ce0

Please sign in to comment.