Class: Datum::Admin::TableListsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/datum/admin/table_lists_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 17

def create
  @table_list = @data_list.table_lists.build(table_list_params)
  @table_list.save

  redirect_to data_list_table_lists_url(@data_list)
end

#create_importObject



41
42
43
44
45
46
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 41

def create_import
  @table_list = @data_list.table_lists.build
  @table_list.import_to_table_list(file_params.tempfile)

  @table_items = @table_list.table_items.page(params[:page]).per(100)
end

#destroyObject



88
89
90
91
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 88

def destroy
  @table_list.destroy
  redirect_to data_list_table_lists_url(@data_list), notice: 'Export file was successfully destroyed.'
end

#directObject



30
31
32
33
34
35
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 30

def direct
  @table_list = @data_list.table_lists.build(parameters: params.permit(*@data_list.parameters.keys).to_h)
  respond_to do |format|
    format.xlsx { send_data @table_list.direct_xlsx, filename: @table_list.file_name(formats[0]), type: 'application/xlsx' }
  end
end

#editObject



64
65
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 64

def edit
end

#findObject



24
25
26
27
28
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 24

def find
  @table_list = @data_list.table_lists.find_or_create_by(parameters: params.permit(*@data_list.parameters.keys).to_h)
  @table_list.cached_run(params[:timestamp])
  @table_items = @table_list.table_items.page(params[:page]).per(100)
end

#indexObject



9
10
11
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 9

def index
  @table_lists = @data_list.table_lists.page(params[:page])
end

#migrateObject



48
49
50
51
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 48

def migrate
  @table_list.migrate
  redirect_back fallback_location: data_list_table_lists_url(@data_list)
end

#newObject



13
14
15
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 13

def new
  @table_list = @data_list.table_lists.build
end

#new_importObject



37
38
39
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 37

def new_import
  @table_list = @data_list.table_lists.build
end

#rowObject



72
73
74
75
76
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 72

def row
  send_data @table_list.to_row_pdf.render,
            filename: @table_list.pdf_file_name,
            type: 'application/pdf'
end

#runObject



84
85
86
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 84

def run
  TableJob.perform_later(@table_list.id, current_user&.id)
end

#showObject



53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 53

def show
  @table_items = @table_list.table_items.page(params[:page]).per(100)

  respond_to do |format|
    format.html
    format.csv { send_data @table_list.to_csv, filename: @table_list.csv_file_name, type: 'application/csv' }
    format.pdf { send_data @table_list.to_pdf.render, filename: @table_list.pdf_file_name, type: 'application/pdf' }
    format.xlsx { send_data @table_list.cached_xlsx, filename: @table_list.file_name(self.formats[0]), type: 'application/xlsx' }
  end
end

#updateObject



67
68
69
70
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 67

def update
  @table_list.update(table_list_params)
  redirect_to data_list_table_lists_url(@data_list)
end

#xlsxObject



78
79
80
81
82
# File 'app/controllers/datum/admin/table_lists_controller.rb', line 78

def xlsx
  respond_to do |format|
    format.xlsx { send_data @table_list.direct_xlsx, filename: @table_list.file_name(formats[0]), type: 'application/xlsx' }
  end
end