Implements optional alphabetical sort for sections

This commit is contained in:
Alicia Sykes 2021-09-04 23:07:50 +01:00
parent a66636bde8
commit 48533f397a
2 changed files with 16 additions and 1 deletions

View File

@ -17,7 +17,7 @@
:style="gridStyle" :style="gridStyle"
> >
<Item <Item
v-for="(item, index) in items" v-for="(item, index) in sortedItems"
:id="`${index}_${makeId(item.title)}`" :id="`${index}_${makeId(item.title)}`"
:key="`${index}_${makeId(item.title)}`" :key="`${index}_${makeId(item.title)}`"
:url="item.url" :url="item.url"
@ -49,6 +49,7 @@
</template> </template>
<script> <script>
import { sortOrder as defaultSortOrder } from '@/utils/defaults';
import Item from '@/components/LinkItems/Item.vue'; import Item from '@/components/LinkItems/Item.vue';
import Collapsable from '@/components/LinkItems/Collapsable.vue'; import Collapsable from '@/components/LinkItems/Collapsable.vue';
import IframeModal from '@/components/LinkItems/IframeModal.vue'; import IframeModal from '@/components/LinkItems/IframeModal.vue';
@ -71,6 +72,18 @@ export default {
IframeModal, IframeModal,
}, },
computed: { computed: {
sortOrder() {
return this.displayData.sortBy || defaultSortOrder;
},
sortedItems() {
const { items } = this;
if (this.sortOrder === 'alphabetical') {
items.sort((a, b) => (a.title > b.title ? 1 : -1));
} else if (this.sortOrder === 'reverse-alphabetical') {
items.sort((a, b) => (a.title < b.title ? 1 : -1));
}
return items;
},
newItemSize() { newItemSize() {
return this.displayData.itemSize || this.itemSize; return this.displayData.itemSize || this.itemSize;
}, },

View File

@ -25,6 +25,8 @@ module.exports = {
fontAwesomeKey: '0821c65656', fontAwesomeKey: '0821c65656',
/* Default API to use for fetching of user service favicon icons (if enabled) */ /* Default API to use for fetching of user service favicon icons (if enabled) */
faviconApi: 'faviconkit', faviconApi: 'faviconkit',
/* The default sort order for sections */
sortOrder: 'auto',
/* The page paths for each route within the app for the router */ /* The page paths for each route within the app for the router */
routePaths: { routePaths: {
home: '/home', home: '/home',