Skip to content

Commit

Permalink
add error handling to all in one dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 26, 2017
1 parent 6dd36ec commit 34dc7a4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
33 changes: 26 additions & 7 deletions src/lib/installation/clients/inst_casp_overview.rb
Expand Up @@ -45,6 +45,7 @@ def run
Yast.import "UI"
Yast.import "Mode"
Yast.import "CWM"
Yast.import "Popup"

textdomain "installation"

Expand All @@ -54,6 +55,7 @@ def run

ret = nil
loop do
content, blocking_widgets = content_and_blocking_widgets
ret = Yast::CWM.show(
content,
# Title for installation overview dialog
Expand All @@ -66,6 +68,15 @@ def run
# do not store stuff when just redrawing
skip_store_for: [:redraw]
)
blocker = blocking_widgets.find(&:blocking?)
if blocker
# %title stands for title of problematic part
Yast::Popup.Error(
_("%{title} blocks installation. Please solve before before proceeding.") %
({title: blocker.label.gsub(/&/, "")})
)
next
end
break if ret != :redraw
end

Expand Down Expand Up @@ -98,10 +109,16 @@ def quadrant_layout(upper_left:, lower_left:, upper_right:, lower_right:)
)
end

# Returns a UI widget-set for the dialog
def content
# Returns a pair with UI widget-set for the dialog and widgets that can
# block installation
def content_and_blocking_widgets
dashboard = Installation::Widgets::DashboardPlace.new
quadrant_layout(
partitions = Installation::Widgets::Overview.new(client: "partitions_proposal")
bootloader = Installation::Widgets::Overview.new(client: "bootloader_proposal")
network = Installation::Widgets::Overview.new(client: "network_proposal")
kdump = Installation::Widgets::Overview.new(client: "kdump_proposal")
blocking = [partitions, bootloader, network, kdump]
content = quadrant_layout(
upper_left: VBox(
::Widgets::RegistrationCode.new,
::Users::PasswordWidget.new(little_space: true),
Expand All @@ -114,15 +131,17 @@ def content
Tune::Widgets::SystemInformation.new
),
upper_right: VBox(
Installation::Widgets::Overview.new(client: "partitions_proposal"),
Installation::Widgets::Overview.new(client: "bootloader_proposal")
partitions,
bootloader
),
lower_right: VBox(
Installation::Widgets::Overview.new(client: "network_proposal"),
Installation::Widgets::Overview.new(client: "kdump_proposal"),
network,
kdump,
Installation::Widgets::InvisibleSoftwareOverview.new
)
)

[content, blocking]
end

# Returns whether we need/ed to create new UI Wizard
Expand Down
25 changes: 24 additions & 1 deletion src/lib/installation/widgets/overview.rb
Expand Up @@ -22,10 +22,13 @@
require "yast"
require "cwm/widget"

Yast.import "Popup"

module Installation
module Widgets
# A widget for an all-in-one installation dialog.
# It uses the `simple_mode` of {Installation::ProposalClient#make_proposal}
# It is immutable, so for showing new values reinitialize widget
class Overview < CWM::CustomWidget
attr_reader :proposal_client

Expand All @@ -35,6 +38,7 @@ def initialize(client:)
@proposal_client = client
# by default widget_id is the class name; must differentiate instances
self.widget_id = "overview_" + client
@blocking = false
end

def contents
Expand All @@ -50,19 +54,38 @@ def label
end

def items
return @items if @items

d = Yast::WFM.CallFunction(proposal_client,
[
"MakeProposal",
{ "simple_mode" => true }
])
d["label_proposal"]
if d["warning"] && !d["warning"].empty? && d["warning_level"] != :notice
Yast::Popup.LongError(
"Problem found when proposing %{client}:<br>" \
"Severity: %{severity}<br>" \
"Message: %{message}" %
({
client: proposal_client,
severity: (d["warning_level"] || :warning).to_s,
message: d["warning"]
})
)
@blocking = [:blocker, :fatal].include?(d["warning_level"])
end
@items = d["label_proposal"]
end

def handle(_event)
Yast::WFM.CallFunction(proposal_client, ["AskUser", {}])
:redraw
end

def blocking?
@blocking
end

private

def button_id
Expand Down

0 comments on commit 34dc7a4

Please sign in to comment.