2016-02-12 23:52:43 +08:00
|
|
|
class ReportsController < ApplicationController
|
2017-01-25 00:06:51 +08:00
|
|
|
include TeamsHelper
|
2017-03-08 21:14:03 +08:00
|
|
|
include ReportActions
|
2021-04-20 19:35:40 +08:00
|
|
|
include ReportsHelper
|
2021-06-10 16:59:34 +08:00
|
|
|
include StringUtility
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2021-04-13 22:36:52 +08:00
|
|
|
before_action :load_vars, only: %i(edit update document_preview generate_pdf generate_docx status
|
|
|
|
save_pdf_to_inventory_modal save_pdf_to_inventory_item)
|
2022-05-23 19:32:15 +08:00
|
|
|
before_action :load_vars_nested, only: %i(create edit update generate_pdf
|
|
|
|
generate_docx new_template_values project_contents)
|
2021-06-17 22:23:27 +08:00
|
|
|
before_action :load_wizard_vars, only: %i(new edit)
|
2021-04-13 22:36:52 +08:00
|
|
|
before_action :load_available_repositories, only: %i(index save_pdf_to_inventory_modal available_repositories)
|
2022-10-14 19:57:13 +08:00
|
|
|
before_action :check_project_read_permissions, only: %i(create edit update generate_pdf
|
|
|
|
generate_docx new_template_values project_contents)
|
2024-01-16 20:53:41 +08:00
|
|
|
before_action :check_read_permissions, except: %i(index new create edit update destroy actions_toolbar generate_pdf
|
2022-10-14 19:57:13 +08:00
|
|
|
generate_docx new_template_values project_contents
|
|
|
|
available_repositories)
|
2022-05-23 19:32:15 +08:00
|
|
|
before_action :check_create_permissions, only: %i(new create)
|
2022-10-14 19:57:13 +08:00
|
|
|
before_action :check_manage_permissions, only: %i(edit update generate_pdf generate_docx)
|
2020-04-23 22:02:36 +08:00
|
|
|
before_action :switch_team_with_param, only: :index
|
2021-05-20 20:16:39 +08:00
|
|
|
after_action :generate_pdf_report, only: %i(create update generate_pdf)
|
2021-04-20 19:35:40 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
# Index showing all reports of a single project
|
2024-01-11 02:56:01 +08:00
|
|
|
def index
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
reports = Lists::ReportsService.new(Report.viewable_by_user(current_user, current_team), params).call
|
|
|
|
render json: reports, each_serializer: Lists::ReportSerializer,
|
|
|
|
user: current_user, meta: pagination_dict(reports)
|
|
|
|
end
|
|
|
|
format.html do
|
|
|
|
render 'index'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-18 22:47:52 +08:00
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
# Report grouped by modules
|
2016-07-21 19:11:15 +08:00
|
|
|
def new
|
2021-04-06 19:56:24 +08:00
|
|
|
@templates = Extends::REPORT_TEMPLATES
|
2021-04-08 23:40:16 +08:00
|
|
|
@report = current_team.reports.new
|
2021-04-06 19:56:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def new_template_values
|
2021-05-18 21:19:51 +08:00
|
|
|
if Extends::REPORT_TEMPLATES.key?(params[:template]&.to_sym)
|
|
|
|
template = params[:template]
|
|
|
|
else
|
|
|
|
return render_404
|
|
|
|
end
|
2021-04-06 19:56:24 +08:00
|
|
|
|
2021-04-19 16:17:44 +08:00
|
|
|
report = current_team.reports.where(project: @project).find_by(id: params[:report_id])
|
2022-10-14 19:57:13 +08:00
|
|
|
if report.present?
|
|
|
|
return render_403 unless can_manage_report?(report)
|
|
|
|
else
|
|
|
|
return render_403 unless can_create_reports?(current_team)
|
|
|
|
|
|
|
|
report = current_team.reports.new(project: @project)
|
|
|
|
end
|
2021-04-19 16:17:44 +08:00
|
|
|
|
2023-11-16 16:05:21 +08:00
|
|
|
if lookup_context.any_templates?("reports/templates/#{template}/edit")
|
2023-07-18 19:36:41 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
template: "reports/templates/#{template}/edit",
|
|
|
|
layout: 'reports/template_values_editor',
|
|
|
|
locals: { report: report },
|
|
|
|
formats: :html
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'reports/wizard/no_template_values',
|
|
|
|
formats: :html)
|
|
|
|
}
|
2021-04-06 19:56:24 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Creating new report from the _save modal of the new page
|
|
|
|
def create
|
|
|
|
@report = Report.new(report_params)
|
|
|
|
@report.project = @project
|
|
|
|
@report.user = current_user
|
2018-04-18 22:47:52 +08:00
|
|
|
@report.team = current_team
|
2021-04-20 19:35:40 +08:00
|
|
|
@report.settings = report_params[:settings]
|
2016-02-12 23:52:43 +08:00
|
|
|
@report.last_modified_by = current_user
|
2021-05-06 16:53:40 +08:00
|
|
|
|
|
|
|
ReportActions::ReportContent.new(
|
2021-04-20 19:35:40 +08:00
|
|
|
@report,
|
|
|
|
params[:project_content],
|
|
|
|
params[:template_values],
|
|
|
|
current_user
|
|
|
|
).save_with_content
|
|
|
|
|
2021-05-06 16:53:40 +08:00
|
|
|
if @report.errors.blank?
|
2019-03-14 02:05:29 +08:00
|
|
|
log_activity(:create_report)
|
2021-05-07 22:23:35 +08:00
|
|
|
flash[:success] = t('projects.reports.index.generation.accepted_message')
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2021-04-20 19:35:40 +08:00
|
|
|
redirect_to reports_path
|
2016-02-12 23:52:43 +08:00
|
|
|
else
|
2021-05-06 16:53:40 +08:00
|
|
|
render json: @report.errors.full_messages, status: :unprocessable_entity
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2021-04-13 20:10:52 +08:00
|
|
|
@edit = true
|
2021-05-20 19:18:57 +08:00
|
|
|
@active_template = @report.settings[:template]
|
2021-05-06 23:33:58 +08:00
|
|
|
@report.settings = Report::DEFAULT_SETTINGS if @report.settings.blank?
|
2021-04-28 15:54:00 +08:00
|
|
|
|
2021-04-13 20:10:52 +08:00
|
|
|
@project_contents = {
|
2021-05-10 21:16:28 +08:00
|
|
|
experiments: @report.report_elements.order(:position).experiment.pluck(:experiment_id),
|
|
|
|
my_modules: @report.report_elements.order(:position).my_module.pluck(:my_module_id),
|
2023-01-25 22:41:59 +08:00
|
|
|
repositories: @report.settings.dig(:task, :repositories) ||
|
|
|
|
@report.report_elements.my_module_repository.distinct(:repository_id).pluck(:repository_id)
|
2021-04-13 20:10:52 +08:00
|
|
|
}
|
|
|
|
render :new
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Updating existing report from the _save modal of the new page
|
|
|
|
def update
|
|
|
|
@report.last_modified_by = current_user
|
2021-06-08 21:07:00 +08:00
|
|
|
@report.assign_attributes(
|
|
|
|
report_params.merge(project_id: @project.id)
|
|
|
|
)
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2021-05-06 16:53:40 +08:00
|
|
|
ReportActions::ReportContent.new(
|
2021-04-20 19:35:40 +08:00
|
|
|
@report,
|
|
|
|
params[:project_content],
|
|
|
|
params[:template_values],
|
|
|
|
current_user
|
|
|
|
).save_with_content
|
|
|
|
|
2021-05-06 16:53:40 +08:00
|
|
|
if @report.errors.blank?
|
2019-03-14 02:05:29 +08:00
|
|
|
log_activity(:edit_report)
|
2021-05-07 22:23:35 +08:00
|
|
|
flash[:success] = t('projects.reports.index.generation.accepted_message')
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2021-04-20 19:35:40 +08:00
|
|
|
redirect_to reports_path
|
2016-02-12 23:52:43 +08:00
|
|
|
else
|
2021-05-06 16:53:40 +08:00
|
|
|
render json: @report.errors.full_messages, status: :unprocessable_entity
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Destroy multiple entries action
|
|
|
|
def destroy
|
|
|
|
begin
|
2024-01-11 02:56:01 +08:00
|
|
|
report_ids = params[:report_ids]
|
2016-02-12 23:52:43 +08:00
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
report_ids.each do |report_id|
|
2022-05-23 19:32:15 +08:00
|
|
|
report = current_team.reports.find_by(id: report_id)
|
|
|
|
next unless report.present? && can_manage_report?(report)
|
2019-07-12 22:44:15 +08:00
|
|
|
|
2017-03-08 21:14:03 +08:00
|
|
|
# record an activity
|
2019-03-21 04:34:47 +08:00
|
|
|
log_activity(:delete_report, report)
|
2017-03-08 21:14:03 +08:00
|
|
|
report.destroy
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2024-01-11 02:56:01 +08:00
|
|
|
render json: { message: I18n.t('projects.reports.index.modal_delete.success') }
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2021-04-14 20:40:13 +08:00
|
|
|
def status
|
2024-01-11 02:56:01 +08:00
|
|
|
render json: @report, serializer: Lists::ReportSerializer
|
2021-04-14 20:40:13 +08:00
|
|
|
end
|
|
|
|
|
2021-04-14 21:45:51 +08:00
|
|
|
# Generation actions
|
|
|
|
def generate_pdf
|
2023-07-18 19:36:41 +08:00
|
|
|
render json: {
|
|
|
|
message: I18n.t('projects.reports.index.generation.accepted_message')
|
|
|
|
}
|
2021-04-14 21:45:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def generate_docx
|
2023-07-18 19:36:41 +08:00
|
|
|
@report.docx_processing!
|
|
|
|
log_activity(:generate_docx_report)
|
|
|
|
|
|
|
|
ensure_report_template!
|
2023-09-06 18:51:34 +08:00
|
|
|
Reports::DocxJob.perform_later(@report.id, user_id: current_user.id, root_url: root_url)
|
2023-07-18 19:36:41 +08:00
|
|
|
render json: {
|
|
|
|
message: I18n.t('projects.reports.index.generation.accepted_message')
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2021-04-13 22:36:52 +08:00
|
|
|
def save_pdf_to_inventory_modal
|
2023-07-18 19:36:41 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'reports/save_PDF_to_inventory_modal', formats: :html)
|
|
|
|
}
|
2021-04-13 22:36:52 +08:00
|
|
|
end
|
|
|
|
|
2018-05-16 15:31:19 +08:00
|
|
|
def save_pdf_to_inventory_item
|
2021-04-13 22:36:52 +08:00
|
|
|
return render_404 unless @report.pdf_file.attached?
|
|
|
|
|
2018-05-17 19:17:19 +08:00
|
|
|
save_pdf_to_inventory_item = ReportActions::SavePdfToInventoryItem.new(
|
2021-04-13 22:36:52 +08:00
|
|
|
@report, current_user, current_team, save_pdf_params
|
2018-05-16 15:31:19 +08:00
|
|
|
)
|
2018-05-17 19:17:19 +08:00
|
|
|
if save_pdf_to_inventory_item.save
|
2018-05-16 15:31:19 +08:00
|
|
|
render json: {
|
|
|
|
message: I18n.t(
|
|
|
|
'projects.reports.new.save_PDF_to_inventory_modal.success_flash'
|
|
|
|
)
|
|
|
|
}, status: :ok
|
|
|
|
else
|
2018-05-17 19:17:19 +08:00
|
|
|
render json: { message: save_pdf_to_inventory_item.error_messages },
|
2018-05-16 15:31:19 +08:00
|
|
|
status: :unprocessable_entity
|
|
|
|
end
|
2021-04-13 22:36:52 +08:00
|
|
|
rescue ReportActions::RepositoryPermissionError => e
|
|
|
|
render json: { message: e.message }, status: :forbidden
|
|
|
|
rescue StandardError => e
|
|
|
|
render json: { message: e.message }, status: :internal_server_error
|
2018-05-16 15:31:19 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
# Modal for adding contents into module element
|
|
|
|
def module_contents_modal
|
2017-06-05 18:24:06 +08:00
|
|
|
my_module = MyModule.find_by_id(params[:my_module_id])
|
2019-07-12 22:44:15 +08:00
|
|
|
return render_403 unless my_module.experiment.project == @project
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2023-07-18 19:36:41 +08:00
|
|
|
if my_module.blank?
|
|
|
|
render json: {}, status: :not_found
|
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'reports/new/modal/module_contents',
|
|
|
|
locals: { project: @project, my_module: my_module },
|
|
|
|
formats: :html
|
|
|
|
)
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-18 00:18:57 +08:00
|
|
|
# Modal for adding contents into step element
|
|
|
|
def step_contents_modal
|
2017-06-05 18:24:06 +08:00
|
|
|
step = Step.find_by_id(params[:step_id])
|
2019-07-12 22:44:15 +08:00
|
|
|
return render_403 unless step.my_module.experiment.project == @project
|
2017-05-18 00:18:57 +08:00
|
|
|
|
2023-07-18 19:36:41 +08:00
|
|
|
if step.blank?
|
|
|
|
render json: {}, status: :not_found
|
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'reports/new/modal/step_contents',
|
|
|
|
locals: { project: @project, step: step },
|
|
|
|
formats: :html
|
|
|
|
)
|
|
|
|
}
|
2017-05-18 00:18:57 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Modal for adding contents into result element
|
|
|
|
def result_contents_modal
|
2017-06-05 18:24:06 +08:00
|
|
|
result = Result.find_by_id(params[:result_id])
|
2019-07-12 22:44:15 +08:00
|
|
|
return render_403 unless result.experiment.project == @project
|
2017-05-18 00:18:57 +08:00
|
|
|
|
2023-07-18 19:36:41 +08:00
|
|
|
if result.blank?
|
|
|
|
render json: {}, status: :not_found
|
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'reports/new/modal/result_contents',
|
|
|
|
locals: { project: @project, result: result },
|
|
|
|
formats: :html
|
|
|
|
)
|
|
|
|
}
|
2017-05-18 00:18:57 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def project_contents
|
2021-04-06 21:27:12 +08:00
|
|
|
render json: {
|
2021-04-08 23:40:16 +08:00
|
|
|
html: render_to_string(
|
2023-06-21 20:13:20 +08:00
|
|
|
partial: 'reports/wizard/project_contents',
|
2023-07-18 19:36:41 +08:00
|
|
|
locals: { project: @project, report: nil },
|
|
|
|
formats: :html
|
2021-04-08 23:40:16 +08:00
|
|
|
)
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2018-05-16 15:31:19 +08:00
|
|
|
def available_repositories
|
2024-01-11 02:56:01 +08:00
|
|
|
render json: { data: @available_repositories.map { |r| [r.id, r.name] } }
|
2018-05-16 15:31:19 +08:00
|
|
|
end
|
|
|
|
|
2021-03-23 22:20:40 +08:00
|
|
|
def document_preview
|
|
|
|
render json: { html: render_to_string(
|
2023-06-21 20:13:20 +08:00
|
|
|
partial: 'reports/content_document_preview',
|
2021-03-23 22:20:40 +08:00
|
|
|
locals: {
|
|
|
|
report: @report,
|
|
|
|
report_type: params[:report_type]
|
2023-07-18 19:36:41 +08:00
|
|
|
},
|
|
|
|
formats: :html
|
2021-03-23 22:20:40 +08:00
|
|
|
) }
|
|
|
|
end
|
|
|
|
|
2023-05-18 04:42:16 +08:00
|
|
|
def actions_toolbar
|
|
|
|
render json: {
|
|
|
|
actions:
|
|
|
|
Toolbars::ReportsService.new(
|
|
|
|
current_user,
|
2024-01-11 02:56:01 +08:00
|
|
|
report_ids: JSON.parse(params[:items]).map { |i| i['id'] }
|
2023-05-18 04:42:16 +08:00
|
|
|
).actions
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
private
|
|
|
|
|
2018-05-16 15:31:19 +08:00
|
|
|
AvailableRepository = Struct.new(:id, :name)
|
2018-04-18 22:47:52 +08:00
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def load_vars
|
2019-10-14 20:50:05 +08:00
|
|
|
@report = current_team.reports.find_by(id: params[:id])
|
2017-03-08 21:14:03 +08:00
|
|
|
render_404 unless @report
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_vars_nested
|
2019-10-14 20:50:05 +08:00
|
|
|
@project = current_team.projects.find_by(id: params[:project_id])
|
2017-03-08 21:14:03 +08:00
|
|
|
render_404 unless @project
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2021-06-17 22:23:27 +08:00
|
|
|
def load_wizard_vars
|
|
|
|
@templates = Extends::REPORT_TEMPLATES
|
2024-08-09 21:56:59 +08:00
|
|
|
live_repositories = Repository.viewable_by_user(current_user).sort_by { |r| r.name.downcase }
|
2021-06-17 22:23:27 +08:00
|
|
|
snapshots_of_deleted = RepositorySnapshot.left_outer_joins(:original_repository)
|
|
|
|
.where(team: current_team)
|
|
|
|
.where.not(original_repository: live_repositories)
|
|
|
|
.select('DISTINCT ON ("repositories"."parent_id") "repositories".*')
|
2023-08-11 19:37:26 +08:00
|
|
|
.sort_by { |r| r.name.downcase }
|
|
|
|
@repositories = live_repositories + snapshots_of_deleted
|
2021-11-05 21:31:05 +08:00
|
|
|
@visible_projects = current_team.projects
|
|
|
|
.active
|
|
|
|
.joins(experiments: :my_modules)
|
|
|
|
.with_granted_permissions(current_user, ProjectPermissions::READ)
|
|
|
|
.merge(Experiment.active)
|
|
|
|
.merge(MyModule.active)
|
2021-12-14 00:02:36 +08:00
|
|
|
.group(:id)
|
2021-11-05 21:31:05 +08:00
|
|
|
.select(:id, :name)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2022-10-14 19:57:13 +08:00
|
|
|
def check_project_read_permissions
|
|
|
|
render_403 unless can_read_project?(@project)
|
|
|
|
end
|
|
|
|
|
2022-05-23 19:32:15 +08:00
|
|
|
def check_read_permissions
|
|
|
|
render_403 unless can_read_report?(@report)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_create_permissions
|
2022-10-10 22:16:08 +08:00
|
|
|
render_403 unless can_create_reports?(current_team)
|
2022-05-23 19:32:15 +08:00
|
|
|
end
|
|
|
|
|
2021-06-17 22:23:27 +08:00
|
|
|
def check_manage_permissions
|
2022-05-23 19:32:15 +08:00
|
|
|
render_403 unless can_manage_report?(@report)
|
2021-06-17 22:23:27 +08:00
|
|
|
end
|
|
|
|
|
2018-05-16 15:31:19 +08:00
|
|
|
def load_available_repositories
|
2020-02-12 18:16:55 +08:00
|
|
|
@available_repositories = []
|
2020-06-22 20:57:35 +08:00
|
|
|
repositories = Repository.active
|
2024-08-09 21:56:59 +08:00
|
|
|
.viewable_by_user(current_user)
|
2024-03-13 20:58:17 +08:00
|
|
|
.name_like(search_params[:query])
|
2019-08-23 17:28:09 +08:00
|
|
|
.limit(Constants::SEARCH_LIMIT)
|
2020-02-12 18:16:55 +08:00
|
|
|
repositories.each do |repository|
|
|
|
|
next unless can_manage_repository_rows?(current_user, repository)
|
|
|
|
|
|
|
|
@available_repositories.push(AvailableRepository.new(repository.id,
|
|
|
|
ellipsize(repository.name, 75, 50)))
|
2018-05-16 15:31:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def report_params
|
2017-03-08 21:14:03 +08:00
|
|
|
params.require(:report)
|
2021-04-20 19:35:40 +08:00
|
|
|
.permit(:name, :description, :grouped_by, :report_contents, settings: {})
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
2018-04-18 22:47:52 +08:00
|
|
|
|
|
|
|
def search_params
|
2024-03-13 20:58:17 +08:00
|
|
|
params.permit(:query)
|
2018-04-18 22:47:52 +08:00
|
|
|
end
|
2018-05-16 15:31:19 +08:00
|
|
|
|
2021-04-13 22:36:52 +08:00
|
|
|
def save_pdf_params
|
2024-01-11 02:56:01 +08:00
|
|
|
params.permit(:repository_id, :repository_column_id, :repository_item_id)
|
2018-05-16 15:31:19 +08:00
|
|
|
end
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2019-03-21 04:34:47 +08:00
|
|
|
def log_activity(type_of, report = @report)
|
2019-03-14 02:05:29 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
2019-03-21 04:34:47 +08:00
|
|
|
subject: report,
|
|
|
|
team: report.team,
|
|
|
|
project: report.project,
|
|
|
|
message_items: { report: report.id })
|
2019-03-14 02:05:29 +08:00
|
|
|
end
|
2021-04-20 19:35:40 +08:00
|
|
|
|
|
|
|
def generate_pdf_report
|
2021-05-20 20:16:39 +08:00
|
|
|
return unless @report.persisted?
|
|
|
|
|
|
|
|
@report.pdf_processing!
|
2021-05-06 20:00:33 +08:00
|
|
|
log_activity(:generate_pdf_report)
|
2021-06-15 18:54:48 +08:00
|
|
|
|
|
|
|
ensure_report_template!
|
2023-09-06 18:51:34 +08:00
|
|
|
Reports::PdfJob.perform_later(@report.id, user_id: current_user.id)
|
2024-03-12 20:57:55 +08:00
|
|
|
rescue ActiveRecord::ActiveRecordError => e
|
|
|
|
Rails.logger.error e.message
|
2021-04-20 19:35:40 +08:00
|
|
|
end
|
2021-06-15 18:54:48 +08:00
|
|
|
|
|
|
|
def ensure_report_template!
|
|
|
|
return if @report.settings['template'].present?
|
|
|
|
|
|
|
|
@report.settings['template'] = 'scinote_template'
|
|
|
|
@report.save
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|