feat/calculator-options #23

Merged
JoeKung merged 5 commits from feat/calculator-options into dev 2026-03-05 15:14:09 +01:00
3 changed files with 30 additions and 15 deletions
Showing only changes of commit d061f21d79 - Show all commits

View File

@@ -1,11 +1,7 @@
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core'; import { Inject, Injectable } from '@angular/core';
import { Title, Meta } from '@angular/platform-browser'; import { Title, Meta } from '@angular/platform-browser';
import { import { ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router';
ActivatedRouteSnapshot,
NavigationEnd,
Router,
} from '@angular/router';
import { filter } from 'rxjs/operators'; import { filter } from 'rxjs/operators';
@Injectable({ @Injectable({
@@ -25,7 +21,11 @@ export class SeoService {
) { ) {
this.applyRouteSeo(this.router.routerState.snapshot.root); this.applyRouteSeo(this.router.routerState.snapshot.root);
this.router.events this.router.events
.pipe(filter((event): event is NavigationEnd => event instanceof NavigationEnd)) .pipe(
filter(
(event): event is NavigationEnd => event instanceof NavigationEnd,
),
)
.subscribe(() => { .subscribe(() => {
this.applyRouteSeo(this.router.routerState.snapshot.root); this.applyRouteSeo(this.router.routerState.snapshot.root);
}); });
@@ -56,7 +56,9 @@ export class SeoService {
this.updateLangAndAlternates(cleanPath); this.updateLangAndAlternates(cleanPath);
} }
private getMergedRouteData(snapshot: ActivatedRouteSnapshot): Record<string, unknown> { private getMergedRouteData(
snapshot: ActivatedRouteSnapshot,
): Record<string, unknown> {
const merged: Record<string, unknown> = {}; const merged: Record<string, unknown> = {};
let cursor: ActivatedRouteSnapshot | null = snapshot; let cursor: ActivatedRouteSnapshot | null = snapshot;
while (cursor) { while (cursor) {
@@ -90,10 +92,13 @@ export class SeoService {
private updateLangAndAlternates(path: string): void { private updateLangAndAlternates(path: string): void {
const segments = path.split('/').filter(Boolean); const segments = path.split('/').filter(Boolean);
const firstSegment = segments[0]?.toLowerCase(); const firstSegment = segments[0]?.toLowerCase();
const hasLang = Boolean(firstSegment && this.supportedLangs.has(firstSegment)); const hasLang = Boolean(
firstSegment && this.supportedLangs.has(firstSegment),
);
const lang = hasLang ? firstSegment : 'it'; const lang = hasLang ? firstSegment : 'it';
const suffixSegments = hasLang ? segments.slice(1) : segments; const suffixSegments = hasLang ? segments.slice(1) : segments;
const suffix = suffixSegments.length > 0 ? `/${suffixSegments.join('/')}` : ''; const suffix =
suffixSegments.length > 0 ? `/${suffixSegments.join('/')}` : '';
this.document.documentElement.lang = lang; this.document.documentElement.lang = lang;
@@ -102,7 +107,10 @@ export class SeoService {
.forEach((node) => node.remove()); .forEach((node) => node.remove());
for (const alt of ['it', 'en', 'de', 'fr']) { for (const alt of ['it', 'en', 'de', 'fr']) {
this.appendAlternateLink(alt, `${this.document.location.origin}/${alt}${suffix}`); this.appendAlternateLink(
alt,
`${this.document.location.origin}/${alt}${suffix}`,
);
} }
this.appendAlternateLink( this.appendAlternateLink(
'x-default', 'x-default',

View File

@@ -571,16 +571,22 @@ export class CalculatorPageComponent implements OnInit {
a.mode === b.mode && a.mode === b.mode &&
a.material === this.normalizeString(b.material) && a.material === this.normalizeString(b.material) &&
a.quality === this.normalizeString(b.quality) && a.quality === this.normalizeString(b.quality) &&
Math.abs(a.nozzleDiameter - this.normalizeNumber(b.nozzleDiameter, 0.4, 2)) < 0.0001 && Math.abs(
Math.abs(a.layerHeight - this.normalizeNumber(b.layerHeight, 0.2, 3)) < 0.0001 && a.nozzleDiameter - this.normalizeNumber(b.nozzleDiameter, 0.4, 2),
Math.abs(a.infillDensity - this.normalizeNumber(b.infillDensity, 20, 2)) < 0.0001 && ) < 0.0001 &&
Math.abs(a.layerHeight - this.normalizeNumber(b.layerHeight, 0.2, 3)) <
0.0001 &&
Math.abs(a.infillDensity - this.normalizeNumber(b.infillDensity, 20, 2)) <
0.0001 &&
a.infillPattern === this.normalizeString(b.infillPattern) && a.infillPattern === this.normalizeString(b.infillPattern) &&
a.supportEnabled === Boolean(b.supportEnabled) a.supportEnabled === Boolean(b.supportEnabled)
); );
} }
private normalizeString(value: string): string { private normalizeString(value: string): string {
return String(value || '').trim().toLowerCase(); return String(value || '')
.trim()
.toLowerCase();
} }
private normalizeNumber( private normalizeNumber(

View File

@@ -286,7 +286,8 @@ export class UploadFormComponent implements OnInit {
); );
const anyPla = this.materials().find( const anyPla = this.materials().find(
(m) => (m) =>
typeof m.value === 'string' && m.value.toUpperCase().startsWith('PLA'), typeof m.value === 'string' &&
m.value.toUpperCase().startsWith('PLA'),
); );
const preferredMaterial = exactPla ?? anyPla ?? this.materials()[0]; const preferredMaterial = exactPla ?? anyPla ?? this.materials()[0];
this.form.get('material')?.setValue(preferredMaterial.value); this.form.get('material')?.setValue(preferredMaterial.value);