Web UI: Sync toolbar table state with url query params

This commit is contained in:
Matthieu Hostache 2019-11-20 19:02:05 +01:00 committed by Traefiker Bot
parent 433c848c8d
commit 2bcc1b7fb4

View file

@ -26,6 +26,8 @@
</template> </template>
<script> <script>
import Helps from '../../_helpers/Helps'
export default { export default {
name: 'ToolBarTable', name: 'ToolBarTable',
props: ['status', 'filter'], props: ['status', 'filter'],
@ -36,6 +38,9 @@ export default {
return { return {
} }
}, },
mounted () {
this.routeToState(this.$route)
},
computed: { computed: {
getStatus: { getStatus: {
get () { get () {
@ -43,6 +48,7 @@ export default {
}, },
set (newValue) { set (newValue) {
this.$emit('update:status', newValue) this.$emit('update:status', newValue)
this.stateToRoute(this.$route, { status: newValue })
} }
}, },
getFilter: { getFilter: {
@ -51,11 +57,30 @@ export default {
}, },
set (newValue) { set (newValue) {
this.$emit('update:filter', newValue) this.$emit('update:filter', newValue)
this.stateToRoute(this.$route, { filter: newValue })
} }
} }
}, },
watch: {
$route (to, from) {
this.routeToState(to)
}
},
methods: { methods: {
routeToState (route) {
for (const query in route.query) {
this.$emit(`update:${query}`, route.query[query])
}
},
stateToRoute (route, values) {
this.$router.push({
path: route.path,
query: Helps.removeEmptyObjects({
...route.query,
...values
})
})
}
}, },
created () { created () {