Skip to content

Commit

Permalink
improved repository selection dialog
Browse files Browse the repository at this point in the history
display details in a separate widget below the main selection widget
  • Loading branch information
lslezak committed Aug 17, 2015
1 parent 9f68732 commit a83a177
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 49 deletions.
12 changes: 0 additions & 12 deletions src/lib/registration/addon_sorter.rb
Expand Up @@ -27,16 +27,4 @@ module Registration
x.name <=> y.name
end
end

# sort the migration products
# first the extensions, then the base product, modules at the end
MIGRATION_SORTER = proc do |x, y|
if x.base != y.base
# base at the end
x.base ? 1 : -1
else
# sort the groups by name
x.name <=> y.name
end
end
end
16 changes: 16 additions & 0 deletions src/lib/registration/migration_sorter.rb
@@ -0,0 +1,16 @@

module Registration
# sort the migration products
# first the extensions, then the base product, modules at the end
# TODO: merge with ADDON_SORTER when SCC provides "free" and "product_type"
# attributes
MIGRATION_SORTER = proc do |x, y|
if x.base != y.base
# base at the end
x.base ? 1 : -1
else
# sort the groups by name
x.name <=> y.name
end
end
end
4 changes: 2 additions & 2 deletions src/lib/registration/registration_ui.rb
Expand Up @@ -102,7 +102,7 @@ def update_base_product
product_service = Yast::Popup.Feedback(
_(CONTACTING_MESSAGE),
# updating base product registration, %s is a new base product name
_("Updating to %s ...") % SwMgmt.base_product_label(
_("Updating to %s ...") % SwMgmt.product_label(
SwMgmt.find_base_product)
) do
registration.upgrade_product(base_product)
Expand Down Expand Up @@ -233,7 +233,7 @@ def register_base_product
base_product = SwMgmt.find_base_product

Yast::Popup.Feedback(_(CONTACTING_MESSAGE),
_("Registering %s ...") % SwMgmt.base_product_label(base_product)
_("Registering %s ...") % SwMgmt.product_label(base_product)
) do
base_product_data = SwMgmt.base_product_to_register
base_product_data["reg_code"] = options.reg_code
Expand Down
2 changes: 1 addition & 1 deletion src/lib/registration/sw_mgmt.rb
Expand Up @@ -137,7 +137,7 @@ def self.remote_product(product)
# create UI label for a base product
# @param base_product [Hash] Product (hash from pkg-bindings)
# @return [String] UI Label
def self.base_product_label(base_product)
def self.product_label(base_product)
base_product["display_name"] ||
base_product["short_name"] ||
base_product["name"] ||
Expand Down
2 changes: 1 addition & 1 deletion src/lib/registration/ui/base_system_registration_dialog.rb
Expand Up @@ -112,7 +112,7 @@ def product_details_widgets
HSquash(
VBox(
VSpacing(1),
Left(Heading(SwMgmt.base_product_label(SwMgmt.find_base_product))),
Left(Heading(SwMgmt.product_label(SwMgmt.find_base_product))),
VSpacing(1),
Registration.is_registered? ? Heading(_("The system is already registered.")) :
Label(info)
Expand Down
48 changes: 35 additions & 13 deletions src/lib/registration/ui/migration_repos_selection_dialog.rb
Expand Up @@ -48,17 +48,25 @@ def run
dialog_content,
# TRANSLATORS: help text
_("<p>In this dialog you can manually select which repositories will" \
"be used for online migration. The packages will be upgraded to the" \
"highest version found in the selected repositories.</p>"),
"be used for online migration. The packages will be upgraded to the" \
"highest version found in the selected repositories.</p>"),
true,
true
)

update_repo_details

loop do
ret = Yast::UI.UserInput

store_values if ret == :next
repo_mgmt if ret == :repo_mgmt
case ret
when :next
store_values
when :repo_mgmt
repo_mgmt
when :repos
update_repo_details
end

return ret if [:next, :back, :cancel, :abort].include?(ret)
end
Expand All @@ -72,9 +80,11 @@ def run
# @return [Yast::Term] UI term
def dialog_content
VBox(
MultiSelectionBox(Id(:repos), Opt(:vstretch),
VWeight(75, MultiSelectionBox(Id(:repos), Opt(:vstretch, :notify),
# TRANSLATORS: Multiselection widget label
_("Select the Migration Repositories"), repo_items
),
)),
MinHeight(6, VWeight(25, RichText(Id(:details), ""))),
# TRANSLATORS: Push button label, starts the repository management module
PushButton(Id(:repo_mgmt), _("Manage Repositories..."))
)
Expand All @@ -94,16 +104,28 @@ def repo_items
end

repos.map do |repo|
Item(Id(repo), repo_label(repo), Yast::Pkg.SourceGeneralData(repo)["enabled"])
repo_props = Yast::Pkg.SourceGeneralData(repo)
Item(Id(repo), repo_props["name"], repo_props["enabled"])
end
end

# repository label, displayed in the MultiSelectionBox widget
# @param [Hash] repository data
# @return [String] label
def repo_label(repo)
repo_data = Yast::Pkg.SourceGeneralData(repo)
"#{repo_data["name"]} (#{repo_data["url"]})"
def repo_details(repo)
# TRANSLATORS: summary text, %s is a repository URL
url_label = _("URL: %s") % repo["url"]
# TRANSLATORS: summary text, %s is a repository priority (1-99)
priority_label = _("Priority: %s") % repo["priority"]

"<p><b><big>#{repo["name"]}</big></b></p><p>#{url_label}<br>#{priority_label}</p>"
end

def update_repo_details
log.debug "Currently selected item: #{Yast::UI.QueryWidget(:repos, :CurrentItem)}"
current = Yast::UI.QueryWidget(:repos, :CurrentItem)

return unless current

Yast::UI.ChangeWidget(Id(:details), :Value,
repo_details(Yast::Pkg.SourceGeneralData(current)))
end

# activate the selection in the dialog
Expand Down
6 changes: 3 additions & 3 deletions src/lib/registration/ui/migration_repos_workflow.rb
Expand Up @@ -52,6 +52,7 @@ def initialize
# The repositories migration workflow is:
#
# - find all installed products
# - TODO: add the registered products
# - ask the registration server for the available product migrations
# - user selects the migration target
# - the registered products are upgraded and new services/repositories
Expand Down Expand Up @@ -188,17 +189,16 @@ def load_migration_products
def select_migration_products
log.info "Displaying migration target selection dialog"
installed_products = SwMgmt.installed_products
log.warn "installed_products: #{installed_products.inspect}"
log.warn "installed_products: #{installed_products.map { |p| p["name"] }.inspect}"
log.info "installed_products: #{installed_products}"
dialog = MigrationSelectionDialog.new(migrations, installed_products)
ret = dialog.run

if ret == :next
self.selected_migration = dialog.selected_migration
self.manual_repo_selection = dialog.manual_repo_selection
log.info "Selected migration: #{selected_migration}"
end

log.info "Selected migration: #{selected_migration}"
ret
end

Expand Down
17 changes: 8 additions & 9 deletions src/lib/registration/ui/migration_selection_dialog.rb
Expand Up @@ -15,7 +15,8 @@
require "cgi/util"

require "yast"
require "registration/addon_sorter"
require "registration/migration_sorter"
require "registration/sw_mgmt"

module Registration
module UI
Expand Down Expand Up @@ -151,8 +152,6 @@ def migration_details(idx)
end

def product_summary(product, installed_product)
log.info "creating summary for: #{product}, installed_product: #{installed_product}"

product_name = CGI.escapeHTML(product.friendly_name)

if !installed_product
Expand All @@ -162,18 +161,18 @@ def product_summary(product, installed_product)
return _("%s <b>will be installed.</b>") % product_name
end

if installed_product["version_version"] == product.version
installed_version = installed_product["version_version"]

if installed_version == product.version
# TRANSLATORS: Summary message, rich text format
# %s is a product name, e.g. "SUSE Linux Enterprise Server 12"
return _("%s <b>stays unchanged.</b>") % product_name
end

installed_version = Gem::Version.new(installed_product["version_version"])
migrated_version = Gem::Version.new(product.version)
old_product_name = installed_product["display_name"] || installed_product["summary"] ||
installed_product["short_name"] || installed_product["name"]
old_product_name = SwMgmt.product_label(installed_product)

if installed_version < migrated_version
# use Gem::Version for version compare
if Gem::Version.new(installed_version) < Gem::Version.new(product.version)
# TRANSLATORS: Summary message, rich text format
# %{old_product} is a product name, e.g. "SUSE Linux Enterprise Server 12"
# %{new_product} is a product name, e.g. "SUSE Linux Enterprise Server 12 SP1 x86_64"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/migration_to_sles12_sp1.yml
Expand Up @@ -5,3 +5,4 @@
:version: '12.1'
:arch: x86_64
:release_type:
:friendly_name: SUSE Linux Enterprise Server SP1 x86_64
7 changes: 4 additions & 3 deletions test/migration_repos_selection_dialog_test.rb
Expand Up @@ -12,13 +12,14 @@
"name" => "name", "url" => "https://example.com", "enabled" => false)
allow(Yast::Pkg).to receive(:SourceGeneralData).with(1).and_return(
"name" => "name2", "url" => "https://example2.com", "enabled" => true)
allow(Yast::UI).to receive(:QueryWidget).with(:repos, :CurrentItem).and_return(0)

