module SmartManagement::Helpers
Constants
- COLUMNS_AT_END
- COLUMNS_AT_FIRST
- PROTECTED_COLUMNS
- UNSEARCHABLE_TYPES
Public Instance Methods
colspan()
click to toggle source
# File lib/smart_management/helpers.rb, line 51 def colspan model_class.columns.length + 2 end
editable_columns()
click to toggle source
# File lib/smart_management/helpers.rb, line 29 def editable_columns model_class.columns.reject do |column| PROTECTED_COLUMNS.include?(column.name) end end
editable_columns_names()
click to toggle source
# File lib/smart_management/helpers.rb, line 35 def editable_columns_names editable_columns.map(&:name) end
field_for(form:, klass:, column:)
click to toggle source
# File lib/smart_management/helpers.rb, line 55 def field_for(form:, klass:, column:) if klass.reflect_on_association(assoc_name(column.name)) form.send(:association, assoc_name(column.name)) else form.send(:input, column.name) end end
json_options()
click to toggle source
# File lib/smart_management/helpers.rb, line 15 def json_options {} end
model_class()
click to toggle source
# File lib/smart_management/helpers.rb, line 47 def model_class singular_model_name.capitalize.camelize.constantize end
plural_model_name()
click to toggle source
# File lib/smart_management/helpers.rb, line 43 def plural_model_name controller_name.to_s end
scope()
click to toggle source
# File lib/smart_management/helpers.rb, line 67 def scope model_class end
searchable?(column)
click to toggle source
# File lib/smart_management/helpers.rb, line 63 def searchable?(column) UNSEARCHABLE_TYPES.include?(column.type) end
singular_model_name()
click to toggle source
# File lib/smart_management/helpers.rb, line 39 def singular_model_name controller_name.to_s.singularize end
smart_management_row(column)
click to toggle source
# File lib/smart_management/helpers.rb, line 8 def smart_management_row(column) if column.sql_type.include?('time') filter = " | date: 'dd-MM-yyyy hh:mm:ss'" end "{{row.resource.#{column.name} #{filter} }}" end
visible_columns()
click to toggle source
# File lib/smart_management/helpers.rb, line 19 def visible_columns model_class.columns.select { |c| visible_columns_names.include? c.name } end
visible_columns_names()
click to toggle source
# File lib/smart_management/helpers.rb, line 23 def visible_columns_names COLUMNS_AT_FIRST + (model_class.columns.map(&:name) - PROTECTED_COLUMNS) + COLUMNS_AT_END end
Private Instance Methods
assoc_name(column)
click to toggle source
# File lib/smart_management/helpers.rb, line 73 def assoc_name(column) column.gsub(/_id$/, '') end