Skip to content

A self-hosted media server and file management system

feat: generic table and folder table without search

aminnausin3063063ad0fd
diff --git a/resources/js/components/cards/FolderCard.vue b/resources/js/components/cards/FolderCard.vue
index 57f74126..38a241e1 100755
--- a/resources/js/components/cards/FolderCard.vue
+++ b/resources/js/components/cards/FolderCard.vue
@@ -9,6 +9,7 @@ import { computed } from 'vue';
import RelativeHoverCard from '@/components/cards/RelativeHoverCard.vue';
import ButtonCorner from '@/components/inputs/ButtonCorner.vue';
+import ChipTag from '@/components/labels/ChipTag.vue';
import CircumFolderOn from '~icons/circum/folder-on';
import CircumShare1 from '~icons/circum/share-1';
@@ -50,7 +51,7 @@ const contextMenuItems = computed(() => {
<template #trigger>
<RouterLink
:to="`/${data.path}`"
- class="text-left relative flex flex-col sm:gap-4 sm:flex-row flex-wrap rounded-lg sm:p-3 dark:bg-primary-dark-800/70 bg-primary-800 dark:hover:bg-primary-dark-600 hover:bg-gray-200 dark:text-white shadow w-full group cursor-pointer divide-gray-300 dark:divide-gray-400"
+ class="text-left relative flex flex-col sm:flex-row flex-wrap rounded-lg sm:p-3 dark:bg-primary-dark-800/70 bg-primary-800 dark:hover:bg-primary-dark-600 hover:bg-gray-200 dark:text-white shadow w-full group cursor-pointer divide-gray-300 dark:divide-gray-400"
@contextmenu="
(e: any) => {
setContextMenu(e, { items: contextMenuItems });
@@ -60,7 +61,7 @@ const contextMenuItems = computed(() => {
<img
:src="handleStorageURL(data.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"
alt="Folder Thumbnail"
- class="hidden xs:block lg:hidden max-h-16 sm:w-12 aspect-square object-cover shadow-md rounded-t-lg sm:rounded-sm"
+ class="hidden xs:block lg:hidden max-h-16 sm:w-12 aspect-square object-cover shadow-md rounded-t-lg sm:rounded-sm sm:me-4"
/>
<span class="w-full flex-1 text-left relative flex flex-col gap-4 lg:gap-2 sm:flex-row flex-wrap p-3 sm:p-0">
<section class="flex justify-between gap-4 w-full items-center">
@@ -103,6 +104,18 @@ const contextMenuItems = computed(() => {
</h3>
</section>
</span>
+ <section
+ v-if="props.data.series?.folder_tags?.length"
+ class="flex gap-1 p-3 sm:p-0 pt-0 transition-[max-height] sm:max-h-[0px] md:group-hover:max-h-[30px] w-full overflow-hidden flex-wrap"
+ title="Tags"
+ >
+ <ChipTag
+ v-for="(tag, index) in props.data.series.folder_tags"
+ v-bind:key="index"
+ :label="tag.name"
+ :colour="'bg-neutral-200 leading-none text-neutral-500 shadow dark:bg-neutral-900 hover:bg-violet-600 hover:text-neutral-50 hover:dark:bg-violet-600/90 !max-h-[22px] sm:mt-2'"
+ />
+ </section>
</RouterLink>
</template>
</RelativeHoverCard>
diff --git a/resources/js/components/dashboard/DashboardLibraryFolders.vue b/resources/js/components/dashboard/DashboardLibraryFolders.vue
index 6a8fe1c6..47ddd3d1 100644
--- a/resources/js/components/dashboard/DashboardLibraryFolders.vue
+++ b/resources/js/components/dashboard/DashboardLibraryFolders.vue
@@ -88,7 +88,7 @@ const handleStartScan = async () => {
}
};
-const handleFolderAction = (e: Event, id: number, action: 'edit' | 'share' = 'edit') => {
+const handleFolderAction = (id: number, action: 'edit' | 'share' = 'edit') => {
let folder = stateLibraryFolders.value?.find((folder: FolderResource) => folder.id === id);
if (folder) cachedFolder.value = folder;
diff --git a/resources/js/components/panels/VideoSidebar.vue b/resources/js/components/panels/VideoSidebar.vue
index 29cb394f..79ce7f61 100755
--- a/resources/js/components/panels/VideoSidebar.vue
+++ b/resources/js/components/panels/VideoSidebar.vue
@@ -13,6 +13,7 @@ import RecordCard from '@/components/cards/RecordCard.vue';
import EditFolder from '@/components/forms/EditFolder.vue';
import ModalBase from '@/components/pinesUI/ModalBase.vue';
import useModal from '@/composables/useModal';
+import TableBase from '@/components/table/TableBase.vue';
const editFolderModal = useModal({ title: 'Edit Folder Details', submitText: 'Submit Details' });
const shareModal = useModal({ title: 'Share Video' });
@@ -41,7 +42,7 @@ const handleFolderAction = (id: number, action: 'edit' | 'share' = 'edit') => {
cachedFolder.value = folder;
if (action === 'edit') editFolderModal.toggleModal();
else {
- shareLink.value = window.location.origin + '/' + folder.path;
+ shareLink.value = encodeURI(window.location.origin + '/' + folder.path);
shareModal.toggleModal(true);
}
};
@@ -67,13 +68,18 @@ watch(
</div>
<section v-if="selectedSideBar === 'folders'" id="list-content-folders" class="flex gap-2 flex-wrap">
- <FolderCard
- v-for="folder in stateDirectory.folders"
- :key="folder.id"
- :data="folder"
- :categoryName="stateDirectory.name"
- :stateFolderName="stateFolder?.name"
- @clickAction="handleFolderAction"
+ <TableBase
+ :data="stateDirectory.folders"
+ :row="FolderCard"
+ :clickAction="handleFolderAction"
+ :useToolbar="false"
+ :startAscending="true"
+ :row-attributes="{
+ categoryName: stateDirectory.name,
+ stateFolderName: stateFolder?.name,
+ }"
+ :items-per-page="10"
+ :pagination-class="'!justify-center !flex-col-reverse'"
/>
</section>
<section v-if="selectedSideBar === 'history'" id="list-content-history" class="flex gap-2 flex-wrap">
diff --git a/resources/js/components/table/TableBase.vue b/resources/js/components/table/TableBase.vue
index 68f69518..fc520e2c 100755
--- a/resources/js/components/table/TableBase.vue
+++ b/resources/js/components/table/TableBase.vue
@@ -1,5 +1,7 @@
-<script setup lang="ts">
-import { onMounted, ref, type Component } from 'vue';
+<script setup lang="ts" generic="T">
+import type { SortOption, TableProps } from '@/types/types';
+
+import { onMounted, ref } from 'vue';
import TextInputLabelled from '@/components/inputs/TextInputLabelled.vue';
import TablePagination from '@/components/table/TablePagination.vue';
@@ -12,60 +14,45 @@ import SvgSpinners90RingWithBg from '~icons/svg-spinners/90-ring-with-bg';
import PhSortDescendingLight from '~icons/ph/sort-descending-light';
import PhSortAscendingLight from '~icons/ph/sort-ascending-light';
-const props = withDefaults(
- defineProps<{
- useToolbar?: boolean;
- usePagination?: boolean;
- useGrid?: string;
- data: any[];
- row: Component;
- rowAttributes?: { [key: string]: any };
- loading?: boolean;
- clickAction?: any;
- otherAction?: any;
- sortAction?: any;
- sortingOptions?: {
- title: string;
- value: string;
- disabled?: boolean;
- }[];
- itemsPerPage?: number;
- searchQuery?: any;
- selectedID?: any;
- tableStyles?: string;
- startAscending?: boolean;
- paginationClass?: string;
- }>(),
- {
- useToolbar: true,
- usePagination: true,
- itemsPerPage: 12,
- selectedID: null,
- startAscending: true,
- searchQuery: '',
- },
-);
+// 👇 Generic prop types
+
+const props = withDefaults(defineProps<TableProps<T>>(), {
+ useToolbar: true,
+ usePagination: true,
+ itemsPerPage: 5,
+ selectedID: null,
+ startAscending: true,
+ searchQuery: '',
+});
+
+const emit = defineEmits<{
+ (e: 'search', value: string): void;
+}>();
+
const tableData = useTable(props);
const sortAscending = ref(props.startAscending);
const lastSortKey = ref('');
-const emit = defineEmits(['search']);
+
const model = defineModel<string | undefined>({
required: false,
default: undefined,
});
-const handleSortChange = (sortKey?: { title?: string; value?: string; disabled?: boolean }) => {
+defineSlots<{
+ row(props: { row: T; index: number; selectedID: any }): any;
+}>();
+
+const handleSortChange = (sortKey?: SortOption) => {
if (sortKey?.value) {
lastSortKey.value = sortKey.value;
}
if (!lastSortKey.value) return;
- props.sortAction(lastSortKey.value, sortAscending.value ? 1 : -1);
+ props.sortAction?.(lastSortKey.value as keyof T, sortAscending.value ? 1 : -1);
};
const handleSearch = (event: InputEvent) => {
const target = event.target as HTMLInputElement;
-
const value = target.value;
if (model.value !== undefined) {
@@ -77,13 +64,13 @@ const handleSearch = (event: InputEvent) => {
};
onMounted(() => {
- if (props.useToolbar && props.sortAction) props.sortAction(lastSortKey.value, props.startAscending ? 1 : -1);
+ if (props.useToolbar && props.sortAction) props.sortAction(lastSortKey.value as keyof T, props.startAscending ? 1 : -1);
});
</script>
<template>
<!-- [&>*:not(:first-child)]:pt-4 -->
- <section class="flex flex-col gap-4">
+ <section class="flex flex-col gap-4 w-full">
<section v-if="props.useToolbar" class="flex justify-center sm:justify-between flex-col sm:flex-row gap-2">
<TextInputLabelled
:value="model ?? tableData.fields.searchQuery"
@@ -94,16 +81,6 @@ onMounted(() => {
title="Search Here"
@input="handleSearch"
/>
- <!-- <TextInputLabelled
- v-else
- v-model="tableData.fields.searchQuery"
- :text="'Search:'"
- :placeholder="'Enter Search Query...'"
- :id="'table-search'"
- class="w-full sm:w-80"
- title="Search Here"
- @input="$emit('search', tableData.fields.searchQuery)"
- /> -->
<span class="flex items-end gap-2 flex-wrap">
<div class="flex gap-2 flex-col w-full sm:w-40 flex-1">
<FormInputLabel :field="{ name: 'sort', text: 'Sort by:' }" />
@@ -142,18 +119,20 @@ onMounted(() => {
<p>{{ loading ? '...Loading' : 'No Results' }}</p>
<SvgSpinners90RingWithBg v-show="loading" />
</div>
- <component
- v-else
- :is="props.row"
- v-for="(row, index) in tableData.filteredPage"
- :key="row?.id ?? index"
- :data="row"
- :index="index"
- :currentID="props.selectedID ?? null"
- v-bind="rowAttributes"
- @clickAction="(...args: any[]) => props.clickAction?.(row?.id, ...args)"
- @otherAction="(...args: any[]) => props.otherAction?.(row?.id, ...args)"
- ></component>
+ <template v-else v-for="(row, index) in tableData.filteredPage" :key="row?.id ?? index">
+ <slot name="row" :row="row" :index="index" :selectedID="props.selectedID">
+ <component
+ :is="props.row"
+ :key="row?.id ?? index"
+ :data="row"
+ :index="index"
+ :currentID="props.selectedID ?? null"
+ v-bind="rowAttributes"
+ @clickAction="(...args: any[]) => props.clickAction?.(row?.id, ...args)"
+ @otherAction="(...args: any[]) => props.otherAction?.(row?.id, ...args)"
+ ></component>
+ </slot>
+ </template>
</section>
<!-- <hr class="p-0" /> -->
<TablePagination
diff --git a/resources/js/components/table/TablePagination.vue b/resources/js/components/table/TablePagination.vue
index f76a2651..552154d9 100755
--- a/resources/js/components/table/TablePagination.vue
+++ b/resources/js/components/table/TablePagination.vue
@@ -38,7 +38,7 @@ const handleSetPage = async (page: number) => {
</script>
<template>
- <div class="flex items-center flex-col sm:flex-row sm:justify-between flex-wrap gap-2 scroll-mb-12" ref="$element">
+ <div :class="`flex items-center flex-col sm:flex-row sm:justify-between flex-wrap gap-2 scroll-mb-12`" ref="$element">
<p class="text-gray-700 dark:text-neutral-300 line-clamp-1 text-sm">
Showing
<span class="font-medium dark:text-neutral-100">{{ props.listLength ? props.itemsPerPage * (currentPage - 1) + 1 : 0 }}</span>
diff --git a/resources/js/types/types.ts b/resources/js/types/types.ts
index bca25956..1d4943dd 100644
--- a/resources/js/types/types.ts
+++ b/resources/js/types/types.ts
@@ -1,5 +1,5 @@
import type { NullConnector, PusherConnector, SocketIoConnector } from 'laravel-echo/dist/connector';
-import type { Component } from 'vue';
+import type { Component, DefineComponent } from 'vue';
import type {
NullChannel,
@@ -255,3 +255,29 @@ export interface SelectItem {
name: string;
relationships?: any;
}
+
+export declare type SortOption = {
+ title: string;
+ value: string;
+ disabled?: boolean;
+};
+
+export interface TableProps<T> {
+ useToolbar?: boolean;
+ usePagination?: boolean;
+ useGrid?: string;
+ data: T[];
+ row: DefineComponent<any, any, any> | Component;
+ rowAttributes?: Record<string, any>;
+ loading?: boolean;
+ clickAction?: (id: number, ...args: any[]) => void;
+ otherAction?: (...args: any[]) => void;
+ sortAction?: (sortKey: keyof T, direction: 1 | -1) => void;
+ sortingOptions?: SortOption[];
+ itemsPerPage?: number;
+ searchQuery?: string;
+ selectedID?: number | string | null;
+ tableStyles?: string;
+ startAscending?: boolean;
+ paginationClass?: string;
+}