Delete stuff in report view

This commit is contained in:
david 2024-11-11 01:40:04 +01:00
parent 644969c613
commit 50e853098b
16 changed files with 64 additions and 31 deletions

View file

@ -57,8 +57,16 @@ class ElementsController < ApplicationController
# DELETE /elements/1
def destroy
@element.destroy!
redirect_to page_elements_url(@element.page), notice: "Element was successfully destroyed.", status: :see_other
Element.connection.transaction do
@element.destroy!
@element.page.elements.where("position > ?", @element.position).update_all("position = position - 1")
end
respond_to do |format|
format.turbo_stream
format.html do
redirect_to page_elements_url(@element.page), notice: "Element was successfully destroyed.", status: :see_other
end
end
end
private

View file

@ -44,7 +44,7 @@ class PagesController < ApplicationController
# DELETE /pages/1
def destroy
@page.destroy!
redirect_to report_pages_url(@page.report), notice: "Page was successfully destroyed.", status: :see_other
redirect_to report_url(@page.report), notice: "Page was successfully destroyed.", status: :see_other
end
private

View file

@ -62,7 +62,10 @@ class SuccessCriteriaController < ApplicationController
# DELETE /success_criteria/1
def destroy
@success_criterion.destroy!
SuccessCriterion.transaction do
@success_criterion.destroy!
@success_criterion.element.success_criteria.where("position > ?", @success_criterion.position).update_all("position = position - 1")
end
respond_to do |format|
format.html do
redirect_to element_success_criteria_url(@success_criterion.element), notice: "Erfolgskriterium was successfully destroyed.", status: :see_other