Sha256: 505d1b661a39621a9055188f9706d80d5fae2cdcf27af8bab2a19dbfad24f85b

Contents?: true

Size: 1.17 KB

Versions: 17

Compression:

Stored size: 1.17 KB

Contents

module EgovUtils
  module GridHelper

    def type_for_grid(type)
      case type
      when 'integer', 'float', 'decimal'
        'Number'
      when 'string', 'list', 'love'
        'String'
      when 'date', 'datetime'
        'Date'
      when 'boolean'
        'Boolean'
      else
        raise "Undefined grid type for type #{type}"
      end
    end

    def field_for_grid(attribute)
      s = "\'"
      s << attribute.name
      s << '\': {path: "'
      s << attribute.path
      s << '", type: '
      s << type_for_grid(attribute.type)
      s << '}'
      s
    end

    def column_for_grid(grid, attribute)
      s = "{"
      s << "field: '#{attribute.name}'"
      s << ", title: '#{attribute.attribute_name.human}'"
      s << ", columnTemplate: '<a href=\"#{polymorphic_path(grid.schema.model)}/{id}\">{#{attribute.name}}</div>'" if attribute.name == grid.schema.main_attribute_name
      if attribute.type == 'list'
        s << ", format: ( (value) -> I18n.t(value, {scope: 'activerecord.attributes.#{attribute.model.model_name.i18n_key}.#{attribute.name.to_s.pluralize}'}) ) "
      end
      s << "}"
    end

    def additional_grid_edit_buttons(schema)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
egov_utils-0.2.2 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.2.1 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.2.0 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.37 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.36 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.35 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.33 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.32 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.31 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.30 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.29 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.28 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.27 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.26 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.23 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.19 app/helpers/egov_utils/grid_helper.rb
egov_utils-0.1.18 app/helpers/egov_utils/grid_helper.rb