From baf11ebc0a2f2338fe7781249bc580431bd3f8dd Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 8 Oct 2025 12:14:14 +0000 Subject: [PATCH] Bug 39320: Follow-up: Add 'move up' and 'move down' options Sponsored-by: UKHSA (UK Health Security Agency) Signed-off-by: Jeremy Evans --- .../ModuleDashboard/ModuleDashboard.vue | 65 ++++++++++++++----- .../WidgetDashboardWrapper.vue | 28 +++++++- .../ModuleDashboard/WidgetWrapper.vue | 10 ++- .../ModuleDashboard/Widgets/ERMCounts.vue | 1 + .../Widgets/ERMLatestSUSHIJobs.vue | 1 + .../Widgets/ERMLicensesNeedingAction.vue | 1 + .../Widgets/ERMRunUsageReport.vue | 1 + .../prog/js/vue/composables/base-widget.js | 6 +- .../intranet-tmpl/prog/js/vue/modules/erm.ts | 6 +- .../integration/ERM/ModuleDashboard_spec.ts | 36 +++++++++- 10 files changed, 130 insertions(+), 25 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/ModuleDashboard.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/ModuleDashboard.vue index 0ec96c92ffe..fdd2738ff35 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/ModuleDashboard.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/ModuleDashboard.vue @@ -20,10 +20,11 @@ > @@ -39,10 +40,11 @@ > @@ -103,33 +105,62 @@ export default { } } - function moveWidget(widget) { - if ( - selectedWidgetsLeft.value.some( - element => element.name === widget.componentName - ) - ) { + function moveWidget(params) { + if (params.direction === "right") { selectedWidgetsRight.value.unshift( selectedWidgetsLeft.value.find( - element => element.name === widget.componentName + element => element.name === params.widgetComponentName ) ); selectedWidgetsLeft.value = selectedWidgetsLeft.value.filter( - element => element.name !== widget.componentName + element => element.name !== params.widgetComponentName ); - } else if ( - selectedWidgetsRight.value.some( - element => element.name === widget.componentName - ) - ) { + } else if (params.direction === "left") { selectedWidgetsLeft.value.unshift( selectedWidgetsRight.value.find( - element => element.name === widget.componentName + element => element.name === params.widgetComponentName ) ); selectedWidgetsRight.value = selectedWidgetsRight.value.filter( - element => element.name !== widget.componentName + element => element.name !== params.widgetComponentName ); + } else if ( + params.direction === "up" || + params.direction === "down" + ) { + const list = + params.currentColumn === "left" + ? selectedWidgetsLeft.value + : selectedWidgetsRight.value; + + const currentIndex = list.findIndex( + element => element.name === params.widgetComponentName + ); + + if (currentIndex === -1) return; + + const newIndex = + params.direction === "up" + ? currentIndex - 1 + : currentIndex + 1; + + if (newIndex < 0 || newIndex >= list.length) return; // Out of bounds + + if (params.currentColumn === "left") { + selectedWidgetsLeft.value = (() => { + const arr = [...selectedWidgetsLeft.value]; + const [item] = arr.splice(currentIndex, 1); + arr.splice(newIndex, 0, item); + return arr; + })(); + } else if (params.currentColumn === "right") { + selectedWidgetsRight.value = (() => { + const arr = [...selectedWidgetsRight.value]; + const [item] = arr.splice(currentIndex, 1); + arr.splice(newIndex, 0, item); + return arr; + })(); + } } } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/WidgetDashboardWrapper.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/WidgetDashboardWrapper.vue index 539f507172c..35d1be52f00 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/WidgetDashboardWrapper.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/WidgetDashboardWrapper.vue @@ -36,6 +36,16 @@ {{ $__("Settings") }} +
  • + +
  • +
  • + +