Class: SnitchReporting::SnitchReportsController

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

Instance Method Summary collapse

Methods included from SnitchReportHelper

#filter_string_from_params, #search_path_from_filter_string

Methods included from ParamsHelper

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

Instance Method Details

#indexObject



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

def index
  ::SnitchReporting::SnitchReport.warn("Error", some: :data)
  @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

#interpret_searchObject



19
20
21
# File 'app/controllers/snitch_reporting/snitch_reports_controller.rb', line 19

def interpret_search
  redirect_to snitch_reports_path(filter_string: params[:filter_string])
end

#showObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/snitch_reporting/snitch_reports_controller.rb', line 23

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



40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/snitch_reporting/snitch_reports_controller.rb', line 40

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