Module: Anoubis::Data::Get
- Included in:
- Anoubis::DataController
- Defined in:
- app/controllers/anoubis/data/get.rb
Overview
Module gets system data for Anoubis::DataController
Block of table data getters collapse
-
#get_data_row(row) ⇒ Hash
Get data fields defined in custom controller for single row.
-
#get_fields_properties(fields = nil) ⇒ Hash
Returns fields for table output.
-
#get_filter_properties ⇒ Hash
Returns fields for filter form.
-
#get_table_action(action, row) ⇒ Boolean
Returns posibility of using action for table data.
-
#get_table_actions(row) ⇒ Hash
Returns current table actions for selected row.
-
#get_table_data ⇒ Object
Load data into the system variable self.etc.data.data and return fields defined in controller.
-
#get_table_data_count ⇒ Integer
Get total number of rows in defined model.
Block of {Anoubis::Data::Actions#edit edit} and {Anoubis::Data::Actions#update update} getters collapse
- #get_edit_data_row(row) ⇒ Hash
- #get_edit_eager_load ⇒ Object
- #get_edit_fields ⇒ Hash
- #get_edit_model ⇒ Object
Block of {Anoubis::Data::Actions#new new} or {Anoubis::Data::Actions#create create} getters collapse
Instance Method Summary collapse
-
#get_autocomplete_data(field, value) ⇒ Hash
Get autocomplete data for field.
-
#get_data_options(time) ⇒ Hash
Get defined fields options.
-
#get_eager_load ⇒ Object
Get default eager load definition for controller action.
-
#get_fields ⇒ Hash
Return current fields hash for defined action.
- #get_filter_where ⇒ Object
- #get_filter_where_array ⇒ Object
- #get_filter_where_hash ⇒ Object
-
#get_formatted_string_field(options) ⇒ Hash
Returns formatted field hash for field type ‘string’.
-
#get_frame_button(key, button) ⇒ Hash
Get frame button.
-
#get_frame_buttons(args = {}) ⇒ Hash
Get frame buttons data based on passed arguments.
-
#get_model ⇒ Object
Get model that is used for controller action.
-
#get_order ⇒ Hash, String
Returns order for current tab.
-
#get_parent_data ⇒ ActiveRecord
Returns current parent data.
-
#get_permited_params ⇒ Hash<Symbol, string>
Returns permitted parameters.
-
#get_tab(tab, options = {}) ⇒ Object
Get tab parameters.
-
#get_tab_where ⇒ Object
Get where for controller action fro defined tab.
- #get_tenant_where(model) ⇒ Object
-
#get_where ⇒ Object
Get where for controller action.
Instance Method Details
#get_autocomplete_data(field, value) ⇒ Hash
Get autocomplete data for field
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'app/controllers/anoubis/data/get.rb', line 474 def get_autocomplete_data(field, value) value = value.to_s if value.index(' ') words = value.split(' ') max_count = 0; words.each do |word| max_count = word.length if word.length > max_count if field.autocomplete[:where].count == 0 field.autocomplete[:where].push field.table_field+' LIKE ?' else field.autocomplete[:where][0] += ' AND '+field.table_field+' LIKE ?' end field.autocomplete[:where].push("%#{word}%") end if max_count < field.autocomplete[:count] field.autocomplete[:where] = [] end else if value.length >= field.autocomplete[:count] field.autocomplete[:where] = [field.table_field+' LIKE ?', '%'+value+'%'] end end if field.autocomplete[:where].count > 0 self.load_autocomplete_data field end if self.etc.data.data self.etc.data.data.each do |item| if item.respond_to? field.model.title self.output.values.push( #id: item.id, value: item.send(field.model.title) ) else self.output.values.push( #id: item.id, value: item.id ) end end end return self.output.values end |
#get_data_options(time) ⇒ Hash
Get defined fields options
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'app/controllers/anoubis/data/get.rb', line 368 def (time) time = time.to_s.to_i self.setup_fields result = {} self.etc.data.fields.each do |key, field| if field. if field..list if time == 0 result[key] = field..list if field..show != 'never' else if field.model if field..show == 'always' result[key] = field..list else if field..show == 'update' && field.model.updated_at > time result[key] = field..list end end else result[key] = field..list if field..show == 'update' || field..show == 'always' end end end end end result end |
#get_data_row(row) ⇒ Hash
Get data fields defined in custom controller for single row
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'app/controllers/anoubis/data/get.rb', line 211 def get_data_row(row) fields = self.get_fields new_row = {} case self.etc.action when 'show' new_row = { id: row.id, sys_title: row.sys_title } when 'index', 'export' new_row = { id: row.id, sys_title: row.sys_title, actions: self.get_table_actions(row) } when 'new', 'create' new_row = {} when 'edit', 'update' new_row = { id: row.id, sys_title: row.sys_title } end fields.each_key do |key| begin value = eval 'row.' + fields[key].field error = false rescue new_row[key] = fields[key].error_text error = true if fields[key].type == 'key' error = false end end new_row = new_row.merge(self.convert_db_to_view_value(key, value)) if !error end return new_row end |
#get_eager_load ⇒ Object
Get default eager load definition for controller action
95 96 97 98 99 |
# File 'app/controllers/anoubis/data/get.rb', line 95 def get_eager_load return self.etc.data.eager_load if self.etc.data.model self.get_model return self.etc.data.eager_load end |
#get_edit_data_row(row) ⇒ Hash
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'app/controllers/anoubis/data/get.rb', line 311 def get_edit_data_row(row) self.setup_edit_fields new_row = { id: row.id, sys_title: row.sys_title } self.etc.data.fields.each do |key, field| if row.respond_to? field.field value = row.send field.field error = false else new_row[key] = field.error_text error = true end new_row = new_row.merge(self.convert_db_to_edit_value(key, value)) if !error end return new_row end |
#get_edit_eager_load ⇒ Object
291 292 293 294 295 |
# File 'app/controllers/anoubis/data/get.rb', line 291 def get_edit_eager_load return self.etc.data.eager_load if self.etc.data.model self.get_edit_model return self.etc.data.eager_load end |
#get_edit_fields ⇒ Hash
301 302 303 304 |
# File 'app/controllers/anoubis/data/get.rb', line 301 def get_edit_fields self.setup_edit_fields self.etc.data.fields end |
#get_edit_model ⇒ Object
281 282 283 284 285 286 |
# File 'app/controllers/anoubis/data/get.rb', line 281 def get_edit_model return self.etc.data.model if self.etc.data.model self.etc.data.model = self.edit_model self.etc.data.eager_load = self.edit_eager_load return self.etc.data.model end |
#get_fields ⇒ Hash
Return current fields hash for defined action.
430 431 432 433 |
# File 'app/controllers/anoubis/data/get.rb', line 430 def get_fields self.setup_fields self.etc.data.fields end |
#get_fields_properties(fields = nil) ⇒ Hash
Returns fields for table output.
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/controllers/anoubis/data/get.rb', line 173 def get_fields_properties(fields = nil) fields = fields_order if !fields result = [] fields.each do |value| if self.etc.data.fields if self.etc.data.fields.key? value.to_sym result.push self.etc.data.fields[value.to_sym].properties(self.etc.data.model, self.etc.action) if self.etc.data.fields[value.to_sym].visible end end end result end |
#get_filter_properties ⇒ Hash
Returns fields for filter form.
189 190 191 192 |
# File 'app/controllers/anoubis/data/get.rb', line 189 def get_filter_properties fields = filter_order self.get_fields_properties fields end |
#get_filter_where ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/anoubis/data/get.rb', line 119 def get_filter_where #puts 'get_filter_where!' #puts self.etc.data.filter.to_h return if self.etc.data.filter filter = {} if params.key? :filter begin filter = JSON.parse(params[:filter]).with_indifferent_access.to_h rescue filter = {} end end self.setup_fields #puts 'get_filter_where' #puts self.etc.data.fields self.etc.data.filter = Anoubis::Etc::Filter.new({ data: filter, fields: self.etc.data.fields }) #puts self.etc.data.filter.to_h end |
#get_filter_where_array ⇒ Object
144 145 146 147 |
# File 'app/controllers/anoubis/data/get.rb', line 144 def get_filter_where_array self.get_filter_where return self.etc.data.filter.array end |
#get_filter_where_hash ⇒ Object
139 140 141 142 |
# File 'app/controllers/anoubis/data/get.rb', line 139 def get_filter_where_hash self.get_filter_where return self.etc.data.filter.hash end |
#get_formatted_string_field(options) ⇒ Hash
Returns formatted field hash for field type ‘string’
464 465 466 467 |
# File 'app/controllers/anoubis/data/get.rb', line 464 def get_formatted_string_field() field = {} return field end |
#get_frame_button(key, button) ⇒ Hash
Get frame button
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/anoubis/data/get.rb', line 34 def (key, ) [:key] = key.to_s [:type] = 'default' unless .has_key? :type [:mode] = 'single' unless .has_key? :mode [:decoration] = 'none' unless .has_key? :decoration text = I18n.t('.buttons.'+[:key]+'.title', default: '') [:title] = text if text != '' text = I18n.t('.buttons.'+[:key]+'.hint', default: '') [:hint] = text if text != '' end |
#get_frame_buttons(args = {}) ⇒ Hash
Get frame buttons data based on passed arguments.
11 12 13 14 15 16 17 |
# File 'app/controllers/anoubis/data/get.rb', line 11 def (args = {}) = self.(args) .each do |key, | [key] = self. key, end end |
#get_model ⇒ Object
Get model that is used for controller action
84 85 86 87 88 89 90 91 |
# File 'app/controllers/anoubis/data/get.rb', line 84 def get_model return self.etc.data.model if self.etc.data.model if defined? self.model self.etc.data.model = self.model self.etc.data.eager_load = self.eager_load end return self.etc.data.model end |
#get_new_data_row1(row) ⇒ Hash
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'app/controllers/anoubis/data/get.rb', line 346 def get_new_data_row1(row) self.setup_new_fields new_row = {} self.etc.data.fields.each do |key, field| if row.respond_to? field.field value = row.send field.field error = false else new_row[key] = field.error_text error = true end new_row = new_row.merge(self.convert_db_to_new_value(key, value)) if !error end return new_row end |
#get_new_fields ⇒ Hash
336 337 338 339 |
# File 'app/controllers/anoubis/data/get.rb', line 336 def get_new_fields self.setup_new_fields self.etc.data.fields end |
#get_order ⇒ Hash, String
Returns order for current tab
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 |
# File 'app/controllers/anoubis/data/get.rb', line 399 def get_order return {id: :desc} if self.etc.tab.sort == nil result = {} field = self.etc.data.fields[self.etc.tab.sort.to_sym].order if field.field.class == Symbol result[field.field] = self.etc.tab.order else if field.field.class == String if field.field.index(',') result = field.field.gsub(',', ' ' + self.etc.tab.order.to_s.upcase + ',') + ' ' + self.etc.tab.order.to_s.upcase else result = field.field + ' ' + self.etc.tab.order.to_s.upcase end else if field.field.class == Array field.field.each do |item| if item.class == Symbol result[item] = self.etc.tab.order end end end end end result end |
#get_parent_data ⇒ ActiveRecord
Returns current parent data. If data not loaded then load it.
521 522 523 524 525 526 |
# File 'app/controllers/anoubis/data/get.rb', line 521 def get_parent_data if !self.etc.data.parent self.load_parent_data end self.etc.data.parent end |
#get_permited_params ⇒ Hash<Symbol, string>
Returns permitted parameters. Parameters is got from standard parameters output and checks according by described self.etc.data.fields.
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'app/controllers/anoubis/data/get.rb', line 439 def get_permited_params permit = [] allowed = self.fields_order self.etc.data.fields.each_key do | key | single = true if self.etc.data.fields[key].type == 'listbox' single = false if self.etc.data.fields[key].format == 'multiple' end if single permit.push key else data = {} data[key] = [] permit.push data end end params[:data].permit(permit).to_h.symbolize_keys end |
#get_tab(tab, options = {}) ⇒ Object
Get tab parameters
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/anoubis/data/get.rb', line 58 def get_tab(tab, = {}) [:tab] = tab.to_s [:title] = I18n.t('.tabs.'+[:tab]+'.title', default: [:tab].humanize) if !.key? :title if !.has_key? :hint hint = I18n.t('.tabs.'+[:tab]+'.hint', default: '') [:hint] = hint if hint != '' end if .key? :export [:export] = true if [:export].class != FalseClass else [:export] = self.is_export({ tab: tab.to_s }) end if .key? :filter [:filter] = true if [:filter].class != FalseClass else [:filter] = self.is_filter({ tab: tab.to_s }) end [:buttons] = self.({ tab: [:tab] }) #options[:where] = self.where if !options.key? :where end |
#get_tab_where ⇒ Object
Get where for controller action fro defined tab
103 104 105 106 |
# File 'app/controllers/anoubis/data/get.rb', line 103 def get_tab_where return self.etc.tab.where if self.etc.tab.where [] end |
#get_table_action(action, row) ⇒ Boolean
Returns posibility of using action for table data
265 266 267 268 269 270 271 272 273 |
# File 'app/controllers/anoubis/data/get.rb', line 265 def get_table_action(action, row) result = false if self.respond_to?(('table_action_'+action).to_sym) result = send 'table_action_'+action, row else result = true end result end |
#get_table_actions(row) ⇒ Hash
Returns current table actions for selected row
249 250 251 252 253 254 255 256 257 258 |
# File 'app/controllers/anoubis/data/get.rb', line 249 def get_table_actions(row) self.etc.data.actions = self.table_actions if !self.etc.data.actions result = {} self.etc.data.actions.each do |value| if self.get_table_action value, row result[value.to_sym] = I18n.t(params[:controller].sub('/', '.')+'.table.actions.'+value, title: row.sys_title, default: I18n.t('actions.'+value, title: row.sys_title)) end end result end |
#get_table_data ⇒ Object
Load data into the system variable self.etc.data.data and return fields defined in controller.
196 197 198 199 200 201 202 203 204 205 |
# File 'app/controllers/anoubis/data/get.rb', line 196 def get_table_data self.load_table_data self.etc.data.limit, self.etc.data.offset data = [] if self.etc.data.data self.etc.data.data.each do |row| data.push get_data_row row end end data end |
#get_table_data_count ⇒ Integer
Get total number of rows in defined model. Also sets additional system properties self.etc.data.limit, self.etc.data.offset and self.etc.data.count
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/controllers/anoubis/data/get.rb', line 156 def get_table_data_count self.load_table_data_count self.etc.data.limit = params[:limit] if params.has_key? :limit self.etc.data.offset = params[:offset] if params.has_key? :offset if self.etc.data.offset >= self.etc.data.count if self.etc.data.count > 0 self.etc.data.offset = ((self.etc.data.count-1) / self.etc.data.limit).truncate * self.etc.data.limit else self.etc.data.offset = 0 end end self.etc.data.count end |
#get_tenant_where(model) ⇒ Object
114 115 116 117 |
# File 'app/controllers/anoubis/data/get.rb', line 114 def get_tenant_where(model) return { tenant_id: self.current_user.tenant_id } if model.new.respond_to? :tenant_id return {} end |
#get_where ⇒ Object
Get where for controller action
110 111 112 |
# File 'app/controllers/anoubis/data/get.rb', line 110 def get_where self.where end |