feat(cms): add static pages module
This commit is contained in:
@@ -11,6 +11,7 @@ import { UiRuntimeFacade } from '../../facades/runtime/ui-runtime.facade';
|
||||
import { UserExperienceFacade } from '../../facades/platform/user-experience.facade';
|
||||
import { ConfigService } from '../../core/config/config.service';
|
||||
import { DEFAULT_HEADER_CONFIG, DEFAULT_USER_EXPERIENCE_CONFIG } from '../../shared/models/config';
|
||||
import { StaticPageResolverService } from '../../core/config/static-page-resolver.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-header',
|
||||
@@ -30,11 +31,13 @@ export class HeaderComponent {
|
||||
private uiRuntime = inject(UiRuntimeFacade);
|
||||
private uxFacade = inject(UserExperienceFacade);
|
||||
private configService = inject(ConfigService);
|
||||
private staticPageResolver = inject(StaticPageResolverService);
|
||||
|
||||
readonly wishlistCount = this.uxFacade.wishlistCount;
|
||||
readonly compareCount = this.uxFacade.compareCount;
|
||||
readonly userExperienceConfig = computed(() => this.resolveUserExperienceConfig());
|
||||
readonly headerConfig = computed(() => this.resolveHeaderConfig());
|
||||
readonly headerPages = computed(() => this.resolveHeaderPages());
|
||||
|
||||
constructor(private cartService: CartService, private router: Router) {
|
||||
this.cartItemCount = this.cartService.itemCount;
|
||||
@@ -111,6 +114,12 @@ export class HeaderComponent {
|
||||
this.router.navigate([`/${lang}/compare`]);
|
||||
}
|
||||
|
||||
navigateToStatic(route: string): void {
|
||||
this.closeMenu();
|
||||
const lang = this.langService.currentLanguage();
|
||||
this.router.navigate([`/${lang}${route.startsWith('/') ? route : `/${route}`}`]);
|
||||
}
|
||||
|
||||
formatCartTotal(total: number): string {
|
||||
const locale = this.langService.currentLanguage() === 'en'
|
||||
? 'en-US'
|
||||
@@ -154,6 +163,31 @@ export class HeaderComponent {
|
||||
...raw,
|
||||
};
|
||||
}
|
||||
|
||||
private resolveHeaderPages() {
|
||||
this.configService.bootstrapRevision();
|
||||
const bootstrap = this.configService.getBootstrapSnapshot();
|
||||
if (!bootstrap?.staticPages) {
|
||||
return [] as Array<{ id: string; title: string; route: string; icon?: string; order: number }>;
|
||||
}
|
||||
|
||||
const lang = this.langService.currentLanguage();
|
||||
const pages = Object.values(bootstrap.staticPages as Record<string, any>)
|
||||
.filter(page => page.showInHeader === true)
|
||||
.map(page => {
|
||||
const resolved = this.staticPageResolver.resolveByKeyFromBootstrap(bootstrap, page.id, lang);
|
||||
return resolved ? {
|
||||
id: resolved.id,
|
||||
title: resolved.title,
|
||||
route: resolved.route,
|
||||
icon: resolved.icon,
|
||||
order: page.order ?? 0,
|
||||
} : null;
|
||||
})
|
||||
.filter((page): page is { id: string; title: string; route: string; icon: string | undefined; order: number } => page !== null);
|
||||
|
||||
return pages.sort((left, right) => left.order - right.order);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user