Skip to content

A self-hosted media server and file management system

Search and sort on history

aminnausin03b0790dbb94
diff --git a/resources/js/components/table/TableBase.vue b/resources/js/components/table/TableBase.vue
index 894e5d4d..0a131281 100644
--- a/resources/js/components/table/TableBase.vue
+++ b/resources/js/components/table/TableBase.vue
@@ -1,26 +1,55 @@
<script setup>
import useTable from '../../composables/useTable';
+import ButtonIcon from '../inputs/ButtonIcon.vue';
import LabelledTextInput from '../inputs/LabelledTextInput.vue';
+import FormInputLabel from '../labels/FormInputLabel.vue';
+import InputSelect from '../pinesUI/InputSelect.vue';
import TablePagination from '../table/TablePagination.vue';
-import { watch } from 'vue';
+import PhSortAscendingLight from '~icons/ph/sort-ascending-light';
+import PhSortDescendingLight from '~icons/ph/sort-descending-light';
+import { ref, watch } from 'vue';
-const props = defineProps(['useToolbar','data', 'row', 'clickAction','loading']);
+
+const props = defineProps(['useToolbar','data', 'row', 'clickAction', 'loading', 'sortAction', 'sortingOptions']);
const tableData = useTable(props);
+const sortAscending = ref(true);
+const lastSortKey = ref('');
+
+const handleSortChange = (sortKey) => {
+ if (sortKey?.value) lastSortKey.value = sortKey?.value;
+
+ if (!lastSortKey.value) return;
+ props.sortAction(lastSortKey.value, sortAscending.value ? 1 : -1)
+}
watch(props.data, tableData.handlePageReset, {immediate: true})
</script>
<template>
<div v-if="props.loading" class="text-center text-lg text-gray-500 dark:text-gray-400 uppercase tracking-wider w-full">Loading</div>
- <div v-else-if="tableData.filteredPage.length === 0 && !props.loading" class="text-center text-lg text-gray-500 dark:text-gray-400 uppercase tracking-wider w-full">No Results</div>
<table v-else class="w-full flex flex-col gap-4 divide-y first:pt-0 [&>*:not(:first-child)]:pt-4">
- <section v-if="props.useToolbar" class="flex justify-center sm:justify-between p-2">
- <LabelledTextInput v-model="tableData.fields.searchQuery" :text="'Search'" :placeholder="'Enter search query'" :id="'table-search'" class="w-80"/>
+ <section v-if="props.useToolbar" class="flex justify-center sm:justify-between py-2 flex-col sm:flex-row gap-2">
+ <!-- <h2 class="text-2xl py-4">Episodes</h2> -->
+ <LabelledTextInput v-model="tableData.fields.searchQuery" :text="'Search:'" :placeholder="'Enter Search Query...'" :id="'table-search'" class="w-full sm:w-80" @input="$emit('search', tableData.fields.searchQuery)"/>
+ <span class="flex items-end gap-2">
+ <div class="flex gap-2 flex-col w-full sm:w-40">
+ <FormInputLabel :field="{ name: 'sort', text: 'Sort by:' }" />
+ <InputSelect :placeholder="'None'" :options="props.sortingOptions" :label="'Sort by:'" class="w-full"
+ @selectItem="handleSortChange" :defaultItem="0" />
+ </div>
+ <ButtonIcon @click="sortAscending = !sortAscending; handleSortChange()">
+ <template #icon>
+ <PhSortAscendingLight v-if="sortAscending" width="24" height="24" />
+ <PhSortDescendingLight v-else width="24" height="24" />
+ </template>
+ </ButtonIcon>
+ </span>
</section>
<tbody class="flex w-full flex-wrap gap-2">
- <component :is="props.row" v-for="(row, index) in tableData.filteredPage" :key="row?.id ?? index" :data="row" @clickAction="props.clickAction"></component>
+ <div v-if="tableData.filteredPage.length === 0 && !props.loading" class="text-center text-lg text-gray-500 dark:text-gray-400 uppercase tracking-wider w-full">No Results</div>
+ <component v-else :is="props.row" v-for="(row, index) in tableData.filteredPage" :key="row?.id ?? index" :data="row" @clickAction="props.clickAction(row?.id)"></component>
</tbody>
<TablePagination :listLength="props.data?.length ?? 0" :itemsPerPage="tableData.fields.itemsPerPage" :currentPage="tableData.fields.currentPage" @setPage="tableData.handlePageChange"/>
</table>
diff --git a/resources/js/stores/ContentStore.js b/resources/js/stores/ContentStore.js
index 17ae0a35..3e410b4e 100644
--- a/resources/js/stores/ContentStore.js
+++ b/resources/js/stores/ContentStore.js
@@ -17,7 +17,7 @@ export const useContentStore = defineStore('Content', () => {
const folders = ref([]);
const videos = ref([]);
const records = ref([]);
-
+
const stateDirectory = ref({id:7, name:'anime', folders: []})
const stateFolder = ref({id:7, name:'ODDTAXI', videos: []})
@@ -92,6 +92,19 @@ export const useContentStore = defineStore('Content', () => {
});
}
+ const recordsSort = (column = 'created_at', dir = 1) => {
+ let tempList = records.value.sort((recordA, recordB) => {
+ if(column === 'created_at'){
+ let dateA = new Date(recordA?.attributes['created_at']);
+ let dateB = new Date(recordB?.attributes['created_at']);
+ return (dateB - dateA) * dir;
+ }
+ return recordB?.relationships[column]?.localeCompare(recordA?.relationships[column]) * dir;
+ });
+ records.value = tempList;
+ return tempList;
+ }
+
async function getCategory(URL_CATEGORY, URL_FOLDER) {
const { data, error } = await mediaAPI.getCategory(`${URL_CATEGORY}${URL_FOLDER ? '/' + URL_FOLDER : ''}`)
if(error || !data?.success){
@@ -179,8 +192,6 @@ export const useContentStore = defineStore('Content', () => {
}
const playlistSort = (column = 'name', dir = 1) => {
- // if(dir === 0 && sortQuery.value[column] === 0) dir = 1; // If never used, sort ascending
- // else if(dir === 0) dir = -sortQuery.value[column]; // if toggle, set negative order
let tempList = statePlaylist.value.sort((videoA, videoB) => {
if(column === 'date'){
let dateA = new Date(videoA?.attributes[column]);
@@ -192,10 +203,6 @@ export const useContentStore = defineStore('Content', () => {
});
stateFilteredPlaylist.value = tempList;
-
- // let tempQuery = sortQuery.value;
- // tempQuery[column] = dir;
- // sortQuery.value = tempQuery;
return tempList;
}
@@ -226,7 +233,7 @@ export const useContentStore = defineStore('Content', () => {
folders, videos, records,
stateDirectory, stateFolder, stateVideo,
searchQuery, filterQuery, stateFilteredPlaylist,
- getRecords, createRecord, deleteRecord,
+ getRecords, createRecord, deleteRecord, recordsSort,
getCategory, getFolder,
updateViewCount, updateVideoData,
playlistSeek, playlistFind, playlistSort
diff --git a/resources/js/views/HistoryView.vue b/resources/js/views/HistoryView.vue
index 9a587f58..54343427 100644
--- a/resources/js/views/HistoryView.vue
+++ b/resources/js/views/HistoryView.vue
@@ -1,53 +1,91 @@
<script setup>
- import RecordCardDetails from '../components/cards/RecordCardDetails.vue';
- import LayoutBase from '../components/layout/LayoutBase.vue';
- import ModalBase from '../components/pinesUI/ModalBase.vue';
- import useModal from '../composables/useModal';
- import TableBase from '../components/table/TableBase.vue';
+import RecordCardDetails from '../components/cards/RecordCardDetails.vue';
+import LayoutBase from '../components/layout/LayoutBase.vue';
+import ModalBase from '../components/pinesUI/ModalBase.vue';
+import useModal from '../composables/useModal';
+import TableBase from '../components/table/TableBase.vue';
- import { storeToRefs } from 'pinia';
- import { useAppStore } from '../stores/AppStore';
- import { useContentStore } from '../stores/ContentStore';
- import { onMounted, ref } from 'vue';
+import { storeToRefs } from 'pinia';
+import { useAppStore } from '../stores/AppStore';
+import { useContentStore } from '../stores/ContentStore';
+import { computed, onMounted, ref } from 'vue';
-
- const appStore = useAppStore();
- const ContentStore = useContentStore();
- const { pageTitle, selectedSideBar } = storeToRefs(appStore);
- const { records } = storeToRefs(ContentStore);
- const { getRecords, deleteRecord } = ContentStore;
- const loading = ref(true);
- const cachedID = ref(null);
- const confirmModal = useModal({title: 'Delete Record?', submitText: 'Confim'});
+const appStore = useAppStore();
+const ContentStore = useContentStore();
+const loading = ref(true);
+const cachedID = ref(null);
+const confirmModal = useModal({ title: 'Delete Record?', submitText: 'Confim' });
+const searchQuery = ref('');
- const handleDelete = (id) => {
- cachedID.value = id;
- confirmModal.toggleModal(true);
- }
+const { pageTitle, selectedSideBar } = storeToRefs(appStore);
+const { records } = storeToRefs(ContentStore);
+const { getRecords, deleteRecord, recordsSort } = ContentStore;
- const submitDelete = async () => {
- if(cachedID.value) await deleteRecord(cachedID.value)
- }
+const filteredRecords = computed(() => {
+ let tempList = searchQuery.value ? records.value.filter((video) => {{
+ try {
+ let strRepresentation = [video.relationships?.video_name, video.relationships?.folder_name, video.attributes.created_at,].join(' ').toLowerCase();
+ return strRepresentation.includes(searchQuery.value.toLowerCase())
+ } catch (error) {
+ console.log(error);
+ return false
+ }
+ }}) : records.value;
+ return tempList;
+})
- onMounted(() => {
- pageTitle.value = "History";
- selectedSideBar.value = '';
- (async () => {
- if( records.value.length <= 10 ) await getRecords();
- // await getRecords();
- loading.value = false;
- })()
- })
+const handleDelete = (id) => {
+ cachedID.value = id;
+ confirmModal.toggleModal(true);
+}
+
+const submitDelete = async () => {
+ if (cachedID.value) await deleteRecord(cachedID.value)
+}
+
+const sortingOptions = ref([
+{
+ title: 'Date',
+ value: 'created_at',
+ disabled: false
+ },
+ {
+ title: 'Title',
+ value: 'video_name',
+ disabled: false
+ },
+ {
+ title: 'Folder',
+ value: 'folder_name',
+ disabled: false
+ },
+]);
+
+const handleSort = (column = 'date', dir = 1) =>{
+ recordsSort(column, dir);
+}
+
+const handleSearch = (query) => {
+ searchQuery.value = query;
+}
+
+onMounted(() => {
+ pageTitle.value = "History";
+ selectedSideBar.value = '';
+ (async () => {
+ if (records.value.length <= 10) await getRecords();
+ // await getRecords();
+ loading.value = false;
+ })()
+})
</script>
<template>
<LayoutBase>
<template v-slot:content>
<section id="content-history" class=" space-y-2 cursor-pointer min-h-[80vh] ">
- <TableBase :data="records" :row="RecordCardDetails" :clickAction="handleDelete" :loading="loading">
-
- </TableBase>
+ <TableBase :data="filteredRecords" :row="RecordCardDetails" :clickAction="handleDelete" :loading="loading" :useToolbar="true" :sortAction="handleSort" :sortingOptions="sortingOptions" @search="handleSearch"/>
</section>
<ModalBase :modalData="confirmModal" :action="submitDelete">
<template #content>