Skip to content

Commit

Permalink
Merge pull request #16 from outl1ne/feature/1
Browse files Browse the repository at this point in the history
MediaHub sorting and filtering features
  • Loading branch information
KasparRosin authored Sep 21, 2022
2 parents ea8f415 + 11d2ad1 commit a6fb2dd
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 63 deletions.
2 changes: 1 addition & 1 deletion dist/css/entry.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/entry.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"novaMediaHub.contextDeselect": "Deselect",
"novaMediaHub.contextDeselectOthers": "Deselect others",
"novaMediaHub.contextOpenCollection": "Open collection",
"novaMediaHub.existingMediaDetected": "Some media items were already found on the server and were not (re)uploaded. However, they were moved to the start of the collection to make them easier to find."
"novaMediaHub.existingMediaDetected": "Some media items were already found on the server and were not (re)uploaded. However, they were moved to the start of the collection to make them easier to find.",
"novaMediaHub.searchMediaTitle": "Search by name",
"novaMediaHub.orderBy.updated_at": "Updated at",
"novaMediaHub.orderBy.created_at": "Created at"
}
6 changes: 2 additions & 4 deletions resources/js/api.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const PREFIX = '/nova-vendor/media-hub';

export default {
async getMedia(collection, page) {
return Nova.request().get(`${PREFIX}/media`, {
params: { collection, page },
});
async getMedia(params) {
return Nova.request().get(`${PREFIX}/media`, { params });
},

async getCollections() {
Expand Down
17 changes: 17 additions & 0 deletions resources/js/components/MediaOrderSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<SelectControl v-bind="$attrs">
<option value="">{{ '> Show all' }}</option>
<template v-for="column in columns" :key="column">
<option v-for="direction in ['asc', 'desc']" :key="`${column}:${direction}`" :value="`${column}:${direction}`">
<span class="o1-ml-auto">{{ direction === 'asc' ? '&uarr;' : '&darr;' }}</span>
{{ __(`novaMediaHub.orderBy.${column}`) }}
</option>
</template>
</SelectControl>
</template>

<script>
export default {
props: ['columns'],
};
</script>
14 changes: 14 additions & 0 deletions resources/js/components/ModalFilterItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div class="o1-flex o1-flex-col o1-w-full">
<div class="o1-leading-tight o1-text-teal-500 o1-font-bold o1-text-md o1-mb-2">
{{ title }}
</div>
<slot />
</div>
</template>

<script>
export default {
props: ['title'],
};
</script>
30 changes: 20 additions & 10 deletions resources/js/mixins/HandlesMediaLists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import API from '../api';

export default {
data: () => ({
collection: void 0,
collection: undefined,
search: undefined,
orderBy: undefined,

collections: [],
mediaItems: [],
orderColumns: ['updated_at', 'created_at'],

currentPage: 1,
mediaResponse: {},
Expand All @@ -15,17 +18,24 @@ export default {
}),

methods: {
async getMedia(collection = void 0, pageNr = void 0) {
async getMedia({
collection = this.collection,
search = this.search,
orderBy = this.orderBy,
orderDirection = this.orderDirection,
page = this.currentPage,
} = {}) {
this.loadingMedia = true;

if (!collection) collection = this.collection;
if (!pageNr) pageNr = this.currentPage;

const { data } = await API.getMedia(collection, pageNr);
this.mediaResponse = data;
this.mediaItems = data.data || [];

this.loadingMedia = false;
await API.getMedia({ collection, page, search, orderBy, orderDirection })
.then(({ data: res }) => {
this.mediaResponse = res;
this.mediaItems = res.data || [];
if (this.currentPage !== page) this.currentPage = page;
})
.finally(() => {
this.loadingMedia = false;
});
},

async getCollections() {
Expand Down
Loading

0 comments on commit a6fb2dd

Please sign in to comment.