Extend text styling to brand/model names and package text, add bold bullets
Rolls the generic text_styles mechanism out to three more areas (Phase 3/4 of the earlier text-styling plan): brands.name, car_models.name, packages.description and packages.price_text. Registry entries reuse each table's existing manage permission (brands.manage/models.manage/ packages.manage). Widgets are gated on an existing row (editingId in Brands.jsx/Models.jsx, row.existing in Packages.jsx's batch editor), since a newly-created row has no id yet to key a style on. Added fieldStyle()/useTextStylesMap() to TextStylesContext.jsx alongside the existing useTextStyle() - brand/model lists are open-ended, so styling each one from inside a .map() can't call a hook per item (rules of hooks); fieldStyle() does a plain lookup against the already-loaded styles map instead. pkg.name stays unstyled (it's chosen from a fixed tier list, not free text). Deleting a brand cascades to its models and their packages in the database, so BrandController/ModelController::destroy() now collect the cascaded ids first and clean up their text_styles rows too (mirroring how they already do this for orphaned uploaded images); SettingsController's catalog reset endpoints get the same cleanup in bulk. Separately: package descriptions can now mark individual bullet points bold. Packages.jsx gained a "Fett" button that wraps the current textarea selection in **markers** (one line per bullet is unchanged); the public ModelPage.jsx renders those through a new BoldText.jsx component that turns **text** into <strong> via a plain regex - no dangerouslySetInnerHTML, since the only possible output is a <strong> tag. Product-name bullets (scraped from the linked shop, not admin-authored) are unaffected. Verified locally: registry rejects packages.name (not free text) and a non-numeric id, and deleting a test brand correctly cascades text_styles cleanup through its model and package. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
ed0d18b9c3
commit
a3767b1c0f
16 changed files with 503 additions and 349 deletions
11
hifi-src/src/components/BoldText.jsx
Normal file
11
hifi-src/src/components/BoldText.jsx
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Sehr eingeschraenkte, bewusst nicht-HTML-basierte Formatierung fuer Stichpunkte, die sonst
|
||||||
|
// reiner Text sind (z.B. Paket-Beschreibungen) - **markierter Text** wird fett dargestellt.
|
||||||
|
// Kein dangerouslySetInnerHTML noetig: der Regex kann nur <strong> erzeugen, nichts anderes.
|
||||||
|
export default function BoldText({ text }) {
|
||||||
|
if (!text) return null;
|
||||||
|
const parts = text.split(/(\*\*[^*]+\*\*)/g);
|
||||||
|
return parts.map((part, i) => {
|
||||||
|
const match = part.match(/^\*\*([^*]+)\*\*$/);
|
||||||
|
return match ? <strong key={i}>{match[1]}</strong> : <span key={i}>{part}</span>;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -7,10 +7,11 @@ const TextStylesContext = createContext({});
|
||||||
|
|
||||||
export const TextStylesProvider = TextStylesContext.Provider;
|
export const TextStylesProvider = TextStylesContext.Provider;
|
||||||
|
|
||||||
/** Liefert {fontFamily, fontSize, color} (nur die tatsaechlich gesetzten Werte) zum
|
/** {fontFamily, fontSize, color} (nur die tatsaechlich gesetzten Werte) aus einer bereits
|
||||||
* Hineinspreaden in ein style-Objekt, oder {} wenn fuer dieses Feld nichts hinterlegt ist. */
|
* geladenen Styles-Map fuer einen bestimmten Key - als eigene, NICHT-Hook-Funktion nutzbar
|
||||||
export function useTextStyle(fieldKey) {
|
* innerhalb einer .map()-Schleife (z.B. eine Liste von Marken/Modellen mit wechselnder Anzahl),
|
||||||
const styles = useContext(TextStylesContext);
|
* wo ein Hook-Aufruf pro Element gegen die Rules of Hooks verstossen wuerde. */
|
||||||
|
export function fieldStyle(styles, fieldKey) {
|
||||||
const entry = styles[fieldKey];
|
const entry = styles[fieldKey];
|
||||||
if (!entry) return {};
|
if (!entry) return {};
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
@ -19,3 +20,17 @@ export function useTextStyle(fieldKey) {
|
||||||
if (entry.color) result.color = entry.color;
|
if (entry.color) result.color = entry.color;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Liefert {fontFamily, fontSize, color} fuer einen einzelnen, zur Build-Zeit bekannten Key
|
||||||
|
* (z.B. eine feste Startseiten-Sektion) - Komfort-Wrapper um fieldStyle() fuer den haeufigen
|
||||||
|
* Fall "genau ein Feld an einer festen Stelle im Markup". */
|
||||||
|
export function useTextStyle(fieldKey) {
|
||||||
|
const styles = useContext(TextStylesContext);
|
||||||
|
return fieldStyle(styles, fieldKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Die komplette geladene Styles-Map - fuer Stellen, die mehrere/dynamisch viele Keys pruefen
|
||||||
|
* muessen (siehe fieldStyle() oben). */
|
||||||
|
export function useTextStylesMap() {
|
||||||
|
return useContext(TextStylesContext);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { api } from '../../api/client.js';
|
import { api } from '../../api/client.js';
|
||||||
import ImageUploadField from '../../components/ImageUploadField.jsx';
|
import ImageUploadField from '../../components/ImageUploadField.jsx';
|
||||||
|
import TextStyleWidget from '../../components/TextStyleWidget.jsx';
|
||||||
|
|
||||||
const emptyForm = { name: '', image_path: '', sort_order: 0 };
|
const emptyForm = { name: '', image_path: '', sort_order: 0 };
|
||||||
|
|
||||||
|
|
@ -103,6 +104,7 @@ export default function Brands() {
|
||||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||||
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
||||||
/>
|
/>
|
||||||
|
{editingId && <TextStyleWidget fieldKey={`brands.${editingId}.name`} previewText={form.name || 'Beispieltext'} />}
|
||||||
</div>
|
</div>
|
||||||
<ImageUploadField
|
<ImageUploadField
|
||||||
value={form.image_path}
|
value={form.image_path}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { api } from '../../api/client.js';
|
import { api } from '../../api/client.js';
|
||||||
import ImageUploadField from '../../components/ImageUploadField.jsx';
|
import ImageUploadField from '../../components/ImageUploadField.jsx';
|
||||||
|
import TextStyleWidget from '../../components/TextStyleWidget.jsx';
|
||||||
|
|
||||||
const emptyForm = { name: '', brand_id: '', image_path: '', sort_order: 0 };
|
const emptyForm = { name: '', brand_id: '', image_path: '', sort_order: 0 };
|
||||||
|
|
||||||
|
|
@ -145,6 +146,7 @@ export default function Models() {
|
||||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||||
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
||||||
/>
|
/>
|
||||||
|
{editingId && <TextStyleWidget fieldKey={`car_models.${editingId}.name`} previewText={form.name || 'Beispieltext'} />}
|
||||||
</div>
|
</div>
|
||||||
<ImageUploadField
|
<ImageUploadField
|
||||||
value={form.image_path}
|
value={form.image_path}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { api } from '../../api/client.js';
|
import { api } from '../../api/client.js';
|
||||||
import { PACKAGE_TIERS, tierSortOrder } from '../../constants/packageTiers.js';
|
import { PACKAGE_TIERS, tierSortOrder } from '../../constants/packageTiers.js';
|
||||||
|
import TextStyleWidget from '../../components/TextStyleWidget.jsx';
|
||||||
|
|
||||||
const inputCls =
|
const inputCls =
|
||||||
'w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900';
|
'w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900';
|
||||||
|
|
@ -86,6 +87,28 @@ export default function Packages() {
|
||||||
const [copyResult, setCopyResult] = useState(null); // { text } | { error }
|
const [copyResult, setCopyResult] = useState(null); // { text } | { error }
|
||||||
const [brandFilter, setBrandFilter] = useState('all');
|
const [brandFilter, setBrandFilter] = useState('all');
|
||||||
const [modelFilter, setModelFilter] = useState('all');
|
const [modelFilter, setModelFilter] = useState('all');
|
||||||
|
const descriptionRefs = useRef(new Map());
|
||||||
|
|
||||||
|
// Umschliesst (oder entfernt, falls schon umschlossen) die aktuelle Textauswahl im
|
||||||
|
// Beschreibungsfeld mit ** - so laesst sich ein einzelner Stichpunkt/Wort fett hervorheben,
|
||||||
|
// ohne dass die Beschreibung insgesamt zu einem vollen Rich-Text-Feld werden muss (siehe
|
||||||
|
// BoldText.jsx fuer die oeffentliche Darstellung).
|
||||||
|
const toggleBoldSelection = (rowKey) => {
|
||||||
|
const el = descriptionRefs.current.get(rowKey);
|
||||||
|
if (!el) return;
|
||||||
|
const { selectionStart: start, selectionEnd: end, value } = el;
|
||||||
|
if (start === end) return;
|
||||||
|
const selected = value.slice(start, end);
|
||||||
|
const isBold = selected.startsWith('**') && selected.endsWith('**') && selected.length >= 4;
|
||||||
|
const replacement = isBold ? selected.slice(2, -2) : `**${selected}**`;
|
||||||
|
const next = value.slice(0, start) + replacement + value.slice(end);
|
||||||
|
updateRowForm(rowKey, { description: next });
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
el.focus();
|
||||||
|
const cursor = start + replacement.length;
|
||||||
|
el.setSelectionRange(cursor, cursor);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
const [pkgs, mdls] = await Promise.all([api.get('/packages'), api.get('/models')]);
|
const [pkgs, mdls] = await Promise.all([api.get('/packages'), api.get('/models')]);
|
||||||
|
|
@ -506,15 +529,32 @@ export default function Packages() {
|
||||||
<div>
|
<div>
|
||||||
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">Beschreibung</label>
|
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">Beschreibung</label>
|
||||||
<p className="mb-1 text-xs text-neutral-500 dark:text-neutral-400">
|
<p className="mb-1 text-xs text-neutral-500 dark:text-neutral-400">
|
||||||
Jede Zeile erscheint als eigener Stichpunkt zusammen mit den Bauteilen.
|
Jede Zeile erscheint als eigener Stichpunkt zusammen mit den Bauteilen. Text markieren und
|
||||||
|
"Fett" klicken, um nur diese Stelle hervorzuheben.
|
||||||
</p>
|
</p>
|
||||||
|
<div className="mb-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => toggleBoldSelection(row.key)}
|
||||||
|
className="rounded-md border border-neutral-300 px-2 py-1 text-xs font-bold text-neutral-600 hover:bg-neutral-100 dark:border-neutral-700 dark:text-neutral-300 dark:hover:bg-neutral-800"
|
||||||
|
>
|
||||||
|
Fett
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<textarea
|
<textarea
|
||||||
|
ref={(el) => descriptionRefs.current.set(row.key, el)}
|
||||||
rows={10}
|
rows={10}
|
||||||
value={row.form.description}
|
value={row.form.description}
|
||||||
onChange={(e) => updateRowForm(row.key, { description: e.target.value })}
|
onChange={(e) => updateRowForm(row.key, { description: e.target.value })}
|
||||||
onInput={autoGrow}
|
onInput={autoGrow}
|
||||||
className={inputCls}
|
className={inputCls}
|
||||||
/>
|
/>
|
||||||
|
{row.existing && (
|
||||||
|
<TextStyleWidget
|
||||||
|
fieldKey={`packages.${row.existing.id}.description`}
|
||||||
|
previewText="Beispieltext"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -561,6 +601,12 @@ export default function Packages() {
|
||||||
className={inputCls}
|
className={inputCls}
|
||||||
/>
|
/>
|
||||||
<p className="mt-1 text-xs text-neutral-400">Ersetzt auf der Kachel den berechneten Preis, solange ausgefüllt.</p>
|
<p className="mt-1 text-xs text-neutral-400">Ersetzt auf der Kachel den berechneten Preis, solange ausgefüllt.</p>
|
||||||
|
{row.existing && (
|
||||||
|
<TextStyleWidget
|
||||||
|
fieldKey={`packages.${row.existing.id}.price_text`}
|
||||||
|
previewText="Beispieltext"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<label className="flex items-center gap-2 text-sm text-neutral-700 dark:text-neutral-300">
|
<label className="flex items-center gap-2 text-sm text-neutral-700 dark:text-neutral-300">
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import MaintenanceNotice from '../../components/MaintenanceNotice.jsx';
|
||||||
import MaintenanceBypassBanner from '../../components/MaintenanceBypassBanner.jsx';
|
import MaintenanceBypassBanner from '../../components/MaintenanceBypassBanner.jsx';
|
||||||
import { useMaintenance } from '../../context/MaintenanceContext.jsx';
|
import { useMaintenance } from '../../context/MaintenanceContext.jsx';
|
||||||
import { useLanguage } from '../../context/LanguageContext.jsx';
|
import { useLanguage } from '../../context/LanguageContext.jsx';
|
||||||
|
import { fieldStyle, useTextStyle, useTextStylesMap } from '../../context/TextStylesContext.jsx';
|
||||||
|
|
||||||
export default function BrandPage() {
|
export default function BrandPage() {
|
||||||
const { brandSlug } = useParams();
|
const { brandSlug } = useParams();
|
||||||
|
|
@ -13,6 +14,8 @@ export default function BrandPage() {
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const maintenance = useMaintenance();
|
const maintenance = useMaintenance();
|
||||||
const { t } = useLanguage();
|
const { t } = useLanguage();
|
||||||
|
const textStyles = useTextStylesMap();
|
||||||
|
const brandNameStyle = useTextStyle(data ? `brands.${data.brand.id}.name` : '');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (maintenance.vehicles.enabled && !maintenance.bypass) return;
|
if (maintenance.vehicles.enabled && !maintenance.bypass) return;
|
||||||
|
|
@ -44,10 +47,10 @@ export default function BrandPage() {
|
||||||
<div className="mx-auto max-w-6xl px-4 py-12 sm:px-6">
|
<div className="mx-auto max-w-6xl px-4 py-12 sm:px-6">
|
||||||
{maintenance.vehicles.enabled && maintenance.bypass && <MaintenanceBypassBanner inline />}
|
{maintenance.vehicles.enabled && maintenance.bypass && <MaintenanceBypassBanner inline />}
|
||||||
<p className="mb-1 text-sm text-neutral-500 dark:text-neutral-400">
|
<p className="mb-1 text-sm text-neutral-500 dark:text-neutral-400">
|
||||||
<Link to="/fahrzeuge" className="hover:text-brand-500">{t('brandPage.breadcrumbVehicles')}</Link> / {data.brand.name}
|
<Link to="/fahrzeuge" className="hover:text-brand-500">{t('brandPage.breadcrumbVehicles')}</Link> / <span style={brandNameStyle}>{data.brand.name}</span>
|
||||||
</p>
|
</p>
|
||||||
<h1 className="mb-8 text-2xl font-bold text-neutral-900 dark:text-white sm:text-3xl">
|
<h1 className="mb-8 text-2xl font-bold text-neutral-900 dark:text-white sm:text-3xl">
|
||||||
{data.brand.name} – {t('brandPage.titleSuffix')}
|
<span style={brandNameStyle}>{data.brand.name}</span> – {t('brandPage.titleSuffix')}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{data.models.length === 0 && (
|
{data.models.length === 0 && (
|
||||||
|
|
@ -64,7 +67,7 @@ export default function BrandPage() {
|
||||||
{model.image_path && (
|
{model.image_path && (
|
||||||
<img src={model.image_path} alt="" className="h-16 w-full object-contain" />
|
<img src={model.image_path} alt="" className="h-16 w-full object-contain" />
|
||||||
)}
|
)}
|
||||||
{model.name}
|
<span style={fieldStyle(textStyles, `car_models.${model.id}.name`)}>{model.name}</span>
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import { ChevronLeft, ChevronRight, Mouse } from 'lucide-react';
|
||||||
import { useMaintenance } from '../../context/MaintenanceContext.jsx';
|
import { useMaintenance } from '../../context/MaintenanceContext.jsx';
|
||||||
import { useLanguage } from '../../context/LanguageContext.jsx';
|
import { useLanguage } from '../../context/LanguageContext.jsx';
|
||||||
import { useSiteSettings } from '../../context/SiteSettingsContext.jsx';
|
import { useSiteSettings } from '../../context/SiteSettingsContext.jsx';
|
||||||
|
import { fieldStyle, useTextStyle, useTextStylesMap } from '../../context/TextStylesContext.jsx';
|
||||||
|
import BoldText from '../../components/BoldText.jsx';
|
||||||
import roadGlowTexture from '../../assets/textures/road-glow.webp';
|
import roadGlowTexture from '../../assets/textures/road-glow.webp';
|
||||||
// Die 8 fertigen "Straßen"-Glow-Bilder aus dem Kunden-Referenzdesign (Kacheln.html) -
|
// Die 8 fertigen "Straßen"-Glow-Bilder aus dem Kunden-Referenzdesign (Kacheln.html) -
|
||||||
// je Preisstufe ein eigenes Bild (Grau -> Petrol -> Gruen -> Gold). Wurden 1:1 aus der
|
// je Preisstufe ein eigenes Bild (Grau -> Petrol -> Gruen -> Gold). Wurden 1:1 aus der
|
||||||
|
|
@ -96,6 +98,9 @@ function PackageCard({ pkg, tier, tierT, layout, bullets, formatPrice, contactUr
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
const hiddenCount = bullets.length - VISIBLE_BULLETS;
|
const hiddenCount = bullets.length - VISIBLE_BULLETS;
|
||||||
const shownBullets = expanded ? bullets : bullets.slice(0, VISIBLE_BULLETS);
|
const shownBullets = expanded ? bullets : bullets.slice(0, VISIBLE_BULLETS);
|
||||||
|
const textStyles = useTextStylesMap();
|
||||||
|
const descriptionStyle = fieldStyle(textStyles, `packages.${pkg.id}.description`);
|
||||||
|
const priceTextStyle = fieldStyle(textStyles, `packages.${pkg.id}.price_text`);
|
||||||
|
|
||||||
// Fuer die Themes ohne eigenes Straßenbild: neutrales Glow-Motiv, per Maske
|
// Fuer die Themes ohne eigenes Straßenbild: neutrales Glow-Motiv, per Maske
|
||||||
// in die Akzentfarbe eingefaerbt (zwei Ebenen: weicher Halo + scharfe Kontur).
|
// in die Akzentfarbe eingefaerbt (zwei Ebenen: weicher Halo + scharfe Kontur).
|
||||||
|
|
@ -201,9 +206,15 @@ function PackageCard({ pkg, tier, tierT, layout, bullets, formatPrice, contactUr
|
||||||
>
|
>
|
||||||
<ul className="space-y-1.5 text-left">
|
<ul className="space-y-1.5 text-left">
|
||||||
{shownBullets.map((line, i) => (
|
{shownBullets.map((line, i) => (
|
||||||
<li key={i} className="flex items-start gap-2" style={{ fontSize: '13px', color: BULLET_COLOR }}>
|
<li
|
||||||
|
key={i}
|
||||||
|
className="flex items-start gap-2"
|
||||||
|
style={{ fontSize: '13px', color: BULLET_COLOR, ...(line.fromDescription ? descriptionStyle : null) }}
|
||||||
|
>
|
||||||
<DynamicIcon name="check" className="mt-0.5 h-3.5 w-3.5 shrink-0" style={{ color: tier.accent }} />
|
<DynamicIcon name="check" className="mt-0.5 h-3.5 w-3.5 shrink-0" style={{ color: tier.accent }} />
|
||||||
<span className="leading-snug">{line}</span>
|
<span className="leading-snug">
|
||||||
|
{line.fromDescription ? <BoldText text={line.text} /> : line.text}
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
@ -243,6 +254,7 @@ function PackageCard({ pkg, tier, tierT, layout, bullets, formatPrice, contactUr
|
||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
letterSpacing: '1px',
|
letterSpacing: '1px',
|
||||||
color: PRICE_COLOR,
|
color: PRICE_COLOR,
|
||||||
|
...(pkg.price_text ? priceTextStyle : null),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{pkg.price_text || formatPrice(pkg.total_price)}
|
{pkg.price_text || formatPrice(pkg.total_price)}
|
||||||
|
|
@ -551,6 +563,8 @@ export default function ModelPage() {
|
||||||
path: `/fahrzeuge/${brandSlug}/${modelSlug}`,
|
path: `/fahrzeuge/${brandSlug}/${modelSlug}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const modelNameStyle = useTextStyle(data ? `car_models.${data.model.id}.name` : '');
|
||||||
|
|
||||||
if (maintenance.vehicles.enabled && !maintenance.bypass) {
|
if (maintenance.vehicles.enabled && !maintenance.bypass) {
|
||||||
return <MaintenanceNotice message={maintenance.vehicles.message} />;
|
return <MaintenanceNotice message={maintenance.vehicles.message} />;
|
||||||
}
|
}
|
||||||
|
|
@ -585,11 +599,12 @@ export default function ModelPage() {
|
||||||
// Stichpunkte einer Kachel = die Produkte des Pakets plus die Freitext-Zeilen der
|
// Stichpunkte einer Kachel = die Produkte des Pakets plus die Freitext-Zeilen der
|
||||||
// Beschreibung (je Zeile ein Punkt). Das ist der einzige Zusatz zum Referenzdesign.
|
// Beschreibung (je Zeile ein Punkt). Das ist der einzige Zusatz zum Referenzdesign.
|
||||||
const bulletsOf = (pkg) => [
|
const bulletsOf = (pkg) => [
|
||||||
...pkg.products.map((p) => p.name_override || p.scraped_name || t('modelPage.productLoading')),
|
...pkg.products.map((p) => ({ text: p.name_override || p.scraped_name || t('modelPage.productLoading'), fromDescription: false })),
|
||||||
...(pkg.description || '')
|
...(pkg.description || '')
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((line) => line.trim())
|
.map((line) => line.trim())
|
||||||
.filter(Boolean),
|
.filter(Boolean)
|
||||||
|
.map((text) => ({ text, fromDescription: true })),
|
||||||
];
|
];
|
||||||
|
|
||||||
const contactUrl = (pkg) => {
|
const contactUrl = (pkg) => {
|
||||||
|
|
@ -609,10 +624,10 @@ export default function ModelPage() {
|
||||||
{maintenance.vehicles.enabled && maintenance.bypass && <MaintenanceBypassBanner inline />}
|
{maintenance.vehicles.enabled && maintenance.bypass && <MaintenanceBypassBanner inline />}
|
||||||
<p className="mb-1 text-sm text-neutral-500 dark:text-neutral-400">
|
<p className="mb-1 text-sm text-neutral-500 dark:text-neutral-400">
|
||||||
<Link to="/fahrzeuge" className="hover:text-brand-500">{t('modelPage.breadcrumbVehicles')}</Link> /{' '}
|
<Link to="/fahrzeuge" className="hover:text-brand-500">{t('modelPage.breadcrumbVehicles')}</Link> /{' '}
|
||||||
<Link to={`/fahrzeuge/${brandSlug}`} className="hover:text-brand-500">{model.brand_name}</Link> / {model.name}
|
<Link to={`/fahrzeuge/${brandSlug}`} className="hover:text-brand-500">{model.brand_name}</Link> / <span style={modelNameStyle}>{model.name}</span>
|
||||||
</p>
|
</p>
|
||||||
<h1 className={`text-2xl font-bold text-neutral-900 dark:text-white sm:text-3xl ${packages.length ? 'mb-2' : 'mb-8'}`}>
|
<h1 className={`text-2xl font-bold text-neutral-900 dark:text-white sm:text-3xl ${packages.length ? 'mb-2' : 'mb-8'}`}>
|
||||||
{model.brand_name} {model.name} – {t('modelPage.titleSuffix')}
|
{model.brand_name} <span style={modelNameStyle}>{model.name}</span> – {t('modelPage.titleSuffix')}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{packages.length === 0 && (
|
{packages.length === 0 && (
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,14 @@ import MaintenanceNotice from '../../components/MaintenanceNotice.jsx';
|
||||||
import MaintenanceBypassBanner from '../../components/MaintenanceBypassBanner.jsx';
|
import MaintenanceBypassBanner from '../../components/MaintenanceBypassBanner.jsx';
|
||||||
import { useMaintenance } from '../../context/MaintenanceContext.jsx';
|
import { useMaintenance } from '../../context/MaintenanceContext.jsx';
|
||||||
import { useLanguage } from '../../context/LanguageContext.jsx';
|
import { useLanguage } from '../../context/LanguageContext.jsx';
|
||||||
|
import { fieldStyle, useTextStylesMap } from '../../context/TextStylesContext.jsx';
|
||||||
|
|
||||||
export default function VehicleSelect() {
|
export default function VehicleSelect() {
|
||||||
const [brands, setBrands] = useState([]);
|
const [brands, setBrands] = useState([]);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const maintenance = useMaintenance();
|
const maintenance = useMaintenance();
|
||||||
const { t } = useLanguage();
|
const { t } = useLanguage();
|
||||||
|
const textStyles = useTextStylesMap();
|
||||||
|
|
||||||
usePageMeta({
|
usePageMeta({
|
||||||
title: t('vehicleSelect.metaTitle'),
|
title: t('vehicleSelect.metaTitle'),
|
||||||
|
|
@ -52,7 +54,7 @@ export default function VehicleSelect() {
|
||||||
{brand.image_path && (
|
{brand.image_path && (
|
||||||
<img src={brand.image_path} alt="" className="h-16 w-full object-contain" />
|
<img src={brand.image_path} alt="" className="h-16 w-full object-contain" />
|
||||||
)}
|
)}
|
||||||
{brand.name}
|
<span style={fieldStyle(textStyles, `brands.${brand.id}.name`)}>{brand.name}</span>
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Controllers;
|
||||||
use App\Config\Database;
|
use App\Config\Database;
|
||||||
use App\Support\Http;
|
use App\Support\Http;
|
||||||
use App\Support\Slug;
|
use App\Support\Slug;
|
||||||
|
use App\Support\TextStyleCleanup;
|
||||||
use App\Support\Uploads;
|
use App\Support\Uploads;
|
||||||
|
|
||||||
class BrandController
|
class BrandController
|
||||||
|
|
@ -80,19 +81,36 @@ class BrandController
|
||||||
$oldStmt->execute([$id]);
|
$oldStmt->execute([$id]);
|
||||||
$oldImagePath = $oldStmt->fetchColumn();
|
$oldImagePath = $oldStmt->fetchColumn();
|
||||||
|
|
||||||
// ON DELETE CASCADE raeumt car_models in der DB mit auf - deren Bilddateien vorher
|
// ON DELETE CASCADE raeumt car_models (und darueber packages) in der DB mit auf - deren
|
||||||
// einsammeln, danach sind die Zeilen (und Pfade) weg.
|
// Bilddateien und text_styles-Zeilen vorher einsammeln, danach sind die Zeilen weg.
|
||||||
$modelImagesStmt = $db->prepare('SELECT image_path FROM car_models WHERE brand_id = ?');
|
$modelsStmt = $db->prepare('SELECT id, image_path FROM car_models WHERE brand_id = ?');
|
||||||
$modelImagesStmt->execute([$id]);
|
$modelsStmt->execute([$id]);
|
||||||
$modelImages = $modelImagesStmt->fetchAll(\PDO::FETCH_COLUMN);
|
$models = $modelsStmt->fetchAll();
|
||||||
|
$modelIds = array_column($models, 'id');
|
||||||
|
|
||||||
|
$packageIds = [];
|
||||||
|
if ($modelIds) {
|
||||||
|
$placeholders = implode(',', array_fill(0, count($modelIds), '?'));
|
||||||
|
$packagesStmt = $db->prepare("SELECT id FROM packages WHERE car_model_id IN ($placeholders)");
|
||||||
|
$packagesStmt->execute($modelIds);
|
||||||
|
$packageIds = $packagesStmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
}
|
||||||
|
|
||||||
$stmt = $db->prepare('DELETE FROM brands WHERE id = ?');
|
$stmt = $db->prepare('DELETE FROM brands WHERE id = ?');
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
foreach ([$oldImagePath, ...$modelImages] as $path) {
|
foreach ([$oldImagePath, ...array_column($models, 'image_path')] as $path) {
|
||||||
Uploads::deleteIfOrphaned($path ?: null, null);
|
Uploads::deleteIfOrphaned($path ?: null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextStyleCleanup::forgetEntity('brands', (string) $id);
|
||||||
|
foreach ($modelIds as $modelId) {
|
||||||
|
TextStyleCleanup::forgetEntity('car_models', (string) $modelId);
|
||||||
|
}
|
||||||
|
foreach ($packageIds as $packageId) {
|
||||||
|
TextStyleCleanup::forgetEntity('packages', (string) $packageId);
|
||||||
|
}
|
||||||
|
|
||||||
Http::send(['ok' => true]);
|
Http::send(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Controllers;
|
||||||
use App\Config\Database;
|
use App\Config\Database;
|
||||||
use App\Support\Http;
|
use App\Support\Http;
|
||||||
use App\Support\Slug;
|
use App\Support\Slug;
|
||||||
|
use App\Support\TextStyleCleanup;
|
||||||
use App\Support\Uploads;
|
use App\Support\Uploads;
|
||||||
|
|
||||||
class ModelController
|
class ModelController
|
||||||
|
|
@ -87,11 +88,22 @@ class ModelController
|
||||||
$oldStmt->execute([$id]);
|
$oldStmt->execute([$id]);
|
||||||
$oldImagePath = $oldStmt->fetchColumn();
|
$oldImagePath = $oldStmt->fetchColumn();
|
||||||
|
|
||||||
|
// ON DELETE CASCADE raeumt packages in der DB mit auf - deren text_styles-Zeilen
|
||||||
|
// vorher einsammeln, danach ist die Zuordnung weg.
|
||||||
|
$packagesStmt = $db->prepare('SELECT id FROM packages WHERE car_model_id = ?');
|
||||||
|
$packagesStmt->execute([$id]);
|
||||||
|
$packageIds = $packagesStmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
$stmt = $db->prepare('DELETE FROM car_models WHERE id = ?');
|
$stmt = $db->prepare('DELETE FROM car_models WHERE id = ?');
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
Uploads::deleteIfOrphaned($oldImagePath ?: null, null);
|
Uploads::deleteIfOrphaned($oldImagePath ?: null, null);
|
||||||
|
|
||||||
|
TextStyleCleanup::forgetEntity('car_models', (string) $id);
|
||||||
|
foreach ($packageIds as $packageId) {
|
||||||
|
TextStyleCleanup::forgetEntity('packages', (string) $packageId);
|
||||||
|
}
|
||||||
|
|
||||||
Http::send(['ok' => true]);
|
Http::send(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Controllers;
|
||||||
use App\Config\Database;
|
use App\Config\Database;
|
||||||
use App\Support\Http;
|
use App\Support\Http;
|
||||||
use App\Support\Slug;
|
use App\Support\Slug;
|
||||||
|
use App\Support\TextStyleCleanup;
|
||||||
|
|
||||||
class PackageController
|
class PackageController
|
||||||
{
|
{
|
||||||
|
|
@ -192,8 +193,10 @@ class PackageController
|
||||||
|
|
||||||
public static function destroy(array $params): void
|
public static function destroy(array $params): void
|
||||||
{
|
{
|
||||||
|
$id = (int) $params['id'];
|
||||||
$stmt = Database::connection()->prepare('DELETE FROM packages WHERE id = ?');
|
$stmt = Database::connection()->prepare('DELETE FROM packages WHERE id = ?');
|
||||||
$stmt->execute([(int) $params['id']]);
|
$stmt->execute([$id]);
|
||||||
|
TextStyleCleanup::forgetEntity('packages', (string) $id);
|
||||||
Http::send(['ok' => true]);
|
Http::send(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -337,14 +337,24 @@ class SettingsController
|
||||||
$db = Database::connection();
|
$db = Database::connection();
|
||||||
$brandCount = (int) $db->query('SELECT COUNT(*) FROM brands')->fetchColumn();
|
$brandCount = (int) $db->query('SELECT COUNT(*) FROM brands')->fetchColumn();
|
||||||
$db->exec('DELETE FROM brands');
|
$db->exec('DELETE FROM brands');
|
||||||
|
self::forgetCatalogTextStyles($db);
|
||||||
Http::send(['ok' => true, 'brands_removed' => $brandCount]);
|
Http::send(['ok' => true, 'brands_removed' => $brandCount]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kaskade beim Loeschen von brands/car_models/packages raeumt selbst keine text_styles-
|
||||||
|
// Zeilen auf (die Tabelle hat keinen Fremdschluessel dorthin) - hier nach einem
|
||||||
|
// Massen-Reset in einem Rutsch erledigt statt pro Zeile einzeln.
|
||||||
|
private static function forgetCatalogTextStyles(\PDO $db): void
|
||||||
|
{
|
||||||
|
$db->exec("DELETE FROM text_styles WHERE field_key LIKE 'brands.%' OR field_key LIKE 'car_models.%' OR field_key LIKE 'packages.%'");
|
||||||
|
}
|
||||||
|
|
||||||
public static function resetAll(): void
|
public static function resetAll(): void
|
||||||
{
|
{
|
||||||
$db = Database::connection();
|
$db = Database::connection();
|
||||||
$brandCount = (int) $db->query('SELECT COUNT(*) FROM brands')->fetchColumn();
|
$brandCount = (int) $db->query('SELECT COUNT(*) FROM brands')->fetchColumn();
|
||||||
$db->exec('DELETE FROM brands');
|
$db->exec('DELETE FROM brands');
|
||||||
|
self::forgetCatalogTextStyles($db);
|
||||||
|
|
||||||
$defaults = self::defaultServices();
|
$defaults = self::defaultServices();
|
||||||
$db->exec('DELETE FROM services');
|
$db->exec('DELETE FROM services');
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,20 @@ class TextStyleFields
|
||||||
'columns' => ['eyebrow', 'title', 'button_label'],
|
'columns' => ['eyebrow', 'title', 'button_label'],
|
||||||
'permission' => 'content.manage',
|
'permission' => 'content.manage',
|
||||||
],
|
],
|
||||||
|
'brands' => [
|
||||||
|
'key_type' => 'id',
|
||||||
|
'columns' => ['name'],
|
||||||
|
'permission' => 'brands.manage',
|
||||||
|
],
|
||||||
|
'car_models' => [
|
||||||
|
'key_type' => 'id',
|
||||||
|
'columns' => ['name'],
|
||||||
|
'permission' => 'models.manage',
|
||||||
|
],
|
||||||
|
'packages' => [
|
||||||
|
'key_type' => 'id',
|
||||||
|
'columns' => ['description', 'price_text'],
|
||||||
|
'permission' => 'packages.manage',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
325
hifi/assets/index-kZ4ovh9r.js
Normal file
325
hifi/assets/index-kZ4ovh9r.js
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -43,7 +43,7 @@
|
||||||
"sameAs": ["https://www.youtube.com/@hifiplanet2812"]
|
"sameAs": ["https://www.youtube.com/@hifiplanet2812"]
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="module" crossorigin src="/assets/index-D4_C7pxq.js"></script>
|
<script type="module" crossorigin src="/assets/index-kZ4ovh9r.js"></script>
|
||||||
<link rel="modulepreload" crossorigin href="/assets/lucide-icons-Cg2IxtAO.js">
|
<link rel="modulepreload" crossorigin href="/assets/lucide-icons-Cg2IxtAO.js">
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-lUKoqEad.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-lUKoqEad.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue