@xy-planning-network/trees 0.3.4 → 0.4.0-rc
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.
- package/dist/style.css +1 -0
- package/dist/trees.es.js +8399 -0
- package/dist/trees.umd.js +10 -0
- package/dist/types/api/base.d.ts +12 -0
- package/dist/types/entry.d.ts +8 -0
- package/dist/types/helpers/Uniques.d.ts +4 -0
- package/dist/types/lib-components/forms/BaseInput.vue.d.ts +38 -0
- package/dist/types/lib-components/forms/Checkbox.vue.d.ts +22 -0
- package/dist/types/lib-components/forms/DateRangePicker.vue.d.ts +45 -0
- package/dist/types/lib-components/forms/InputHelp.vue.d.ts +22 -0
- package/dist/types/lib-components/forms/InputLabel.vue.d.ts +22 -0
- package/dist/types/lib-components/forms/MultiCheckboxes.vue.d.ts +34 -0
- package/dist/types/lib-components/forms/Radio.vue.d.ts +44 -0
- package/dist/types/lib-components/forms/Select.vue.d.ts +58 -0
- package/dist/types/lib-components/forms/TextArea.vue.d.ts +32 -0
- package/dist/types/lib-components/forms/Toggle.vue.d.ts +17 -0
- package/dist/types/lib-components/forms/YesOrNoRadio.vue.d.ts +33 -0
- package/dist/types/lib-components/index.d.ts +28 -0
- package/dist/types/lib-components/layout/DateFilter.vue.d.ts +34 -0
- package/dist/types/lib-components/layout/SidebarLayout.vue.d.ts +33 -0
- package/dist/types/lib-components/layout/StackedLayout.vue.d.ts +40 -0
- package/dist/types/lib-components/lists/Cards.vue.d.ts +23 -0
- package/dist/types/lib-components/lists/DetailList.vue.d.ts +34 -0
- package/dist/types/lib-components/lists/DownloadCell.vue.d.ts +20 -0
- package/dist/types/lib-components/lists/StaticTable.vue.d.ts +18 -0
- package/dist/types/lib-components/lists/Table.vue.d.ts +29 -0
- package/dist/types/lib-components/navigation/ActionsDropdown.vue.d.ts +26 -0
- package/dist/types/lib-components/navigation/Paginator.vue.d.ts +27 -0
- package/dist/types/lib-components/navigation/Steps.vue.d.ts +53 -0
- package/dist/types/lib-components/navigation/Tabs.vue.d.ts +36 -0
- package/dist/types/lib-components/overlays/ContentModal.vue.d.ts +24 -0
- package/dist/types/lib-components/overlays/Flash.vue.d.ts +6 -0
- package/dist/types/lib-components/overlays/Modal.vue.d.ts +51 -0
- package/dist/types/lib-components/overlays/Slideover.vue.d.ts +30 -0
- package/dist/types/lib-components/overlays/Spinner.vue.d.ts +2 -0
- package/dist/types/types/nav.d.ts +7 -0
- package/dist/types/types/table.d.ts +32 -0
- package/dist/types/types/users.d.ts +9 -0
- package/package.json +47 -66
- package/src/lib-components/forms/BaseInput.vue +51 -45
- package/src/lib-components/forms/Checkbox.vue +31 -22
- package/src/lib-components/forms/DateRangePicker.vue +56 -56
- package/src/lib-components/forms/InputHelp.vue +12 -9
- package/src/lib-components/forms/InputLabel.vue +12 -9
- package/src/lib-components/forms/MultiCheckboxes.vue +48 -44
- package/src/lib-components/forms/Radio.vue +34 -24
- package/src/lib-components/forms/Select.vue +40 -46
- package/src/lib-components/forms/TextArea.vue +23 -17
- package/src/lib-components/forms/Toggle.vue +7 -11
- package/src/lib-components/forms/YesOrNoRadio.vue +31 -27
- package/src/lib-components/layout/DateFilter.vue +31 -30
- package/src/lib-components/layout/SidebarLayout.vue +36 -51
- package/src/lib-components/layout/StackedLayout.vue +32 -55
- package/src/lib-components/lists/Cards.vue +8 -12
- package/src/lib-components/lists/DetailList.vue +83 -83
- package/src/lib-components/lists/DownloadCell.vue +8 -12
- package/src/lib-components/lists/StaticTable.vue +30 -23
- package/src/lib-components/lists/Table.vue +146 -122
- package/src/lib-components/navigation/ActionsDropdown.vue +39 -43
- package/src/lib-components/navigation/Paginator.vue +65 -80
- package/src/lib-components/navigation/Steps.vue +38 -27
- package/src/lib-components/navigation/Tabs.vue +64 -60
- package/src/lib-components/overlays/ContentModal.vue +27 -31
- package/src/lib-components/overlays/Flash.vue +85 -70
- package/src/lib-components/overlays/Modal.vue +39 -42
- package/src/lib-components/overlays/Slideover.vue +30 -35
- package/src/lib-components/overlays/Spinner.vue +51 -51
- package/src/types/env.d.ts +18 -0
- package/src/types/global.d.ts +10 -0
- package/dist/trees.esm.js +0 -10994
- package/dist/trees.min.js +0 -7
- package/dist/trees.ssr.js +0 -11669
- package/trees.d.ts +0 -43
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import Flash from "../overlays/Flash.vue"
|
|
3
|
+
import Spinner from "../overlays/Spinner.vue"
|
|
4
|
+
import {
|
|
5
|
+
Disclosure,
|
|
6
|
+
DisclosureButton,
|
|
7
|
+
DisclosurePanel,
|
|
8
|
+
Menu,
|
|
9
|
+
MenuButton,
|
|
10
|
+
MenuItem,
|
|
11
|
+
MenuItems,
|
|
12
|
+
} from "@headlessui/vue"
|
|
13
|
+
import { MenuIcon, UserCircleIcon, XIcon } from "@heroicons/vue/outline"
|
|
14
|
+
import * as NavTypes from "../../types/nav"
|
|
15
|
+
import User from "../../types/users"
|
|
16
|
+
|
|
17
|
+
const props = withDefaults(
|
|
18
|
+
defineProps<{
|
|
19
|
+
activeURL?: string
|
|
20
|
+
currentUser: User
|
|
21
|
+
iconURL: string
|
|
22
|
+
navigation: NavTypes.Item[]
|
|
23
|
+
userNavigation: NavTypes.Item[]
|
|
24
|
+
}>(),
|
|
25
|
+
{
|
|
26
|
+
activeURL: "",
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
const isActive = (url: string): boolean => {
|
|
30
|
+
return props.activeURL === url
|
|
31
|
+
}
|
|
32
|
+
</script>
|
|
1
33
|
<template>
|
|
2
34
|
<div class="min-h-screen bg-gray-100">
|
|
3
35
|
<Disclosure as="nav" class="bg-white shadow-sm" v-slot="{ open }">
|
|
@@ -137,58 +169,3 @@
|
|
|
137
169
|
<Flash />
|
|
138
170
|
<Spinner />
|
|
139
171
|
</template>
|
|
140
|
-
|
|
141
|
-
<script lang="ts">
|
|
142
|
-
import { Options, Prop, Vue } from "vue-property-decorator";
|
|
143
|
-
import Flash from "../overlays/Flash.vue";
|
|
144
|
-
import Spinner from "../overlays/Spinner.vue";
|
|
145
|
-
import {
|
|
146
|
-
Disclosure,
|
|
147
|
-
DisclosureButton,
|
|
148
|
-
DisclosurePanel,
|
|
149
|
-
Menu,
|
|
150
|
-
MenuButton,
|
|
151
|
-
MenuItem,
|
|
152
|
-
MenuItems,
|
|
153
|
-
} from "@headlessui/vue";
|
|
154
|
-
import {
|
|
155
|
-
BellIcon,
|
|
156
|
-
MenuIcon,
|
|
157
|
-
UserCircleIcon,
|
|
158
|
-
XIcon,
|
|
159
|
-
} from "@heroicons/vue/outline";
|
|
160
|
-
import NavTypes from "../../types/nav";
|
|
161
|
-
import UserTypes from "../../types/users";
|
|
162
|
-
|
|
163
|
-
@Options({
|
|
164
|
-
components: {
|
|
165
|
-
Flash,
|
|
166
|
-
Spinner,
|
|
167
|
-
Disclosure,
|
|
168
|
-
DisclosureButton,
|
|
169
|
-
DisclosurePanel,
|
|
170
|
-
Menu,
|
|
171
|
-
MenuButton,
|
|
172
|
-
MenuItem,
|
|
173
|
-
MenuItems,
|
|
174
|
-
BellIcon,
|
|
175
|
-
MenuIcon,
|
|
176
|
-
UserCircleIcon,
|
|
177
|
-
XIcon,
|
|
178
|
-
},
|
|
179
|
-
name: "StackedLayout",
|
|
180
|
-
})
|
|
181
|
-
export default class StackedLayout extends Vue {
|
|
182
|
-
@Prop({ type: String, required: false }) activeURL?: string;
|
|
183
|
-
@Prop({ type: Object, required: true }) currentUser!: UserTypes.User;
|
|
184
|
-
@Prop({ type: String, required: true }) iconURL!: string;
|
|
185
|
-
@Prop({ type: Array, required: true }) navigation!: NavTypes.Item[];
|
|
186
|
-
@Prop({ type: Array, required: true }) userNavigation!: NavTypes.Item[];
|
|
187
|
-
|
|
188
|
-
sidebarOpen = false;
|
|
189
|
-
|
|
190
|
-
isActive(url: string): boolean {
|
|
191
|
-
return this.activeURL === url;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
</script>
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{
|
|
3
|
+
cards: {
|
|
4
|
+
primary: string
|
|
5
|
+
secondary: string
|
|
6
|
+
}[]
|
|
7
|
+
}>()
|
|
8
|
+
</script>
|
|
1
9
|
<template>
|
|
2
10
|
<div
|
|
3
11
|
class="mt-5 grid grid-cols-1 gap-5"
|
|
@@ -23,15 +31,3 @@
|
|
|
23
31
|
</div>
|
|
24
32
|
</div>
|
|
25
33
|
</template>
|
|
26
|
-
|
|
27
|
-
<script lang="ts">
|
|
28
|
-
import { Options, Prop, Vue } from "vue-property-decorator";
|
|
29
|
-
|
|
30
|
-
@Options({ name: "Cards" })
|
|
31
|
-
export default class Cards extends Vue {
|
|
32
|
-
@Prop({ type: Array, required: true }) cards!: {
|
|
33
|
-
primary: string;
|
|
34
|
-
secondary: string;
|
|
35
|
-
}[];
|
|
36
|
-
}
|
|
37
|
-
</script>
|
|
@@ -1,3 +1,86 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch } from "vue"
|
|
3
|
+
import BaseAPI from "../../api/base"
|
|
4
|
+
import DateFilter from "../layout/DateFilter.vue"
|
|
5
|
+
import Paginator from "../navigation/Paginator.vue"
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(
|
|
8
|
+
defineProps<{
|
|
9
|
+
refreshTrigger?: number
|
|
10
|
+
reloadTrigger?: number
|
|
11
|
+
title: string
|
|
12
|
+
url: string
|
|
13
|
+
}>(),
|
|
14
|
+
{
|
|
15
|
+
refreshTrigger: 0,
|
|
16
|
+
reloadTrigger: 0,
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const dateRange = ref<{ minDate: number; maxDate: number }>({
|
|
21
|
+
minDate: 0,
|
|
22
|
+
maxDate: 0,
|
|
23
|
+
})
|
|
24
|
+
const hasContent = ref(true)
|
|
25
|
+
const items = ref<any[]>([])
|
|
26
|
+
const pagination = ref({
|
|
27
|
+
page: 1,
|
|
28
|
+
perPage: 10,
|
|
29
|
+
totalItems: 0,
|
|
30
|
+
totalPages: 0,
|
|
31
|
+
})
|
|
32
|
+
const sortDir = ref("DESC")
|
|
33
|
+
|
|
34
|
+
const loadAndRender = (checkForContent: boolean): void => {
|
|
35
|
+
const params = {
|
|
36
|
+
page: pagination.value.page,
|
|
37
|
+
perPage: pagination.value.perPage,
|
|
38
|
+
sortDir: sortDir.value,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
BaseAPI.get(props.url, {}, Object.assign(params, dateRange.value)).then(
|
|
42
|
+
(success: any) => {
|
|
43
|
+
pagination.value = {
|
|
44
|
+
page: success.data.page,
|
|
45
|
+
perPage: success.data.perPage,
|
|
46
|
+
totalItems: success.data.totalItems,
|
|
47
|
+
totalPages: success.data.totalPages,
|
|
48
|
+
}
|
|
49
|
+
items.value = success.data.items
|
|
50
|
+
if (checkForContent) hasContent.value = items.value.length != 0
|
|
51
|
+
},
|
|
52
|
+
() => {
|
|
53
|
+
// TODO: let's make this really generic or configurable
|
|
54
|
+
window.VueBus.emit(
|
|
55
|
+
"Flash-show-generic-error",
|
|
56
|
+
"archive@xyplanningnetwork.com"
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
watch([sortDir, dateRange], () => {
|
|
63
|
+
loadAndRender(false)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
watch(
|
|
67
|
+
() => props.refreshTrigger,
|
|
68
|
+
() => {
|
|
69
|
+
loadAndRender(false)
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
watch(
|
|
74
|
+
() => props.reloadTrigger,
|
|
75
|
+
() => {
|
|
76
|
+
// This lets parent components trigger a refresh of the current page depending on external actions.
|
|
77
|
+
pagination.value.page = 1
|
|
78
|
+
loadAndRender(true)
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
loadAndRender(true)
|
|
83
|
+
</script>
|
|
1
84
|
<template>
|
|
2
85
|
<div>
|
|
3
86
|
<DateFilter
|
|
@@ -29,86 +112,3 @@
|
|
|
29
112
|
/>
|
|
30
113
|
</div>
|
|
31
114
|
</template>
|
|
32
|
-
|
|
33
|
-
<script lang="ts">
|
|
34
|
-
import { Options, Prop, Vue, Watch } from "vue-property-decorator";
|
|
35
|
-
import BaseAPI from "../../api/base";
|
|
36
|
-
import DateFilter from "../layout/DateFilter.vue";
|
|
37
|
-
import Paginator from "../navigation/Paginator.vue";
|
|
38
|
-
|
|
39
|
-
@Options({ components: { DateFilter, Paginator }, name: "DetailList" })
|
|
40
|
-
export default class DetailList extends Vue {
|
|
41
|
-
@Prop({ type: Number, required: false }) refreshTrigger?: number;
|
|
42
|
-
@Prop({ type: Number, required: false }) reloadTrigger?: number;
|
|
43
|
-
@Prop({ type: String, required: true }) title!: string;
|
|
44
|
-
@Prop({ type: String, required: true }) url!: string;
|
|
45
|
-
|
|
46
|
-
@Watch("sortDir")
|
|
47
|
-
onSortDir(): void {
|
|
48
|
-
this.loadAndRender(false);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@Watch("dateRange")
|
|
52
|
-
onDateRange(): void {
|
|
53
|
-
this.loadAndRender(false);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@Watch("refreshTrigger")
|
|
57
|
-
onRefreshTrigger(): void {
|
|
58
|
-
// This lets parent components trigger a refresh of the current page depending on external actions.
|
|
59
|
-
this.loadAndRender(false);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@Watch("reloadTrigger")
|
|
63
|
-
onReloadTrigger(): void {
|
|
64
|
-
// This lets parent components trigger a refresh of the current page depending on external actions.
|
|
65
|
-
this.pagination.page = 1;
|
|
66
|
-
this.loadAndRender(true);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
dateRange: { minDate: number; maxDate: number } = {
|
|
70
|
-
minDate: 0,
|
|
71
|
-
maxDate: 0,
|
|
72
|
-
};
|
|
73
|
-
hasContent = true;
|
|
74
|
-
items: any[] = [];
|
|
75
|
-
pagination = {
|
|
76
|
-
page: 1,
|
|
77
|
-
perPage: 10,
|
|
78
|
-
totalItems: 0,
|
|
79
|
-
totalPages: 0,
|
|
80
|
-
};
|
|
81
|
-
sortDir = "DESC";
|
|
82
|
-
|
|
83
|
-
created() {
|
|
84
|
-
this.loadAndRender(true);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
loadAndRender(checkForContent: boolean): void {
|
|
88
|
-
const params = {
|
|
89
|
-
page: this.pagination.page,
|
|
90
|
-
perPage: this.pagination.perPage,
|
|
91
|
-
sortDir: this.sortDir,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
BaseAPI.get(this.url, {}, Object.assign(params, this.dateRange)).then(
|
|
95
|
-
(success: any) => {
|
|
96
|
-
this.pagination = {
|
|
97
|
-
page: success.data.page,
|
|
98
|
-
perPage: success.data.perPage,
|
|
99
|
-
totalItems: success.data.totalItems,
|
|
100
|
-
totalPages: success.data.totalPages,
|
|
101
|
-
};
|
|
102
|
-
this.items = success.data.items;
|
|
103
|
-
if (checkForContent) this.hasContent = this.items.length != 0;
|
|
104
|
-
},
|
|
105
|
-
() => {
|
|
106
|
-
window.VueBus.emit(
|
|
107
|
-
"Flash-show-generic-error",
|
|
108
|
-
"archive@xyplanningnetwork.com"
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
</script>
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { DownloadIcon } from "@heroicons/vue/solid"
|
|
3
|
+
defineProps<{
|
|
4
|
+
propsData: Record<string, unknown>
|
|
5
|
+
attribute: string
|
|
6
|
+
}>()
|
|
7
|
+
</script>
|
|
1
8
|
<template>
|
|
2
|
-
<a :href="propsData[attribute]">
|
|
9
|
+
<a :href="propsData[attribute] as string">
|
|
3
10
|
<DownloadIcon class="h-6 w-6 group-hover:text-gray-500 transition" />
|
|
4
11
|
</a>
|
|
5
12
|
</template>
|
|
6
|
-
|
|
7
|
-
<script lang="ts">
|
|
8
|
-
import { Options, Prop, Vue } from "vue-property-decorator";
|
|
9
|
-
import { DownloadIcon } from "@heroicons/vue/solid";
|
|
10
|
-
|
|
11
|
-
@Options({ name: "DownloadCell", components: { DownloadIcon } })
|
|
12
|
-
export default class DownloadCell extends Vue {
|
|
13
|
-
@Prop({ type: Object, required: true }) propsData!: Record<string, unknown>;
|
|
14
|
-
@Prop({ type: String, required: true }) attribute!: string;
|
|
15
|
-
}
|
|
16
|
-
</script>
|
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ComponentPublicInstance, getCurrentInstance } from "vue"
|
|
3
|
+
import * as TableTypes from "../../types/table"
|
|
4
|
+
|
|
5
|
+
defineProps<{
|
|
6
|
+
tableData: TableTypes.Static
|
|
7
|
+
}>()
|
|
8
|
+
|
|
9
|
+
const cellValue = (
|
|
10
|
+
item: Record<string, any>,
|
|
11
|
+
col: TableTypes.Column
|
|
12
|
+
): string => {
|
|
13
|
+
if (col.key) {
|
|
14
|
+
return item[col.key]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (col.presenter) {
|
|
18
|
+
// TODO: discuss this pattern. Current usage can be replaced with modules.
|
|
19
|
+
// https://v3.vuejs.org/api/composition-api.html#getcurrentinstance
|
|
20
|
+
const internalInstance = getCurrentInstance()
|
|
21
|
+
return col.presenter(
|
|
22
|
+
item,
|
|
23
|
+
internalInstance?.proxy as ComponentPublicInstance
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return ""
|
|
28
|
+
}
|
|
29
|
+
</script>
|
|
1
30
|
<template>
|
|
2
31
|
<div class="flex flex-col">
|
|
3
32
|
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
|
@@ -19,7 +48,7 @@
|
|
|
19
48
|
<tbody class="bg-white divide-y divide-gray-200">
|
|
20
49
|
<tr
|
|
21
50
|
v-for="(item, rowIdx) in tableData.items"
|
|
22
|
-
:key="item.id ? item.id : rowIdx"
|
|
51
|
+
:key="item.id ? (item.id as string) : rowIdx"
|
|
23
52
|
>
|
|
24
53
|
<td
|
|
25
54
|
class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap leading-5"
|
|
@@ -52,25 +81,3 @@
|
|
|
52
81
|
</div>
|
|
53
82
|
</div>
|
|
54
83
|
</template>
|
|
55
|
-
|
|
56
|
-
<script lang="ts">
|
|
57
|
-
import { Options, Prop, Vue } from "vue-property-decorator";
|
|
58
|
-
import TableTypes from "../../types/table";
|
|
59
|
-
|
|
60
|
-
@Options({ name: "StaticTable" })
|
|
61
|
-
export default class StaticTable extends Vue {
|
|
62
|
-
@Prop({ type: Object, required: true }) tableData!: TableTypes.Static;
|
|
63
|
-
|
|
64
|
-
cellValue(item: Record<string, any>, col: TableTypes.Column): string {
|
|
65
|
-
if (col.key) {
|
|
66
|
-
return item[col.key];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (col.presenter) {
|
|
70
|
-
return col.presenter(item, this);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return "";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
</script>
|
|
@@ -1,3 +1,147 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { AxiosResponse } from "axios"
|
|
3
|
+
import {
|
|
4
|
+
ComponentPublicInstance,
|
|
5
|
+
computed,
|
|
6
|
+
getCurrentInstance,
|
|
7
|
+
ref,
|
|
8
|
+
watch,
|
|
9
|
+
} from "vue"
|
|
10
|
+
import DateRangePicker from "../forms/DateRangePicker.vue"
|
|
11
|
+
import Paginator from "../navigation/Paginator.vue"
|
|
12
|
+
import BaseAPI from "../../api/base"
|
|
13
|
+
import * as TableTypes from "../../types/table"
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(
|
|
16
|
+
defineProps<{
|
|
17
|
+
clickable?: boolean
|
|
18
|
+
loader?: boolean
|
|
19
|
+
tableData: TableTypes.Dynamic
|
|
20
|
+
}>(),
|
|
21
|
+
{
|
|
22
|
+
clickable: false,
|
|
23
|
+
loader: true,
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const currentSort = ref(
|
|
28
|
+
props.tableData.defaultSort ? props.tableData.defaultSort : ""
|
|
29
|
+
)
|
|
30
|
+
const currentSortDirection = ref(
|
|
31
|
+
props.tableData.defaultSortDirection
|
|
32
|
+
? props.tableData.defaultSortDirection
|
|
33
|
+
: "desc"
|
|
34
|
+
)
|
|
35
|
+
const dateRange = ref({
|
|
36
|
+
minDate: 0,
|
|
37
|
+
maxDate: 0,
|
|
38
|
+
})
|
|
39
|
+
const items = ref<any[]>([])
|
|
40
|
+
const pagination = ref({
|
|
41
|
+
page: 1,
|
|
42
|
+
perPage: 10,
|
|
43
|
+
totalItems: 0,
|
|
44
|
+
totalPages: 0,
|
|
45
|
+
})
|
|
46
|
+
const query = ref("")
|
|
47
|
+
const cellValue = (
|
|
48
|
+
item: Record<string, any>,
|
|
49
|
+
col: TableTypes.Column
|
|
50
|
+
): string => {
|
|
51
|
+
if (col.key) {
|
|
52
|
+
// NOTE(dlk): supports dot notation for nested keys
|
|
53
|
+
return col.key.split(".").reduce((o, i) => o[i], item as any)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (col.presenter) {
|
|
57
|
+
// TODO: discuss this pattern. Current usage can be replaced with modules.
|
|
58
|
+
// https://v3.vuejs.org/api/composition-api.html#getcurrentinstance
|
|
59
|
+
const internalInstance = getCurrentInstance()
|
|
60
|
+
return col.presenter(
|
|
61
|
+
item,
|
|
62
|
+
internalInstance?.proxy as ComponentPublicInstance
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return ""
|
|
67
|
+
}
|
|
68
|
+
const dateRangeChanged = (newDateRange: {
|
|
69
|
+
minDate: number
|
|
70
|
+
maxDate: number
|
|
71
|
+
}): void => {
|
|
72
|
+
pagination.value.page = 1
|
|
73
|
+
dateRange.value = newDateRange
|
|
74
|
+
loadAndRender()
|
|
75
|
+
}
|
|
76
|
+
const handleSort = (selectedSort: string): void => {
|
|
77
|
+
if (currentSort.value == selectedSort) {
|
|
78
|
+
currentSortDirection.value =
|
|
79
|
+
currentSortDirection.value === "desc" ? "asc" : "desc"
|
|
80
|
+
} else {
|
|
81
|
+
currentSort.value = selectedSort
|
|
82
|
+
currentSortDirection.value = "desc"
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
loadAndRender()
|
|
86
|
+
}
|
|
87
|
+
const loadAndRender = (): void => {
|
|
88
|
+
const params = {
|
|
89
|
+
minDate: dateRange.value.minDate,
|
|
90
|
+
maxDate: dateRange.value.maxDate,
|
|
91
|
+
page: pagination.value.page,
|
|
92
|
+
perPage: pagination.value.perPage,
|
|
93
|
+
sort: currentSort.value,
|
|
94
|
+
sortDir: currentSortDirection.value,
|
|
95
|
+
q: query.value,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
BaseAPI.get(props.tableData.url, { skipLoader: !props.loader }, params).then(
|
|
99
|
+
(success: AxiosResponse) => {
|
|
100
|
+
pagination.value = {
|
|
101
|
+
page: success.data.page,
|
|
102
|
+
perPage: success.data.perPage,
|
|
103
|
+
totalItems: success.data.totalItems,
|
|
104
|
+
totalPages: success.data.totalPages,
|
|
105
|
+
}
|
|
106
|
+
items.value = success.data.items
|
|
107
|
+
},
|
|
108
|
+
() => {
|
|
109
|
+
window.VueBus.emit(
|
|
110
|
+
"Flash-show-generic-error",
|
|
111
|
+
"membership@xyplanningnetwork.com"
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const reloadTable = (): void => {
|
|
118
|
+
pagination.value.page = 1
|
|
119
|
+
loadAndRender()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const hasContent = computed((): boolean => {
|
|
123
|
+
return items.value.length ? true : false
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
watch(
|
|
127
|
+
() => props.tableData.refreshTrigger,
|
|
128
|
+
() => {
|
|
129
|
+
// This lets parent components trigger a refresh of the current page depending on external actions.
|
|
130
|
+
loadAndRender()
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
watch(
|
|
135
|
+
() => props.tableData.reloadTrigger,
|
|
136
|
+
() => {
|
|
137
|
+
// This lets parent components trigger a reload of page 1 depending on external actions.
|
|
138
|
+
reloadTable()
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
// onCreated
|
|
143
|
+
loadAndRender()
|
|
144
|
+
</script>
|
|
1
145
|
<template>
|
|
2
146
|
<div>
|
|
3
147
|
<div
|
|
@@ -52,7 +196,7 @@
|
|
|
52
196
|
<span v-if="!!col.display.length">{{ col.display }}</span>
|
|
53
197
|
<span
|
|
54
198
|
class="cursor-pointer"
|
|
55
|
-
@click.prevent="handleSort(col.sort)"
|
|
199
|
+
@click.prevent="handleSort(col.sort as string)"
|
|
56
200
|
v-if="col.sort"
|
|
57
201
|
>
|
|
58
202
|
<svg
|
|
@@ -140,128 +284,8 @@
|
|
|
140
284
|
|
|
141
285
|
<Paginator
|
|
142
286
|
v-model="pagination"
|
|
143
|
-
@update:modelValue="loadAndRender(
|
|
287
|
+
@update:modelValue="loadAndRender()"
|
|
144
288
|
v-if="hasContent"
|
|
145
289
|
/>
|
|
146
290
|
</div>
|
|
147
291
|
</template>
|
|
148
|
-
|
|
149
|
-
<script lang="ts">
|
|
150
|
-
import { Options, Prop, Watch, Vue } from "vue-property-decorator";
|
|
151
|
-
import { AxiosResponse } from "axios";
|
|
152
|
-
import DateRangePicker from "../forms/DateRangePicker.vue";
|
|
153
|
-
import Paginator from "../navigation/Paginator.vue";
|
|
154
|
-
import BaseAPI from "../../api/base";
|
|
155
|
-
import TableTypes from "../../types/table";
|
|
156
|
-
|
|
157
|
-
@Options({ components: { DateRangePicker, Paginator }, name: "Table" })
|
|
158
|
-
export default class Table extends Vue {
|
|
159
|
-
@Prop({ type: Boolean, required: false, default: false }) clickable!: boolean;
|
|
160
|
-
@Prop({ type: Boolean, required: false, default: true }) loader!: boolean;
|
|
161
|
-
@Prop({ type: Object, required: true }) tableData!: TableTypes.Dynamic;
|
|
162
|
-
|
|
163
|
-
currentSort = "";
|
|
164
|
-
currentSortDirection = "";
|
|
165
|
-
dateRange: { minDate: number; maxDate: number } = {
|
|
166
|
-
minDate: 0,
|
|
167
|
-
maxDate: 0,
|
|
168
|
-
};
|
|
169
|
-
items: any[] = [];
|
|
170
|
-
pagination = {
|
|
171
|
-
page: 1,
|
|
172
|
-
perPage: 10,
|
|
173
|
-
totalItems: 0,
|
|
174
|
-
totalPages: 0,
|
|
175
|
-
};
|
|
176
|
-
query = "";
|
|
177
|
-
|
|
178
|
-
@Watch("tableData.refreshTrigger")
|
|
179
|
-
onRefreshTrigger(): void {
|
|
180
|
-
// This lets parent components trigger a refresh of the current page depending on external actions.
|
|
181
|
-
this.loadAndRender();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
@Watch("tableData.reloadTrigger")
|
|
185
|
-
onReloadTrigger(): void {
|
|
186
|
-
// This lets parent components trigger a reload of page 1 depending on external actions.
|
|
187
|
-
this.reloadTable();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
created() {
|
|
191
|
-
if (this.tableData.defaultSort) {
|
|
192
|
-
this.currentSort = this.tableData.defaultSort;
|
|
193
|
-
this.currentSortDirection = this.tableData.defaultSortDirection
|
|
194
|
-
? this.tableData.defaultSortDirection
|
|
195
|
-
: "desc";
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
this.loadAndRender();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
cellValue(item: Record<string, any>, col: TableTypes.Column): string {
|
|
202
|
-
if (col.key) {
|
|
203
|
-
// NOTE(dlk): supports dot notation for nested keys
|
|
204
|
-
return col.key.split(".").reduce((o, i) => o[i], item as any);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (col.presenter) {
|
|
208
|
-
return col.presenter(item, this);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return "";
|
|
212
|
-
}
|
|
213
|
-
dateRangeChanged(dateRange: { minDate: number; maxDate: number }): void {
|
|
214
|
-
this.pagination.page = 1;
|
|
215
|
-
this.dateRange = dateRange;
|
|
216
|
-
this.loadAndRender();
|
|
217
|
-
}
|
|
218
|
-
handleSort(selectedSort: string): void {
|
|
219
|
-
if (this.currentSort == selectedSort) {
|
|
220
|
-
this.currentSortDirection =
|
|
221
|
-
this.currentSortDirection === "desc" ? "asc" : "desc";
|
|
222
|
-
} else {
|
|
223
|
-
this.currentSort = selectedSort;
|
|
224
|
-
this.currentSortDirection = "desc";
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
this.loadAndRender();
|
|
228
|
-
}
|
|
229
|
-
loadAndRender(): void {
|
|
230
|
-
const params = {
|
|
231
|
-
minDate: this.dateRange.minDate,
|
|
232
|
-
maxDate: this.dateRange.maxDate,
|
|
233
|
-
page: this.pagination.page,
|
|
234
|
-
perPage: this.pagination.perPage,
|
|
235
|
-
sort: this.currentSort,
|
|
236
|
-
sortDir: this.currentSortDirection,
|
|
237
|
-
q: this.query,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
BaseAPI.get(this.tableData.url, { skipLoader: !this.loader }, params).then(
|
|
241
|
-
(success: AxiosResponse) => {
|
|
242
|
-
this.pagination = {
|
|
243
|
-
page: success.data.page,
|
|
244
|
-
perPage: success.data.perPage,
|
|
245
|
-
totalItems: success.data.totalItems,
|
|
246
|
-
totalPages: success.data.totalPages,
|
|
247
|
-
};
|
|
248
|
-
this.items = success.data.items;
|
|
249
|
-
},
|
|
250
|
-
() => {
|
|
251
|
-
window.VueBus.emit(
|
|
252
|
-
"Flash-show-generic-error",
|
|
253
|
-
"membership@xyplanningnetwork.com"
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
reloadTable(): void {
|
|
259
|
-
this.pagination.page = 1;
|
|
260
|
-
this.loadAndRender();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
get hasContent(): boolean {
|
|
264
|
-
return this.items.length ? true : false;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
</script>
|