Class: Clevic::View
Overview
This contains the definition of a particular view of an entity. See Clevic::ModelBuilder.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#entity_class ⇒ Object
For descendants to override easily.
- #model_builder(value = nil, &block) ⇒ Object
-
#title ⇒ Object
The title to display, eg in a tab.
Class Method Summary collapse
- .[](view_name) ⇒ Object
- .define_ui_block(&block) ⇒ Object
- .entity_class(*args) ⇒ Object
- .entity_class=(some_class) ⇒ Object
- .order ⇒ Object
-
.order=(array) ⇒ Object
Handle situations where the array passed to Clevic::View.order has entity_class objects in it.
-
.views ⇒ Object
sometimes order has duplicates.
- .widget_name(*args) ⇒ Object
Instance Method Summary collapse
-
#define_actions(table_view, action_builder) ⇒ Object
callback for view/model specific actions.
-
#define_ui ⇒ Object
return a default UI constructed from model metadata.
-
#define_ui_block ⇒ Object
use block from constructor, or class ui block from eg Clevic::Record.
- #fields ⇒ Object
-
#initialize(args = {}, &block) ⇒ View
constructor
args can be anything that has a writer method.
-
#notify_data_changed(table_view, top_left, bottom_right) ⇒ Object
Define data changed events.
-
#notify_field(table_view, model_index) ⇒ Object
callback for notify.
-
#notify_key_press(table_view, key_press_event, current_model_index) ⇒ Object
callback for key presses.
-
#widget_name ⇒ Object
used by the framework-specific code to name widgets.
Constructor Details
#initialize(args = {}, &block) ⇒ View
args can be anything that has a writer method. Often this will be entity_class block contains the ModelBuilder DSL
69 70 71 72 73 74 75 76 |
# File 'lib/clevic/view.rb', line 69 def initialize( args = {}, &block ) @define_ui_block = block unless args.nil? args.each do |key,value| self.send( "#{key}=", value ) end end end |
Instance Attribute Details
#entity_class ⇒ Object
For descendants to override easily
84 85 86 |
# File 'lib/clevic/view.rb', line 84 def entity_class @entity_class || self.class.entity_class end |
#model_builder(value = nil, &block) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/clevic/view.rb', line 104 def model_builder( value = nil, &block ) if value.nil? @model_builder ||= ModelBuilder.new( self ) @model_builder.exec_ui_block( &block ) else @model_builder end end |
#title ⇒ Object
The title to display, eg in a tab
90 91 92 |
# File 'lib/clevic/view.rb', line 90 def title @title || self.class.name end |
Class Method Details
.[](view_name) ⇒ Object
24 25 26 27 28 |
# File 'lib/clevic/view.rb', line 24 def []( view_name ) order.find do |view| view.name =~ /#{view_name.to_s}/i end end |
.define_ui_block(&block) ⇒ Object
10 11 12 |
# File 'lib/clevic/view.rb', line 10 def define_ui_block( &block ) @define_ui_block ||= block end |
.entity_class(*args) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/clevic/view.rb', line 44 def entity_class( *args ) if args.size == 0 @entity_class || raise( "entity_class not specified for #{name}" ) else self.entity_class = args.first end end |
.entity_class=(some_class) ⇒ Object
52 53 54 |
# File 'lib/clevic/view.rb', line 52 def entity_class=( some_class ) @entity_class = some_class end |
.order ⇒ Object
14 15 16 |
# File 'lib/clevic/view.rb', line 14 def order @order ||= [] end |
.order=(array) ⇒ Object
Handle situations where the array passed to Clevic::View.order has entity_class objects in it. In other words, if there is one, pass back it’s default view class rather than the entity_class
34 35 36 37 38 39 40 41 42 |
# File 'lib/clevic/view.rb', line 34 def order=( array ) @order = array.map do |x| if x.ancestors.include?( Clevic.base_entity_class ) x.default_view_class else x end end end |
.views ⇒ Object
sometimes order has duplicates. So this is all unique defined views in order of definition, or as specified.
20 21 22 |
# File 'lib/clevic/view.rb', line 20 def views order.uniq end |
.widget_name(*args) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/clevic/view.rb', line 56 def ( *args ) if args.size == 0 # the class name by default || name else = args.first end end |
Instance Method Details
#define_actions(table_view, action_builder) ⇒ Object
callback for view/model specific actions
128 129 |
# File 'lib/clevic/view.rb', line 128 def define_actions( table_view, action_builder ) end |
#define_ui ⇒ Object
return a default UI constructed from model metadata
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/clevic/view.rb', line 115 def define_ui if define_ui_block.nil? # use the define_ui from Clevic::View to build a default UI model_builder do default_ui end else # use the provided block model_builder( &define_ui_block ) end end |
#define_ui_block ⇒ Object
use block from constructor, or class ui block from eg Clevic::Record
79 80 81 |
# File 'lib/clevic/view.rb', line 79 def define_ui_block @define_ui_block || self.class.define_ui_block end |
#fields ⇒ Object
95 96 97 |
# File 'lib/clevic/view.rb', line 95 def fields @fields ||= define_ui.fields end |
#notify_data_changed(table_view, top_left, bottom_right) ⇒ Object
Define data changed events. Default is to call notify_data_changed for each field in the rectangular area defined by top_left and bottom_right (which are include Clevic::TableIndex)
146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/clevic/view.rb', line 146 def notify_data_changed( table_view, top_left, bottom_right ) if top_left == bottom_right # shortcut to just the one, seeing as it's probably the most common notify_field( table_view, top_left ) else # do the entire rectagular area (top_left.row..bottom_right.row).each do |row_index| (top_left.column..bottom_right.column).each do |column_index| model_index = table_view.model.create_index( row_index, column_index ) notify_field( table_view, model_index ) end end end end |
#notify_field(table_view, model_index) ⇒ Object
callback for notify
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/clevic/view.rb', line 132 def notify_field( table_view, model_index ) ndc = model_index.field.notify_data_changed case ndc when Proc ndc.call( self, table_view, model_index ) when Symbol send( ndc, table_view, model_index ) end end |
#notify_key_press(table_view, key_press_event, current_model_index) ⇒ Object
callback for key presses
162 163 |
# File 'lib/clevic/view.rb', line 162 def notify_key_press( table_view, key_press_event, current_model_index ) end |
#widget_name ⇒ Object
used by the framework-specific code to name widgets
100 101 102 |
# File 'lib/clevic/view.rb', line 100 def || self.class. end |