bt-core-app 0.0.0
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/.vscode/extensions.json +3 -0
- package/README.md +45 -0
- package/index.html +13 -0
- package/package.json +39 -0
- package/public/vite.svg +1 -0
- package/src/assets/vue.svg +1 -0
- package/src/components/BT-Btn.vue +40 -0
- package/src/components/BT-Col.vue +36 -0
- package/src/components/BT-Span.vue +21 -0
- package/src/components/Dialog-Confirm.vue +47 -0
- package/src/components/Dialog-Select-Date.vue +89 -0
- package/src/components/Dialog-Select.vue +140 -0
- package/src/components/Dialog-Text.vue +59 -0
- package/src/composables/actions-tracker.ts +99 -0
- package/src/composables/actions.ts +354 -0
- package/src/composables/api.ts +471 -0
- package/src/composables/auth.ts +382 -0
- package/src/composables/cosmetics.ts +178 -0
- package/src/composables/csv.ts +198 -0
- package/src/composables/dates.ts +79 -0
- package/src/composables/demo.ts +25 -0
- package/src/composables/dialogs.ts +115 -0
- package/src/composables/document-meta.ts +40 -0
- package/src/composables/draggable.ts +189 -0
- package/src/composables/filters.ts +256 -0
- package/src/composables/forage.ts +49 -0
- package/src/composables/helpers.ts +694 -0
- package/src/composables/id.ts +20 -0
- package/src/composables/list.ts +601 -0
- package/src/composables/navigation.ts +214 -0
- package/src/composables/presets.ts +20 -0
- package/src/composables/pwa.ts +89 -0
- package/src/composables/resizable.ts +382 -0
- package/src/composables/rules.ts +40 -0
- package/src/composables/stores.ts +797 -0
- package/src/composables/track.ts +55 -0
- package/src/composables/urls.ts +11 -0
- package/src/core.ts +92 -0
- package/src/index.ts +16 -0
- package/src/types.ts +13 -0
- package/src/useApi.ts +68 -0
- package/src/vite-env.d.ts +1 -0
- package/test/api.test.ts +84 -0
- package/test/forage.test.ts +31 -0
- package/test/helpers.test.ts +231 -0
- package/test/navigation.test.ts +99 -0
- package/test/stores-last-update.test.ts +138 -0
- package/test/stores-session.test.ts +118 -0
- package/test/track.test.ts +29 -0
- package/test/utils.ts +15 -0
- package/tsconfig.json +33 -0
- package/tsconfig.node.json +11 -0
- package/vite.config.ts +19 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { getLocationLine, isMinDate } from '@/composables/helpers';
|
|
2
|
+
import { BTDates } from './dates';
|
|
3
|
+
|
|
4
|
+
export interface BTFilters {
|
|
5
|
+
findFilter: (mFilter: string | undefined) => Function
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface UseFiltersOptions {
|
|
9
|
+
dates: BTDates
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createFilters(options: UseFiltersOptions): BTFilters {
|
|
13
|
+
// const { tzString, tzDate, utcString } = useDates()
|
|
14
|
+
|
|
15
|
+
function toTimeZoneFormat(value?: string, format?: string, placeholder?: string): string {
|
|
16
|
+
if (!value)
|
|
17
|
+
return placeholder ?? value ?? '';
|
|
18
|
+
|
|
19
|
+
if (isMinDate(value))
|
|
20
|
+
return placeholder ?? '';
|
|
21
|
+
|
|
22
|
+
return options.dates.tzString(value, format)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function toCompanyNameAndLocationLine(value: object | null | any): string {
|
|
26
|
+
if (!value) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof value !== 'object') {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var rStr = '';
|
|
35
|
+
|
|
36
|
+
if (value.companyAccount != null) {
|
|
37
|
+
rStr = value.companyAccount.companyName + ' | ';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (value.addressLineOne != null) {
|
|
41
|
+
rStr = rStr + value.addressLineOne + ' ';
|
|
42
|
+
}
|
|
43
|
+
if (value.streetNumber != null) {
|
|
44
|
+
rStr = rStr + value.streetNumber + ' ';
|
|
45
|
+
}
|
|
46
|
+
if (value.streetName != null) {
|
|
47
|
+
rStr = rStr + value.streetName + ', ';
|
|
48
|
+
}
|
|
49
|
+
if (value.suburb != null) {
|
|
50
|
+
rStr = rStr + value.suburb + ' ';
|
|
51
|
+
}
|
|
52
|
+
if (value.state != null) {
|
|
53
|
+
rStr = rStr + value.state + ' ';
|
|
54
|
+
}
|
|
55
|
+
if (value.postcode != null) {
|
|
56
|
+
rStr = rStr + value.postcode;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return rStr;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function toCurrency(val: any): string {
|
|
63
|
+
if (typeof val !== 'number') {
|
|
64
|
+
return val;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var formatter = new Intl.NumberFormat('en-US', {
|
|
68
|
+
style: 'currency',
|
|
69
|
+
currency: 'AUD',
|
|
70
|
+
minimumFractionDigits: 2
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return formatter.format(val);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function toDayDate(value?: string, placeholder?: string): string {
|
|
77
|
+
return toTimeZoneFormat(value, 'ccc | d LLL', placeholder)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function toDayMonth(value?: string, placeholder?: string): string {
|
|
81
|
+
return toTimeZoneFormat(value, 'd LLL', placeholder)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function toDayOfWeek(value?: string, placeholder?: string): string {
|
|
85
|
+
return toTimeZoneFormat(value, 'ccc', placeholder);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function toDayShortDate(value?: string, placeholder?: string): string {
|
|
89
|
+
return toTimeZoneFormat(value, 'ccc dd LLL yyyy', placeholder);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function toDayShortDateAndTime(value?: string, placeholder?: string): string {
|
|
93
|
+
return toTimeZoneFormat(value, 'ccc dd LLL @ hh:mm a', placeholder);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function toDisplayNumber(val: number): string {
|
|
97
|
+
return new Intl.NumberFormat().format(val);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function toDisplayNumberOver(val: number): string {
|
|
101
|
+
if (val == 0) {
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return new Intl.NumberFormat().format(val);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function toDisplayNumberSigned(val: number): string {
|
|
109
|
+
if (val == 0) {
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var r = new Intl.NumberFormat().format(val);
|
|
114
|
+
|
|
115
|
+
if (val > 0) {
|
|
116
|
+
return '+' + r;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return r;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function toFormat(val?: string, format?: string) {
|
|
124
|
+
return options.dates.utcString(val, format);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function toLocationLine(val: any): string {
|
|
128
|
+
return getLocationLine(val, false);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function toLocationLineNoCommas(value: any): string {
|
|
132
|
+
if (!value) {
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (typeof value !== 'object') {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var rStr = '';
|
|
141
|
+
|
|
142
|
+
if (value.addressLineOne != null) {
|
|
143
|
+
rStr = value.addressLineOne + ' ';
|
|
144
|
+
}
|
|
145
|
+
if (value.streetNumber != null) {
|
|
146
|
+
rStr = rStr + value.streetNumber + ' ';
|
|
147
|
+
}
|
|
148
|
+
if (value.streetName != null) {
|
|
149
|
+
rStr = rStr + value.streetName + ' ';
|
|
150
|
+
}
|
|
151
|
+
if (value.suburb != null) {
|
|
152
|
+
rStr = rStr + value.suburb + ' ';
|
|
153
|
+
}
|
|
154
|
+
if (value.state != null) {
|
|
155
|
+
rStr = rStr + value.state + ' ';
|
|
156
|
+
}
|
|
157
|
+
if (value.postcode != null) {
|
|
158
|
+
rStr = rStr + value.postcode;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
rStr = rStr.replaceAll(',', ' ');
|
|
162
|
+
|
|
163
|
+
return rStr;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function toLongDate(value?: string, placeholder?: string): string {
|
|
167
|
+
return toTimeZoneFormat(value, 'ddd DD MMM YYYY', placeholder);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function toLongDateAndTime(value?: string, placeholder?: string): string {
|
|
171
|
+
return toTimeZoneFormat(value, 'ccc dd LLL yyyy hh:mm a', placeholder);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function toPercent(val: number): string {
|
|
175
|
+
var formatter = new Intl.NumberFormat('en-US', {
|
|
176
|
+
style: 'percent',
|
|
177
|
+
minimumFractionDigits: 2
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return formatter.format(val);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function toPrettyCSV(val: string): string {
|
|
184
|
+
return val.replaceAll(',', ' ');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function toShortDate(value?: string, placeholder?: string): string {
|
|
188
|
+
return toTimeZoneFormat(value, 'dd LLL yyyy', placeholder);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function toShortDateAndTime(value?: string, placeholder?: string): string {
|
|
192
|
+
return toTimeZoneFormat(value, 'dd LLL yyyy hh:mm a', placeholder);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function toTime(value?: string, placeholder?: string): string {
|
|
196
|
+
return toTimeZoneFormat(value, 'hh:mm a', placeholder);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function toTimeOfDay(val?: string | number): string {
|
|
200
|
+
if (val == null) {
|
|
201
|
+
return '';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (typeof val == 'number') {
|
|
205
|
+
return options.dates.tzDate().startOf('day').plus({ minutes: val }).toFormat('T')
|
|
206
|
+
}
|
|
207
|
+
else if (typeof val == 'string') {
|
|
208
|
+
return options.dates.tzString(val, 't')
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return 'unknown';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const e = {
|
|
216
|
+
toCompanyNameAndLocationLine,
|
|
217
|
+
toCurrency,
|
|
218
|
+
toDayDate,
|
|
219
|
+
toDayMonth,
|
|
220
|
+
toDayOfWeek,
|
|
221
|
+
toDayShortDate,
|
|
222
|
+
toDayShortDateAndTime,
|
|
223
|
+
toDisplayNumber,
|
|
224
|
+
toDisplayNumberOver,
|
|
225
|
+
toDisplayNumberSigned,
|
|
226
|
+
toFormat,
|
|
227
|
+
toLocationLine,
|
|
228
|
+
toLocationLineNoCommas,
|
|
229
|
+
toLongDate,
|
|
230
|
+
toLongDateAndTime,
|
|
231
|
+
toPercent,
|
|
232
|
+
toPrettyCSV,
|
|
233
|
+
toShortDate,
|
|
234
|
+
toShortDateAndTime,
|
|
235
|
+
toTime,
|
|
236
|
+
toTimeOfDay
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function findFilter(mFilter: undefined | string): Function {
|
|
240
|
+
if (mFilter != null) {
|
|
241
|
+
let filter = mFilter as keyof typeof e
|
|
242
|
+
if (filter != null && e[filter] != null) {
|
|
243
|
+
return e[filter] as Function
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return (v: any) => v
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
findFilter,
|
|
252
|
+
...e
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export type Textfilter = 'toLocationLine' | 'toLocationLineNoCommas' | 'toLongDate' | 'toLongDateAndTime' | 'toPercent' | 'toPrettyCSV' | 'toShortDate' | 'toShortDateAndTime' | 'toTime' | 'toTimeOfDay' | 'toCompanyNameAndLocationLine' | 'toCurrency' | 'toDayDate' | 'toDayMonth' | 'toDayOfWeek' | 'toDayShortDate' | 'toDayShortDateAndTime' | 'toDisplayNumber' | 'toDisplayNumberOver' | 'toDisplayNumberSigned' | 'toFormat'
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import localforage from 'localforage';
|
|
2
|
+
import { useUrl } from '@/composables/urls';
|
|
3
|
+
|
|
4
|
+
let localDb: LocalForage | null = null;
|
|
5
|
+
|
|
6
|
+
localforage.config({
|
|
7
|
+
name: useUrl(`Db_${import.meta.env.MODE}`)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export function useLocalDb(): LocalForage {
|
|
11
|
+
const dbName = `Db_${useUrl('LOCAL_DB_NAME')}`
|
|
12
|
+
if (localDb == null || localDb.config.name != dbName) {
|
|
13
|
+
localDb = localforage.createInstance({ name: dbName })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return localDb
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useLocalCache() {
|
|
20
|
+
|
|
21
|
+
async function clearAsync(storeName: string) {
|
|
22
|
+
const db = useLocalDb()
|
|
23
|
+
const keys = await db.keys()
|
|
24
|
+
let filteredKeys = keys.filter(key => key.startsWith(storeName))
|
|
25
|
+
|
|
26
|
+
filteredKeys.forEach(fKey => {
|
|
27
|
+
db.removeItem(fKey)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function getAsync<T>(key: string) {
|
|
32
|
+
return await useLocalDb().getItem<T>(key)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function removeAsync(key: string) {
|
|
36
|
+
return await useLocalDb().removeItem(key)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function saveAsync<T>(data: T, key: string) {
|
|
40
|
+
await useLocalDb().setItem(key, data)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
clearAsync,
|
|
45
|
+
getAsync,
|
|
46
|
+
removeAsync,
|
|
47
|
+
saveAsync
|
|
48
|
+
}
|
|
49
|
+
}
|