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)
|
2022-06-07 00:21:57 +08:00
|
|
|
before_action :check_read_permissions, except: %i(index datatable new create edit update destroy 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
|
2018-04-18 22:47:52 +08:00
|
|
|
def index; end
|
|
|
|
|
|
|
|
def datatable
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: ::ReportDatatable.new(
|
|
|
|
view_context,
|
|
|
|
current_user,
|
2019-03-26 00:35:54 +08:00
|
|
|
Report.viewable_by_user(current_user, current_team)
|
2018-04-18 22:47:52 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
|
|
|
2021-04-06 19:56:24 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
if lookup_context.template_exists?("reports/templates/#{template}/edit.html.erb")
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
template: "reports/templates/#{template}/edit.html.erb",
|
|
|
|
layout: 'reports/template_values_editor',
|
2021-04-19 16:17:44 +08:00
|
|
|
locals: { report: report }
|
2021-04-06 19:56:24 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'reports/wizard/no_template_values.html.erb')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
report_ids = JSON.parse(params[:report_ids])
|
|
|
|
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
|
|
|
|
|
2018-04-18 22:47:52 +08:00
|
|
|
redirect_to reports_path
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2021-04-14 20:40:13 +08:00
|
|
|
def status
|
|
|
|
docx = @report.docx_file.attached? ? document_preview_report_path(@report, report_type: :docx) : nil
|
|
|
|
pdf = @report.pdf_file.attached? ? document_preview_report_path(@report, report_type: :pdf) : nil
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
docx: {
|
2021-05-11 19:28:28 +08:00
|
|
|
processing: @report.docx_processing?,
|
2021-04-14 20:40:13 +08:00
|
|
|
preview_url: docx,
|
2021-05-11 19:28:28 +08:00
|
|
|
error: @report.docx_error?
|
2021-04-14 20:40:13 +08:00
|
|
|
},
|
|
|
|
pdf: {
|
2021-05-11 19:28:28 +08:00
|
|
|
processing: @report.pdf_processing?,
|
2021-04-14 20:40:13 +08:00
|
|
|
preview_url: pdf,
|
2021-05-11 19:28:28 +08:00
|
|
|
error: @report.pdf_error?
|
2021-04-14 20:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-14 21:45:51 +08:00
|
|
|
# Generation actions
|
|
|
|
def generate_pdf
|
2016-02-12 23:52:43 +08:00
|
|
|
respond_to do |format|
|
2021-04-14 21:45:51 +08:00
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
message: I18n.t('projects.reports.index.generation.accepted_message')
|
|
|
|
}
|
2021-03-16 20:47:23 +08:00
|
|
|
end
|
2021-04-14 21:45:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_docx
|
|
|
|
respond_to do |format|
|
2021-03-16 20:47:23 +08:00
|
|
|
format.json do
|
2021-05-11 19:28:28 +08:00
|
|
|
@report.docx_processing!
|
2021-05-06 20:00:33 +08:00
|
|
|
log_activity(:generate_docx_report)
|
2021-06-15 18:54:48 +08:00
|
|
|
|
|
|
|
ensure_report_template!
|
2021-05-26 20:34:58 +08:00
|
|
|
Reports::DocxJob.perform_later(@report.id, current_user, root_url)
|
2021-04-14 21:45:51 +08:00
|
|
|
render json: {
|
|
|
|
message: I18n.t('projects.reports.index.generation.accepted_message')
|
|
|
|
}
|
2019-07-01 16:14:16 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-13 22:36:52 +08:00
|
|
|
def save_pdf_to_inventory_modal
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'reports/save_PDF_to_inventory_modal.html.erb')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if my_module.blank?
|
2016-07-29 22:53:50 +08:00
|
|
|
format.json do
|
2016-02-12 23:52:43 +08:00
|
|
|
render json: {}, status: :not_found
|
2016-07-29 22:53:50 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
else
|
2016-07-29 22:53:50 +08:00
|
|
|
format.json do
|
2016-02-12 23:52:43 +08:00
|
|
|
render json: {
|
2016-07-29 22:53:50 +08:00
|
|
|
html: render_to_string(
|
2017-03-08 21:14:03 +08:00
|
|
|
partial: 'reports/new/modal/module_contents.html.erb',
|
2016-02-12 23:52:43 +08:00
|
|
|
locals: { project: @project, my_module: my_module }
|
2016-07-29 22:53:50 +08:00
|
|
|
)
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
2016-07-29 22:53:50 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if step.blank?
|
|
|
|
format.json do
|
|
|
|
render json: {}, status: :not_found
|
|
|
|
end
|
|
|
|
else
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'reports/new/modal/step_contents.html.erb',
|
|
|
|
locals: { project: @project, step: step }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if result.blank?
|
|
|
|
format.json do
|
|
|
|
render json: {}, status: :not_found
|
|
|
|
end
|
|
|
|
else
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'reports/new/modal/result_contents.html.erb',
|
|
|
|
locals: { project: @project, result: result }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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(
|
|
|
|
partial: 'reports/wizard/project_contents.html.erb',
|
2022-05-23 19:32:15 +08:00
|
|
|
locals: { project: @project, report: nil }
|
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
|
|
|
|
render json: { results: @available_repositories }, status: :ok
|
|
|
|
end
|
|
|
|
|
2021-03-23 22:20:40 +08:00
|
|
|
def document_preview
|
|
|
|
render json: { html: render_to_string(
|
|
|
|
partial: 'reports/content_document_preview.html.erb',
|
|
|
|
locals: {
|
|
|
|
report: @report,
|
|
|
|
report_type: params[:report_type]
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
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
|
|
|
|
live_repositories = Repository.accessible_by_teams(current_team)
|
|
|
|
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".*')
|
|
|
|
@repositories = (live_repositories + snapshots_of_deleted).sort_by { |r| r.name.downcase }
|
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
|
|
|
|
.accessible_by_teams(current_team)
|
2019-08-23 17:28:09 +08:00
|
|
|
.name_like(search_params[:q])
|
|
|
|
.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
|
|
|
|
params.permit(:q)
|
|
|
|
end
|
2018-05-16 15:31:19 +08:00
|
|
|
|
2021-04-13 22:36:52 +08:00
|
|
|
def save_pdf_params
|
|
|
|
params.permit(:repository_id, :respository_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!
|
2021-05-20 20:16:39 +08:00
|
|
|
Reports::PdfJob.perform_later(@report.id, current_user)
|
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
|