2018-04-18 22:47:52 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ReportDatatable < CustomDatatable
|
2018-07-10 16:58:39 +08:00
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2018-04-18 22:47:52 +08:00
|
|
|
TABLE_COLUMNS = %w(
|
2018-12-13 18:18:09 +08:00
|
|
|
Report.project_name
|
|
|
|
Report.name
|
|
|
|
Report.created_by
|
|
|
|
Report.modified_by
|
|
|
|
Report.created_at
|
|
|
|
Report.updated_at
|
2018-04-18 22:47:52 +08:00
|
|
|
).freeze
|
|
|
|
|
|
|
|
def_delegator :@view, :edit_project_report_path
|
|
|
|
def initialize(view, user, reports)
|
|
|
|
super(view)
|
|
|
|
@user = user
|
|
|
|
@reports = reports
|
|
|
|
end
|
|
|
|
|
|
|
|
def sortable_columns
|
|
|
|
@sortable_columns ||= TABLE_COLUMNS
|
|
|
|
end
|
|
|
|
|
|
|
|
def searchable_columns
|
|
|
|
@searchable_columns ||= TABLE_COLUMNS
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def data
|
|
|
|
records.map do |record|
|
|
|
|
{
|
2018-12-13 18:18:09 +08:00
|
|
|
'0' => record.id,
|
|
|
|
'1' => sanitize_input(record.project_name),
|
|
|
|
'2' => sanitize_input(record.name),
|
|
|
|
'3' => sanitize_input(record.created_by),
|
|
|
|
'4' => sanitize_input(record.modified_by),
|
|
|
|
'5' => I18n.l(record.created_at, format: :full),
|
|
|
|
'6' => I18n.l(record.updated_at, format: :full),
|
2018-04-18 22:47:52 +08:00
|
|
|
'edit' => edit_project_report_path(record.project_id, record.id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_raw_records
|
2018-12-13 18:18:09 +08:00
|
|
|
res = @reports.joins(:project)
|
|
|
|
.joins(
|
|
|
|
'LEFT OUTER JOIN users AS creators ' \
|
|
|
|
'ON reports.user_id = creators.id'
|
|
|
|
).joins(
|
|
|
|
'LEFT OUTER JOIN users AS modifiers '\
|
|
|
|
'ON reports.last_modified_by_id = modifiers.id'
|
|
|
|
)
|
|
|
|
.select('reports.* AS reports')
|
|
|
|
.select('projects.name AS project_name')
|
|
|
|
.select('creators.full_name AS created_by')
|
|
|
|
.select('modifiers.full_name AS modified_by')
|
|
|
|
Report.from(res, :reports)
|
2018-04-18 22:47:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==== Insert 'presenter'-like methods below if necessary
|
|
|
|
end
|