Skip to content

Commit

Permalink
use "product_type" attribute for sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Sep 3, 2014
1 parent 9ec0cf3 commit b069c4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 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
17 changes: 11 additions & 6 deletions src/lib/registration/addon_sorter.rb
Expand Up @@ -7,22 +7,27 @@ class AddonSorter
def initialize(addons)
@addons = addons
end


# sort the addons in the required display order
def sort
# first paid extensions, then free extensions, modules at the end
# see https://bugzilla.novell.com/show_bug.cgi?id=888567#c21
sort_addons(paid_extensions) + sort_addons(free_extensions) + sort_addons(modules)
result = sort_addons(paid_extensions) + sort_addons(free_extensions) + sort_addons(modules)

# just make sure unknown product types are not removed
unknown = addons - result

result += sort_addons(unknown)
end

private

def modules
# TODO FIXME use a SCC flag
addons.select { |addon| addon.name.match(/module/i)}
addons.select { |addon| addon.product_type == "module"}
end

def extensions
addons - modules
addons.select { |addon| addon.product_type == "extension"}
end

def paid_extensions
Expand All @@ -33,7 +38,7 @@ def free_extensions
extensions.select(&:free)
end

# sort addon by name
# sort given addons by name
def sort_addons(addons)
addons.sort_by { |addon| addon.name }
end
Expand Down
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 b069c4f

Please sign in to comment.