start of iteration 2
This commit is contained in:
parent
9fb87a74ce
commit
729ed13521
75 changed files with 705 additions and 170 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ElementsController < ApplicationController
|
||||
before_action :set_page, only: %i[index new create]
|
||||
before_action :set_element, only: %i[show edit update destroy]
|
||||
|
||||
# GET /elements
|
||||
|
|
@ -13,7 +14,8 @@ class ElementsController < ApplicationController
|
|||
|
||||
# GET /elements/new
|
||||
def new
|
||||
@element = Element.new(report_id: params[:report_id])
|
||||
@element = Element.new(page_id: params[:page_id])
|
||||
@element.page = @page
|
||||
end
|
||||
|
||||
# GET /elements/1/edit
|
||||
|
|
@ -21,16 +23,20 @@ class ElementsController < ApplicationController
|
|||
|
||||
# POST /elements
|
||||
def create
|
||||
checklist_id = element_params.delete(:checklist_id)
|
||||
checklist = Checklist.find(checklist_id)
|
||||
# checklist_id = element_params.delete(:checklist_id)
|
||||
# checklist = Checklist.find(checklist_id)
|
||||
@element = Element.new(element_params)
|
||||
@element.title = checklist.name if @element.title.blank?
|
||||
@element.page = @page
|
||||
# @element.title = checklist.name if @element.title.blank?
|
||||
|
||||
if @element.save
|
||||
checklist.checks.each do |check|
|
||||
@element.success_criteria.create!(title: check.t_name, description_html: check.t_criterion,
|
||||
level: check.level)
|
||||
end
|
||||
# checklist.checks.each do |check|
|
||||
# @element.success_criteria.create!(
|
||||
# check:,
|
||||
# title: check.t_name,
|
||||
# level: check.conformity_level,
|
||||
# quick_criterion: check.t_quick_criterion)
|
||||
# end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @element.report, notice: "Element was successfully created." }
|
||||
format.turbo_stream
|
||||
|
|
@ -62,8 +68,12 @@ class ElementsController < ApplicationController
|
|||
@element = Element.find(params[:id])
|
||||
end
|
||||
|
||||
def set_page
|
||||
@page = Page.find(params[:page_id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def element_params
|
||||
params.require(:element).permit(:report_id, :path, :title, :description_html, :checklist_id)
|
||||
params.require(:element).permit(:page_id, :title, :description)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
64
app/controllers/pages_controller.rb
Normal file
64
app/controllers/pages_controller.rb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
class PagesController < ApplicationController
|
||||
before_action :set_page, only: %i[ show edit update destroy ]
|
||||
before_action :set_report, only: %i[ new create index ]
|
||||
|
||||
# GET /pages
|
||||
def index
|
||||
@pages = Page.all
|
||||
end
|
||||
|
||||
# GET /pages/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /pages/new
|
||||
def new
|
||||
@page = Page.new
|
||||
@page.report = @report
|
||||
end
|
||||
|
||||
# GET /pages/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /pages
|
||||
def create
|
||||
@page = Page.new(page_params)
|
||||
@page.report = @report
|
||||
if @page.save
|
||||
redirect_to [ @page.report, page_id: @page.id ], notice: "Page was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /pages/1
|
||||
def update
|
||||
if @page.update(page_params)
|
||||
redirect_to @page, notice: "Page was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /pages/1
|
||||
def destroy
|
||||
@page.destroy!
|
||||
redirect_to pages_url, notice: "Page was successfully destroyed.", status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_page
|
||||
@page = Page.find(params[:id])
|
||||
end
|
||||
|
||||
def set_report
|
||||
@report = Report.find(params[:report_id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def page_params
|
||||
params.require(:page).permit(:position, :path, :url, :report_id)
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,9 @@ class ReportsController < ApplicationController
|
|||
# GET /reports/1
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.html do
|
||||
@current_page = page_param && @report.pages.find(page_param) || @report.pages.first
|
||||
end
|
||||
format.pdf
|
||||
format.xlsx do
|
||||
response.headers["Content-Disposition"] = %(attachment; filename="#{filename(@report, extension: 'xlsx')}")
|
||||
|
|
@ -35,7 +37,7 @@ class ReportsController < ApplicationController
|
|||
format.docx do
|
||||
send_file(Docx::Document.new.generate do |document|
|
||||
document.heading1(@report.name)
|
||||
document.paragraph(@report.comment_html)
|
||||
document.paragraph(@report.comment)
|
||||
# document.heading1("slfkj")
|
||||
# document.paragraph("sldkfj")
|
||||
@report.elements.each do |element|
|
||||
|
|
@ -127,10 +129,14 @@ class ReportsController < ApplicationController
|
|||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def report_params
|
||||
params.require(:report).permit(:name, :comment_html)
|
||||
params.require(:report).permit(:name, :comment)
|
||||
end
|
||||
|
||||
def filename(report, extension: "html")
|
||||
"#{report.name}-#{Time.current.strftime('%Y%m%d%H%M')}.#{extension}"
|
||||
end
|
||||
|
||||
def page_param
|
||||
params[:page_id]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SuccessCriteriaController < ApplicationController
|
||||
before_action :set_element, only: %i[new create index new_from_checklist create_from_checklist]
|
||||
before_action :set_success_criterion, only: %i[show edit update destroy]
|
||||
|
||||
# GET /success_criteria
|
||||
|
|
@ -13,7 +14,7 @@ class SuccessCriteriaController < ApplicationController
|
|||
|
||||
# GET /success_criteria/new
|
||||
def new
|
||||
@success_criterion = SuccessCriterion.new
|
||||
@success_criterion = SuccessCriterion.new(element: @element)
|
||||
end
|
||||
|
||||
# GET /success_criteria/1/edit
|
||||
|
|
@ -21,11 +22,26 @@ class SuccessCriteriaController < ApplicationController
|
|||
|
||||
# POST /success_criteria
|
||||
def create
|
||||
@success_criterion = SuccessCriterion.new(success_criterion_params)
|
||||
check_id = success_criterion_params.delete(:check_id)
|
||||
check = Check.find(check_id)
|
||||
merge_params = {
|
||||
element: @element,
|
||||
title: check.name_de,
|
||||
quick_criterion: check.quick_criterion_de,
|
||||
quick_fail: check.quick_fail_de,
|
||||
quick_fix: check.quick_fix_de
|
||||
}
|
||||
@success_criterion = SuccessCriterion.new(success_criterion_params.merge(merge_params))
|
||||
|
||||
if @success_criterion.save
|
||||
redirect_to @success_criterion, notice: "Erfolgskriterium was successfully created."
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to @success_criterion, notice: "Erfolgskriterium was successfully created."
|
||||
end
|
||||
format.turbo_stream
|
||||
end
|
||||
else
|
||||
Rails.logger.debug(@success_criterion.errors)
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
|
@ -50,6 +66,38 @@ class SuccessCriteriaController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def new_from_checklist
|
||||
@success_criterion = SuccessCriterion.new(element: @element)
|
||||
end
|
||||
|
||||
def create_from_checklist
|
||||
checklist = Checklist.find(params[:checklist_id])
|
||||
success = false
|
||||
SuccessCriterion.transaction do
|
||||
@success_criteria = checklist.checks.map do |check|
|
||||
SuccessCriterion.create!(check:,
|
||||
element: @element,
|
||||
title: check.name_de,
|
||||
quick_criterion: check.quick_criterion_de,
|
||||
quick_fail: check.quick_fail_de,
|
||||
quick_fix: check.quick_fix_de,
|
||||
level: check.conformity_level)
|
||||
end
|
||||
success = true
|
||||
end
|
||||
if success
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to @success_criteria.first.element, notice: "Erfolgskriterium was successfully created."
|
||||
end
|
||||
format.turbo_stream
|
||||
end
|
||||
else
|
||||
Rails.logger.debug(@success_criterion.errors)
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
|
|
@ -59,6 +107,10 @@ class SuccessCriteriaController < ApplicationController
|
|||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def success_criterion_params
|
||||
params.require(:success_criterion).permit(:element_id, :title, :description_html, :level, :result, :comment_html)
|
||||
params.require(:success_criterion).permit(:element_id, :title, :quick_criterion, :quick_fail, :quick_fix, :priority, :level, :result, :test_comment, :check_id)
|
||||
end
|
||||
|
||||
def set_element
|
||||
@element = Element.find(params[:element_id])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue