Skip to content

A self-hosted media server and file management system

Pagination UI and Table UI Update

aminnausin99cebd2a21af
diff --git a/resources/js/components/VideoTable.vue b/resources/js/components/VideoTable.vue
index 373f5bad..2c979070 100644
--- a/resources/js/components/VideoTable.vue
+++ b/resources/js/components/VideoTable.vue
@@ -1,16 +1,16 @@
<script setup>
-import VideoCard from './VideoCard.vue';
+import VideoCard from './cards/VideoCard.vue';
import LabelledTextInput from './inputs/LabelledTextInput.vue';
import { useContentStore } from '../stores/ContentStore';
import { storeToRefs } from 'pinia';
import { ref } from 'vue';
+import TablePagination from './table/TablePagination.vue';
const ContentStore = useContentStore();
-const { searchQuery, stateFilteredPlaylist, stateFolder, stateVideo } = storeToRefs(ContentStore);
+const { searchQuery, stateFilteredPlaylist, stateVideo } = storeToRefs(ContentStore);
const { playlistFind } = ContentStore;
-const videosPerPage = ref(10);
const currentPage = ref(1);
const handlePageChange = (page) => {
@@ -18,21 +18,21 @@ const handlePageChange = (page) => {
}
const tableColumnGroups = [
- [{ name: 'Title', colspan: '2', minWidth: 'min-w-48' },
- { name: 'Length', colspan: '1', minWidth: 'min-w-6' }],
- [{ name: 'Views', colspan: '1', minWidth: 'min-w-6' },
- { name: 'Date', colspan: '2', minWidth: 'min-w-40' }],
+ [{ name: 'Title', colspan: '2', minWidth: 'lg:min-w-48' },
+ { name: 'Length', colspan: '1', minWidth: 'xl:min-w-6' }],
+ [{ name: 'Views', colspan: '1', minWidth: 'xl:min-w-6' },
+ { name: 'Date', colspan: '2', minWidth: 'xl:min-w-40' }],
];
</script>
<template>
- <table class="w-full overflow-x-hidden flex flex-col gap-2">
- <section class="folder-header flex justify-center sm:justify-start p-2">
+ <table class="w-full overflow-clip flex flex-col gap-2">
+ <section class="folder-header flex justify-center sm:justify-between p-2">
<!-- <h2 class="text-2xl py-4">Episodes</h2> -->
- <LabelledTextInput v-model="searchQuery" :text="'Search'" class="w-80" />
+ <LabelledTextInput v-model="searchQuery" :text="'Search'" class="w-80"/>
</section>
<hr>
- <thead class="w-full flex">
+ <thead class="w-full flex-col hidden sm:flex">
<tr class="w-full flex justify-between gap-12 text-left">
<th class="px-3 flex gap-12 w-full items-center">
<span v-for="(column, idx) in tableColumnGroups[0]" :key="idx" :class="column.minWidth">{{
@@ -46,27 +46,28 @@ const tableColumnGroups = [
</tr>
</thead>
<tbody
- class="flex w-full flex-wrap gap-2 [&>*:nth-child(odd)]:bg-violet-200 hover:[&>*:nth-child(odd)]:bg-violet-300 dark:[&>*:nth-child(odd)]:bg-zinc-700 dark:hover:[&>*:nth-child(odd)]:bg-indigo-900">
- <!-- <VideoCard v-for="(video, index) in stateFilteredPlaylist.slice(videosPerPage * currentPage - videosPerPage, Math.min(videosPerPage * currentPage, stateFilteredPlaylist.length))" :key="index" :video="video" :index="index" -->
- <!-- :currentID="stateVideo.id" @playByID="playlistFind" /> -->
+ class="flex w-full flex-wrap gap-2">
+ <!-- <VideoCard v-for="(video, index) in stateFilteredPlaylist.slice(videosPerPage * currentPage - videosPerPage, Math.min(videosPerPage * currentPage, stateFilteredPlaylist.length))" :key="index" :video="video" :index="index"
+ :currentID="stateVideo.id" @playByID="playlistFind" /> -->
<VideoCard v-for="(video, index) in stateFilteredPlaylist" :key="index" :video="video" :index="index"
- :currentID="stateVideo.id" @playByID="playlistFind" />
+ :currentID="stateVideo?.id" @playByID="playlistFind" />
</tbody>
- <hr>
- <section class="flex w-full justify-between">
+ <hr >
+ <!-- <section class="w-full justify-between flex">
<div class="">
<p>{{ `Showing ${stateFilteredPlaylist.length} of ${stateFolder.videos.length}
Result${stateFolder.videos.length > 1 ? 's' : ''} ${searchQuery ? '(Filtered)' : ''}` }}</p>
- <!-- <p>{{ `Showing ${stateFilteredPlaylist.slice(videosPerPage * currentPage - videosPerPage, Math.min(videosPerPage * currentPage, stateFilteredPlaylist.length)).length} of ${stateFolder.videos.length} -->
- <!-- Result${stateFolder.videos.length > 1 ? 's' : ''} ${searchQuery ? '(Filtered)' : ''}`}}</p> -->
+ <p>{{ `Showing ${stateFilteredPlaylist.slice(videosPerPage * currentPage - videosPerPage, Math.min(videosPerPage * currentPage, stateFilteredPlaylist.length)).length} of ${stateFolder.videos.length}
+ Result${stateFolder.videos.length > 1 ? 's' : ''} ${searchQuery ? '(Filtered)' : ''}`}}</p>
</div>
- <div class="gap-2 items-center hidden">
+ <div class="gap-2 items-center">
<button v-for="index in Math.ceil(stateFilteredPlaylist?.length / videosPerPage)" :key="index"
class="aspect-square bg-button-100 dark:bg-button-900 rounded-lg hover:ring-indigo-500 hover:ring-[0.125rem] ring-inset"
@click="handlePageChange(index)">
{{ index }}
</button>
</div>
- </section>
+ </section> -->
+ <TablePagination :listLength="stateFilteredPlaylist?.length ?? 0" :currentPage="currentPage" @setPage="handlePageChange"/>
</table>
</template>
\ No newline at end of file
diff --git a/resources/js/components/cards/VideoCard.vue b/resources/js/components/cards/VideoCard.vue
index 9a35ede9..e34ca3f6 100644
--- a/resources/js/components/cards/VideoCard.vue
+++ b/resources/js/components/cards/VideoCard.vue
@@ -18,12 +18,12 @@ const handlePlay = () => {
class="vid-row w-full rounded-md dark:bg-neutral-800 dark:hover:bg-indigo-900 bg-violet-100 hover:bg-violet-300 odd:bg-violet-200 hover:odd:bg-violet-300 dark:odd:bg-zinc-700 dark:hover:odd:bg-indigo-900 p-3 flex ring-inset flex-wrap flex-col sm:flex-row sm:flex-nowrap"
:data-id="props.video.id" :data-path="`../${props.video.attributes.path}`" @click="handlePlay">
<td class="flex gap-12 w-full">
- <span class="vid-row-title truncate xl:min-w-48">{{ props.video.attributes.name }}</span>
+ <span class="vid-row-title xl:min-w-48 max-w-1/2 line-clamp-1">{{ props.video.attributes.name }}</span>
<span class="vid-row-duration truncate hidden sm:block">20m 30s</span>
</td>
<td class="flex gap-12 w-full sm:justify-end">
<span class="vid-row-title hidden sm:block">{{ currentID === props.video.id }} {{ index }}</span>
- <span class="vid-row-date truncate overflow-hidden xl:min-w-36">{{ toFormattedDate(rawDate) }}</span>
+ <span class="vid-row-date line-clamp-1 xl:min-w-36 max-w-1/3">{{ toFormattedDate(rawDate) }}</span>
</td>
</tr>
</template>
\ No newline at end of file
diff --git a/resources/js/components/inputs/LabelledTextInput.vue b/resources/js/components/inputs/LabelledTextInput.vue
index 96cf90f1..1d27833c 100644
--- a/resources/js/components/inputs/LabelledTextInput.vue
+++ b/resources/js/components/inputs/LabelledTextInput.vue
@@ -4,7 +4,7 @@ const { text } = defineProps(['text'])
</script>
<template>
<div class="flex justify-start items-center gap-2">
- <label class="text-neutral-950 dark:text-white text-lg" :for="text">{{ text }}:</label>
+ <label class="text-neutral-950 dark:text-white" :for="text">{{ text }}:</label>
<input type="text" v-model="model"
class="p-2 text-neutral-950 dark:text-white bg-input-100 border-input-200 shadow-sm leading-none dark:bg-input-800 dark:border-indigo-800 rounded-lg w-full">
</div>
diff --git a/resources/js/components/table/TablePagination.vue b/resources/js/components/table/TablePagination.vue
new file mode 100644
index 00000000..f8ea80a2
--- /dev/null
+++ b/resources/js/components/table/TablePagination.vue
@@ -0,0 +1,61 @@
+<script setup>
+import { computed, ref } from 'vue';
+import TablePaginationButton from './TablePaginationButton.vue';
+
+const props = defineProps(['listLength', 'currentPage']);
+const itemsPerPage = ref(5);
+const pageCount = computed(() => { return Math.ceil(props.listLength / itemsPerPage.value); });
+</script>
+
+<template>
+ <div class="flex items-center flex-col sm:flex-row sm:justify-between flex-wrap gap-2">
+ <p class="text-gray-700 dark:text-neutral-100 line-clamp-1">
+ Showing
+ <span class="font-medium">{{ itemsPerPage * (currentPage - 1) + 1 }}</span>
+ to
+ <span class="font-medium">{{ Math.min(itemsPerPage * (currentPage), props.listLength) }}</span>
+ of
+ <span class="font-medium">{{ listLength }}</span>
+ Results
+ </p>
+ <nav class="">
+ <ul
+ class="flex items-center text-sm leading-tight bg-white dark:bg-gray-700 border divide-x rounded h-9 text-neutral-500 dark:text-neutral-200 divide-neutral-200 dark:divide-neutral-700 border-neutral-200 dark:border-neutral-700">
+ <TablePaginationButton :pageNumber="-1" :text="'Previous'"
+ @click="$emit('setPage', Math.max(1, props.currentPage - 1))" />
+ <TablePaginationButton v-for="page in pageCount" :key="page" :pageNumber="page"
+ :currentPage="props.currentPage" @click="$emit('setPage', page)" />
+ <TablePaginationButton :pageNumber="-1" :text="'Next'"
+ @click="$emit('setPage', Math.min(pageCount, props.currentPage + 1))" />
+
+
+ <!-- <li class="h-full">
+ <button @click="$emit('setPage', Math.max(1, props.currentPage - 1))"
+ class="relative inline-flex items-center h-full px-3 ml-0 rounded-l group hover:text-neutral-900">
+ <span>Previous</span>
+ </button>
+ </li> -->
+ <!-- <li v-for="page in pageCount" :key="page" :class="{'hidden' : props.currentPage !== page}" class="h-full md:block" >
+ <button @click="$emit('setPage', page)" class="relative inline-flex items-center h-full px-3" :class="{'text-neutral-900 group bg-gray-50' : props.currentPage === page, 'group hover:text-neutral-900' : props.currentPage !== page}">
+ <span>{{ page }}</span>
+ <span v-if="props.currentPage === page"
+ class="box-content absolute bottom-0 left-0 w-full h-px -mx-px translate-y-px border-l border-r bg-neutral-900 border-neutral-900"></span>
+ <span v-else
+ class="box-content absolute bottom-0 w-0 h-px -mx-px duration-200 ease-out translate-y-px border-transparent bg-neutral-900 group-hover:border-l group-hover:border-r group-hover:border-neutral-900 left-1/2 group-hover:left-0 group-hover:w-full"></span>
+ </button>
+ </li> -->
+ <!-- <li class="hidden h-full md:block">
+ <div class="relative inline-flex items-center h-full px-2.5 group">
+ <span>...</span>
+ </div>
+ </li> -->
+ <!-- <li class="h-full">
+ <button @click="$emit('setPage', Math.min(pageCount, props.currentPage + 1))"
+ class="relative inline-flex items-center h-full px-3 rounded-r group hover:text-neutral-900">
+ <span>Next</span>
+ </button>
+ </li> -->
+ </ul>
+ </nav>
+ </div>
+</template>
\ No newline at end of file
diff --git a/resources/js/components/table/TablePaginationButton.vue b/resources/js/components/table/TablePaginationButton.vue
new file mode 100644
index 00000000..3772e3e6
--- /dev/null
+++ b/resources/js/components/table/TablePaginationButton.vue
@@ -0,0 +1,18 @@
+<script setup>
+const props = defineProps(['currentPage', 'pageNumber', 'text']);
+</script>
+
+<template>
+ <li :class="{ 'hidden': props.currentPage !== props.pageNumber && !props.text }" class="h-full md:block">
+ <button class="relative inline-flex items-center h-full px-3 group hover:text-neutral-900 hover:dark:text-neutral-50" :class="{ 'text-neutral-900 dark:text-neutral-50 bg-gray-50 dark:bg-gray-800': props.currentPage === props.pageNumber, }">
+ <span>
+ {{ props?.text ?? props.pageNumber }}
+ </span>
+
+ <span v-if="!props.text"
+ class="box-content absolute bottom-0 w-0 h-px -mx-px duration-200 ease-out translate-y-px border-transparent group-hover:left-0 group-hover:w-full group-hover:border-l group-hover:border-r bg-neutral-900 dark:bg-neutral-200 group-hover:border-neutral-900 group-hover:dark:border-neutral-200"
+ :class="{'left-0 w-full border-l border-r' : props.currentPage === props.pageNumber, 'left-1/2' : props.currentPage !== props.pageNumber}">
+ </span>
+ </button>
+ </li>
+</template>
\ No newline at end of file
diff --git a/resources/js/service/util.js b/resources/js/service/util.js
index a095282f..8d3c066c 100644
--- a/resources/js/service/util.js
+++ b/resources/js/service/util.js
@@ -20,4 +20,8 @@ export function toTimeSpan(rawDate) {
export function toFormattedDate(rawDate) {
return (rawDate.toLocaleString([], {year: 'numeric', month: '2-digit', day:'2-digit', hour:'2-digit', minute:'2-digit', hour12: true})).toLocaleUpperCase().replaceAll('.','');
+}
+
+export function formatInteger(integer, minimumDigits = 2) {
+ return integer.toLocaleString('en-CA', { minimumIntegerDigits: minimumDigits})
}
\ No newline at end of file
diff --git a/resources/js/views/VideoView.vue b/resources/js/views/VideoView.vue
index 08ad1226..e20092c6 100644
--- a/resources/js/views/VideoView.vue
+++ b/resources/js/views/VideoView.vue
@@ -2,13 +2,13 @@
import VideoSidebar from '../components/panels/VideoSidebar.vue';
import LayoutBase from '../components/layout/LayoutBase.vue';
import VideoPlayer from '../components/VideoPlayer.vue';
+ import VideoTable from '../components/VideoTable.vue';
import { ref, onMounted, watch } from 'vue';
import { useContentStore } from '../stores/ContentStore';
import { useAppStore } from '../stores/AppStore';
import { storeToRefs } from 'pinia';
import { useRoute } from 'vue-router'
- import VideoTable from '../components/VideoTable.vue';
const route = useRoute();
@@ -18,6 +18,7 @@
const { stateVideo} = storeToRefs(ContentStore);
const { getFolder, getCategory, getRecords, playlistSeek } = ContentStore;
+
async function cycleSideBar(state){
if(state === "history"){
getRecords(10);