From ffa5ad82fda2986698bce5e395cb1ea1f2eb375f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 2 Mar 2026 15:31:36 +0100 Subject: [PATCH] feat: scroll timeline to today's date on first load closes #869b9vhrj --- .../controllers/timeline_scroll_controller.js | 22 +++++++++++++++++++ .../assignment/timeline.html.twig | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 assets/controllers/timeline_scroll_controller.js diff --git a/assets/controllers/timeline_scroll_controller.js b/assets/controllers/timeline_scroll_controller.js new file mode 100644 index 0000000..6c65e57 --- /dev/null +++ b/assets/controllers/timeline_scroll_controller.js @@ -0,0 +1,22 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + static targets = [ 'today' ] + + connect() { + if (false === this.hasTodayTarget) { + return + } + + requestAnimationFrame(() => { + const containerRect = this.element.getBoundingClientRect() + const todayRect = this.todayTarget.getBoundingClientRect() + + const scrollLeft = todayRect.left - containerRect.left + this.element.scrollLeft + const centered = scrollLeft - (this.element.clientWidth / 2) + (todayRect.width / 2) + const maxScrollLeft = this.element.scrollWidth - this.element.clientWidth + + this.element.scrollLeft = Math.min(Math.max(0, centered), maxScrollLeft) + }) + } +} diff --git a/templates/administrative/assignment/timeline.html.twig b/templates/administrative/assignment/timeline.html.twig index 4bbed51..54c88d0 100644 --- a/templates/administrative/assignment/timeline.html.twig +++ b/templates/administrative/assignment/timeline.html.twig @@ -68,12 +68,12 @@ {% endif %} -
+
{% for day in filterDto.period %} - {% endfor %}
+ {{ day | date('d.m.Y') }}