bt-core-app 1.3.4 → 1.3.6

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.
@@ -0,0 +1,61 @@
1
+ <template>
2
+ <v-list-group v-if="doShowItem && relevantChildren.length > 0"
3
+ color="accent"
4
+ :subGroup="isSubGroup"
5
+ fluid>
6
+ <template #activator="{ props }">
7
+ <v-list-item v-bind="props"
8
+ :prepend-icon="item.icon"
9
+ :title="item.displayName" />
10
+ </template>
11
+ <BT-Nav-Menu-Item
12
+ v-for="child in relevantChildren"
13
+ :key="child.name"
14
+ isSubGroup
15
+ :item="child" />
16
+ </v-list-group>
17
+ <v-list-item v-else-if="doShowItem"
18
+ color="accent"
19
+ :prepend-icon="item.icon"
20
+ nav
21
+ :title="item.displayName ?? item.name"
22
+ :to="{ name: item.name }">
23
+ </v-list-item>
24
+ <v-divider v-else-if="item.isDivider" />
25
+ <div v-else>test</div>
26
+ </template>
27
+
28
+ <script setup lang="ts">
29
+ import BTNavMenuItem from './BT-Nav-Menu-Item.vue'
30
+ import { computed } from 'vue'
31
+ import { useAuth } from '../composables/auth'
32
+ import { isLengthyArray } from '../composables/helpers'
33
+ import { type NavigationItem } from '../composables/navigation'
34
+
35
+
36
+ interface ItemProps {
37
+ allowedSubscriptionCodes?: string[],
38
+ isSubGroup?: boolean,
39
+ item?: any
40
+ }
41
+
42
+ const props = withDefaults(defineProps<ItemProps>(), {
43
+ allowedSubscriptionCodes: () => [],
44
+ isSubGroup: false,
45
+ item: null
46
+ })
47
+
48
+ const { doShowByNav } = useAuth()
49
+
50
+ const relevantChildren = computed(() => {
51
+ const l = props.item.children?.filter((x: NavigationItem) => x.isInNavMenu !== false) ?? []
52
+ if (!isLengthyArray(props.allowedSubscriptionCodes)) {
53
+ return l
54
+ }
55
+
56
+ return l.filter((navItem: NavigationItem) => !isLengthyArray(navItem.subFilters) || props.allowedSubscriptionCodes.some(code => navItem.subFilters?.some(sFilter => sFilter == code)))
57
+ })
58
+
59
+ const doShowItem = computed(() => doShowByNav(props.item, true))
60
+
61
+ </script>
@@ -0,0 +1,78 @@
1
+ <template>
2
+ <v-navigation-drawer
3
+ v-if="isLoggedIn"
4
+ disabled-resize-watcher
5
+ expand-on-hover
6
+ :rail="!state.drawerStick"
7
+ permanent
8
+ v-model="state.drawer">
9
+ <slot>
10
+ <v-list class="pt-1">
11
+ <v-list-item nav :title="title">
12
+ <template #prepend>
13
+ <v-avatar size="36">
14
+ <v-img :src="iconSrc" />
15
+ </v-avatar>
16
+ </template>
17
+ <template #append>
18
+ <v-row class="mr-1">
19
+ <v-btn
20
+ @click="toggleDrawerStick"
21
+ flat
22
+ icon
23
+ size="small"
24
+ title="Pin/Unpin Menu">
25
+ <v-icon>{{ state.drawerStick ? 'mdi-pin-off' : 'mdi-pin' }}</v-icon>
26
+ </v-btn>
27
+ </v-row>
28
+ </template>
29
+ </v-list-item>
30
+ <slot name="top-list">
31
+
32
+ </slot>
33
+ </v-list>
34
+
35
+ <slot name="middle-list">
36
+ <v-list nav>
37
+ <BT-Nav-Menu-Item
38
+ v-for="(item, index) in navItems"
39
+ :key="index"
40
+ :item="item" />
41
+ </v-list>
42
+ </slot>
43
+ </slot>
44
+ <template #append>
45
+ <slot name="bottom-list">
46
+ <v-list v-if="isLoggedIn" class="ma-0 pa-0">
47
+ <v-list-item
48
+ class="bg-primary"
49
+ prepend-icon="mdi-logout"
50
+ title="Logout"
51
+ @click="() => logout()" />
52
+ </v-list>
53
+ </slot>
54
+ </template>
55
+ </v-navigation-drawer>
56
+ </template>
57
+
58
+ <script setup lang="ts">
59
+ import BTNavMenuItem from './BT-Nav-Menu-Item.vue'
60
+ import { useCosmetics } from '../composables/cosmetics'
61
+ import { useNavigation } from '../composables/navigation'
62
+ import { useAuth } from '../composables/auth'
63
+ import { computed } from 'vue'
64
+
65
+ interface SidebarProps {
66
+ // greeting?: string
67
+ iconSrc?: string
68
+ title?: string
69
+ }
70
+
71
+ defineProps<SidebarProps>()
72
+ const { state, toggleDrawerStick } = useCosmetics()
73
+ const { isLoggedIn, logout } = useAuth()
74
+ const navigation = useNavigation()
75
+
76
+ const navItems = computed(() => navigation.navigationItems.filter(x => x.isInNavMenu !== false && navigation.backgroundName.value == x.background));
77
+
78
+ </script>
@@ -16,7 +16,7 @@
16
16
  :model-auto="range"
