arch(sprint1): resolve dynamic pages by route config

This commit is contained in:
sdarbinyan
2026-07-03 02:04:01 +04:00
parent ac48799d9a
commit d6a1d5e3f5
4 changed files with 59 additions and 9 deletions

View File

@@ -0,0 +1,49 @@
import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { ConfigService } from '../../core/config/config.service';
import { PageConfig } from '../../shared/models/config';
@Injectable({ providedIn: 'root' })
export class PageResolverService {
constructor(private readonly configService: ConfigService) {}
resolveByUrl(url: string): Observable<PageConfig | null> {
const pagePath = this.toPagePath(url);
return this.configService.loadBootstrap().pipe(
map((bootstrap) => {
return (
bootstrap.pages.find((page) => {
if (page.visible === false) {
return false;
}
return this.normalizePath(page.route.path) === pagePath;
}) ?? null
);
})
);
}
private toPagePath(url: string): string {
const noHash = url.split('#')[0];
const noQuery = noHash.split('?')[0];
const segments = noQuery.split('/').filter(Boolean);
const withoutLang = segments.length > 0 ? segments.slice(1) : [];
if (withoutLang.length === 0) {
return '/';
}
return this.normalizePath(`/${withoutLang.join('/')}`);
}
private normalizePath(path: string): string {
const trimmed = path.trim();
if (!trimmed || trimmed === '/') {
return '/';
}
return `/${trimmed.replace(/^\/+/, '').replace(/\/+$/, '')}`;
}
}

View File

@@ -1,16 +1,16 @@
import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { ConfigService } from '../../core/config/config.service';
import { BrandingEngineService } from '../../theme/runtime/branding-engine.service';
import { ThemeEngineService } from '../../theme/runtime/theme-engine.service';
import { PageRendererService } from '../../dynamic-renderer/page-renderer/page-renderer.service';
import { PageRenderModel } from '../../dynamic-renderer/page-renderer/page-renderer.model';
import { WidgetRegistryBootstrapService } from '../../widgets/registry/widget-registry.bootstrap.service';
import { PageResolverService } from '../../dynamic-renderer/page-resolver/page-resolver.service';
@Injectable({ providedIn: 'root' })
export class WebsiteRuntimeFacade {
constructor(
private readonly configService: ConfigService,
private readonly pageResolver: PageResolverService,
private readonly pageRenderer: PageRendererService,
private readonly registryBootstrap: WidgetRegistryBootstrapService,
private readonly themeEngine: ThemeEngineService,
@@ -23,10 +23,9 @@ export class WebsiteRuntimeFacade {
this.brandingEngine.initialize();
}
getPageRenderModel(pageKey: string): Observable<PageRenderModel | null> {
return this.configService.loadBootstrap().pipe(
map(bootstrap => {
const page = bootstrap.pages.find(p => p.key === pageKey && p.visible !== false);
getPageRenderModelForUrl(url: string): Observable<PageRenderModel | null> {
return this.pageResolver.resolveByUrl(url).pipe(
map(page => {
return page ? this.pageRenderer.toRenderModel(page) : null;
})
);

View File

@@ -1,4 +1,5 @@
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { Router } from '@angular/router';
import { DynamicPageLayoutComponent } from '../../layouts/containers/dynamic-page-layout.component';
import { PageRenderModel } from '../../dynamic-renderer/page-renderer/page-renderer.model';
import { WebsiteRuntimeFacade } from '../../facades/website/website-runtime.facade';
@@ -26,10 +27,11 @@ import { WebsiteRuntimeFacade } from '../../facades/website/website-runtime.faca
export class PlatformHomeComponent {
readonly model = signal<PageRenderModel | null>(null);
readonly loading = signal(true);
private readonly router = inject(Router);
constructor(private readonly websiteRuntime: WebsiteRuntimeFacade) {
this.websiteRuntime.initializeRuntime();
this.websiteRuntime.getPageRenderModel('home').subscribe({
this.websiteRuntime.getPageRenderModelForUrl(this.router.url).subscribe({
next: (model) => {
this.model.set(model);
this.loading.set(false);