Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add column level sorting to nendo library #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions src/components/apps/nendo_library/nendo_library_main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const currentTrack = ref({})
const audioPlayerRef = ref(null)
const scrollComponent = ref(null)
const isLoading = ref(false)
const sortAscending = ref(true)
const sortRowHighlight = ref('')
const selectedTracks = ref([])
const collectionSelector = ref({ options: [], collectionSelected: [] })
const exporterShow = ref(false)
Expand Down Expand Up @@ -980,12 +982,46 @@ function onDragStart($event, track) {
<table class="min-w-full table-auto" v-if="searchResultDisplayType === 'list'">
<thead class="text-left text-xs text-gray-600 dark:text-gray-400">
<tr class="border-b dark:border-black h-[44px] dark:h-[45px]">
<th class="px-2 py-2 dark:pt-2 w-5 pl-5">
Title
<th class="px-2 py-2 dark:pt-2 pl-5 cursor-pointer hover:text-npurple"
@click="() => {
sortAscending = !sortAscending
sortRowHighlight = 'title'
trackStore.sortTracksByMeta('title', sortAscending)
}"
>
<div class="flex flex-row p-1">
Title
<font-awesome-icon
v-if="sortRowHighlight === 'title'"
:icon="sortAscending ? 'arrow-down' : 'arrow-up'"
size="sm" class="p-1 pl-2"
/>
</div>
</th>
<th class="px-2 py-2 dark:pt-2"></th>
<template v-for="(row, rowindex) in searchResultTableRows.optionsSelected" :key="rowindex">
<th class="px-2 py-2 dark:pt-2">{{ row.name }}</th>
<th class="px-2 py-2 dark:pt-2 cursor-pointer hover:text-npurple"
@click="() => {
sortAscending = !sortAscending
sortRowHighlight = row.key
console.log('row', row)
if (row.type === 'meta') {
trackStore.sortTracksByMeta(row.name.toLowerCase(), sortAscending)
} else {
trackStore.sortTracksByPluginData(row.plugin, row.key, sortAscending)
}

}"
>
<div class="flex flex-row p-1">
{{ row.name }}
<font-awesome-icon
v-if="sortRowHighlight === row.key"
:icon="sortAscending ? 'arrow-down' : 'arrow-up'"
size="sm" class="m-1 ml-2"
/>
</div>
</th>
</template>
<th class="px-3 pl-1 py-1.5 dark:pt-1 text-right cursor-pointer hover:text-npurple whitespace-nowrap">
</th>
Expand Down
24 changes: 24 additions & 0 deletions src/stores/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ export const useTrackStore = defineStore({
}
},
actions: {
sortTracksByMeta: function (metaField, sortAscending) {
this.tracks.sort((a, b) => {
if (sortAscending) {
return a.meta[metaField] > b.meta[metaField]
} else {
return a.meta[metaField] < b.meta[metaField]
}
})
},
sortTracksByPluginData: function (pluginName, pluginDataKey, sortAscending) {
this.tracks.sort((a, b) => {
const value_a = a.plugin_data.find((pluginData) =>
pluginName === pluginData.plugin_name && pluginDataKey === pluginData.key
)
const value_b = b.plugin_data.find((pluginData) =>
pluginName === pluginData.plugin_name && pluginDataKey === pluginData.key
)
if (sortAscending) {
return value_a.value > value_b.value
} else {
return value_a.value < value_b.value
}
})
},
getSearchFilterParams: function () {
let searchFilterParams = {
search: filterStore.search,
Expand Down