Skip to content

Commit be0e304

Browse files
authored
Merge pull request #355 from devforth/SettingsView
Settings view
2 parents 895bda7 + 6a3aefb commit be0e304

File tree

5 files changed

+19
-38
lines changed

5 files changed

+19
-38
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import os from 'os';
66
import path from 'path';
77
import { promisify } from 'util';
88
import AdminForth, { AdminForthConfigMenuItem } from '../index.js';
9-
import { ADMIN_FORTH_ABSOLUTE_PATH, getComponentNameFromPath, transformObject, deepMerge, md5hash } from './utils.js';
9+
import { ADMIN_FORTH_ABSOLUTE_PATH, getComponentNameFromPath, transformObject, deepMerge, md5hash, slugifyString } from './utils.js';
1010
import { ICodeInjector } from '../types/Back.js';
1111
import { StylesGenerator } from './styleGenerator.js';
1212

adminforth/modules/configValidator.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

1818
import fs from 'fs';
1919
import path from 'path';
20-
import { guessLabelFromName, md5hash, suggestIfTypo } from './utils.js';
20+
import { guessLabelFromName, md5hash, suggestIfTypo, slugifyString } from './utils.js';
2121
import {
2222
AdminForthSortDirections,
2323
type AdminForthComponentDeclarationFull,
@@ -30,7 +30,6 @@ import AdminForth from "adminforth";
3030
import { AdminForthConfigMenuItem } from "adminforth";
3131

3232

33-
3433
export default class ConfigValidator implements IConfigValidator {
3534

3635
customComponentsDir: string | undefined;
@@ -169,9 +168,8 @@ export default class ConfigValidator implements IConfigValidator {
169168
}
170169

171170
// slug should have only lowercase letters, dashes and numbers
172-
customization.brandNameSlug = customization.brandName.toLowerCase().replace(/[^a-z0-9-]/g, '');
171+
customization.brandNameSlug = slugifyString(customization.brandName);
173172

174-
175173
if (customization.brandLogo) {
176174
errors.push(...this.checkCustomFileExists(customization.brandLogo));
177175
}
@@ -1005,6 +1003,7 @@ export default class ConfigValidator implements IConfigValidator {
10051003
if (newConfig.auth.userMenuSettingsPages) {
10061004
for (const page of newConfig.auth.userMenuSettingsPages) {
10071005
this.validateComponent({file: page.component}, errors);
1006+
page.slug = page.slug ?? slugifyString(page.pageLabel);
10081007
}
10091008
}
10101009

adminforth/modules/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,12 @@ export function isProbablyUUIDColumn(column: { name: string; type?: string; samp
509509
}
510510

511511
return false;
512+
}
513+
514+
export function slugifyString(str: string): string {
515+
return str
516+
.toString()
517+
.toLowerCase()
518+
.replace(/\s+/g, '-')
519+
.replace(/[^a-z0-9-_]/g, '-');
512520
}

adminforth/spa/src/components/UserMenuSettingsButton.vue

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,10 @@ const options = computed(() => {
5959
});
6060
});
6161
62-
function slugifyString(str: string): string {
63-
return str
64-
.toString()
65-
.toLowerCase()
66-
.replace(/\s+/g, '-')
67-
.replace(/[^a-z0-9-_]/g, '-');
68-
}
69-
7062
function getRoute(option: { slug?: string | null, pageLabel: string }) {
7163
return {
7264
name: 'settings',
73-
params: { page: option.slug ?? slugifyString(option.pageLabel) }
65+
params: { page: option.slug }
7466
}
7567
}
7668

adminforth/spa/src/views/SettingsView.vue

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<p>No setting pages configured or still loading...</p>
55
</div>
66
<VerticalTabs v-else ref="VerticalTabsRef" v-model:active-tab="activeTab" @update:active-tab="setURL({slug: $event, pageLabel: ''})">
7-
<template v-for="(c,i) in coreStore?.config?.settingPages" :key="`tab:${settingPageSlotName(c,i)}`" v-slot:['tab:'+settingPageSlotName(c,i)]>
7+
<template v-for="(c,i) in coreStore?.config?.settingPages" :key="`tab:${settingPageSlotName(c,i)}`" v-slot:['tab:'+c.slug]>
88
<div class="flex items-center justify-center whitespace-nowrap w-full px-4 gap-2" @click="setURL(c)">
99
<component v-if="c.icon" :is="getIcon(c.icon)" class="w-5 h-5 group-hover:text-lightSidebarIconsHover transition duration-75 dark:group-hover:text-darkSidebarIconsHover dark:text-darkSidebarIcons" ></component>
1010
{{ c.pageLabel }}
1111
</div>
1212
</template>
1313

14-
<template v-for="(c,i) in coreStore?.config?.settingPages" :key="`${settingPageSlotName(c,i)}-content`" v-slot:[settingPageSlotName(c,i)]>
14+
<template v-for="(c,i) in coreStore?.config?.settingPages" :key="`${settingPageSlotName(c,i)}-content`" v-slot:[c.slug]>
1515
<component
1616
:is="getCustomComponent({file: c.component || ''})"
1717
:resource="coreStore.resource"
@@ -52,15 +52,6 @@ async function initRouter() {
5252
routerIsReady.value = true;
5353
}
5454
55-
function settingPageSlotName(c: { slug?: string; pageLabel?: string }, idx: number) {
56-
const base = (c.slug && c.slug.trim()) || (c.pageLabel && c.pageLabel.trim()) || `tab-${idx}`;
57-
return base
58-
.toString()
59-
.toLowerCase()
60-
.replace(/\s+/g, '-')
61-
.replace(/[^a-z0-9-_]/g, '-') || `tab-${idx}`;
62-
}
63-
6455
watch(dropdownUserButton, (el) => {
6556
if (el) {
6657
const dd = new Dropdown(
@@ -103,19 +94,10 @@ function setURL(item: {
10394
pageLabel: string;
10495
slug?: string | undefined;
10596
}) {
106-
const slug = item?.slug;
107-
if (slug) {
108-
router.replace({
109-
name: 'settings',
110-
params: { page: slug }
111-
});
112-
} else {
113-
const slugified = slugifyString(item.pageLabel);
114-
router.replace({
115-
name: 'settings',
116-
params: { page: slugified }
117-
});
118-
}
97+
router.replace({
98+
name: 'settings',
99+
params: { page: item?.slug }
100+
});
119101
}
120102
121103
function handleURLChange(val: string | null) {

0 commit comments

Comments
 (0)