Skip to content

Commit

Permalink
Merge pull request #476 from mvidner/roles_additional_dialogs_casp
Browse files Browse the repository at this point in the history
Symbols; recursion.
  • Loading branch information
jreidinger committed Dec 12, 2016
2 parents 9970948 + f43c9ef commit 65af738
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/lib/installation/select_system_role.rb
Expand Up @@ -26,9 +26,6 @@
Yast.import "ProductFeatures"

module Installation
# marker exception when additional dialog return abort
class AbortException < RuntimeError; end

class SelectSystemRole < ::UI::InstallationDialog
class << self
# once the user selects a role, remember it in case they come back
Expand All @@ -53,12 +50,13 @@ def run
end

if Yast::GetInstArgs.going_back
return :next if run_clients(self.class.original_role_id, going_back: true)
# If coming back, we have to run the additional dialogs first...
direction = run_clients(self.class.original_role_id, going_back: true)
# ... and only run the main dialog (super) if we are *still* going back
return direction unless direction == :back
end

super
rescue AbortException
return :abort
end

def dialog_title
Expand Down Expand Up @@ -100,29 +98,23 @@ def next_handler

apply_role(role_id)

# if run clients goes back, then show again this dialog
if !run_clients(role_id)
create_dialog
return
end

super

rescue AbortException
finish_dialog(:abort)
return
result = run_clients(role_id)
# We show the main role dialog; but the additional clients have
# drawn over it, so do it again, and propagate its result.
result = self.class.run if result == :back
finish_dialog(result)
end

private

# @return true if clients successfully go to next dialog after roles
# @return [:next,:back,:abort] which direction the additional dialogs exited
def run_clients(role_id, going_back: false)
clients = raw_roles.find { |r| r["id"] == role_id }["additional_dialogs"]
clients ||= ""
clients = clients.split(",").map!(&:strip)

return !going_back if clients.empty?
result = going_back ? :back : :next
return result if clients.empty?

client_to_show = going_back ? clients.size - 1 : 0
loop do
Expand All @@ -143,7 +135,7 @@ def run_clients(role_id, going_back: false)
when :back
-1
when :abort
raise AbortException, "client aborted"
return :abort
else
raise "unsupported client response #{result.inspect}"
end
Expand All @@ -152,7 +144,7 @@ def run_clients(role_id, going_back: false)
break unless (0..(clients.size - 1)).cover?(client_to_show)
end

client_to_show >= clients.size
client_to_show >= clients.size ? :next : :back
end

def clear_role
Expand Down

0 comments on commit 65af738

Please sign in to comment.