feat/calculator-options #23
@@ -1,11 +1,7 @@
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { Title, Meta } from '@angular/platform-browser';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
NavigationEnd,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
import { ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
@@ -25,7 +21,11 @@ export class SeoService {
|
||||
) {
|
||||
this.applyRouteSeo(this.router.routerState.snapshot.root);
|
||||
this.router.events
|
||||
.pipe(filter((event): event is NavigationEnd => event instanceof NavigationEnd))
|
||||
.pipe(
|
||||
filter(
|
||||
(event): event is NavigationEnd => event instanceof NavigationEnd,
|
||||
),
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.applyRouteSeo(this.router.routerState.snapshot.root);
|
||||
});
|
||||
@@ -56,7 +56,9 @@ export class SeoService {
|
||||
this.updateLangAndAlternates(cleanPath);
|
||||
}
|
||||
|
||||
private getMergedRouteData(snapshot: ActivatedRouteSnapshot): Record<string, unknown> {
|
||||
private getMergedRouteData(
|
||||
snapshot: ActivatedRouteSnapshot,
|
||||
): Record<string, unknown> {
|
||||
const merged: Record<string, unknown> = {};
|
||||
let cursor: ActivatedRouteSnapshot | null = snapshot;
|
||||
while (cursor) {
|
||||
@@ -90,10 +92,13 @@ export class SeoService {
|
||||
private updateLangAndAlternates(path: string): void {
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
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 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;
|
||||
|
||||
@@ -102,7 +107,10 @@ export class SeoService {
|
||||
.forEach((node) => node.remove());
|
||||
|
||||
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(
|
||||
'x-default',
|
||||
|
||||
@@ -571,16 +571,22 @@ export class CalculatorPageComponent implements OnInit {
|
||||
a.mode === b.mode &&
|
||||
a.material === this.normalizeString(b.material) &&
|
||||
a.quality === this.normalizeString(b.quality) &&
|
||||
Math.abs(a.nozzleDiameter - this.normalizeNumber(b.nozzleDiameter, 0.4, 2)) < 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 &&
|
||||
Math.abs(
|
||||
a.nozzleDiameter - this.normalizeNumber(b.nozzleDiameter, 0.4, 2),
|
||||
) < 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.supportEnabled === Boolean(b.supportEnabled)
|
||||
);
|
||||
}
|
||||
|
||||
private normalizeString(value: string): string {
|
||||
return String(value || '').trim().toLowerCase();
|
||||
return String(value || '')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
private normalizeNumber(
|
||||
|
||||
@@ -286,7 +286,8 @@ export class UploadFormComponent implements OnInit {
|
||||
);
|
||||
const anyPla = this.materials().find(
|
||||
(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];
|
||||
this.form.get('material')?.setValue(preferredMaterial.value);
|
||||
|
||||
Reference in New Issue
Block a user