class Thinreports::Core::Shape::List::Manager

Attributes

current_page[R]

@return [Thinreports::Core::Shape:::List::Page]

current_page_state[R]

@return [Thinreports::Core::Shape::List::PageState]

page_count[RW]

@return [Integer]

page_finalize_handler[RW]

@return [Proc]

Public Class Methods

new(page) click to toggle source

@param [Thinreports::Core::Shape::List::Page] page

# File lib/thinreports/core/shape/list/manager.rb, line 29
def initialize(page)
  switch_current!(page)

  @finalized = false
  @page_count = 0

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

Public Instance Methods

add_detail(values = {}, &block) click to toggle source

@param (see build_section) @return [Boolean]

# File lib/thinreports/core/shape/list/manager.rb, line 76
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?() click to toggle source

@return [Boolean]

# File lib/thinreports/core/shape/list/manager.rb, line 155
def auto_page_break?
  format.auto_page_break?
end
build_header(values = {}, &block) click to toggle source

@param [Hash] values ({}) @yield [header] @yieldparam [Thinreports::Core::Shape::List::SectionInterface] header @return [Thinreports::Core::Shape::List::SectionInterface] @raise [Thinreports::Errors::DisabledListSection]

# File lib/thinreports/core/shape/list/manager.rb, line 62
def build_header(values = {}, &block)
  raise Thinreports::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 = {}, &block) click to toggle source

@param [Thinreports::Core::Shape::List::SectionInterface] section @param values (see Thinreports::Core::Shape::Manager::Target#values) @yield [section,] @yieldparam [Thinreports::Core::Shape::List::SectionInterface] section @return [Thinreports::Core::Shape::List::SectionInterface]

# File lib/thinreports/core/shape/list/manager.rb, line 120
def build_section(section, values = {}, &block)
  section.values(values)
  call_block_in(section, &block)
end
change_new_page(&block) click to toggle source

@yield [new_list] @yieldparam [Thinreports::Core::Shape::List::Page] new_list

# File lib/thinreports/core/shape/list/manager.rb, line 50
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
finalize() click to toggle source
# File lib/thinreports/core/shape/list/manager.rb, line 185
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 = {}) click to toggle source

@param [Hash] options @option options [Boolean] :ignore_page_footer (false)

When the switch of the page is generated by #finalize, it is used.
# File lib/thinreports/core/shape/list/manager.rb, line 162
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
finalized?() click to toggle source

@return [Boolean]

# File lib/thinreports/core/shape/list/manager.rb, line 207
def finalized?
  @finalized
end
format() click to toggle source

@return [Thinreports::Core::Shape::List::Format]

# File lib/thinreports/core/shape/list/manager.rb, line 222
def format
  current_page_state.format
end
header_section() click to toggle source

@return [Thinreports::Core::Shape::List::SectionInterface]

# File lib/thinreports/core/shape/list/manager.rb, line 70
def header_section
  current_page_state.header
end
init_section(section_name) click to toggle source

@param [Symbol] section_name @return [Thinreports::Core::Shape::List::SectionInterface]

# File lib/thinreports/core/shape/list/manager.rb, line 127
def init_section(section_name)
  List::SectionInterface.new(current_page,
                             format.sections[section_name],
                             section_name)
end
insert_detail(values = {}, &block) click to toggle source

@param values (see Thinreports::Core::Shape::Manager::Target#values) @yield [section,] @yieldparam [Thinreports::Core::Shape::List::SectionInterface] section @return [Thinreports::Core::Shape::List::SectionInterface]

# File lib/thinreports/core/shape/list/manager.rb, line 100
def insert_detail(values = {}, &block)
  detail = build_section(init_section(:detail), values, &block)
  insert_row(detail)
end
insert_row(row) click to toggle source

@param [Thinreports::Core::Shape::List::SectionInterface] row @return [Thinreports::Core::Shape::List::SectionInterface]

# File lib/thinreports/core/shape/list/manager.rb, line 107
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
layout() click to toggle source

@return [Thinreports::Layout::Base]

# File lib/thinreports/core/shape/list/manager.rb, line 217
def layout
  current_page_state.parent.layout
end
overflow_with?(section_name = :detail) click to toggle source

@param [Symbol] section_name @return [Boolean]

# File lib/thinreports/core/shape/list/manager.rb, line 135
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_height() click to toggle source

@return [Numeric]

# File lib/thinreports/core/shape/list/manager.rb, line 145
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
report() click to toggle source

@return [Thinreports::Report::Base]

# File lib/thinreports/core/shape/list/manager.rb, line 212
def report
  current_page_state.parent.report
end
switch_current!(page) click to toggle source

@param [Thinreports::Core::Shape::List::Page] page @return [Thinreports::Core::Shape::List::Manager]

# File lib/thinreports/core/shape/list/manager.rb, line 42
def switch_current!(page)
  @current_page = page
  @current_page_state = page.internal
  self
end