2026-07-10 13:43:53 +04:00
|
|
|
import { CdkDragDrop, DragDropModule, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
|
|
|
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
|
|
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
|
import { ProjectEditorFacade } from '../facade/project-editor.facade';
|
|
|
|
|
import { TranslatePipe } from '../../../i18n/translate.pipe';
|
|
|
|
|
|
feat(project-editor): finish field descriptions + enum dropdowns across all sections
Wires up the remaining editor sections (theme, header, footer, homepage,
widgets, features, languages, navigation) with the description text and
dropdown UX started for General/Branding:
- Every enum-backed field is now a <select> with a description per option,
not free text: theme.mode, the new site-wide layout.type (previously had
no editor at all - added to the Theme section, and added to that
section's reset-scope), homepage section layout.strategy, and
catalog.navigationMode (also previously unedited, added to Features).
- Every other field (colors, header toggles, footer contact/company fields,
widget props, feature flags, language add, nav link label/url/visible)
gets a one-line plain-language description under its label via the new
*Desc i18n keys (en/ru/hy) prepared earlier.
- Genuinely open text (widget layout variant strings, JSON props) stays
free text, description-only, per the existing widgetLayoutDesc/widgetJsonDesc
wording - not force-fit into a dropdown.
Verified: tsc --noEmit and ng build both clean.
2026-07-15 00:45:41 +04:00
|
|
|
export interface LayoutStrategyOption {
|
|
|
|
|
value: 'stack' | 'grid' | 'hero' | 'carousel' | 'split';
|
|
|
|
|
labelKey: string;
|
|
|
|
|
descKey: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 13:43:53 +04:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-project-editor-homepage-section',
|
|
|
|
|
standalone: true,
|
|
|
|
|
imports: [DragDropModule, FormsModule, TranslatePipe],
|
|
|
|
|
templateUrl: './homepage-section.component.html',
|
|
|
|
|
styleUrls: ['./section.shared.scss'],
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
|
})
|
|
|
|
|
export class ProjectEditorHomepageSectionComponent {
|
|
|
|
|
private readonly facade = inject(ProjectEditorFacade);
|
|
|
|
|
readonly homePage = this.facade.homepagePage;
|
|
|
|
|
readonly sections = computed(() => [...(this.homePage()?.sections ?? [])].sort((a, b) => a.order - b.order));
|
|
|
|
|
|
feat(project-editor): finish field descriptions + enum dropdowns across all sections
Wires up the remaining editor sections (theme, header, footer, homepage,
widgets, features, languages, navigation) with the description text and
dropdown UX started for General/Branding:
- Every enum-backed field is now a <select> with a description per option,
not free text: theme.mode, the new site-wide layout.type (previously had
no editor at all - added to the Theme section, and added to that
section's reset-scope), homepage section layout.strategy, and
catalog.navigationMode (also previously unedited, added to Features).
- Every other field (colors, header toggles, footer contact/company fields,
widget props, feature flags, language add, nav link label/url/visible)
gets a one-line plain-language description under its label via the new
*Desc i18n keys (en/ru/hy) prepared earlier.
- Genuinely open text (widget layout variant strings, JSON props) stays
free text, description-only, per the existing widgetLayoutDesc/widgetJsonDesc
wording - not force-fit into a dropdown.
Verified: tsc --noEmit and ng build both clean.
2026-07-15 00:45:41 +04:00
|
|
|
readonly layoutStrategyOptions: LayoutStrategyOption[] = [
|
|
|
|
|
{ value: 'stack', labelKey: 'builder.layoutStrategyStack', descKey: 'builder.layoutStrategyStackDesc' },
|
|
|
|
|
{ value: 'grid', labelKey: 'builder.layoutStrategyGrid', descKey: 'builder.layoutStrategyGridDesc' },
|
|
|
|
|
{ value: 'hero', labelKey: 'builder.layoutStrategyHero', descKey: 'builder.layoutStrategyHeroDesc' },
|
|
|
|
|
{ value: 'carousel', labelKey: 'builder.layoutStrategyCarousel', descKey: 'builder.layoutStrategyCarouselDesc' },
|
|
|
|
|
{ value: 'split', labelKey: 'builder.layoutStrategySplit', descKey: 'builder.layoutStrategySplitDesc' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
layoutStrategyDescKey(strategy: string | undefined): string {
|
|
|
|
|
return this.layoutStrategyOptions.find(option => option.value === strategy)?.descKey ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 13:43:53 +04:00
|
|
|
drop(event: CdkDragDrop<any[]>): void {
|
|
|
|
|
const sections = [...this.sections()];
|
|
|
|
|
moveItemInArray(sections, event.previousIndex, event.currentIndex);
|
|
|
|
|
this.facade.updateBootstrap(current => ({
|
|
|
|
|
...current,
|
|
|
|
|
pages: current.pages.map(page => page.id !== this.homePage()?.id ? page : ({
|
|
|
|
|
...page,
|
|
|
|
|
sections: sections.map((section, index) => ({ ...section, order: index + 1 }))
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateSection(sectionId: string, field: 'visible' | 'type', value: unknown): void {
|
|
|
|
|
this.facade.updateBootstrap(current => ({
|
|
|
|
|
...current,
|
|
|
|
|
pages: current.pages.map(page => page.id !== this.homePage()?.id ? page : ({
|
|
|
|
|
...page,
|
|
|
|
|
sections: page.sections.map(section => section.id !== sectionId ? section : ({
|
|
|
|
|
...section,
|
|
|
|
|
...(field === 'type' ? { type: String(value) } : { visible: Boolean(value) })
|
|
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateLayout(sectionId: string, key: 'strategy' | 'columns', value: string): void {
|
|
|
|
|
this.facade.updateBootstrap(current => ({
|
|
|
|
|
...current,
|
|
|
|
|
pages: current.pages.map(page => page.id !== this.homePage()?.id ? page : ({
|
|
|
|
|
...page,
|
|
|
|
|
sections: page.sections.map(section => section.id !== sectionId ? section : ({
|
|
|
|
|
...section,
|
|
|
|
|
layout: {
|
|
|
|
|
...section.layout,
|
|
|
|
|
[key]: key === 'columns' ? Number(value) || 1 : value,
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|