Skip to content

Commit

Permalink
use real data in roles widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger authored and mvidner committed Jan 25, 2017
1 parent ac17b81 commit 748281a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/lib/installation/select_system_role.rb
Expand Up @@ -34,7 +34,8 @@ class << self

NON_OVERLAY_ATTRIBUTES = [
"additional_dialogs",
"id"
"id",
"services"
].freeze

def initialize
Expand Down
78 changes: 70 additions & 8 deletions src/lib/installation/widgets/system_role.rb
Expand Up @@ -21,32 +21,94 @@

require "yast"
require "cwm/widget"
require "installation/services"

Yast.import "ProductControl"
Yast.import "ProductFeatures"


module Installation
module Widgets
# TODO: steal / refactor Installation::SelectSystemRole
# from src/lib/installation/select_system_role.rb
class SystemRole < CWM::ComboBox
class << self
# once the user selects a role, remember it in case they come back
attr_accessor :original_role_id
end

def initialize
textdomain "installation"
end

def label
_("System Role")
Yast::ProductControl.GetTranslatedText("roles_caption")
end

def opt
[:hstretch]
end

def init
self.class.original_role_id ||= roles_attributes.first[:id]
self.value = self.class.original_role_id
end

def items
[
# FIXME: still hardcoding for easier testing
["foo", _("Adminstration Dashboard")],
["bar", _("Worker")],
["baz", _("Plain System")],
["qux", _("FIXME use real data")]
]
roles_description.map do |attr|
[attr[:id], attr[:label]]
end
end

def help
Yast::ProductControl.GetTranslatedText("roles_help") + "\n\n"
roles_description.map { |r| r[:label] + "\n\n" + r[:description] + "\n\n\n"}
end

NON_OVERLAY_ATTRIBUTES = [
"additional_dialogs",
"id"
].freeze
private_constant :NON_OVERLAY_ATTRIBUTES


def store
log.info "Applying system role '#{value}'"
features = raw_roles.find { |r| r["id"] == value }
features = features.dup
NON_OVERLAY_ATTRIBUTES.each { |a| features.delete(a) }
Yast::ProductFeatures.SetOverlay(features)
adapt_services
self.class.original_role_id = value
end


private

def raw_roles
@raw_roles ||= Yast::ProductControl.productControl.fetch("system_roles", [])
end

def roles_description
@roles_description ||= raw_roles.map do |r|
id = r["id"]

{
id: id,
label: Yast::ProductControl.GetTranslatedText(id),
description: Yast::ProductControl.GetTranslatedText(id + "_description")
}
end
end

def adapt_services
services = raw_roles.find { |r| r["id"] == role_id }["services"]
services ||= []

to_enable = services.map { |s| s["name"] }
log.info "enable for #{role_id} these services: #{to_enable.inspect}"

Installation::Services.enabled = to_enable
end
end
end
Expand Down

0 comments on commit 748281a

Please sign in to comment.