Class: HmxClient::Command::View
Overview
Display the results of a view and list all views
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#create ⇒ Object
view:create.
-
#delete ⇒ Object
view:delete.
-
#get ⇒ Object
view:get.
-
#index ⇒ Object
view .
-
#list ⇒ Object
view:list.
-
#updateFilter ⇒ Object
view:updateFilter .
-
#updateMap ⇒ Object
view:updateMap .
-
#updateParam ⇒ Object
view:updateParam .
-
#updateResult ⇒ Object
view:updateResult .
Methods inherited from Base
#hmx, #initialize, #loadConfig!, namespace, #removeConfig, #storeConfig, #writeConfig
Methods included from Helpers
#display, #display_row, #display_tab, #display_table, #error, #getFromUser, #longest
Constructor Details
This class inherits a constructor from HmxClient::Command::Base
Instance Method Details
#create ⇒ Object
view:create
Create a new (initially blank) view. You will then need to call update to set the filter function, map function, query params and result columns.
Views are based on types, for create define a name and the type
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/hmx/command/view.rb', line 64 def create unless args.size > 1 raise CommanFailed, "Usage: hmx view:create <viewName> <typeName>" end view = args.shift viewName = "sys.view/#{view}" typeName = args.shift dataDocument = { "MXView" => { :typeName => typeName, :parameterNames => [], :filterFn => "", :mappingFn => "", :resultColumns => [], :viewName => view } } dout JSON.pretty_generate(hmx.doPutSimpleData([viewName, JSON.generate(dataDocument)])) end |
#delete ⇒ Object
view:delete
Delete a view definition
151 152 153 154 155 156 157 158 |
# File 'lib/hmx/command/view.rb', line 151 def delete unless args.size >0 raise CommandFailed, "Usage: hmx view:delete <viewName>" end view = args.shift viewName = "sys.view/#{view}" display hmx.doDeleteData([viewName]) end |
#get ⇒ Object
view:get
Retrieves the definition of a view
48 49 50 51 52 53 54 55 |
# File 'lib/hmx/command/view.rb', line 48 def get unless args.size > 0 raise CommandFailed, "Usage: hmx view:get <viewName>" end typeName = "sys.view/#{args.shift}" display "Retrieving #{ typeName }" dout JSON.pretty_generate(hmx.doGetData([typeName])) end |
#index ⇒ Object
view
run a view in hmx, passing in a view name and an input to the filter function
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hmx/command/view.rb', line 14 def index unless args.size > 0 raise CommandFailed, "Usage: hmx view <viewName> <filterContext>" end viewData = hmx.doRunView([args.shift, JSON.parse(args.shift)]) resp = '' viewData.each { | line | line.each { | cell | if (cell.is_a? Array) cell.each { | inner | resp = resp + "%20.20s\t" % inner } else resp = resp + "%20.20s\t" % cell end } resp = resp + "\n" } dout resp end |
#list ⇒ Object
view:list
Lists all of the views in the system
37 38 39 40 41 42 |
# File 'lib/hmx/command/view.rb', line 37 def list views = hmx.doQuery(["sys.view", nil]) views.each { | v | display v.rpartition('/')[2] } end |
#updateFilter ⇒ Object
view:updateFilter
Set the filter function for a view
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/hmx/command/view.rb', line 90 def updateFilter unless args.size > 1 raise CommandFailed, "Usage: hmx view:updateFilter <viewName> <filterFn>" end view = args.shift viewName = "sys.view/#{view}" filterFn = args.shift dataDocument = hmx.doGetData([viewName]) puts dataDocument dataDocument['document']['MXView']['filterFn'] = filterFn display hmx.doPutData([JSON.generate(dataDocument)]) end |
#updateMap ⇒ Object
view:updateMap
Set the map function for a view
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/hmx/command/view.rb', line 107 def updateMap unless args.size > 1 raise CommandFailed, "Usage: hmx view:updateMap <viewName> <filterFn>" end view = args.shift viewName = "sys.view/#{view}" mapFn = args.shift dataDocument = hmx.doGetData([viewName]) dataDocument['document']['MXView']['mappingFn'] = mapFn display hmx.doPutData([JSON.generate(dataDocument)]) end |
#updateParam ⇒ Object
view:updateParam
Set the parameter names for a view
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/hmx/command/view.rb', line 122 def updateParam unless args.size > 1 raise CommandFailed, "Usage: hmx view:updateParam <viewName> <param> [<param2> ...]" end view = args.shift viewName = "sys.view/#{view}" dataDocument = hmx.doGetData([viewName]) dataDocument['document']['MXView']['parameterNames'] = args display hmx.doPutData([JSON.generate(dataDocument)]) end |
#updateResult ⇒ Object
view:updateResult
Set the result names for a view
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/hmx/command/view.rb', line 136 def updateResult unless args.size > 1 raise CommandFailed, "Usage: hmx view:updateResult <viewName> <param> [<param2> ...]" end view = args.shift viewName = "sys.view/#{view}" dataDocument = hmx.doGetData([viewName]) dataDocument['document']['MXView']['resultColumns'] = args display hmx.doPutData([JSON.generate(dataDocument)]) end |