From 5ca0cd651da1022c79ce8b25643f7395b53ee17b Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Wed, 4 Jun 2025 22:12:06 -0500 Subject: [PATCH] wip: toggling visibility of newly added download --- .../controllers/download_list_controller.js | 39 ++++++++++++++++++- src/Twig/Components/DownloadListRow.php | 2 + templates/broadcast/Download.stream.html.twig | 4 +- templates/components/DownloadList.html.twig | 22 ++++++----- .../components/DownloadListRow.html.twig | 2 +- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/assets/controllers/download_list_controller.js b/assets/controllers/download_list_controller.js index 09889e0..eeff276 100644 --- a/assets/controllers/download_list_controller.js +++ b/assets/controllers/download_list_controller.js @@ -7,7 +7,13 @@ import { getComponent } from '@symfony/ux-live-component'; /* stimulusFetch: 'lazy' */ export default class extends Controller { - static targets = ['download'] + static targets = ['download', 'downloadRow', 'viewAllBtn'] + static values = { + isWidget: Boolean, + perPage: Number, + } + + component = null; async initialize() { this.component = await getComponent(this.element); @@ -22,9 +28,38 @@ export default class extends Controller { // this.fooTarget.addEventListener('click', this._fooBar) } + downloadRowTargetConnected(target) { + if (Boolean(target.getAttribute('isBroadcasted')) === true) { + this.viewAllBtnTarget.parentElement.append(this.viewAllBtnTarget); + if (this.downloadRowTargets.length > this.perPageValue) { + target.classList.add('hidden'); + this.viewAllBtnTarget.classList.remove('hidden'); + } else { + this.viewAllBtnTarget.classList.add('hidden'); + } + } + } + + downloadRowTargetDisconnected(target) { + this.viewAllBtnTarget.parentElement.append(this.viewAllBtnTarget); + let i = 1; + this.downloadRowTargets.forEach((downloadRow) => { + console.log(downloadRow) + if (i <= this.perPageValue) { + downloadRow.classList.remove('hidden'); + } else { + downloadRow.classList.add('hidden'); + } + }) + + if (this.downloadRowTargets.length > this.perPage) { + this.viewAllBtnTarget.classList.remove('hidden'); + } + } + downloadTargetConnected(target) { let downloads = this.element.querySelectorAll('tbody tr'); - if (downloads.length > 5) { + if (downloads.length > this.perPageValue) { target.classList.add('hidden'); } } diff --git a/src/Twig/Components/DownloadListRow.php b/src/Twig/Components/DownloadListRow.php index 1def6f0..2c8d81c 100644 --- a/src/Twig/Components/DownloadListRow.php +++ b/src/Twig/Components/DownloadListRow.php @@ -11,4 +11,6 @@ final class DownloadListRow public Download $download; public bool $isWidget = true; + + public bool $isBroadcasted = false; } diff --git a/templates/broadcast/Download.stream.html.twig b/templates/broadcast/Download.stream.html.twig index 53e5afa..61ea23f 100644 --- a/templates/broadcast/Download.stream.html.twig +++ b/templates/broadcast/Download.stream.html.twig @@ -5,7 +5,7 @@ {% endblock %} @@ -35,7 +35,7 @@ {% endif %} diff --git a/templates/components/DownloadList.html.twig b/templates/components/DownloadList.html.twig index 637c180..bcf8b5c 100644 --- a/templates/components/DownloadList.html.twig +++ b/templates/components/DownloadList.html.twig @@ -1,5 +1,11 @@ - + {% set table_body_id = (type == "complete") ? "complete_downloads" : "active_downloads" %} + {% if this.isWidget == true and this.downloads.items|length > this.perPage %} + {% set show_view_all = true %} + {% else %} + {% set show_view_all = false %} + {% endif %} + @@ -31,15 +37,13 @@ {% if this.downloads.items|length > 0 %} {% for download in this.downloads.items %} - + {% endfor %} - {% if this.isWidget == true and this.downloads.items|length > this.perPage %} - - - - {% endif %} + + + {% else %}
- View All Downloads -
+ View All Downloads +
diff --git a/templates/components/DownloadListRow.html.twig b/templates/components/DownloadListRow.html.twig index 16d538e..741fc53 100644 --- a/templates/components/DownloadListRow.html.twig +++ b/templates/components/DownloadListRow.html.twig @@ -1,4 +1,4 @@ - + {{ download.title }}