@afeefa/vue-app 0.0.63 → 0.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,110 +0,0 @@
1
- <template>
2
- <component
3
- :is="Component"
4
- v-if="isLoaded"
5
- :models="models"
6
- :meta="meta"
7
- />
8
- </template>
9
-
10
- <script>
11
- import { Component, Vue, Watch } from '@a-vue'
12
- import { ListAction } from '@a-vue/api-resources/ApiActions'
13
- import { NextRouteFilterSource } from '@a-vue/components/list/NextRouteFilterSource'
14
- import { ListViewModel } from '@afeefa/api-resources-client'
15
-
16
- Component.registerHooks([
17
- 'beforeRouteEnter',
18
- 'beforeRouteUpdate'
19
- ])
20
-
21
- /**
22
- * keep track 'this' in beforeRouteEnter
23
- * in order to avoid rendering list pages with a stale set
24
- * of models because next(vm => ...) will first create the
25
- * list page with the existing set of models and update the
26
- * models afterwards.
27
- */
28
- let lastVm = null
29
-
30
- function load (route) {
31
- const routeDefinition = route.meta.routeDefinition
32
- const Component = routeDefinition.config.list
33
-
34
- if (!Component.getListRouteConfig) {
35
- console.warn('A list route component must implement a static getListRouteConfig property.')
36
- }
37
-
38
- const request = new ListViewModel(Component.getListRouteConfig(route))
39
- // read from next route query string, but do not push
40
- // list component will be init with used_filters
41
- .filterSource(new NextRouteFilterSource(route), false)
42
- // read from history, but do not push
43
- // list component will be init with used_filters
44
- .historyKey(route.path, false)
45
- .initFilters({
46
- source: true,
47
- history: true
48
- })
49
- .getApiRequest()
50
-
51
- return new ListAction()
52
- .setRequest(request)
53
- .load()
54
- }
55
-
56
- let routerHookCalled = false
57
-
58
- @Component
59
- export default class ListRoute extends Vue {
60
- models = null
61
- meta = null
62
- isLoaded = false
63
-
64
- async beforeRouteEnter (to, from, next) {
65
- routerHookCalled = true
66
- const result = await load(to)
67
-
68
- if (lastVm) {
69
- lastVm.isLoaded = false
70
- }
71
-
72
- next(vm => {
73
- if (result !== false) {
74
- const {models, meta} = result
75
- vm.models = models
76
- vm.meta = meta
77
- vm.isLoaded = true
78
- }
79
-
80
- lastVm = vm
81
- routerHookCalled = false
82
- })
83
- }
84
-
85
- /**
86
- * triggered both, if route name or route params change
87
- */
88
- @Watch('$route.params')
89
- async routeParamsChanged () {
90
- if (routerHookCalled) {
91
- return
92
- }
93
-
94
- if (!this.isLoaded) {
95
- const result = await load(this.$route)
96
-
97
- if (result !== false) {
98
- const {models, meta} = result
99
- this.models = models
100
- this.meta = meta
101
- this.isLoaded = true
102
- }
103
- }
104
- }
105
-
106
- get Component () {
107
- return this.$routeDefinition.config.list
108
- }
109
- }
110
- </script>