Basic feature implemented, very basic poc
This commit is contained in:
parent
216089a3e7
commit
48c0067076
118 changed files with 2113 additions and 20 deletions
64
app/controllers/elements_controller.rb
Normal file
64
app/controllers/elements_controller.rb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
class ElementsController < ApplicationController
|
||||
before_action :set_element, only: %i[show edit update destroy]
|
||||
|
||||
# GET /elements
|
||||
def index
|
||||
@elements = Element.all
|
||||
end
|
||||
|
||||
# GET /elements/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /elements/new
|
||||
def new
|
||||
@element = Element.new
|
||||
end
|
||||
|
||||
# GET /elements/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /elements
|
||||
def create
|
||||
checklist_id = element_params.delete(:checklist_id)
|
||||
checklist = Checklist.find(checklist_id)
|
||||
@element = Element.new(element_params.merge(title: checklist.name))
|
||||
|
||||
if @element.save
|
||||
checklist.checks.each do |check|
|
||||
@element.success_criteria.create!(title: check.name, description: check.success_criterion, level: check.level)
|
||||
end
|
||||
redirect_to [:work, @element.report], notice: 'Element was successfully created.'
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /elements/1
|
||||
def update
|
||||
if @element.update(element_params)
|
||||
redirect_to @element, notice: 'Element was successfully updated.', status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /elements/1
|
||||
def destroy
|
||||
@element.destroy!
|
||||
redirect_to elements_url, notice: 'Element was successfully destroyed.', status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_element
|
||||
@element = Element.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def element_params
|
||||
params.require(:element).permit(:report_id, :path, :title, :description, :checklist_id)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue