2026-07-13 08:10:00 +04:00
|
|
|
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
|
|
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
|
import { ProjectEditorFacade } from '../facade/project-editor.facade';
|
|
|
|
|
import { TranslatePipe } from '../../../i18n/translate.pipe';
|
2026-07-17 16:18:22 +04:00
|
|
|
import { TranslateService } from '../../../i18n/translate.service';
|
feat(project-editor): adopt Design System primitives across editor sections
Applied app-input/app-form-field/app-button to 9 of 11 Project Editor
sections: general, branding, theme, footer, homepage, widgets, languages,
navigation, preview. header and features sections were left unchanged -
they contain only checkboxes and selects, and no Checkbox/Select primitive
exists yet.
Theme section's 8 color pickers stay native <input type=color> (app-input's
type union doesn't include 'color') but are now wrapped in app-form-field
for consistent label/hint treatment. Added app-form-field.full grid-column
rule to section.shared.scss (shared by all 11 sections) alongside the
existing label.full rule, since the custom element doesn't match that
selector.
Production build green, arch:check passes.
2026-07-15 07:55:38 +04:00
|
|
|
import { ButtonComponent } from '../../../shared/ui/button/button.component';
|
|
|
|
|
import { InputComponent } from '../../../shared/ui/input/input.component';
|
2026-07-16 02:10:38 +04:00
|
|
|
import { SectionCardComponent } from '../../../shared/ui/section-card/section-card.component';
|
|
|
|
|
import { LocaleTabsComponent } from '../../../shared/ui/locale-tabs/locale-tabs.component';
|
2026-07-13 08:10:00 +04:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-project-editor-languages-section',
|
|
|
|
|
standalone: true,
|
2026-07-16 02:10:38 +04:00
|
|
|
imports: [FormsModule, TranslatePipe, ButtonComponent, InputComponent, SectionCardComponent, LocaleTabsComponent],
|
2026-07-13 08:10:00 +04:00
|
|
|
templateUrl: './languages-section.component.html',
|
|
|
|
|
styleUrls: ['./section.shared.scss'],
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
|
})
|
|
|
|
|
export class ProjectEditorLanguagesSectionComponent {
|
|
|
|
|
private readonly facade = inject(ProjectEditorFacade);
|
2026-07-17 16:18:22 +04:00
|
|
|
private readonly translate = inject(TranslateService);
|
2026-07-13 08:10:00 +04:00
|
|
|
readonly bootstrap = this.facade.bootstrap;
|
2026-07-17 16:18:22 +04:00
|
|
|
readonly fieldError = (key: string): string | null => {
|
|
|
|
|
const messageKey = this.facade.fieldError(key);
|
|
|
|
|
return messageKey ? this.translate.t(messageKey) : null;
|
|
|
|
|
};
|
2026-07-13 08:10:00 +04:00
|
|
|
readonly locales = computed(() => this.bootstrap()?.localization.supportedLocales ?? []);
|
|
|
|
|
readonly defaultLocale = computed(() => this.bootstrap()?.localization.defaultLocale ?? '');
|
2026-07-16 02:10:38 +04:00
|
|
|
readonly supportedLocales = computed(() => this.bootstrap()?.tenant.supportedLocales ?? []);
|
|
|
|
|
readonly tenantDefaultLocale = computed(() => this.bootstrap()?.tenant.defaultLocale ?? '');
|
|
|
|
|
readonly activeLocale = signal<string | null>(null);
|
2026-07-13 08:10:00 +04:00
|
|
|
readonly newLocale = signal('');
|
|
|
|
|
|
2026-07-16 02:10:38 +04:00
|
|
|
onActiveLocaleChange(locale: string): void {
|
|
|
|
|
this.activeLocale.set(locale);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 08:10:00 +04:00
|
|
|
updateNewLocale(value: string): void {
|
|
|
|
|
this.newLocale.set(value);
|
2026-07-17 18:31:01 +04:00
|
|
|
if (this.addLocaleError()) {
|
|
|
|
|
this.addLocaleError.set(null);
|
|
|
|
|
}
|
2026-07-13 08:10:00 +04:00
|
|
|
}
|
|
|
|
|
|
2026-07-17 18:31:01 +04:00
|
|
|
readonly addLocaleError = signal<string | null>(null);
|
|
|
|
|
|
2026-07-13 08:10:00 +04:00
|
|
|
addLocale(): void {
|
2026-07-17 18:31:01 +04:00
|
|
|
const code = this.newLocale().trim().toLowerCase();
|
2026-07-13 08:10:00 +04:00
|
|
|
if (!code) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-17 18:31:01 +04:00
|
|
|
if (this.locales().includes(code)) {
|
|
|
|
|
this.addLocaleError.set(this.translate.t('builder.languageAlreadyAdded'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-13 08:10:00 +04:00
|
|
|
this.facade.addLocale(code);
|
|
|
|
|
this.newLocale.set('');
|
2026-07-17 18:31:01 +04:00
|
|
|
this.addLocaleError.set(null);
|
2026-07-13 08:10:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeLocale(code: string): void {
|
|
|
|
|
this.facade.removeLocale(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setDefault(code: string): void {
|
|
|
|
|
this.facade.setDefaultLocale(code);
|
|
|
|
|
}
|
|
|
|
|
}
|