From e4aef0ec2d69d4601ff724617ff64a381be40cb1 Mon Sep 17 00:00:00 2001 From: Silke Date: Fri, 26 Jan 2024 10:08:03 +0100 Subject: [PATCH] feat(Design View): provide page structure tree information for the Design View (#1577) * provide include IDs * provide page IDs * provide view context IDs * add resource type to the content artifacts --- .../utils/design-view/design-view.service.ts | 42 +++++++++++++++++-- .../pages/content/content-page.component.html | 7 +++- .../content-viewcontext.component.ts | 12 +++++- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/app/core/utils/design-view/design-view.service.ts b/src/app/core/utils/design-view/design-view.service.ts index 94d313ad82..d7cac5b890 100644 --- a/src/app/core/utils/design-view/design-view.service.ts +++ b/src/app/core/utils/design-view/design-view.service.ts @@ -1,7 +1,7 @@ import { ApplicationRef, Injectable } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; import { Store, select } from '@ngrx/store'; -import { filter, first, fromEvent, map, switchMap } from 'rxjs'; +import { filter, first, fromEvent, map, switchMap, tap } from 'rxjs'; import { getCurrentLocale } from 'ish-core/store/core/configuration'; import { DomService } from 'ish-core/utils/dom/dom.service'; @@ -14,7 +14,8 @@ interface DesignViewMessage { | 'dv-clientReady' | 'dv-clientRefresh' | 'dv-clientLocale' - | 'dv-clientStable'; + | 'dv-clientStable' + | 'dv-clientContentIds'; // eslint-disable-next-line @typescript-eslint/no-explicit-any payload?: any; } @@ -97,10 +98,18 @@ export class DesignViewService { const navigationStable$ = navigation$.pipe(switchMap(() => stable$)); // send `dv-clientNavigation` event for each route change - navigation$.subscribe(e => this.messageToHost({ type: 'dv-clientNavigation', payload: { url: e.url } })); + navigation$ + .pipe( + tap(e => this.messageToHost({ type: 'dv-clientNavigation', payload: { url: e.url } })), + switchMap(() => this.appRef.isStable.pipe(whenTruthy(), first())) + ) + .subscribe(() => { + this.sendContentIds(); + }); stable$.subscribe(() => { this.applyHierarchyHighlighting(); + this.sendContentIds(); }); // send `dv-clientStable` event when application is stable or loading of the content included finished @@ -137,7 +146,6 @@ export class DesignViewService { /** * Workaround for the missing Firefox CSS support for :has to highlight * only the last .design-view-wrapper in the .design-view-wrapper hierarchy. - * */ private applyHierarchyHighlighting() { const designViewWrapper: NodeListOf = document.querySelectorAll('.design-view-wrapper'); @@ -148,4 +156,30 @@ export class DesignViewService { } }); } + + /** + * Send IDs of the content artifacts (content includes, content pages, view contexts) to the Design View system. + */ + private sendContentIds() { + const contentIds: { id: string; resource: 'includes' | 'pages' | 'viewcontexts' }[] = []; + document.querySelectorAll('[includeid], [pageid], [viewcontextid]').forEach(element => { + // transfer only view contexts that have call parameters + if (element.getAttribute('viewcontextid')) { + const callParams = element.getAttribute('callparametersstring'); + if (callParams) { + contentIds.push({ + id: `${element.getAttribute('viewcontextid')}/entrypoint?${callParams}`, + resource: 'viewcontexts', + }); + } + } else { + contentIds.push( + element.getAttribute('includeid') + ? { id: element.getAttribute('includeid'), resource: 'includes' } + : { id: element.getAttribute('pageid'), resource: 'pages' } + ); + } + }); + this.messageToHost({ type: 'dv-clientContentIds', payload: { contentIds } }); + } } diff --git a/src/app/pages/content/content-page.component.html b/src/app/pages/content/content-page.component.html index cf2d0ae51e..5902e60862 100644 --- a/src/app/pages/content/content-page.component.html +++ b/src/app/pages/content/content-page.component.html @@ -1,5 +1,10 @@ - + + diff --git a/src/app/shared/cms/components/content-viewcontext/content-viewcontext.component.ts b/src/app/shared/cms/components/content-viewcontext/content-viewcontext.component.ts index 06818a303e..7a7c3907bb 100644 --- a/src/app/shared/cms/components/content-viewcontext/content-viewcontext.component.ts +++ b/src/app/shared/cms/components/content-viewcontext/content-viewcontext.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core'; +import { ChangeDetectionStrategy, Component, ElementRef, Input, OnChanges } from '@angular/core'; import { Observable } from 'rxjs'; import { CMSFacade } from 'ish-core/facades/cms.facade'; @@ -34,9 +34,17 @@ export class ContentViewcontextComponent implements OnChanges { viewContextEntrypoint$: Observable; - constructor(private cmsFacade: CMSFacade) {} + constructor(private cmsFacade: CMSFacade, private hostElement: ElementRef) {} ngOnChanges() { this.viewContextEntrypoint$ = this.cmsFacade.viewContext$(this.viewContextId, this.callParameters); + + // the 'callparametersstring' attribute is needed for the Design View - do not remove this code + this.hostElement.nativeElement.setAttribute( + 'callparametersstring', + Object.keys(this.callParameters) + .map(key => `${key}=${this.callParameters[key]}`) + .join('&') + ); } }