2024-09-05 22:54:38 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-07-16 20:22:59 +02:00
|
|
|
class SuccessCriteriaController < ApplicationController
|
2024-10-31 23:13:18 +01:00
|
|
|
before_action :set_element, only: %i[new create index new_from_checklist create_from_checklist]
|
2024-07-19 02:29:18 +02:00
|
|
|
before_action :set_success_criterion, only: %i[show edit update destroy]
|
2024-07-16 20:22:59 +02:00
|
|
|
|
|
|
|
|
# GET /success_criteria
|
|
|
|
|
def index
|
|
|
|
|
@success_criteria = SuccessCriterion.all
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# GET /success_criteria/1
|
2024-09-05 22:54:38 +02:00
|
|
|
def show; end
|
2024-07-16 20:22:59 +02:00
|
|
|
|
|
|
|
|
# GET /success_criteria/new
|
|
|
|
|
def new
|
2024-10-31 23:13:18 +01:00
|
|
|
@success_criterion = SuccessCriterion.new(element: @element)
|
2024-07-16 20:22:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# GET /success_criteria/1/edit
|
2024-11-23 19:10:09 +01:00
|
|
|
def edit
|
|
|
|
|
render_modal()
|
|
|
|
|
end
|
2024-07-16 20:22:59 +02:00
|
|
|
|
|
|
|
|
# POST /success_criteria
|
|
|
|
|
def create
|
2024-10-31 23:13:18 +01:00
|
|
|
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))
|
2024-07-16 20:22:59 +02:00
|
|
|
|
|
|
|
|
if @success_criterion.save
|
2024-10-31 23:13:18 +01:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
|
|
|
|
redirect_to @success_criterion, notice: "Erfolgskriterium was successfully created."
|
|
|
|
|
end
|
|
|
|
|
format.turbo_stream
|
|
|
|
|
end
|
2024-07-16 20:22:59 +02:00
|
|
|
else
|
2024-10-31 23:13:18 +01:00
|
|
|
Rails.logger.debug(@success_criterion.errors)
|
2024-07-16 20:22:59 +02:00
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# PATCH/PUT /success_criteria/1
|
|
|
|
|
def update
|
|
|
|
|
if @success_criterion.update(success_criterion_params)
|
2024-11-07 01:24:55 +01:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.turbo_stream
|
|
|
|
|
format.html do
|
|
|
|
|
redirect_to @success_criterion, notice: "Erfolgskriterium was successfully updated.", status: :see_other
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-16 20:22:59 +02:00
|
|
|
else
|
|
|
|
|
render :edit, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# DELETE /success_criteria/1
|
|
|
|
|
def destroy
|
2024-11-11 01:40:04 +01:00
|
|
|
SuccessCriterion.transaction do
|
|
|
|
|
@success_criterion.destroy!
|
|
|
|
|
@success_criterion.element.success_criteria.where("position > ?", @success_criterion.position).update_all("position = position - 1")
|
|
|
|
|
end
|
2024-07-22 22:40:56 +02:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
2024-11-03 21:58:25 +01:00
|
|
|
redirect_to element_success_criteria_url(@success_criterion.element), notice: "Erfolgskriterium was successfully destroyed.", status: :see_other
|
2024-07-22 22:40:56 +02:00
|
|
|
end
|
|
|
|
|
format.turbo_stream
|
|
|
|
|
end
|
2024-07-16 20:22:59 +02:00
|
|
|
end
|
|
|
|
|
|
2024-10-31 23:13:18 +01:00
|
|
|
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
|
|
|
|
|
|
2024-07-16 20:22:59 +02:00
|
|
|
private
|
|
|
|
|
|
2024-07-19 02:29:18 +02:00
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
|
def set_success_criterion
|
|
|
|
|
@success_criterion = SuccessCriterion.find(params[:id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
|
|
|
def success_criterion_params
|
2024-11-11 04:04:13 +01:00
|
|
|
params.require(:success_criterion).permit(:element_id, :title, :quick_criterion, :quick_fail, :quick_fix, :priority, :level, :result, :test_comment, :check_id, :position)
|
2024-10-31 23:13:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def set_element
|
|
|
|
|
@element = Element.find(params[:element_id])
|
2024-07-19 02:29:18 +02:00
|
|
|
end
|
2024-07-16 20:22:59 +02:00
|
|
|
end
|