summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/DataTable.vue
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/src/components/DataTable.vue')
-rw-r--r--webapp/src/components/DataTable.vue41
1 files changed, 33 insertions, 8 deletions
diff --git a/webapp/src/components/DataTable.vue b/webapp/src/components/DataTable.vue
index 93eb674..94ee5a6 100644
--- a/webapp/src/components/DataTable.vue
+++ b/webapp/src/components/DataTable.vue
@@ -134,7 +134,7 @@
:class="{
'sortable-header': !noSort && header.text !== undefined,
'header-sorted': headerSortState[header.sortKey || header.key] !== undefined,
- 'header-sorted-desc': headerSortState[header.sortKey || header.key] === 'desc',
+ 'header-sorted-desc': (headerSortState[header.sortKey || header.key] || {}).direction === 'desc',
'auto-width': header.width === undefined
}"
>
@@ -300,9 +300,14 @@ export default {
const rows = this.rows.slice(0)
for (let key in this.headerSortState) {
if (!this.headers.some(header => header.sortKey || header.key === key)) continue
- const direction = this.headerSortState[key]
- if (direction === 'asc') rows.sort((a, b) => String(a.data[key]).localeCompare(String(b.data[key])))
- if (direction === 'desc') rows.sort((b, a) => String(a.data[key]).localeCompare(String(b.data[key])))
+ const direction = this.headerSortState[key].direction
+ const type = this.headerSortState[key].type
+ let compareFunction
+ if (type === 'number') compareFunction = (a, b) => (Number(a.data[key]) - Number(b.data[key]))
+ else if (type === 'ipv4') compareFunction = (a, b) => this.ipv4Compare(a.data[key], b.data[key])
+ else compareFunction = (a, b) => String(a.data[key]).localeCompare(String(b.data[key]))
+ rows.sort(compareFunction)
+ if (direction === 'desc') rows.reverse()
}
return Object.freeze(rows)
},
@@ -428,10 +433,10 @@ export default {
const key = header.sortKey || header.key
const state = this.headerSortState[key]
const newSortState = {}
- if (state === undefined || state === 'desc') {
- newSortState[key] = 'asc'
- } else if (state === 'asc') {
- newSortState[key] = 'desc'
+ if (state === undefined || state.direction === 'desc') {
+ newSortState[key] = { direction: 'asc', type: header.sortType }
+ } else {
+ newSortState[key] = { direction: 'desc', type: header.sortType }
}
this.headerSortState = newSortState
},
@@ -492,6 +497,26 @@ export default {
document.execCommand('copy')
copyHelper.style.display = 'none'
this.$snackbar({ text: this.$t('copyDone'), color: 'primary', timeout: 1200 })
+ },
+ ipv4Compare (a, b) {
+ if (!this.isValidIpv4(a)) return 1
+ if (!this.isValidIpv4(b)) return -1
+ a = a.split('.').map(x => parseInt(x))
+ b = b.split('.').map(x => parseInt(x))
+ for (let i in a) {
+ if (a[i] < b[i]) return -1
+ else if (a[i] > b[i]) return 1
+ }
+ return 0
+ },
+ isValidIpv4 (ip) {
+ if (!ip) return false
+ ip = ip.split('.')
+ if (ip.length !== 4) return false
+ for (let i in ip) {
+ if (ip[i] < 0 || ip[i] > 255) return false
+ }
+ return true
}
}
}