Class: UU::OS::VUC::ViewModel
- Inherits:
-
Object
- Object
- UU::OS::VUC::ViewModel
- Defined in:
- uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb
Overview
Class is used for building view response. Use ViewModel if you want get components, add message, change view template etc.
Constant Summary
- RESPONSE_VIEW_ATTRIBUTES =
Key used for storing view model attributes in JSON format.
:uuUcContextAttributes
Instance Method Summary (collapse)
-
- (Object) [](key)
Returns attribute's value.
-
- (Object) []=(key, value)
Set attribute's value.
-
- (Object) add_message(message)
Add user message, which will be displayed on form after this action.
-
- (UU::OS::GVC::Component?) component(code)
Returns component with code passed as parameter or nil if component with this code does not exists.
-
- (UU::OS::GVC::Component?) event_source_component
Returns component which trigger event.
-
- (Array) find_components(code_regex = nil) {|comp| ... }
Search for component by regular expression or filtering block.
-
- (Object) focus_component(code)
Change focus of components.
-
- (Object) height=(height)
Sets height of the VUC view.
-
- (ViewModel) initialize(ctx)
constructor
A new instance of ViewModel.
-
- (Array) messages
Returns all messages added by #add_message method.
-
- (Object) template_uri(*uu_uri)
Because of historical reasons (due to backward compatibility), this method acts as getter (if no parameter is provided) or setter (the method is called with a template_uri parameter).
-
- (Object) to_json(opt = {})
Serialize object to JSON in format corresponding to schema ues:SYSTEM:UU.OS.VUC/RESPONSE_MESSAGE-SCHEMA-V3.
-
- (Object) width=(width)
Sets width of the VUC view.
Constructor Details
- (ViewModel) initialize(ctx)
Returns a new instance of ViewModel
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 77 def initialize(ctx) @ctx = ctx @raw_attrs = UU::OS::Lang::UniformHash.new uuView = @template_uri = @ctx.parameters[:uuView] if uuView != nil @template_uri = uuView[:templateUri] end # restore parameters previously set to the ctx.view if ( @ctx.parameters[RESPONSE_VIEW_ATTRIBUTES] != nil ) @ctx.parameters[RESPONSE_VIEW_ATTRIBUTES].each do |key,value| @raw_attrs[key]=value; end @ctx.parameters[RESPONSE_VIEW_ATTRIBUTES].clear; end end |
Instance Method Details
- (Object) [](key)
Attribute’s key have some restrictions:
-
Key of the attribute must not start with ‘uu’ prefix (e.g. uuName, uusage), prefix ‘uu’ is reserved for internal usage.
-
Key of the attribute must not be same as code of some component. It may cause conflict and the component will not work as expected. E.g. you have component with code ‘NAME_INPUT’ so you can not use this code as attribute code.
Returns attribute's value.
112 113 114 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 112 def [](key) @raw_attrs[key] end |
- (Object) []=(key, value)
Attribute’s key have some restrictions:
-
Key of the attribute must not start with ‘uu’ prefix (e.g. uuName, uusage), prefix ‘uu’ is reserved for internal usage.
-
Key of the attribute must not be same as code of some component. It may cause conflict and the component will not work as expected. For example you have component with code ‘NAME_INPUT’ so you can not use this code as attribute code.
Set attribute's value. Attributes has a Use Case scope. It's means that attribute will be available in all following actions on same Controller. E.g. If you set attribute in on_init(ctx) method, you can get this attribute in on_value_change(ctx) or on_submit(ctx) actions. Attributes are not forwarded to next Uca Case or between modal dialogs.
137 138 139 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 137 def []=(key, value) @raw_attrs[key] = value end |
- (Object) add_message(message)
Add user message, which will be displayed on form after this action.
252 253 254 255 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 252 def () container.() return self end |
- (UU::OS::GVC::Component?) component(code)
Returns component with code passed as parameter or nil if component with this code does not exists.
156 157 158 159 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 156 def component(code) code = code.to_sym if code.kind_of? String container.component_by_code(code) end |
- (UU::OS::GVC::Component?) event_source_component
Returns component which trigger event. Result may be nil if event is not triggered by component. E.g. in UU::OS::VUC::VisualUseCaseController#on_init method.
369 370 371 372 373 374 375 376 377 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 369 def event_source_component uu_view = @ctx.parameters[:uuView] if (uu_view.nil?) || (uu_view[:sourceComponent].nil?) return nil end source_comp_code = uu_view[:sourceComponent] source_comp_code = source_comp_code.to_sym unless source_comp_code.nil? return container.component_by_code(source_comp_code) end |
- (Array) find_components(code_regex = nil) {|comp| ... }
It is forbidden to modify components in filtering block.
Search for component by regular expression or filtering block. If both expression and block are used, so block has bigger priority and expression is discarded. If no expression or block are available so all components are included in result. If expression or block match no component, empty array is returned.
will not be included in result. Otherwise component will be part of result.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 203 def find_components(code_regex = nil, &block) result = [] if block_given? comps_list = container.components comps_list.each do |comp| include_comp = yield(comp) result << comp if include_comp end elsif !code_regex.nil? code_regex = code_regex.to_s comps_hash = container.get_components comps_hash.each do |key, comp| if key.to_s.match(code_regex) result << comp end end else result = container.components end return result end |
- (Object) focus_component(code)
Change focus of components.
275 276 277 278 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 275 def focus_component(code) container.focus_by_code(code) return self end |
- (Object) height=(height)
Sets height of the VUC view. View size may be used by a page layout to set specific size of the VUC visual container. For example dialog window, in which the VUC view is showed, may used view size as the dialog size.
301 302 303 304 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 301 def height=(height) container.height = height return self end |
- (Array) messages
Returns all messages added by #add_message method.
264 265 266 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 264 def container..clone end |
- (Object) template_uri(*uu_uri)
This parameters can be set only in on_before_init method, if you set template_uri in another
Because of historical reasons (due to backward compatibility), this method acts as getter (if no parameter is provided) or setter (the method is called with a template_uri parameter).
If this method is used as setter, it sets new view template. This template will be rendered as form. Default value is the main sheet of registered VUC. You can use sheets from this VUC only, it's means that only sheets related to actual VUC artifact are allowed, otherwise form execution fails with error. If you set non-exists uri than form execution will fail as well.
method, it will have no effect.
345 346 347 348 349 350 351 352 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 345 def template_uri(*uu_uri) if uu_uri.size == 0 return @template_uri else @template_uri = uu_uri[0] end return self end |
- (Object) to_json(opt = {})
Serialize object to JSON in format corresponding to schema ues:SYSTEM:UU.OS.VUC/RESPONSE_MESSAGE-SCHEMA-V3
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 384 def to_json(opt = {}) response = {} # add components comp_list = container.get_components comp_list.each do |k, v| response[k] = v.attributes end # add raw attributes if (@raw_attrs != nil and @raw_attrs.size > 0) uuUcContextAttributes = {}; @raw_attrs.each do |key, param| uuUcContextAttributes[key] = param end response[RESPONSE_VIEW_ATTRIBUTES] = uuUcContextAttributes; end # add messages msgs = container. if (!msgs.nil? && !msgs.empty?) view = create_view(response) view[:messages] = [] msgs.each do || view[:messages] << .raw_attrs end end # add focus if any focus = container.get_focus if focus view = create_view(response) view[:focus] = focus end # add view width width = container.width if width view = create_view(response) view[:width] = width end # add view height height = container.height if height view = create_view(response) view[:height] = height end # add view template unless @template_uri.nil? view = create_view(response) view[:templateUri] = @template_uri end response[:schemaUri] = RESPONSE_JSON_SCHEMA_URI return response.to_json(opt) end |
- (Object) width=(width)
Sets width of the VUC view. View size may be used by a page layout to set specific size of the VUC visual container. For example dialog window, in which the VUC view is showed, may used view size as the dialog size.
288 289 290 291 |
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/view_model.rb', line 288 def width=(width) container.width = width return self end |