Class: Installation::Widgets::ProductSelector

Inherits:
CWM::RadioButtons
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/installation/widgets/product_selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(products, skip_validation: false) ⇒ ProductSelector

Returns a new instance of ProductSelector.

Parameters:

  • products (Array<Y2Packager::Product>)

    products to display

  • skip_validation (Boolean) (defaults to: false)

    Skip value validation


42
43
44
45
46
47
48
# File 'src/lib/installation/widgets/product_selector.rb', line 42

def initialize(products, skip_validation: false)
  super()
  @products = products
  @items = products.sort(&Y2Packager::PRODUCT_SORTER).map { |p| [item_id(p), p.label] }
  @skip_validation = skip_validation
  textdomain "installation"
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.


37
38
39
# File 'src/lib/installation/widgets/product_selector.rb', line 37

def items
  @items
end

#productObject (readonly)

Returns the value of attribute product.


38
39
40
# File 'src/lib/installation/widgets/product_selector.rb', line 38

def product
  @product
end

#productsObject (readonly)

Returns the value of attribute products.


37
38
39
# File 'src/lib/installation/widgets/product_selector.rb', line 37

def products
  @products
end

Instance Method Details

#hspacingObject


50
51
52
# File 'src/lib/installation/widgets/product_selector.rb', line 50

def hspacing
  1
end

#initObject


58
59
60
61
62
63
64
65
66
# File 'src/lib/installation/widgets/product_selector.rb', line 58

def init
  selected = products.find(&:selected?)
  # disable changing the base product after registering it, in the offline
  # installation we cannot easily change the base product repository
  disable if registered? || offline_product_selected?
  return unless selected

  self.value = item_id(selected)
end

#item_id(prod) ⇒ String

unique widget ID for the product

Returns:

  • (String)

    widget ID


108
109
110
111
112
# File 'src/lib/installation/widgets/product_selector.rb', line 108

def item_id(prod)
  return prod.dir if prod.respond_to?(:dir)

  "#{prod.name}-#{prod.version}-#{prod.arch}"
end

#labelObject


54
55
56
# File 'src/lib/installation/widgets/product_selector.rb', line 54

def label
  _("Product to Install")
end

#offline_product_selected?Boolean

has been an offline installation product selected?

Returns:

  • (Boolean)

    true if an offline installation product has been selected


102
103
104
# File 'src/lib/installation/widgets/product_selector.rb', line 102

def offline_product_selected?
  Y2Packager::MediumType.offline? && products.any?(&:selected?)
end

#registered?Boolean

Determine whether the system is registered

Returns:

  • (Boolean)

93
94
95
96
97
98
# File 'src/lib/installation/widgets/product_selector.rb', line 93

def registered?
  require "registration/registration"
  Registration::Registration.is_registered?
rescue LoadError
  false
end

#skip_validation?Boolean

Determine whether the validation should be skipped

Returns:

  • (Boolean)

See Also:


88
89
90
# File 'src/lib/installation/widgets/product_selector.rb', line 88

def skip_validation?
  @skip_validation
end

#storeObject


68
69
70
71
72
73
74
75
76
# File 'src/lib/installation/widgets/product_selector.rb', line 68

def store
  log.info "Selected product: #{value}"
  @product = products.find { |p| item_id(p) == value }
  log.info "Found product: #{@product}"

  return unless @product

  @product.select unless @product.selected?
end

#validateObject


78
79
80
81
82
83
# File 'src/lib/installation/widgets/product_selector.rb', line 78

def validate
  return true if value || skip_validation?

  Yast::Popup.Error(_("Please select a product to install."))
  false
end