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 3, 2014
1 parent 708d438 commit 9ec0cf3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/lib/registration/addon_sorter.rb
@@ -0,0 +1,42 @@

module Registration

class AddonSorter
attr_reader :addons

def initialize(addons)
@addons = addons
end

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)
end

private

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

def extensions
addons - modules
end

def paid_extensions
extensions.reject(&:free)
end

def free_extensions
extensions.select(&:free)
end

# sort addon by name
def sort_addons(addons)
addons.sort_by { |addon| addon.name }
end
end

end
8 changes: 7 additions & 1 deletion 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 All @@ -27,7 +28,12 @@ def self.run(registration)

def initialize(registration)
textdomain "registration"
@addons = Addon.find_all(registration)
addons = Addon.find_all(registration)

# sort the addons
sorter = AddonSorter.new(addons)
@addons = sorter.sort

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

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

require_relative "spec_helper"

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

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

subject(:addon_sorter) do
Registration::AddonSorter.new(available_addons)
end

describe "#sort" do
it "sorts the addons" 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(subject.sort.map(&:identifier)).to eql(expected)
end
end

end

0 comments on commit 9ec0cf3

Please sign in to comment.