Sort working
Former-commit-id: 82fb8c7c1e2fe754e7da9a26a800a7814e562033 [formerly 4bca5432790eef9a06bda1a3779b060c0ee8717c] [formerly 2dd333885a261827f95692a8d68dfdf81f81a303 [formerly ce6557997a
]]
Former-commit-id: cfbf8f1a49e5cde20ec71edd1d61389bd1f820c6 [formerly 94762c33a82b2b1a8fbd1c1969dc8d0f4dfce1d5]
Former-commit-id: 623a70bda4ea4b7a821ca756234addcb97dfb1c3
pull/726/head
parent
869cd562e7
commit
c3b882aee5
|
@ -8,14 +8,14 @@
|
||||||
<div class="item header">
|
<div class="item header">
|
||||||
<div></div>
|
<div></div>
|
||||||
<div>
|
<div>
|
||||||
<p v-bind:class="{ active: req.sort === 'name' }" class="name"><span>Name</span>
|
<p :class="{ active: nameSorted }" class="name" @click="sort('name')">
|
||||||
<a v-if="req.sort === 'name' && req.order != 'asc'" href="?sort=name&order=asc"><i class="material-icons">arrow_upward</i></a>
|
<span>Name</span>
|
||||||
<a v-else href="?sort=name&order=desc"><i class="material-icons">arrow_downward</i></a>
|
<i class="material-icons">{{ nameIcon }}</i>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p v-bind:class="{ active: req.sort === 'size' }" class="size"><span>Size</span>
|
<p :class="{ active: !nameSorted }" class="size" @click="sort('size')">
|
||||||
<a v-if="req.sort === 'size' && req.order != 'asc'" href="?sort=size&order=asc"><i class="material-icons">arrow_upward</i></a>
|
<span>Size</span>
|
||||||
<a v-else href="?sort=size&order=desc"><i class="material-icons">arrow_downward</i></a>
|
<i class="material-icons">{{ sizeIcon }}</i>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="modified">Last modified</p>
|
<p class="modified">Last modified</p>
|
||||||
|
@ -74,7 +74,29 @@ import api from '@/utils/api'
|
||||||
export default {
|
export default {
|
||||||
name: 'listing',
|
name: 'listing',
|
||||||
components: { Item },
|
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 () {
|
mounted: function () {
|
||||||
document.addEventListener('dragover', function (event) {
|
document.addEventListener('dragover', function (event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
@ -151,6 +173,23 @@ export default {
|
||||||
})
|
})
|
||||||
|
|
||||||
return false
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
api.go
2
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 {
|
if sortCookie, sortErr := r.Cookie("sort"); sortErr == nil {
|
||||||
sort = sortCookie.Value
|
sort = sortCookie.Value
|
||||||
}
|
}
|
||||||
case "name", "size", "type":
|
case "name", "size":
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "sort",
|
Name: "sort",
|
||||||
Value: sort,
|
Value: sort,
|
||||||
|
|
16
file.go
16
file.go
|
@ -313,8 +313,6 @@ func (l listing) ApplySort() {
|
||||||
sort.Sort(sort.Reverse(byName(l)))
|
sort.Sort(sort.Reverse(byName(l)))
|
||||||
case "size":
|
case "size":
|
||||||
sort.Sort(sort.Reverse(bySize(l)))
|
sort.Sort(sort.Reverse(bySize(l)))
|
||||||
case "time":
|
|
||||||
sort.Sort(sort.Reverse(byTime(l)))
|
|
||||||
default:
|
default:
|
||||||
// If not one of the above, do nothing
|
// If not one of the above, do nothing
|
||||||
return
|
return
|
||||||
|
@ -325,8 +323,6 @@ func (l listing) ApplySort() {
|
||||||
sort.Sort(byName(l))
|
sort.Sort(byName(l))
|
||||||
case "size":
|
case "size":
|
||||||
sort.Sort(bySize(l))
|
sort.Sort(bySize(l))
|
||||||
case "time":
|
|
||||||
sort.Sort(byTime(l))
|
|
||||||
default:
|
default:
|
||||||
sort.Sort(byName(l))
|
sort.Sort(byName(l))
|
||||||
return
|
return
|
||||||
|
@ -337,7 +333,6 @@ func (l listing) ApplySort() {
|
||||||
// Implement sorting for listing
|
// Implement sorting for listing
|
||||||
type byName listing
|
type byName listing
|
||||||
type bySize listing
|
type bySize listing
|
||||||
type byTime listing
|
|
||||||
|
|
||||||
// By Name
|
// By Name
|
||||||
func (l byName) Len() int {
|
func (l byName) Len() int {
|
||||||
|
@ -382,17 +377,6 @@ func (l bySize) Less(i, j int) bool {
|
||||||
return iSize < jSize
|
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{
|
var textExtensions = [...]string{
|
||||||
".md", ".markdown", ".mdown", ".mmark",
|
".md", ".markdown", ".mdown", ".mmark",
|
||||||
".asciidoc", ".adoc", ".ad",
|
".asciidoc", ".adoc", ".ad",
|
||||||
|
|
Loading…
Reference in New Issue