Class: Installation::AutoinstIssues::IssuesPresenter

Inherits:
Object
  • Object
show all
Includes:
Yast::I18n
Defined in:
library/general/src/lib/installation/autoinst_issues/issues_presenter.rb

Overview

This class converts a list of issues into a message to be shown to users

The message will summarize the list of issues, separating them into non-fatal and fatal issues.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issues_list) ⇒ IssuesPresenter

Constructor

Parameters:


38
39
40
41
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 38

def initialize(issues_list)
  textdomain "base"
  @issues_list = issues_list
end

Instance Attribute Details

#issues_listInstallation::AutoinstIssues::List (readonly)

Returns List of issues.

Returns:


33
34
35
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 33

def issues_list
  @issues_list
end

Instance Method Details

#error_text(issues) ⇒ String

Return error message with a list of issues

Parameters:

Returns:

  • (String)

    Message


85
86
87
88
89
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 85

def error_text(issues)
  Yast::HTML.Para(
    _("Important issues were detected:")
  ) + issues_list_content(issues)
end

#issues_by_section(issues) ⇒ Hash<(#parent,#section_name),Installation::AutoinstIssues::Issue>

Return issues grouped by section where they were found

Returns:


120
121
122
123
124
125
126
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 120

def issues_by_section(issues)
  issues.each_with_object({}) do |issue, all|
    section = issue.section || :nosection
    all[section] ||= []
    all[section] << issue
  end
end

#issues_list_content(issues) ⇒ String

Return an HTML representation for a list of issues

The issues are grouped by the section of the profile where they were detected. General issues (with no section) are listed first.

Returns:

  • (String)

    Issues list content

See Also:


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 99

def issues_list_content(issues)
  all_issues = []
  issues_map = issues_by_section(issues)

  if issues_map[:nosection]
    all_issues += issues_map[:nosection].map(&:message)
    issues_map.delete(:nosection)
  end

  issues_map.each do |section, items|
    messages = Yast::HTML.List(items.map(&:message))
    all_issues << "#{location(section)}:#{messages}"
  end

  Yast::HTML.List(all_issues)
end

#location(section) ⇒ String

Return a human string identifying in which section was detected

For instance: "drive[0] > partitions[2] > raid_options"

Parameters:

  • section (#parent, #section_name)

    Section where the problem was detected

Returns:

  • (String)

See Also:

  • Y2Storage::AutoinstProfile

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 136

def location(section)
  return section.section_name if section.parent.nil?

  value = section.parent.send(section.section_name)
  text =
    if value.is_a?(Array)
      index = value.index(section)
      "#{section.section_name}[#{index + 1}]"
    else
      section.section_name
    end

  prefix = location(section.parent)
  prefix << " > " unless prefix.empty?
  prefix + text
end

#to_htmlString

Return the text to be shown to the user regarding the list of issues

Returns:

  • (String)

    HTML formatted text


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 53

def to_html
  fatal, non_fatal = issues_list.partition(&:fatal?)

  parts = []
  parts << error_text(fatal) unless fatal.empty?
  parts << warning_text(non_fatal) unless non_fatal.empty?
  parts << Yast::HTML.Newline

  parts <<
    if fatal.empty?
      _("Do you want to continue?")
    else
      _("Please, correct these problems and try again.")
    end

  parts.join
end

#to_plainString

Return the text to be shown to the user regarding the list of issues

Returns:

  • (String)

    Plain text


46
47
48
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 46

def to_plain
  Yast::RichText.Rich2Plain(to_html)
end

#warning_text(issues) ⇒ String

Return warning message with a list of issues

Parameters:

Returns:

  • (String)

    Message


75
76
77
78
79
# File 'library/general/src/lib/installation/autoinst_issues/issues_presenter.rb', line 75

def warning_text(issues)
  Yast::HTML.Para(
    _("Minor issues were detected:")
  ) + issues_list_content(issues)
end