Skip to content

Commit

Permalink
sort displayed addons (bnc#888567)
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Sep 4, 2014
1 parent 78d5375 commit eb4bb64
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/registration/addon.rb
Expand Up @@ -77,6 +77,7 @@ def create_addon_with_deps(root)
:friendly_name,
:identifier,
:name,
:product_type,
:release_type,
:version

Expand Down
21 changes: 21 additions & 0 deletions src/lib/registration/addon_sorter.rb
@@ -0,0 +1,21 @@

module Registration

# Sorter for sorting Addons in required display order
# (first paid extensions, then free extensions, modules at the end
# see https://bugzilla.novell.com/show_bug.cgi?id=888567#c21)
ADDON_SORTER = Proc.new do |x, y|
if x.product_type != y.product_type
# simplification: "extension" is lexicographically before "module"
# as requested in the display order so take advantage of this...
x.product_type.to_s <=> y.product_type.to_s
elsif x.free != y.free
# paid (non-free) first
x.free ? 1 : -1
else
# sort the groups by name
x.name <=> y.name
end
end

end
5 changes: 5 additions & 0 deletions src/lib/registration/ui/addon_selection_dialog.rb
@@ -1,6 +1,7 @@

require "yast"
require "registration/addon"
require "registration/addon_sorter"

module Registration
module UI
Expand Down Expand Up @@ -28,6 +29,10 @@ def self.run(registration)
def initialize(registration)
textdomain "registration"
@addons = Addon.find_all(registration)

# sort the addons
@addons.sort!(&::Registration::ADDON_SORTER)

log.info "Available addons: #{@addons}"
end

Expand Down
20 changes: 20 additions & 0 deletions test/addon_sorter_spec.rb
@@ -0,0 +1,20 @@
#! /usr/bin/env rspec

require_relative "spec_helper"

require "yaml"
require "registration/addon"
require "registration/addon_sorter"

describe "Registration::ADDON_SORTER" do
let(:available_addons) { YAML.load_file(fixtures_file("available_addons.yml")) }

it "sorts the addons in display order" do
expected = ["sle-hae", "sle-ha-geo", "sle-sdk", "sle-we",
"sle-module-adv-systems-management", "sle-module-legacy",
"sle-module-public-cloud", "sle-module-web-scripting"]

expect(available_addons.sort(&Registration::ADDON_SORTER).map(&:identifier)).to eql(expected)
end

end
8 changes: 8 additions & 0 deletions test/fixtures/available_addons.yml
Expand Up @@ -7,6 +7,7 @@
:identifier: sle-we
:version: '12'
:release_type:
:product_type: 'extension'
:arch: x86_64
:friendly_name: SUSE Linux Enterprise Workstation Extension 12 x86_64
:product_class:
Expand Down Expand Up @@ -54,6 +55,7 @@
:identifier: sle-sdk
:version: '12'
:release_type:
:product_type: 'extension'
:arch: x86_64
:friendly_name: SUSE Linux Enterprise Software Development Kit 12 x86_64
:product_class:
Expand Down Expand Up @@ -98,6 +100,7 @@
:identifier: sle-hae
:version: '12'
:release_type:
:product_type: 'extension'
:arch: x86_64
:friendly_name: SUSE Linux Enterprise High Availability Extension 12 x86_64
:product_class:
Expand All @@ -116,6 +119,7 @@
:identifier: sle-ha-geo
:version: '12'
:release_type:
:product_type: 'extension'
:arch: x86_64
:friendly_name: SUSE Linux Enterprise High Availability GEO Extension 12
x86_64
Expand Down Expand Up @@ -175,6 +179,7 @@
:identifier: sle-module-legacy
:version: '12'
:release_type:
:product_type: 'module'
:arch: x86_64
:friendly_name: Legacy Module 12 x86_64
:product_class:
Expand Down Expand Up @@ -209,6 +214,7 @@
:identifier: sle-module-adv-systems-management
:version: '12'
:release_type:
:product_type: 'module'
:arch: x86_64
:friendly_name: Advanced Systems Management Module 12 x86_64
:product_class:
Expand Down Expand Up @@ -239,6 +245,7 @@
:name: Web and Scripting Module
:identifier: sle-module-web-scripting
:version: '12'
:product_type: 'module'
:release_type:
:arch: x86_64
:friendly_name: Web and Scripting Module 12 x86_64
Expand Down Expand Up @@ -274,6 +281,7 @@
:identifier: sle-module-public-cloud
:version: '12'
:release_type:
:product_type: 'module'
:arch: x86_64
:friendly_name: Public Cloud Module 12 x86_64
:product_class:
Expand Down

0 comments on commit eb4bb64

Please sign in to comment.