Added projects
Some checks failed
/ Run tests (push) Failing after 2m3s
/ Run system tests (push) Failing after 2m17s
/ Build, push and deploy image (push) Has been skipped

This commit is contained in:
david 2024-11-24 22:08:36 +01:00
parent 0964187f22
commit 8b4ffb83ec
37 changed files with 470 additions and 1935 deletions

View file

@ -1,11 +1,12 @@
# frozen_string_literal: true
class ReportsController < ApplicationController
before_action :set_project, only: %i[index new create]
before_action :set_report, only: %i[show edit update destroy work]
# GET /reports
def index
@reports = Report.all
@reports = @project.reports
end
# GET /reports/1
@ -85,7 +86,7 @@ class ReportsController < ApplicationController
# GET /reports/new
def new
@report = Report.new
@report = Report.new(project_id: @project.id)
end
# GET /reports/1/edit
@ -93,10 +94,45 @@ class ReportsController < ApplicationController
# POST /reports
def create
@report = Report.new(report_params)
success = if params[:copy_from_id]
original = Report.find(params[:copy_from_id])
@report = original.dup
@report.pages = original.pages.map do |page|
page.dup.tap do |p|
p.elements = page.elements.map do |element|
element.dup.tap do |e|
e.success_criteria = element.success_criteria.map do |sc|
csc = sc.dup
SuccessCriterion.rich_text_association_names
.map { _1.to_s.sub(/^rich_text_/, "") }
.each do |a|
csc.send("#{a}=", sc.send(a).dup)
end
csc
end
e.screenshot = element.screenshot&.dup
Element.rich_text_association_names
.map { _1.to_s.sub(/^rich_text_/, "") }
.each do |a|
e.send("#{a}=", element.send(a).dup)
end
end
end
Page.rich_text_association_names
.map { _1.to_s.sub(/^rich_text_/, "") }
.each do |a|
p.send("#{a}=", page.send(a).dup)
end
end
end
@report.save
else
@report = Report.new(report_params.merge(project_id: @project.id))
@report.save
end
if @report.save
redirect_to @report, notice: "Report was successfully created."
if success
redirect_to @report.reload, notice: "Report was successfully created."
else
render :new, status: :unprocessable_entity
end
@ -114,7 +150,7 @@ class ReportsController < ApplicationController
# DELETE /reports/1
def destroy
@report.destroy!
redirect_to reports_url, notice: "Report was successfully destroyed.", status: :see_other
redirect_to project_url(@report.project), notice: "Report was successfully destroyed.", status: :see_other
end
def work
@ -130,7 +166,7 @@ class ReportsController < ApplicationController
# Only allow a list of trusted parameters through.
def report_params
params.require(:report).permit(:name, :comment, :url)
params.require(:report).permit(:name, :comment, :url, :project_id)
end
def filename(report, extension: "html")
@ -140,4 +176,8 @@ class ReportsController < ApplicationController
def page_param
params[:page_id]
end
def set_project
@project = Project.find(params[:project_id])
end
end