Class: SampleManifestExcel::Worksheet::DataWorksheet

Inherits:
SequencescapeExcel::Worksheet::Base show all
Includes:
SequencescapeExcel::Helpers::Worksheet
Defined in:
app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb

Overview

DataWorksheet creates a data worksheet to be filled in by a client.

Constant Summary

Constants included from SequencescapeExcel::Helpers::Worksheet

SequencescapeExcel::Helpers::Worksheet::STYLES

Instance Attribute Summary collapse

Attributes inherited from SequencescapeExcel::Worksheet::Base

#axlsx_worksheet, #columns, #name, #password, #ranges, #workbook

Instance Method Summary collapse

Methods included from SequencescapeExcel::Helpers::Worksheet

#add_headers, #create_styles, #first_row, #styles

Methods inherited from SequencescapeExcel::Worksheet::Base

#add_row, #add_rows, #create_worksheet, #insert_axlsx_worksheet, #protect

Constructor Details

#initialize(attributes = {}) ⇒ DataWorksheet

Returns a new instance of DataWorksheet.


15
16
17
18
19
20
21
22
23
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 15

def initialize(attributes = {})
  super
  @extra_rows_added = 0
  create_styles
  add_title_and_description(sample_manifest.study.abbreviation, sample_manifest.supplier.name,
                            sample_manifest.count)
  add_columns
  freeze_panes
end

Instance Attribute Details

#sample_manifestObject

Returns the value of attribute sample_manifest


8
9
10
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 8

def sample_manifest
  @sample_manifest
end

#typeObject


25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 25

def type
  @type ||= case sample_manifest.asset_type
            when '1dtube', 'multiplexed_library', 'library'
              'Tubes'
            when 'plate'
              'Plates'
            when 'tube_rack'
              'Tube Racks'
            else
              ''
            end
end

Instance Method Details

#add_columnsObject

Adds columns with all required data to a worksheet


70
71
72
73
74
75
76
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 70

def add_columns
  columns.update(computed_first_row, last_row, ranges, axlsx_worksheet)
  add_headers
  sample_manifest.details_array.each do |detail|
    create_row(detail)
  end
end

#add_extra_cells_for_tube_rack(count) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 53

def add_extra_cells_for_tube_rack(count)
  rack_size = sample_manifest.tube_rack_purpose.size
  add_row ['Rack size:', rack_size]
  count.times do |num|
    axlsx_worksheet.add_row do |row|
      row.add_cell "Rack barcode (#{num + 1}):", type: :string
      row.add_cell nil, type: :string, style: styles[:unlocked_no_border].reference
    end
  end
  @extra_rows_added += count + 1
end

#add_multiplexed_library_tube_barcodeObject


117
118
119
120
121
122
123
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 117

def add_multiplexed_library_tube_barcode
  if sample_manifest.asset_type == 'multiplexed_library'
    add_row ['Multiplexed library tube barcode:', sample_manifest.labware.first.human_barcode]
  else
    add_row
  end
end

#add_title_and_description(study, supplier, count) ⇒ Object

Adds title and description (study abbreviation, supplier name, number of assets sent) to a worksheet.


41
42
43
44
45
46
47
48
49
50
51
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 41

def add_title_and_description(study, supplier, count)
  add_row ['DNA Collections Form']
  add_rows(2)
  add_multiplexed_library_tube_barcode

  add_row ['Study:', study]
  add_row ['Supplier:', supplier]
  add_row ["No. #{type} Sent:", count]
  add_extra_cells_for_tube_rack(count) if type == 'Tube Racks'
  add_rows(1)
end

#computed_first_rowObject


125
126
127
128
129
130
131
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 125

def computed_first_row
  if type == 'Tube Racks'
    first_row + @extra_rows_added
  else
    first_row
  end
end

#create_row(detail) ⇒ Object

Creates row filled in with required column values, also unlocks (adds unlock style) the cells that should be filled in by clients


81
82
83
84
85
86
87
88
89
90
91
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 81

def create_row(detail)
  axlsx_worksheet.add_row do |row|
    columns.each do |column|
      if column.unlocked?
        row.add_cell column.attribute_value(detail), type: column.type, style: styles[:unlocked].reference
      else
        row.add_cell column.attribute_value(detail), type: column.type
      end
    end
  end
end

#freeze_after_column(name) ⇒ Object

Finds the column after which the panes should be frozen. If the column was not found freezes the panes after column 0 (basically not frozen vertically)


108
109
110
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 108

def freeze_after_column(name)
  columns.find_by(:name, name) ? columns.find_by(:name, name).number : 0
end

#freeze_panes(name = :sanger_sample_id) ⇒ Object

Freezes panes vertically after particular column (sanger_sample_id by default) and horizontally after headings


96
97
98
99
100
101
102
103
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 96

def freeze_panes(name = :sanger_sample_id)
  axlsx_worksheet.sheet_view.pane do |pane|
    pane.state = :frozen
    pane.y_split = computed_first_row - 1
    pane.x_split = freeze_after_column(name)
    pane.active_pane = :bottom_right
  end
end

#last_rowObject

The row where the table with data end


113
114
115
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 113

def last_row
  @last_row ||= sample_manifest.details_array.count + computed_first_row - 1
end