diff --git a/app/controllers/checklist_entries_controller.rb b/app/controllers/checklist_entries_controller.rb index 10ac787..1091922 100644 --- a/app/controllers/checklist_entries_controller.rb +++ b/app/controllers/checklist_entries_controller.rb @@ -33,8 +33,13 @@ class ChecklistEntriesController < ApplicationController # PATCH/PUT /checklist_entries/1 def update if @checklist_entry.update(checklist_entry_params) - redirect_to @checklist_entry.checklist, notice: "Checklist entry was successfully updated.", - status: :see_other + respond_to do |format| + format.turbo_stream + format.html do + redirect_to @checklist_entry.checklist, notice: "Checklist entry was successfully updated.", + status: :see_other + end + end else render :edit, status: :unprocessable_entity end diff --git a/app/javascript/controllers/drag_controller.js b/app/javascript/controllers/drag_controller.js new file mode 100644 index 0000000..d3f7af8 --- /dev/null +++ b/app/javascript/controllers/drag_controller.js @@ -0,0 +1,38 @@ +import { Controller } from "@hotwired/stimulus" +import Sortable from "sortablejs" +import { put } from "@rails/request.js"; + +// Connects to data-controller="drag" +export default class extends Controller { + static values = { + group: String + } + + connect() { + this.element.style.cursor = "grab" + new Sortable(this.element, { + group: this.groupValue, + onEnd: this.onEnd, + animation: 150, + swap: true, + swapThreshold: 0.65, + ghostClass: 'dragFrom', + swapClass: 'dragTo', + forceFallback: false, + }) + + } + + onEnd(event) { + const position = event.newIndex + 1 + const url = event.item.dataset["sortableUrl"] + // Expect backend to update list items via turbo if necessary + put(url, { + body: JSON.stringify({ checklist_entry: { position: position }}), + contentType: "application/json", + headers: { + "Accept": "text/vnd.turbo-stream.html, text/html, application/xhtml+xml" + } + }) + } +} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index a76470e..9d6b531 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -13,6 +13,9 @@ application.register("check-link", CheckLinkController) import CollapseChevronTogglerController from "./collapse_chevron_toggler_controller" application.register("collapse-chevron-toggler", CollapseChevronTogglerController) +import DragController from "./drag_controller" +application.register("drag", DragController) + import HelloController from "./hello_controller" application.register("hello", HelloController) diff --git a/app/models/check.rb b/app/models/check.rb index 815c08f..a85fc11 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -105,14 +105,24 @@ class Check < ApplicationRecord end def display_target_disabilities - %i[visual auditory physical cognitive].select { |d| send(:"#{d}?") }.map { |d| I18n.t("disability.#{d}") }.join(", ") + %i[visual auditory physical cognitive].select { |d| send(:"#{d}?") } + .map { |d| I18n.t("disability.#{d}") } + .sort + .join(", ") end def display_applicabilities - %i[applicable_to_analogue applicable_to_app applicable_to_document applicable_to_non_web applicable_to_web].select { |a| send(:"#{a}?") }.map { |a| I18n.t("applicability.#{a}") }.join(", ") + %i[applicable_to_analogue + applicable_to_app + applicable_to_document + applicable_to_non_web + applicable_to_web].select { |a| send(:"#{a}?") } + .map { |a| I18n.t("applicability.#{a}") } + .sort + .join(", ") end def display_label - "#{name_de} (#{[number, external_number].compact_blank.join("/")})" + [external_number, name_de].compact_blank.join(" ") end end diff --git a/app/views/checklist_entries/_checklist_entry.html.erb b/app/views/checklist_entries/_checklist_entry.html.erb index 96f2cc8..658c63e 100644 --- a/app/views/checklist_entries/_checklist_entry.html.erb +++ b/app/views/checklist_entries/_checklist_entry.html.erb @@ -3,13 +3,18 @@