Class: Thinreports::BasicReport::Core::Shape::List::Manager

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/thinreports/basic_report/core/shape/list/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#blank_value?, #call_block_in, #deep_copy, included

Constructor Details

#initialize(page) ⇒ Manager

Returns a new instance of Manager.



30
31
32
33
34
35
36
37
38
39
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 30

def initialize(page)
  switch_current!(page)

  @finalized = false
  @page_count = 0

  @page_finalize_handler = nil
  @page_footer_handler = nil
  @footer_handler = nil
end

Instance Attribute Details

#current_pageThinreports::BasicReport::Core::Shape:::List::Page (readonly)

Returns:

  • (Thinreports::BasicReport::Core::Shape:::List::Page)


12
13
14
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 12

def current_page
  @current_page
end

#current_page_stateThinreports::BasicReport::Core::Shape::List::PageState (readonly)



15
16
17
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 15

def current_page_state
  @current_page_state
end

Returns:

  • (Proc)


27
28
29
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 27

def footer_handler
  @footer_handler
end

#page_countInteger

Returns:

  • (Integer)


18
19
20
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 18

def page_count
  @page_count
end

#page_finalize_handlerProc

Returns:

  • (Proc)


21
22
23
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 21

def page_finalize_handler
  @page_finalize_handler
end

Returns:

  • (Proc)


24
25
26
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 24

def page_footer_handler
  @page_footer_handler
end

Instance Method Details

#add_detail(values = {}, &block) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 77

def add_detail(values = {}, &block)
  return false if current_page_state.finalized?

  successful = true

  if overflow_with?(:detail)
    if auto_page_break?
      change_new_page do |new_list|
        new_list.manager.insert_detail(values, &block)
      end
    else
      finalize
      successful = false
    end
  else
    insert_detail(values, &block)
  end
  successful
end

#auto_page_break?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 156

def auto_page_break?
  format.auto_page_break?
end

#build_header(values = {}) {|header| ... } ⇒ Thinreports::BasicReport::Core::Shape::List::SectionInterface

Parameters:

  • values (Hash) (defaults to: {})

    ({})

Yields:

  • (header)

Yield Parameters:

Returns:

Raises:



63
64
65
66
67
68
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 63

def build_header(values = {}, &block)
  raise Thinreports::BasicReport::Errors::DisabledListSection, 'header' unless format.has_header?

  current_page_state.header ||= init_section(:header)
  build_section(header_section, values, &block)
end

#build_section(section, values = {}) {|section, | ... } ⇒ Thinreports::BasicReport::Core::Shape::List::SectionInterface



121
122
123
124
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 121

def build_section(section, values = {}, &block)
  section.values(values)
  call_block_in(section, &block)
end

#change_new_page {|new_list| ... } ⇒ Object

Yields:

  • (new_list)

Yield Parameters:



51
52
53
54
55
56
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 51

def change_new_page(&block)
  finalize_page
  new_page = report.internal.copy_page

  block.call(new_page.list(current_page.id)) if block_given?
end

#finalizeObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 186

def finalize
  return if finalized?
  finalize_page

  if format.has_footer?
    footer = init_section(:footer)

    @footer_handler.call(footer) if @footer_handler

    if auto_page_break? && overflow_with?(:footer)
      change_new_page do |new_list|
        new_list.manager.insert_row(footer)
        new_list.manager.finalize_page(ignore_page_footer: true)
      end
    else
      insert_row(footer)
    end
  end
  @finalized = true
end

#finalize_page(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :ignore_page_footer (Boolean) — default: false

    When the switch of the page is generated by #finalize, it is used.



163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 163

def finalize_page(options = {})
  return if current_page_state.finalized?

  build_header if format.has_header?

  finalize_page_footer unless options[:ignore_page_footer]

  current_page_state.finalized!
  @page_finalize_handler.call if @page_finalize_handler

  @page_count += 1
  current_page_state.no = @page_count
end


177
178
179
180
181
182
183
184
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 177

def finalize_page_footer
  return unless format.has_page_footer?

  page_footer = init_section(:page_footer)
  insert_row(page_footer)

  @page_footer_handler.call(page_footer) if @page_footer_handler
end

#finalized?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 208

def finalized?
  @finalized
end

#formatThinreports::BasicReport::Core::Shape::List::Format



223
224
225
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 223

def format
  current_page_state.format
end

#header_sectionThinreports::BasicReport::Core::Shape::List::SectionInterface



71
72
73
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 71

def header_section
  current_page_state.header
end

#init_section(section_name) ⇒ Thinreports::BasicReport::Core::Shape::List::SectionInterface

Parameters:

  • section_name (Symbol)

Returns:



128
129
130
131
132
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 128

def init_section(section_name)
  List::SectionInterface.new(current_page,
                             format.sections[section_name],
                             section_name)
end

#insert_detail(values = {}) {|section, | ... } ⇒ Thinreports::BasicReport::Core::Shape::List::SectionInterface



101
102
103
104
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 101

def insert_detail(values = {}, &block)
  detail = build_section(init_section(:detail), values, &block)
  insert_row(detail)
end

#insert_row(row) ⇒ Thinreports::BasicReport::Core::Shape::List::SectionInterface



108
109
110
111
112
113
114
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 108

def insert_row(row)
  row.internal.move_top_to(current_page_state.height)

  current_page_state.rows << row
  current_page_state.height += row.height
  row
end

#layoutThinreports::BasicReport::Layout::Base



218
219
220
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 218

def layout
  current_page_state.parent.layout
end

#overflow_with?(section_name = :detail) ⇒ Boolean

Parameters:

  • section_name (Symbol) (defaults to: :detail)

Returns:

  • (Boolean)


136
137
138
139
140
141
142
143
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 136

def overflow_with?(section_name = :detail)
  max_height = page_max_height

  max_height += format.section_height(:page_footer) if section_name == :footer && format.has_page_footer?

  height = format.section_height(section_name)
  (current_page_state.height + height) > max_height
end

#page_max_heightNumeric

Returns:

  • (Numeric)


146
147
148
149
150
151
152
153
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 146

def page_max_height
  @page_max_height ||= begin
    h = format.height
    h -= format.section_height(:page_footer)
    h -= format.section_height(:footer) unless auto_page_break?
    h
  end
end

#reportThinreports::BasicReport::Report::Base



213
214
215
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 213

def report
  current_page_state.parent.report
end

#switch_current!(page) ⇒ Thinreports::BasicReport::Core::Shape::List::Manager



43
44
45
46
47
# File 'lib/thinreports/basic_report/core/shape/list/manager.rb', line 43

def switch_current!(page)
  @current_page = page
  @current_page_state = page.internal
  self
end