Skip to content

Commit 4ba7e88

Browse files
committed
✨ Debug mode for admin
1 parent 77d1f99 commit 4ba7e88

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed

components/tw/NavigationBar.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
>
3434
{{ $t('app.tabByod') }}
3535
</TwNavigationBarButton>
36+
<TwNavigationBarButton
37+
:to="localePath('/debug')"
38+
:icon="mdiTools"
39+
v-if="debugMode"
40+
>
41+
Debug
42+
</TwNavigationBarButton>
3643
</ul>
3744
</nav>
3845
</template>
@@ -45,6 +52,7 @@ import {
4552
mdiMapOutline,
4653
mdiFolderUpload,
4754
mdiFolderUploadOutline,
55+
mdiTools,
4856
} from '@mdi/js'
4957
export default {
5058
data: () => ({
@@ -58,13 +66,17 @@ export default {
5866
'M19 19v-3H5v3h14Zm0-5v-4H5v4h14Zm0-6V5H5v3h14ZM5 21q-.825 0-1.413-.587Q3 19.825 3 19V5q0-.825.587-1.413Q4.175 3 5 3h14q.825 0 1.413.587Q21 4.175 21 5v14q0 .825-.587 1.413Q19.825 21 19 21Z',
5967
mdiFolderUpload,
6068
mdiFolderUploadOutline,
69+
mdiTools,
6170
}),
6271
computed: {
6372
region() {
6473
return (
6574
this.$route.params.region || this.$store.state.settings.currentRegion
6675
)
6776
},
77+
debugMode() {
78+
return this.$store.state.settings.debugMode
79+
},
6880
},
6981
}
7082
</script>

components/tw/NavigationRail.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252
{{ $t('app.tabByod') }}
5353
</TwNavigationBarButton>
5454
<div class="tw-grow"></div>
55+
<TwNavigationBarButton
56+
:to="localePath('/debug')"
57+
:icon="mdiTools"
58+
v-if="debugMode"
59+
>
60+
Debug
61+
</TwNavigationBarButton>
5562
<TwStandardIconButton
5663
v-if="dataIsLoaded"
5764
@click="open('NotificationsCentre')"
@@ -79,6 +86,7 @@ import {
7986
mdiBell,
8087
mdiCity,
8188
mdiCog,
89+
mdiTools,
8290
} from '@mdi/js'
8391
export default {
8492
data: () => ({
@@ -95,6 +103,7 @@ export default {
95103
mdiBell,
96104
mdiCity,
97105
mdiCog,
106+
mdiTools,
98107
}),
99108
computed: {
100109
region() {
@@ -105,6 +114,9 @@ export default {
105114
dataIsLoaded() {
106115
return this.$store.state.app.dataIsLoaded
107116
},
117+
debugMode() {
118+
return this.$store.state.settings.debugMode
119+
},
108120
},
109121
methods: {
110122
open(setting) {

nuxt.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default {
5454
// Axios module configuration (https://go.nuxtjs.dev/config-axios)
5555
axios: {
5656
baseURL: `${process.env.BACKEND_HOST}/v2` || 'http://backend.test/v2',
57+
credentials: true,
5758
},
5859

5960
// i18n module configuration

pages/debug.vue

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<template>
2+
<div class="tw-m-4">
3+
<div>
4+
<p v-if="debugMode">Debug mode is On</p>
5+
<p v-else>Debug mode is Off</p>
6+
<button
7+
@click="toggleDebug(true)"
8+
class="tw-bg-primary-40 tw-p-2 tw-text-white"
9+
>
10+
Turn On
11+
</button>
12+
<button
13+
@click="toggleDebug(false)"
14+
class="tw-bg-primary-40 tw-p-2 tw-text-white"
15+
>
16+
Turn Off
17+
</button>
18+
</div>
19+
<div class="tw-my-8"></div>
20+
<h2>Login</h2>
21+
<p v-if="user.id">Welcome {{ user.name }} (id {{ user.id }})</p>
22+
<p v-else>Please log in</p>
23+
<input
24+
v-model="email"
25+
placeholder="Email"
26+
:disabled="disableLogin"
27+
class="tw-border tw-border-solid tw-border-primary-20 tw-bg-white tw-p-2"
28+
type="email"
29+
/>
30+
<input
31+
v-model="password"
32+
placeholder="Password"
33+
type="password"
34+
class="tw-border tw-border-solid tw-border-primary-20 tw-bg-white tw-p-2"
35+
:disabled="disableLogin"
36+
/>
37+
<button
38+
@click="login"
39+
:disabled="disableLogin"
40+
class="tw-bg-primary-40 tw-p-2 tw-text-white"
41+
>
42+
Login
43+
</button>
44+
<div class="tw-my-8"></div>
45+
<h2>Load hidden agency</h2>
46+
<p v-if="addedAgency">{{ addedAgency }} is now loaded</p>
47+
<input
48+
v-model="agency"
49+
placeholder="slug"
50+
class="tw-border tw-border-solid tw-border-primary-20 tw-bg-white tw-p-2"
51+
/>
52+
<button @click="load" class="tw-bg-primary-40 tw-p-2 tw-text-white">
53+
Load
54+
</button>
55+
</div>
56+
</template>
57+
58+
<script>
59+
export default {
60+
async asyncData({ app, env }) {
61+
const baseDomain = env.backendHost
62+
await app.$axios.get(`${baseDomain}/sanctum/csrf-cookie`)
63+
64+
return { baseDomain }
65+
},
66+
data: () => ({
67+
email: '',
68+
password: '',
69+
disableLogin: false,
70+
agency: null,
71+
addedAgency: null,
72+
agencyError: null,
73+
user: {},
74+
}),
75+
computed: {
76+
debugMode() {
77+
return this.$store.state.settings.debugMode
78+
},
79+
},
80+
mounted() {
81+
this.$axios.get('/admin/user').then(({ data }) => {
82+
this.user = data
83+
})
84+
},
85+
methods: {
86+
async login() {
87+
this.disableLogin = true
88+
const { data } = await this.$axios.post(`${this.baseDomain}/login`, {
89+
email: this.email,
90+
password: this.password,
91+
})
92+
93+
this.user = data
94+
this.disableLogin = false
95+
},
96+
load() {
97+
this.$axios
98+
.get(`/admin/agencies/${this.agency}`)
99+
.then(({ data }) => {
100+
this.$store.commit('agencies/add', data.data)
101+
this.$store.dispatch('vehicles/load', data.data)
102+
this.addedAgency = data.data.name
103+
})
104+
.catch((error) => {
105+
this.agencyError = error.response
106+
? error.response.status
107+
: error.reqest
108+
? error.reqest
109+
: error.message
110+
})
111+
},
112+
toggleDebug(newState) {
113+
this.$store.commit('settings/set', {
114+
setting: 'debugMode',
115+
value: newState,
116+
})
117+
},
118+
},
119+
}
120+
</script>

store/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const state = () => ({
4848
'startTime',
4949
'actions',
5050
],
51+
debugMode: false,
5152
})
5253

5354
export const mutations = {

tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
`components/settings/TableColumns.vue`,
1313
`pages/regions/_region/index.vue`,
1414
`pages/regions/_region/table.vue`,
15+
`pages/debug.vue`,
1516
`./nuxt.config.js`,
1617
],
1718
theme: {

0 commit comments

Comments
 (0)