Skip to content

Commit

Permalink
initial attempt for generic proposal client
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 20, 2014
1 parent e0c9c0c commit 137e529
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/general/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ ydata_DATA = \
fillup_DATA = \
fillup/sysconfig.yast2

ylibdir = "${yast2dir}/lib/installation"
ylib_DATA = \
lib/installation/proposal_client.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(scrconf_DATA) $(agent_SCRIPTS) $(ydata_DATA) $(fillup_DATA)

include $(top_srcdir)/Makefile.am.common
83 changes: 83 additions & 0 deletions library/general/src/lib/installation/proposal_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
require "yast"

module Installation
# Abstract class that simplify writting proposal clients for installation.
# It provides single entry point and abstract methods, that all proposal clients
# need to implement.
# @example how to run client
# require "installation/example_proposal"
# ::Installation::ExampleProposal.run
# @see for example client in installation clone_proposal.rb
# @see proposal_api_reference to get overview of proposal client API
class ProposalClient < Client
include Yast::Logger

# Entry point for calling client. Only part needed in client rb file.
# @return response from abstract methods
def self.run
self.new.run
end

# Dispatches to abstract method based on passed Arguments to client
def run
func, param = Yast::WFM.Args
case func
when "MakeProposal"
make_proposal(param)
when "AskUser"
ask_user(param)
when "Description"
description
when "Write"
write(param)
else
raise "Invalid action for proposal '#{func.inspect}'"
end
end

protected

# Abstract method to create proposal suggestion
# @param [Map<String,Object>] attrs. Currently passed keys are "force_reset"
# which indicate that user preference should be thrown away and
# "language_changed" that indicate that language is changed, so cache with
# text should be renew.
# @return [Map] with proposal attributes. Expected keys are "help" for
# client specific help, "preformatted_proposal" for richtext formatted
# proposal result, "links" with list of anchors used in proposal text.
# Optional keys are "warning_level" and "warning" used for showing warnings.
def make_proposal(attrs)
raise NotImplementedError, "Calling abstract method 'make_proposal'"
end

# Abstract method to react on user action
# @param [Map<String,Object>] attrs. Currently passed key is "chosen_id"
# where is specified action user made. It can be anything from links passed
# in make_proposal or it can be click on tittle, in which case id from
# description is passed.
# @return [Map] with key "workflow_sequence" which specify what should happen.
# Possible values are :next if everything is correct, :back if user requested
# to go back, :again if client should be called again, :auto if it depends on
# previous client response and :finish if to finish installation.
# Optional key is "language_changed" if module changed installation language.
def ask_user(attrs)
raise NotImplementedError, "Calling abstract method 'ask_user'"
end

# Abstract method to return human readable titles both for the RichText
# (HTML) widget and for menuentries. Also specify id which is used when
# user select module.
# @return [Map] with keys "rich_text_title", "menu_title" and "id".
def description
raise NotImplementedError, "Calling abstract method 'description'"
end

# Optional abstract method to write settings.
# @return true if succeed
def write(attrs)
log.error "Write called, but proposal do not implement it"

nil
end
end
end

0 comments on commit 137e529

Please sign in to comment.