Class: Infold::Views::IndexWriter

Inherits:
BaseWriter show all
Defined in:
lib/infold/writers/views/index_writer.rb

Instance Attribute Summary collapse

Attributes inherited from BaseWriter

#resource

Instance Method Summary collapse

Methods inherited from BaseWriter

#field_display_code

Methods inherited from BaseWriter

#edit_path, #indent, #index_path, #new_path, #resource_name, #show_path

Constructor Details

#initialize(resource) ⇒ IndexWriter

Returns a new instance of IndexWriter.



8
9
10
# File 'lib/infold/writers/views/index_writer.rb', line 8

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#app_titleObject (readonly)

Returns the value of attribute app_title.



6
7
8
# File 'lib/infold/writers/views/index_writer.rb', line 6

def app_title
  @app_title
end

Instance Method Details

#association_search_conditionsObject



16
# File 'lib/infold/writers/views/index_writer.rb', line 16

def association_search_conditions; @resource.conditions(:association_search)&.sort_by { |c| c.association_seq } end

#association_search_list_fieldsObject



17
# File 'lib/infold/writers/views/index_writer.rb', line 17

def association_search_list_fields; @resource.association_search_list_fields end

#condition_form_code(condition) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/infold/writers/views/index_writer.rb', line 19

def condition_form_code(condition)
  code = "= render Admin::FieldsetComponent.new(form, " +
    ":#{condition.scope}, :#{condition.form_kind(:index)}, alignment: false, \n" +
    "[TAB]label: Admin::#{resource_name(:model)}.human_attribute_name(:#{condition.field.name})"
  case condition.form_kind(:index)
  when :association_search
    "#{code}, #{belongs_to_search_form_option(condition.field.association)})"
  when :select
    "#{code}, list: #{form_field_list(condition.field)}, " +
      "selected_value: form.object.#{condition.scope})"
  when :checkbox
    "#{code}, #{checkbox_form_option(condition.field, condition.scope)})"
  when :switch
    "#{code}, include_hidden: false)"
  else
    option = text_form_option(condition.field, placeholder: condition.sign_label).presence
    option ? "#{code}, #{option})" : "#{code})"
  end
end

#csv_field_code(csv_field) ⇒ Object



44
45
46
47
48
# File 'lib/infold/writers/views/index_writer.rb', line 44

def csv_field_code(csv_field)
  code = "#{resource_name(:snake)}.#{csv_field.name}"
  code = "#{code}_i18n" if csv_field.enum
  code
end

#csv_fieldsObject



14
# File 'lib/infold/writers/views/index_writer.rb', line 14

def csv_fields; @resource.csv_fields end

#index_conditionsObject



12
# File 'lib/infold/writers/views/index_writer.rb', line 12

def index_conditions; @resource.conditions(:index)&.sort_by { |c| c.index_seq } end

#index_list_fieldsObject



13
# File 'lib/infold/writers/views/index_writer.rb', line 13

def index_list_fields; @resource.index_list_fields end

#list_header_code(list_field) ⇒ Object



39
40
41
42
# File 'lib/infold/writers/views/index_writer.rb', line 39

def list_header_code(list_field)
  "= render Admin::SortableComponent.new(@search, :#{list_field.name}, " +
    "label: Admin::#{resource_name(:model)}.human_attribute_name(:#{list_field.name}))"
end