# check the displayed content
expect(Yast::Wizard).to receive(:SetContents) do |_title, content, _help, _back, _next|
term = content.nested_find do |t|
t.respond_to?(:value) && t.value == :MultiSelectionBox &&
t.params[3].include?(Item(Id(0), "name (https://example.com)", false)) &&
t.params[3].include?(Item(Id(1), "name2 (https://example2.com)", true))
t.params[3].include?(Item(Id(0), "name", false)) &&
t.params[3].include?(Item(Id(1), "name2", true))
end

expect(term).to_not eq(nil)
Expand Down Expand Up @@ -49,7 +50,7 @@
expect(Yast::WFM).to receive(:call).with("repositories", ["refresh-enabled"])
.and_return(:next)

expect(Yast::UI).to receive(:ChangeWidget)
expect(Yast::UI).to receive(:ChangeWidget).twice

expect(subject.run).to eq(:abort)
end
Expand Down
4 changes: 2 additions & 2 deletions test/migration_repos_workflow_spec.rb
Expand Up @@ -39,7 +39,7 @@

let(:set_success_expectations) do
# installed SLES12
expect(Registration::SwMgmt).to receive(:installed_products)
allow(Registration::SwMgmt).to receive(:installed_products)
.and_return([load_yaml_fixture("products_legacy_installation.yml")[1]])

