Skip to content

Commit

Permalink
make the titles for the read-only proposals not clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Oct 21, 2016
1 parent 5d016df commit f0dac5c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/lib/installation/proposal_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@ def submod_descriptions_and_build_menu

# now build the menu button
menu_list = @submodules_presentation.each_with_object([]) do |submod, menu|
# skip read-only proposals
next if @store.read_only?(submod)

descr = @store.description_for(submod) || {}
next if descr.empty?

Expand Down Expand Up @@ -787,18 +790,44 @@ def assign_next_button
nil
end

# Get the header for the specific proposal module
# @param submod [String] the proposal module name
# @return [String] richtext string with the proposal header
def html_header(submod)
# the read-only proposals do not have a clickable title
heading = @store.read_only?(submod) ? plain_header(submod) : link_header(submod)

Yast::HTML.Heading(heading)
end

# Get a richtext clickable text header for the specific proposal module
# @param submod [String] the proposal module name
# @return [String] richtext string with the proposal header
def link_header(submod)
title = @store.title_for(submod)
heading = if title.include?("<a")

if title.include?("<a")
title
else
Yast::HTML.Link(
title,
@store.id_for(submod)
)
end
end

Yast::HTML.Heading(heading)
# Get a plain text header for the specific proposal module
# @param submod [String] the proposal module name
# @return [String] plain string with the proposal header
def plain_header(submod)
title = @store.title_for(submod)

# a link is usually not present, skip the substitution
return title unless title.include?("<a")

# use the non-greedy .*? repetition to handle
# the "<a>foo</a> <a>bar</a>" case correctly
title.gsub(/<a.*?>(.*?)<\/a>/, "\\1")
end
end
end
26 changes: 26 additions & 0 deletions src/lib/installation/proposal_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ def title_for(client)
client
end

# Returns the read-only flag
#
# @param [String] client
# @return [String] a title provided by the description API
def read_only?(client)
read_only_proposals.include?(client)
end

# Calls client('AskUser'), to change a setting interactively (if link is the
# heading for the part) or noninteractively (if it is a "shortcut")
def handle_link(link)
Expand Down Expand Up @@ -273,6 +281,24 @@ def client_for_link(link)
matching_client.first
end

def read_only_proposals
return @read_only_proposals unless @read_only_proposals.nil?

@read_only_proposals = []
log.info "all proposals: #{properties["proposal_modules"]}"

properties.fetch("proposal_modules", []).each do |proposal|
if proposal["read_only"]
name = proposal["name"]
name += "_proposal" unless name.end_with?("_proposal")
@read_only_proposals << name
end
end

log.info "Found read-only proposals: #{@read_only_proposals}"
@read_only_proposals
end

private

# Evaluates the given description map, and handles all the events
Expand Down

0 comments on commit f0dac5c

Please sign in to comment.