Added projects
This commit is contained in:
parent
0964187f22
commit
8b4ffb83ec
37 changed files with 470 additions and 1935 deletions
|
|
@ -22,9 +22,13 @@ class ApplicationController < ActionController::Base
|
|||
path: :root
|
||||
},
|
||||
{
|
||||
label: Report.model_name.human(count: 2),
|
||||
icon: :'journal-text',
|
||||
path: :reports },
|
||||
label: Project.model_name.human(count: 2),
|
||||
icon: :'folder',
|
||||
path: :projects },
|
||||
# {
|
||||
# label: Report.model_name.human(count: 2),
|
||||
# icon: :'journal-text',
|
||||
# path: :reports },
|
||||
{
|
||||
label: I18n.t("backoffice"),
|
||||
icon: :gear,
|
||||
|
|
|
|||
|
|
@ -20,11 +20,6 @@ class HomeController < ApplicationController
|
|||
path: profile_path,
|
||||
active: action_name == "profile"
|
||||
},
|
||||
# {
|
||||
# label: "Passwort ändern",
|
||||
# path: new_password_path,
|
||||
# icon: :lock
|
||||
# },
|
||||
{
|
||||
label: "Logout",
|
||||
icon: :"box-arrow-right",
|
||||
|
|
|
|||
62
app/controllers/projects_controller.rb
Normal file
62
app/controllers/projects_controller.rb
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
class ProjectsController < ApplicationController
|
||||
before_action :set_project, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /projects
|
||||
def index
|
||||
@projects = Project.all
|
||||
end
|
||||
|
||||
# GET /projects/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /projects/new
|
||||
def new
|
||||
@project = Project.new
|
||||
end
|
||||
|
||||
# GET /projects/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /projects
|
||||
def create
|
||||
@project = if params[:copy_from_id]
|
||||
Project.find(params[:copy_from_id]).dup
|
||||
else
|
||||
Project.new(project_params)
|
||||
end
|
||||
|
||||
if @project.save
|
||||
redirect_to @project, notice: "Project was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /projects/1
|
||||
def update
|
||||
if @project.update(project_params)
|
||||
redirect_to @project, notice: "Project was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /projects/1
|
||||
def destroy
|
||||
@project.destroy!
|
||||
redirect_to projects_url, notice: "Project was successfully destroyed.", status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_project
|
||||
@project = Project.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def project_params
|
||||
params.require(:project).permit(:name, :details)
|
||||
end
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue