Skip to content

Commit

Permalink
showing popup in proposal when non-blocking error is there
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 14, 2016
1 parent 7cc48ea commit 225ecb3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/lib/installation/proposal_errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "yast"

Yast.import "UI"
Yast.import "Label"
Yast.import "Mode"
Yast.import "Popup"

module Installation
class ProposalErrors
include Yast::I18n
include Yast::Logger

ERROR_PROPOSAL_TIMEOUT = 60

def initialize
textdomain "installation"
@errors = []
end

# clears previously stored errros
def clear
@errors = []
end

# appends new error with given message
def append(message)
@errors << message
end

# returns true if there is no error or user approved stored errors
def approved?
return true if @errors.empty?

headline = _("Error Found in Installation Settings")
text = _("The following errors were found in the configuration proposal.\n" \
"If you continue with the installation it may not be successful.\n" \
"Errors:\n")
sep = Yast::UI.TextMode ? "-" : "•"
text += "#{sep} " + @errors.join("\n#{sep} ")

if Yast::Mode.auto
!Yast::Popup.TimedErrorAnyQuestion(headline, text,
Yast::Label.BackButton, Yast::Label.ContinueButton, :focus_yes,
ERROR_PROPOSAL_TIMEOUT)
else
!Yast::Popup.ErrorAnyQuestion(headline, text,
Yast::Label.BackButton, Yast::Label.ContinueButton, :focus_yes)
end
end
end
end
7 changes: 7 additions & 0 deletions src/lib/installation/proposal_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require "yast"

require "installation/proposal_store"
require "installation/proposal_errors"

module Installation
# Create and display reasonable proposal for basic
Expand Down Expand Up @@ -66,6 +67,7 @@ def initialize(store = ::Installation::ProposalStore)
# BNC #463567
@submods_already_called = []
@store_class = store
@errors = ProposalErrors.new
end

def run
Expand Down Expand Up @@ -278,6 +280,8 @@ def pre_continue_handling
return nil
end

return nil unless @errors.approved?

if Yast::Stage.stage == "initial"
input = Yast::WFM.CallFunction("inst_doit", [])
# bugzilla #219097, #221571, yast2-update on running system
Expand Down Expand Up @@ -441,6 +445,7 @@ def make_proposal(force_reset, language_changed)
end
end

@errors.clear
@store.make_proposals(
force_reset: force_reset,
language_changed: language_changed,
Expand Down Expand Up @@ -469,13 +474,15 @@ def format_sub_proposal(prop)

if !warning.empty?
level = prop["warning_level"] || :warning
log.info "proposal returns warning with level #{level} and msg #{warning}"

case level
when :notice
warning = Yast::HTML.Bold(warning)
when :warning
warning = Yast::HTML.Colorize(warning, "red")
when :error
@errors.append(warning)
warning = Yast::HTML.Colorize(warning, "red")
when :blocker, :fatal
@have_blocker = true
Expand Down
33 changes: 33 additions & 0 deletions test/proposal_errors_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env rspec

require_relative "./test_helper"

require "installation/proposal_errors"

describe ::Installation::ProposalErrors do
describe "#approved?" do
it "returns true if there is no error stored" do
expect(Yast::Popup).to_not receive(:ErrorAnyQuestion)
expect(subject.approved?).to eq true
end

it "asks user to approve errors and returns true if approved" do
subject.append("test")

expect(Yast::Popup).to receive(:ErrorAnyQuestion).and_return(false)
expect(subject.approved?).to eq true

expect(Yast::Popup).to receive(:ErrorAnyQuestion).and_return(true)
expect(subject.approved?).to eq false
end

it "in autoyast ask with timeout and return true if timeout exceed" do
subject.append("test")
allow(Yast::Mode).to receive(:auto).and_return(true)

# timed error return false when timeout exceed
expect(Yast::Popup).to receive(:TimedErrorAnyQuestion).and_return(false)
expect(subject.approved?).to eq true
end
end
end

0 comments on commit 225ecb3

Please sign in to comment.