From 8d60ac3ffcaa94b4e9aef77655fc7297a7ce47a2 Mon Sep 17 00:00:00 2001 From: Mishig Date: Wed, 26 Feb 2025 19:23:37 +0100 Subject: [PATCH] [vizualisation] Add pagination for many episodes (#776) --- .../templates/visualize_dataset_template.html | 144 ++++++++++++++---- 1 file changed, 111 insertions(+), 33 deletions(-) diff --git a/lerobot/templates/visualize_dataset_template.html b/lerobot/templates/visualize_dataset_template.html index 08de3e3..e5a2f82 100644 --- a/lerobot/templates/visualize_dataset_template.html +++ b/lerobot/templates/visualize_dataset_template.html @@ -14,21 +14,7 @@ - +
- + + -
- {% for episode in episodes %} -

- - {{ episode }} - -

- {% endfor %} +
+ +
+ +
+
@@ -452,6 +468,68 @@ } }; } + + document.addEventListener('alpine:init', () => { + // Episode pagination component + Alpine.data('episodePagination', () => ({ + episodes: {{ episodes }}, + pageSize: 100, + page: 1, + + init() { + // Find which page contains the current episode_id + const currentEpisodeId = {{ episode_id }}; + const episodeIndex = this.episodes.indexOf(currentEpisodeId); + if (episodeIndex !== -1) { + this.page = Math.floor(episodeIndex / this.pageSize) + 1; + } + }, + + get totalPages() { + return Math.ceil(this.episodes.length / this.pageSize); + }, + + get paginatedEpisodes() { + const start = (this.page - 1) * this.pageSize; + const end = start + this.pageSize; + return this.episodes.slice(start, end); + }, + + nextPage() { + if (this.page < this.totalPages) { + this.page++; + } + }, + + prevPage() { + if (this.page > 1) { + this.page--; + } + } + })); + }); + + +