diff --git a/_assets/src/components/Listing.vue b/_assets/src/components/Listing.vue index d9cbd635..465cc1a5 100644 --- a/_assets/src/components/Listing.vue +++ b/_assets/src/components/Listing.vue @@ -8,14 +8,14 @@
Name - arrow_upward - arrow_downward +
+ Name + {{ nameIcon }}
-Size - arrow_upward - arrow_downward +
+ Size + {{ sizeIcon }}
Last modified
@@ -74,7 +74,29 @@ import api from '@/utils/api' export default { name: 'listing', components: { Item }, - computed: mapState(['req']), + computed: { + ...mapState(['req']), + nameSorted () { + return (this.req.sort === 'name') + }, + ascOrdered () { + return (this.req.order === 'asc') + }, + nameIcon () { + if (this.nameSorted && !this.ascOrdered) { + return 'arrow_upward' + } + + return 'arrow_downward' + }, + sizeIcon () { + if (!this.nameSorted && this.ascOrdered) { + return 'arrow_downward' + } + + return 'arrow_upward' + } + }, mounted: function () { document.addEventListener('dragover', function (event) { event.preventDefault() @@ -151,6 +173,23 @@ export default { }) return false + }, + sort (sort) { + let order = 'desc' + + if (sort === 'name') { + if (this.nameIcon === 'arrow_upward') { + order = 'asc' + } + } else { + if (this.sizeIcon === 'arrow_upward') { + order = 'asc' + } + } + + document.cookie = `sort=${sort}; max-age=31536000; path=${this.$store.state.baseURL}` + document.cookie = `order=${order}; max-age=31536000; path=${this.$store.state.baseURL}` + this.$store.commit('setReload', true) } } } diff --git a/api.go b/api.go index 11c7be3c..cadee412 100644 --- a/api.go +++ b/api.go @@ -268,7 +268,7 @@ func handleSortOrder(w http.ResponseWriter, r *http.Request, scope string) (sort if sortCookie, sortErr := r.Cookie("sort"); sortErr == nil { sort = sortCookie.Value } - case "name", "size", "type": + case "name", "size": http.SetCookie(w, &http.Cookie{ Name: "sort", Value: sort, diff --git a/file.go b/file.go index 6e6abccc..1e15f228 100644 --- a/file.go +++ b/file.go @@ -313,8 +313,6 @@ func (l listing) ApplySort() { sort.Sort(sort.Reverse(byName(l))) case "size": sort.Sort(sort.Reverse(bySize(l))) - case "time": - sort.Sort(sort.Reverse(byTime(l))) default: // If not one of the above, do nothing return @@ -325,8 +323,6 @@ func (l listing) ApplySort() { sort.Sort(byName(l)) case "size": sort.Sort(bySize(l)) - case "time": - sort.Sort(byTime(l)) default: sort.Sort(byName(l)) return @@ -337,7 +333,6 @@ func (l listing) ApplySort() { // Implement sorting for listing type byName listing type bySize listing -type byTime listing // By Name func (l byName) Len() int { @@ -382,17 +377,6 @@ func (l bySize) Less(i, j int) bool { return iSize < jSize } -// By Time -func (l byTime) Len() int { - return len(l.Items) -} -func (l byTime) Swap(i, j int) { - l.Items[i], l.Items[j] = l.Items[j], l.Items[i] -} -func (l byTime) Less(i, j int) bool { - return l.Items[i].ModTime.Before(l.Items[j].ModTime) -} - var textExtensions = [...]string{ ".md", ".markdown", ".mdown", ".mmark", ".asciidoc", ".adoc", ".ad",