This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js: added table sortable mixin; namespaces using it
So far the column sorting was possible but user wasn't able to share the state of it to someone through copying and pasting url. Now every sorting action the user makes on the namespaces table, for example, will create a new url state that can be visited and navigated back and forth. Fixes #1373
- Loading branch information
1 parent
06af252
commit 76909e9
Showing
10 changed files
with
214 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import Vue from 'vue'; | ||
|
||
import queryString from 'query-string'; | ||
|
||
const { set } = Vue; | ||
|
||
export default { | ||
props: { | ||
sortable: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
sortBy: { | ||
type: String, | ||
required: true, | ||
}, | ||
// Seems stupid to set it as String but I wanted | ||
// to have the type equal to the query string. | ||
// I can handle is the same way as the query string. | ||
sortAsc: { | ||
type: String, | ||
default: 'true', | ||
}, | ||
}, | ||
|
||
data() { | ||
return { | ||
sorting: { | ||
by: this.sortBy, | ||
asc: this.sortAsc, | ||
}, | ||
}; | ||
}, | ||
|
||
beforeMount() { | ||
if (!this.sortable) { | ||
return; | ||
} | ||
|
||
const queryObject = queryString.parse(window.location.search); | ||
const sortByQuery = queryObject[this.prefix + 'sort_by'] || this.sorting.by; | ||
const sortAscQuery = (queryObject[this.prefix + 'sort_asc'] || this.sorting.asc) === 'true'; | ||
|
||
set(this.sorting, 'by', sortByQuery); | ||
set(this.sorting, 'asc', sortAscQuery); | ||
}, | ||
|
||
methods: { | ||
sort(attribute) { | ||
if (!this.sortable) { | ||
return; | ||
} | ||
|
||
// if sort column has changed, go always asc | ||
// inverse current order otherwise | ||
if (this.sorting.by === attribute) { | ||
set(this.sorting, 'asc', !this.sorting.asc); | ||
} else { | ||
set(this.sorting, 'asc', true); | ||
} | ||
|
||
set(this.sorting, 'by', attribute); | ||
|
||
this.updateUrlState(); | ||
}, | ||
|
||
updateUrlState() { | ||
const queryObject = queryString.parse(window.location.search); | ||
|
||
queryObject[this.prefix + 'sort_asc'] = this.sorting.asc; | ||
queryObject[this.prefix + 'sort_by'] = this.sorting.by; | ||
|
||
const queryParams = queryString.stringify(queryObject); | ||
const url = [location.protocol, '//', location.host, location.pathname].join(''); | ||
history.pushState('', '', `${url}?${queryParams}`); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters