Class: Releaf::Builders::IndexBuilder

Inherits:
Object
  • Object
show all
Includes:
Collection, View
Defined in:
app/builders/releaf/builders/index_builder.rb

Direct Known Subclasses

Admin::Books::IndexBuilder

Instance Attribute Summary

Attributes included from Collection

#collection

Attributes included from Template

#template

Instance Method Summary collapse

Methods included from Collection

#initialize

Methods included from View

#breadcrumb_item, #breadcrumbs, #dialog_name, #flash_item, #flash_notices, #footer_primary_block, #footer_secondary_block, #footer_secondary_tools, #footer_tools, #header, #output, #section, #section_attributes, #section_blocks, #section_footer, #section_footer_class, #section_header

Methods included from Template

#initialize

Methods included from Base

#default_translation_scope, #html_escape, #icon, #layout_settings, #locale_options, #resource_title, #safe_join, #t, #tag, #template_variable, #translate_locale, #wrapper

Instance Method Details

#dialog?Boolean

Returns:

  • (Boolean)

9
10
11
# File 'app/builders/releaf/builders/index_builder.rb', line 9

def dialog?
  false
end

#extra_search_available?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'app/builders/releaf/builders/index_builder.rb', line 17

def extra_search_available?
  extra_search_block.present?
end

#extra_search_blockObject


48
49
50
51
52
53
54
55
# File 'app/builders/releaf/builders/index_builder.rb', line 48

def extra_search_block
  if @extra_search
    @extra_search
  else
    content = extra_search_content
    @extra_search = tag(:div, class: ["extras"]){ [content, extra_search_button] } if content.present?
  end
end

#extra_search_buttonObject


44
45
46
# File 'app/builders/releaf/builders/index_builder.rb', line 44

def extra_search_button
  button(t("Filter"), "search", type: "submit", title: t("Search"))
end

#extra_search_contentObject


42
# File 'app/builders/releaf/builders/index_builder.rb', line 42

def extra_search_content; end

82
83
84
85
86
87
# File 'app/builders/releaf/builders/index_builder.rb', line 82

def footer_blocks
  list = [footer_primary_block]
  list << pagination_block if pagination?
  list << footer_secondary_block
  list
end

89
90
91
92
93
# File 'app/builders/releaf/builders/index_builder.rb', line 89

def footer_primary_tools
  items = []
  items << resource_creation_button if feature_available?(:create)
  items
end

#header_extrasObject


5
6
7
# File 'app/builders/releaf/builders/index_builder.rb', line 5

def header_extras
  search_block if feature_available?(:search)
end

#pagination?Boolean

Returns:

  • (Boolean)

95
96
97
# File 'app/builders/releaf/builders/index_builder.rb', line 95

def pagination?
  collection.respond_to?(:page)
end

#pagination_blockObject


103
104
105
# File 'app/builders/releaf/builders/index_builder.rb', line 103

def pagination_block
  pagination_builder_class.new(template, collection: collection, params: params).output
end

#pagination_builder_classObject


99
100
101
# File 'app/builders/releaf/builders/index_builder.rb', line 99

def pagination_builder_class
  Releaf::Builders::PaginationBuilder
end

#resource_creation_buttonObject


107
108
109
110
111
# File 'app/builders/releaf/builders/index_builder.rb', line 107

def resource_creation_button
  url = url_for(controller: controller_name, action: "new")
  text = t("Create new resource")
  button(text, "plus", class: "primary", href: url)
end

#search_blockObject


57
58
59
60
# File 'app/builders/releaf/builders/index_builder.rb', line 57

def search_block
  parts = [text_search_block, extra_search_block].compact
  tag(:form, search_form_attributes){ parts } if parts.present?
end

#search_field(name) ⇒ Object


35
36
37
38
39
# File 'app/builders/releaf/builders/index_builder.rb', line 35

def search_field( name )
  tag(:div, class: "search-field", data: { name: name } ) do
    yield
  end
end

#search_form_attributesObject


62
63
64
65
66
67
68
69
# File 'app/builders/releaf/builders/index_builder.rb', line 62

def search_form_attributes
  classes = ["search"]
  classes << "has-text-search" if text_search_available?
  classes << "has-extra-search" if extra_search_available?
  url = url_for(controller: controller_name, action: "index")

  {class: classes, action: url}
end

#section_bodyObject


120
121
122
123
124
# File 'app/builders/releaf/builders/index_builder.rb', line 120

def section_body
  tag(:div, class: "body") do
    template.releaf_table(collection, template.resource_class, table_options)
  end
end

#section_header_extrasObject


75
76
77
78
79
80
# File 'app/builders/releaf/builders/index_builder.rb', line 75

def section_header_extras
  return unless collection.respond_to? :total_entries
  tag(:span, class: "extras totals only-text") do
    t("Resources found", count: collection.total_entries, default: "%{count} resources found", create_plurals: true)
  end
end

#section_header_textObject


71
72
73
# File 'app/builders/releaf/builders/index_builder.rb', line 71

def section_header_text
  t("All resources")
end

#table_optionsObject


113
114
115
116
117
118
# File 'app/builders/releaf/builders/index_builder.rb', line 113

def table_options
  {
    builder: builder_class(:table),
    toolbox: feature_available?(:toolbox)
  }
end

#text_search_available?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'app/builders/releaf/builders/index_builder.rb', line 13

def text_search_available?
  controller.searchable_fields.present?
end

#text_search_blockObject


21
22
23
24
# File 'app/builders/releaf/builders/index_builder.rb', line 21

def text_search_block
  return unless text_search_available?
  tag(:div, class: "text-search"){ text_search_content }
end

#text_search_contentObject


26
27
28
29
30
31
32
33
# File 'app/builders/releaf/builders/index_builder.rb', line 26

def text_search_content
  search_field "search" do
    [
      tag(:input, "", name: "search", type: "search", class: "text", value: params[:search], autofocus: true),
      button(nil, "search", type: "submit", title: t('Search'))
    ]
  end
end