forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathveutify.ts
More file actions
67 lines (55 loc) · 1.56 KB
/
veutify.ts
File metadata and controls
67 lines (55 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import Vue from 'vue'
import { Route } from 'vue-router'
import { DataOptions } from 'vuetify'
export type VForm = Vue & {
validate: () => boolean
resetValidation: () => boolean
reset: () => void
}
export type FormInputType = string | null | File
export type FormValidationRule = (value: FormInputType) => string | boolean
export type FormValidationRules = Array<FormValidationRule>
export interface SelectItem {
text: string
value: string | number | boolean
}
export interface DatatableFooterProps {
itemsPerPage: number
itemsPerPageOptions: Array<number>
}
export const DefaultFooterProps: DatatableFooterProps = {
itemsPerPage: 100,
itemsPerPageOptions: [10, 50, 100, 200],
}
export type ParseParamsResponse = {
options: DataOptions
query: string | null
}
export const parseFilterOptionsFromParams = (
route: Route,
options: DataOptions,
): ParseParamsResponse => {
let query = null
Object.keys(route.query).forEach((value: string) => {
if (value === 'itemsPerPage') {
options.itemsPerPage = parseInt(
(route.query[value] as string) ?? options.itemsPerPage.toString(),
)
}
if (value === 'sortBy') {
options.sortBy = [(route.query[value] as string) ?? options.sortBy[0]]
}
if (value === 'sortDesc') {
options.sortDesc = [!(route.query[value] === 'false')]
}
if (value === 'page') {
options.page = parseInt(
(route.query[value] as string) ?? options.page.toString(),
)
}
if (value === 'query') {
query = route.query[value]
}
})
return { options, query }
}