Class: Cellscan::FilesController

Inherits:
ApplicationController show all
Includes:
ActionView::Helpers::UrlHelper, Pagy::Backend
Defined in:
app/controllers/cellscan/files_controller.rb

Instance Method Summary collapse

Instance Method Details

#openObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/cellscan/files_controller.rb', line 11

def open
  @path = params[:path]
  @highlight = params[:highlight]&.to_i
  @error = nil
  if @path.present?
    begin
      @headers, data = Cellscan.file_loader.call(@path)
      data = convert_links(data) if @headers.first == "ZIPCONTENT"
      @headers.unshift("index")
      opts = { page: (@highlight.to_f / Pagy::DEFAULT[:items]).ceil } if @highlight
      data = data.map.with_index { |row, i| [i + 1, *row] }
      @pagy, @rows = pagy_array(data, **opts || {})
    rescue => e
      @error = e.message
    end
  end
end