Class: SnitchReporting::SnitchReportsController

Inherits:
ApplicationController show all
Includes:
ParamsHelper
Defined in:
app/controllers/snitch_reporting/snitch_reports_controller.rb

Instance Method Summary collapse

Methods included from ParamsHelper

#sort_order, #sortable, #svg, #toggled_sort_order, #true_param?, #truthy?

Instance Method Details

#indexObject



9
10
11
12
13
14
15
# File 'app/controllers/snitch_reporting/snitch_reports_controller.rb', line 9

def index
  @reports = ::SnitchReporting::SnitchReport.order("last_occurrence_at DESC NULLS LAST").page(params[:page]).per(params[:per] || 25)

  # set_report_preferences
  filter_reports
  # sort_reports
end

#showObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/snitch_reporting/snitch_reports_controller.rb', line 17

def show
  @report = ::SnitchReporting::SnitchReport.find(params[:id])
  occurrences = @report.occurrences.order(created_at: :asc)
  @occurrence = occurrences.find_by(id: params[:occurrence]) || occurrences.last
  occurrence_ids = occurrences.ids
  occurrence_idx = occurrence_ids.index(@occurrence.id)
  @paged_ids = {
    first: occurrence_idx == 0 ? nil : occurrence_ids.first,
    prev:  occurrence_idx == 0 ? nil : occurrence_ids[occurrence_idx - 1],
    next:  occurrence_idx == occurrence_ids.length - 1 ? nil : occurrence_ids[occurrence_idx + 1],
    last:  occurrence_idx == occurrence_ids.length - 1 ? nil : occurrence_ids.last,
  }
  # @formatted_occurrence_data = occurrences.staggered_occurrence_data
  # @comments = @report.comments.order(created_at: :desc)
end

#updateObject



34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/snitch_reporting/snitch_reports_controller.rb', line 34

def update
  @report = ::SnitchReporting::SnitchReport.find(params[:id])
  # @report.acting_user = current_user
  @report.update(report_params)

  respond_to do |format|
    format.html { redirect_to @report }
    format.json
  end
end