Skip to content

A self-hosted media server and file management system

basic sorting

aminnausin282f64265f89
diff --git a/resources/js/components/cards/VideoCard.vue b/resources/js/components/cards/VideoCard.vue
index 1f435951..cf5c9b4b 100644
--- a/resources/js/components/cards/VideoCard.vue
+++ b/resources/js/components/cards/VideoCard.vue
@@ -3,7 +3,6 @@ import { toFormattedDate } from '../../service/util';
const props = defineProps(['video', 'index', 'currentID']);
-const rawDate = new Date(props.video.attributes.date + ' GMT');
const emit = defineEmits(['playByID']);
const handlePlay = () => {
@@ -23,7 +22,7 @@ const handlePlay = () => {
</td>
<td class="flex gap-12 w-full sm:justify-end">
<p class="vid-row-title truncate hidden sm:block">20 Views</p>
- <p class="vid-row-date w-full xl:min-w-36 sm:max-w-1/3 sm:w-auto flex justify-between items-center gap-12 sm:gap-0"><span class="sm:hidden">Date: </span><span class="line-clamp-1">{{ toFormattedDate(rawDate) }}</span></p>
+ <p class="vid-row-date w-full xl:min-w-36 sm:max-w-1/3 sm:w-auto flex justify-between items-center gap-12 sm:gap-0"><span class="sm:hidden">Date: </span><span class="line-clamp-1">{{ toFormattedDate(new Date(props.video.attributes.date + ' GMT')) }}</span></p>
</td>
</tr>
</template>
\ No newline at end of file
diff --git a/resources/js/components/video/VideoTable.vue b/resources/js/components/video/VideoTable.vue
index 848edc1c..def6379e 100644
--- a/resources/js/components/video/VideoTable.vue
+++ b/resources/js/components/video/VideoTable.vue
@@ -10,7 +10,7 @@ import { computed, ref } from 'vue';
const ContentStore = useContentStore();
const { searchQuery, stateFilteredPlaylist, stateVideo } = storeToRefs(ContentStore);
-const { playlistFind } = ContentStore;
+const { playlistFind, playlistSort } = ContentStore;
const currentPage = ref(1);
const itemsPerPage = ref(10);
@@ -26,10 +26,10 @@ const handlePageChange = (page) => {
}
const tableColumnGroups = [
- [{ 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' }],
+ [{ name: 'Title', colspan: '2', minWidth: 'lg:min-w-48', colName: 'name' },
+ { name: 'Length', colspan: '1', minWidth: 'xl:min-w-6', colName: 'name' }],
+ [{ name: 'Views', colspan: '1', minWidth: 'xl:min-w-6', colName: 'date' },
+ { name: 'Date', colspan: '2', minWidth: 'xl:min-w-40', colName: 'date' }],
];
</script>
@@ -41,14 +41,12 @@ const tableColumnGroups = [
</section>
<hr>
<thead class="w-full flex-col hidden sm:flex">
- <tr class="w-full flex justify-between gap-12 text-left">
+ <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">{{
- column.name }}</span>
+ <span v-for="(column, idx) in tableColumnGroups[0]" :key="idx" :class="column.minWidth" @click="playlistSort(column.colName, 0)">{{column.name }}</span>
</th>
<th class="px-3 flex gap-12 w-full justify-end text-right items-center">
- <span v-for="(column, idx) in tableColumnGroups[1]" :key="idx" :class="column.minWidth">{{
- column.name }}</span>
+ <span v-for="(column, idx) in tableColumnGroups[1]" :key="idx" :class="column.minWidth" @click="playlistSort(column.colName, 0)">{{ column.name }}</span>
</th>
</tr>
</thead>
diff --git a/resources/js/stores/ContentStore.js b/resources/js/stores/ContentStore.js
index 3daea8e5..61b1948f 100644
--- a/resources/js/stores/ContentStore.js
+++ b/resources/js/stores/ContentStore.js
@@ -27,6 +27,7 @@ export const useContentStore = defineStore('Content', () => {
const searchQuery = ref('');
const filterQuery = ref({search: '', season: -1, tag: ''});
+ const sortQuery = ref({name: 0, date: 0});
async function getRecords(limit){
if(!userData.value) return;
@@ -85,7 +86,7 @@ export const useContentStore = defineStore('Content', () => {
}
stateDirectory.value = data.data.dir;
- stateFolder.value = data.data.folder
+ stateFolder.value = data.data.folder;
folders.value = data.data.dir.folders;
pageTitle.value = stateFolder.value.name;
@@ -147,10 +148,26 @@ export const useContentStore = defineStore('Content', () => {
statePlaylist.value = stateFolder.value.videos.map((video, index) => { return {index, ...video}; } );
stateVideo.value = statePlaylist.value.length > 0 ? statePlaylist.value[0] : {};
-
+ playlistSort();
playlistFilter();
}
+ const playlistSort = (column = 'date', 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) => {
+ return videoA?.attributes[column].localeCompare(videoB?.attributes[column]) * dir;
+ });
+
+ stateFilteredPlaylist.value = tempList;
+
+ let tempQuery = sortQuery.value;
+ tempQuery[column] = dir;
+ sortQuery.value = tempQuery;
+ return tempList;
+ }
+
const playlistFilter = (query) => {
let tempList = query ? statePlaylist.value.filter((video) => {{
try {
@@ -171,6 +188,6 @@ export const useContentStore = defineStore('Content', () => {
stateDirectory, stateFolder, stateVideo,
searchQuery, filterQuery, stateFilteredPlaylist,
getRecords, createRecord, deleteRecord,
- getCategory, getFolder, playlistSeek, playlistFind
+ getCategory, getFolder, playlistSeek, playlistFind, playlistSort
};
});
\ No newline at end of file