expect_any_instance_of(Registration::RegistrationUI).to receive(:migration_products)
Expand Down Expand Up @@ -111,7 +111,7 @@

it "reports error and aborts when registering the migration products fails" do
# installed SLES12
expect(Registration::SwMgmt).to receive(:installed_products)
allow(Registration::SwMgmt).to receive(:installed_products)
.and_return([load_yaml_fixture("products_legacy_installation.yml")[1]])

expect_any_instance_of(Registration::RegistrationUI).to receive(:migration_products)
Expand Down
6 changes: 3 additions & 3 deletions test/migration_selection_dialog_test.rb
Expand Up @@ -14,7 +14,7 @@

# check the displayed content
expect(Yast::Wizard).to receive(:SetContents) do |_title, content, _help, _back, _next|
expected_list_item = Item(Id(0), "SLES-12.1-x86_64")
expected_list_item = Item(Id(0), "SLES-12.1")

term = content.nested_find do |t|
t.respond_to?(:value) && t.value == :MinHeight &&
Expand All @@ -25,7 +25,7 @@
expect(term).to_not eq(nil)
end

expect(subject.run(migration_products)).to eq(:abort)
expect(subject.run(migration_products, [])).to eq(:abort)
end

it "saves the entered values when clicking Next" do
Expand All @@ -35,7 +35,7 @@
.and_return(0).twice
expect(Yast::UI).to receive(:QueryWidget).with(:manual_repos, :Value).and_return(true)

dialog = subject.new(migration_products)
dialog = subject.new(migration_products, [])
expect(dialog.run).to eq(:next)

# check the saved values
Expand Down

0 comments on commit a83a177

Please sign in to comment.