17
17
  :range="range"
18
18
  :time-picker-inline="!range && useTime"
19
- :timezone="credentials.timeZone"
19
+ :timezone="timeZone"
20
20
  utc
21
21
  v-bind="$attrs"
22
22
  v-model="date" />
@@ -50,7 +50,7 @@
50
50
 
51
51
  const emit = defineEmits(['confirm', 'cancel'])
52
52
  const date = ref()
53
- const { credentials } = useAuth()
53
+ const { timeZone } = useAuth()
54
54
 
55
55
  const canAccept = computed(() => {
56
56
  return !props.required || date.value
@@ -188,13 +188,13 @@ export function createApi(options?: UseApiOptions): BTApi {
188
188
 
189
189
  function defaultBuildHeaders(path: PathOptions): HeadersInit {
190
190
  let fetchOptions:any = { ...path.headers }
191
- const auth = options?.auth?.credentials
191
+ //const auth = options?.auth?.credentials
192
192
 
193
193
  if (path.proxyID)
194
194
  fetchOptions.ManagedCompanyAccountID ??= path.proxyID
195
195
 
196
- if (options?.useBearerToken != false && auth?.isLoggedIn == true)
197
- fetchOptions.authorization ??= `bearer ${auth.token}`
196
+ if (options?.useBearerToken != false && options?.auth?.isLoggedIn.value == true)
197
+ fetchOptions.authorization ??= `bearer ${options?.auth?.credentials.value.token}`
198
198
 
199
199
  fetchOptions['Content-Type'] ??= (path.contentType ?? options?.defaultContentType ?? 'application/json')
200
200
 
@@ -3,7 +3,7 @@ import { DateTime } from 'luxon'
3
3
  import { type RemovableRef, useStorage } from '@vueuse/core'
4
4
  import { type BTDemo } from '../composables/demo'
5
5
  import { useRouter } from 'vue-router'
6
- import { toValue } from 'vue'
6
+ import { computed, type ComputedRef, toValue } from 'vue'
7
7
  import { useAuthUrl } from './urls'
8
8
  import { useApi } from './api'
9
9
 
@@ -66,15 +66,17 @@ export interface BTAuth {
66
66
  canEditPermit: (permit: string) => boolean
67
67
  canView: (navName?: string) => boolean
68
68
  canViewPermit: (permit: string) => boolean
69
- credentials: any
69
+ credentials: RemovableRef<any>
70
70
  doShow: (subcodes?: string[], permissions?: string[], action?: 'view' | 'edit') => boolean
71
71
  doShowByNav: (navName?: string | AuthItem, includeChildren?: boolean) => boolean
72
72
  getAuthorizeUrl: (redirectPath?: string) => string
73
73
  getTimeZone: () => string
74
74
  getToken: (code?: string, state?: string) => Promise<void>
75
+ isLoggedIn: ComputedRef<boolean>
75
76
  login: (redirectPath?: string) => void
76
77
  logout: (navNameRedirect?: string) => void
77
78
  setAuth: (jwtToken?: string) => void
79
+ timeZone: ComputedRef<string>
78
80
  tryLogin: () => boolean | undefined
79
81
  }
80
82
 
@@ -430,15 +432,19 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
430
432
  canEditPermit,
431
433
  canView,
432
434
  canViewPermit,
433
- credentials: state.value,
435
+ credentials: state,
434
436
  doShow,
435
437
  doShowByNav,
436
438
  getAuthorizeUrl,
437
439
  getTimeZone,
438
440
  getToken,
441
+ isLoggedIn: computed(() => state.value.isLoggedIn === true),
439
442
  login,
440
443
  logout,
441
444
  setAuth,
445
+ timeZone: computed(() => {
446
+ return state.value.timeZone ?? options.defaultTimeZone ?? defaultTimeZone
447
+ }),
442
448
  tryLogin
443
449
  }
444
450
 
@@ -48,7 +48,7 @@ export interface UseCosmeticsOptions<T extends BaseCosmeticTheme> {
48
48
  }
49
49
 
50
50
  export interface BTCosmetics {
51
- state: CosmeticData
51
+ state: RemovableRef<CosmeticData>
52
52
  initiate: () => void
53
53
  resetCosmetics: (toDefault: boolean) => void
54
54
  setTemporaryColor: (color: string) => void
@@ -153,7 +153,7 @@ export function useCosmetics(): BTCosmetics {
153
153
  }
154
154
 
155
155
  return {
156
- state: state.value,
156
+ state: state,
157
157
  initiate: loadCosmetics,
158
158
  resetCosmetics,
159
159
  setTemporaryColor,
@@ -193,14 +193,14 @@ export function createSessionStoreDefinition(options: UseSessionStoreOptions): B
193
193
  // const authData = useAuthData()
194
194
 
195
195
  function getKey(dOptions: PathOptions) {
196
- return `${options.storeName}_${options.auth?.credentials.userID ?? 'no-user-id'}_${dOptions.id ?? dOptions.data?.id ?? 'no-item-id'}`
196
+ return `${options.storeName}_${options.auth?.credentials.value.userID ?? 'no-user-id'}_${dOptions.id ?? dOptions.data?.id ?? 'no-item-id'}`
197
197
  }
198
198
 
199
199
  async function getAll<T extends BaseModel>(dOptions: PathOptions): Promise<StoreGetAllReturn<T>> {
200
200
  dOptions.additionalUrl ??= '/getAll'
201
201
 
202
202
  const path = buildPath(dOptions)
203
- const key = `${options.storeName}_${options.auth?.credentials.userID ?? 'no-user-id'}_${path}`
203
+ const key = `${options.storeName}_${options.auth?.credentials.value.userID ?? 'no-user-id'}_${path}`
204
204
  const refresh = dOptions.refresh
205
205
 
206
206
  if (!refresh && searchMemory.value[key] !== undefined)
@@ -508,7 +508,7 @@ export function createWholeLastUpdateStoreDefinition(options: UseWholeLastUpdate
508
508
  const cacheLocally = options.storageMode == 'local-cache'
509
509
 
510
510
  function getKey() {
511
- return `${options.storeName}_${options.auth?.credentials.userID ?? 'no-user-id'}`
511
+ return `${options.storeName}_${options.auth?.credentials.value.userID ?? 'no-user-id'}`
512
512
  }
513
513
 
514
514
  async function trySaveToLocalCache() {
package/src/index.ts CHANGED
@@ -42,6 +42,10 @@ export * from './types'
42
42
  export type { CoreApp, CreateCoreOptions } from './core'
43
43
  export { createCore } from './core'
44
44
 
45
+ import BTNavMenuItem from './components/BT-Nav-Menu-Item.vue'
46
+ import BTNavSidebar from './components/BT-Nav-Sidebar.vue'
47
+
48
+ export { BTNavMenuItem, BTNavSidebar }
45
49
 
46
50
  // import BTBtn from './components/BT-Btn.vue'
47
51
  // import BTCol from './components/BT-Col.vue'
package/test/auth.test.ts CHANGED
@@ -47,7 +47,7 @@ describe('default auth', () => {
47
47
 
48
48
  test('creates successfully', () => {
49
49
  const state = auth.authState
50
- const creds = auth.credentials
50
+ const creds = auth.credentials.value
51
51
 
52
52
  expect(state).not.toBeNull()
53
53
  expect(auth.credentials).not.toBeNull()