Compare commits
1 Commits
feat/ssr
...
feee2b0bff
| Author | SHA1 | Date | |
|---|---|---|---|
| feee2b0bff |
@@ -1,13 +1,14 @@
|
||||
FROM node:22-alpine
|
||||
# Stage 1: Build
|
||||
FROM node:20 as build
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci --legacy-peer-deps
|
||||
RUN npm install
|
||||
COPY . .
|
||||
RUN npm run build -- --configuration=production
|
||||
RUN npm run build --configuration=production
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=80
|
||||
# Stage 2: Serve
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /app/dist/frontend/browser /usr/share/nginx/html
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["node", "dist/frontend/server/server.mjs"]
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
FROM node:22-alpine
|
||||
# Stage 1: Build
|
||||
FROM node:20 as build
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci --legacy-peer-deps
|
||||
RUN npm install
|
||||
COPY . .
|
||||
|
||||
# Use development configuration to pick up environment.ts (localhost)
|
||||
RUN npm run build -- --configuration=development
|
||||
|
||||
ENV NODE_ENV=development
|
||||
ENV PORT=80
|
||||
# Stage 2: Serve
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /app/dist/frontend/browser /usr/share/nginx/html
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["node", "dist/frontend/server/server.mjs"]
|
||||
|
||||
@@ -36,12 +36,7 @@
|
||||
"@angular/material/prebuilt-themes/azure-blue.css",
|
||||
"src/styles.scss"
|
||||
],
|
||||
"scripts": [],
|
||||
"server": "src/main.server.ts",
|
||||
"prerender": false,
|
||||
"ssr": {
|
||||
"entry": "src/server.ts"
|
||||
}
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
|
||||
901
frontend/package-lock.json
generated
901
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,41 +6,35 @@
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test",
|
||||
"serve:ssr:frontend": "node dist/frontend/server/server.mjs"
|
||||
"test": "ng test"
|
||||
},
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": "^22.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@angular/cdk": "19.2.19",
|
||||
"@angular/common": "19.2.19",
|
||||
"@angular/compiler": "19.2.19",
|
||||
"@angular/core": "19.2.19",
|
||||
"@angular/forms": "19.2.19",
|
||||
"@angular/material": "19.2.19",
|
||||
"@angular/platform-browser": "19.2.19",
|
||||
"@angular/platform-browser-dynamic": "19.2.19",
|
||||
"@angular/platform-server": "19.2.19",
|
||||
"@angular/router": "19.2.19",
|
||||
"@angular/ssr": "19.2.19",
|
||||
"@angular/cdk": "^19.2.19",
|
||||
"@angular/common": "^19.2.18",
|
||||
"@angular/compiler": "^19.2.18",
|
||||
"@angular/core": "^19.2.18",
|
||||
"@angular/forms": "^19.2.18",
|
||||
"@angular/material": "^19.2.19",
|
||||
"@angular/platform-browser": "^19.2.18",
|
||||
"@angular/platform-browser-dynamic": "^19.2.18",
|
||||
"@angular/router": "^19.2.18",
|
||||
"@ngx-translate/core": "^17.0.0",
|
||||
"@ngx-translate/http-loader": "^17.0.0",
|
||||
"@types/three": "^0.182.0",
|
||||
"express": "^4.18.2",
|
||||
"rxjs": "~7.8.0",
|
||||
"three": "^0.182.0",
|
||||
"tslib": "^2.3.0",
|
||||
"zone.js": "~0.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "19.2.19",
|
||||
"@angular/cli": "19.2.19",
|
||||
"@angular/compiler-cli": "19.2.19",
|
||||
"@types/express": "^4.17.17",
|
||||
"@angular-devkit/build-angular": "^19.2.19",
|
||||
"@angular/cli": "^19.2.19",
|
||||
"@angular/compiler-cli": "^19.2.18",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"@types/node": "^18.18.0",
|
||||
"jasmine-core": "~5.6.0",
|
||||
"karma": "~6.4.0",
|
||||
"karma-chrome-launcher": "~3.2.0",
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
|
||||
import { provideServerRendering } from '@angular/platform-server';
|
||||
import { appConfig } from './app.config';
|
||||
|
||||
const serverConfig: ApplicationConfig = {
|
||||
providers: [provideServerRendering()],
|
||||
};
|
||||
|
||||
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
||||
@@ -17,10 +17,6 @@ import {
|
||||
TranslateHttpLoader,
|
||||
} from '@ngx-translate/http-loader';
|
||||
import { adminAuthInterceptor } from './core/interceptors/admin-auth.interceptor';
|
||||
import {
|
||||
provideClientHydration,
|
||||
withEventReplay,
|
||||
} from '@angular/platform-browser';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
@@ -47,6 +43,5 @@ export const appConfig: ApplicationConfig = {
|
||||
},
|
||||
}),
|
||||
),
|
||||
provideClientHydration(withEventReplay()),
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { Component, OnInit, PLATFORM_ID, inject } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import {
|
||||
AdminCadInvoice,
|
||||
@@ -16,7 +16,6 @@ import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.d
|
||||
styleUrl: './admin-cad-invoices.component.scss',
|
||||
})
|
||||
export class AdminCadInvoicesComponent implements OnInit {
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
private readonly adminOperationsService = inject(AdminOperationsService);
|
||||
private readonly adminOrdersService = inject(AdminOrdersService);
|
||||
|
||||
@@ -113,17 +112,11 @@ export class AdminCadInvoicesComponent implements OnInit {
|
||||
}
|
||||
|
||||
openCheckout(path: string): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const url = this.toCheckoutUrl(path);
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
|
||||
copyCheckout(path: string): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const url = this.toCheckoutUrl(path);
|
||||
navigator.clipboard?.writeText(url);
|
||||
this.successMessage = 'Link checkout CAD copiato negli appunti.';
|
||||
@@ -133,9 +126,6 @@ export class AdminCadInvoicesComponent implements OnInit {
|
||||
if (!orderId) return;
|
||||
this.adminOrdersService.downloadOrderInvoice(orderId).subscribe({
|
||||
next: (blob) => {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
@@ -152,16 +142,10 @@ export class AdminCadInvoicesComponent implements OnInit {
|
||||
private toCheckoutUrl(path: string): string {
|
||||
const safePath = path.startsWith('/') ? path : `/${path}`;
|
||||
const lang = this.resolveLang();
|
||||
if (!this.isBrowser) {
|
||||
return `/${lang}${safePath}`;
|
||||
}
|
||||
return `${window.location.origin}/${lang}${safePath}`;
|
||||
}
|
||||
|
||||
private resolveLang(): string {
|
||||
if (!this.isBrowser) {
|
||||
return 'it';
|
||||
}
|
||||
const firstSegment = window.location.pathname
|
||||
.split('/')
|
||||
.filter(Boolean)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { Component, PLATFORM_ID, inject, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import {
|
||||
AdminContactRequest,
|
||||
@@ -17,7 +17,6 @@ import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.d
|
||||
styleUrl: './admin-contact-requests.component.scss',
|
||||
})
|
||||
export class AdminContactRequestsComponent implements OnInit {
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
private readonly adminOperationsService = inject(AdminOperationsService);
|
||||
|
||||
readonly statusOptions = ['NEW', 'PENDING', 'IN_PROGRESS', 'DONE', 'CLOSED'];
|
||||
@@ -172,9 +171,6 @@ export class AdminContactRequestsComponent implements OnInit {
|
||||
}
|
||||
|
||||
private downloadBlob(blob: Blob, filename: string): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { Component, PLATFORM_ID, inject, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import {
|
||||
AdminOrder,
|
||||
@@ -16,7 +16,6 @@ import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.d
|
||||
styleUrl: './admin-dashboard.component.scss',
|
||||
})
|
||||
export class AdminDashboardComponent implements OnInit {
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
private readonly adminOrdersService = inject(AdminOrdersService);
|
||||
|
||||
orders: AdminOrder[] = [];
|
||||
@@ -499,9 +498,6 @@ export class AdminDashboardComponent implements OnInit {
|
||||
}
|
||||
|
||||
private downloadBlob(blob: Blob, filename: string): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import {
|
||||
Component,
|
||||
PLATFORM_ID,
|
||||
inject,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, inject, OnDestroy, OnInit } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { of, switchMap } from 'rxjs';
|
||||
import {
|
||||
@@ -91,7 +85,6 @@ const MEDIA_LANGUAGE_LABELS: Readonly<Record<AdminMediaLanguage, string>> = {
|
||||
styleUrl: './admin-home-media.component.scss',
|
||||
})
|
||||
export class AdminHomeMediaComponent implements OnInit, OnDestroy {
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
private readonly adminMediaService = inject(AdminMediaService);
|
||||
readonly mediaLanguages = SUPPORTED_MEDIA_LANGUAGES;
|
||||
readonly mediaLanguageLabels = MEDIA_LANGUAGE_LABELS;
|
||||
@@ -250,8 +243,7 @@ export class AdminHomeMediaComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.revokePreviewUrl(formState.previewUrl);
|
||||
formState.file = file;
|
||||
formState.previewUrl =
|
||||
file && this.isBrowser ? URL.createObjectURL(file) : null;
|
||||
formState.previewUrl = file ? URL.createObjectURL(file) : null;
|
||||
|
||||
if (file && this.areAllTitlesBlank(formState.translations)) {
|
||||
const nextTitle = this.deriveDefaultTitle(file.name);
|
||||
@@ -591,9 +583,6 @@ export class AdminHomeMediaComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private revokePreviewUrl(previewUrl: string | null): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
if (!previewUrl?.startsWith('blob:')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { Component, PLATFORM_ID, inject, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import {
|
||||
AdminOperationsService,
|
||||
AdminQuoteSession,
|
||||
@@ -15,7 +15,6 @@ import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.d
|
||||
styleUrl: './admin-sessions.component.scss',
|
||||
})
|
||||
export class AdminSessionsComponent implements OnInit {
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
private readonly adminOperationsService = inject(AdminOperationsService);
|
||||
|
||||
sessions: AdminQuoteSession[] = [];
|
||||
@@ -52,11 +51,9 @@ export class AdminSessionsComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmed =
|
||||
this.isBrowser &&
|
||||
window.confirm(
|
||||
`Vuoi eliminare la sessione ${session.id}? Questa azione non si puo annullare.`,
|
||||
);
|
||||
const confirmed = window.confirm(
|
||||
`Vuoi eliminare la sessione ${session.id}? Questa azione non si puo annullare.`,
|
||||
);
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -878,7 +878,6 @@
|
||||
class="ui-form-control"
|
||||
[(ngModel)]="material.materialCode"
|
||||
[name]="'material-code-' + index"
|
||||
(ngModelChange)="onMaterialCodeChange(index, $event)"
|
||||
>
|
||||
<option [ngValue]="''" disabled>Seleziona materiale</option>
|
||||
<option
|
||||
@@ -916,30 +915,6 @@
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label class="ui-form-field" *ngIf="material.isDefault">
|
||||
<span class="ui-form-caption">Colore default</span>
|
||||
<select
|
||||
class="ui-form-control"
|
||||
[(ngModel)]="material.defaultColorKey"
|
||||
[name]="'material-default-color-' + index"
|
||||
[disabled]="materialColorCount(material.materialCode) === 0"
|
||||
>
|
||||
<option [ngValue]="''" disabled>
|
||||
Seleziona colore default
|
||||
</option>
|
||||
<option
|
||||
*ngFor="
|
||||
let option of materialColorOptions(
|
||||
material.materialCode
|
||||
)
|
||||
"
|
||||
[ngValue]="option.key"
|
||||
>
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<div class="toggle-row toggle-row--compact">
|
||||
<label class="ui-checkbox">
|
||||
<input
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import {
|
||||
Component,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
PLATFORM_ID,
|
||||
ViewChild,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
@@ -54,7 +53,6 @@ interface CategoryFormState {
|
||||
|
||||
interface ProductMaterialFormState {
|
||||
materialCode: string;
|
||||
defaultColorKey: string;
|
||||
priceChf: string;
|
||||
isDefault: boolean;
|
||||
isActive: boolean;
|
||||
@@ -140,9 +138,6 @@ const RICH_TEXT_ALLOWED_TAGS = new Set([
|
||||
styleUrl: './admin-shop.component.scss',
|
||||
})
|
||||
export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
private readonly platformId = inject(PLATFORM_ID);
|
||||
private readonly isBrowser = isPlatformBrowser(this.platformId);
|
||||
private readonly documentRef = inject(DOCUMENT);
|
||||
private readonly adminShopService = inject(AdminShopService);
|
||||
private readonly adminOperationsService = inject(AdminOperationsService);
|
||||
private descriptionEditorElement: HTMLDivElement | null = null;
|
||||
@@ -205,14 +200,12 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.revokeImagePreviewUrl(this.imageUploadState.previewUrl);
|
||||
if (this.isBrowser) {
|
||||
this.documentRef.body?.style.removeProperty('cursor');
|
||||
}
|
||||
document.body.style.removeProperty('cursor');
|
||||
}
|
||||
|
||||
@HostListener('window:pointermove', ['$event'])
|
||||
onWindowPointerMove(event: PointerEvent): void {
|
||||
if (!this.isBrowser || !this.isResizingPanels) {
|
||||
if (!this.isResizingPanels) {
|
||||
return;
|
||||
}
|
||||
this.updateListPanelWidthFromPointer(event.clientX);
|
||||
@@ -221,13 +214,11 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
@HostListener('window:pointerup')
|
||||
@HostListener('window:pointercancel')
|
||||
onWindowPointerUp(): void {
|
||||
if (!this.isBrowser || !this.isResizingPanels) {
|
||||
if (!this.isResizingPanels) {
|
||||
return;
|
||||
}
|
||||
this.isResizingPanels = false;
|
||||
if (this.documentRef.body) {
|
||||
this.documentRef.body.style.cursor = '';
|
||||
}
|
||||
document.body.style.cursor = '';
|
||||
this.persistListPanelWidth();
|
||||
}
|
||||
|
||||
@@ -377,7 +368,7 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
if (
|
||||
!this.confirmBrowser(
|
||||
!window.confirm(
|
||||
"Eliminare questo prodotto? L'azione non puo essere annullata.",
|
||||
)
|
||||
) {
|
||||
@@ -421,14 +412,12 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
startPanelResize(event: PointerEvent): void {
|
||||
if (!this.isBrowser || window.innerWidth <= 1060) {
|
||||
if (window.innerWidth <= 1060) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
this.isResizingPanels = true;
|
||||
if (this.documentRef.body) {
|
||||
this.documentRef.body.style.cursor = 'col-resize';
|
||||
}
|
||||
document.body.style.cursor = 'col-resize';
|
||||
this.updateListPanelWidthFromPointer(event.clientX);
|
||||
}
|
||||
|
||||
@@ -518,7 +507,7 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
if (
|
||||
!this.confirmBrowser(
|
||||
!window.confirm(
|
||||
'Eliminare questa categoria? Fallira se contiene sottocategorie o prodotti.',
|
||||
)
|
||||
) {
|
||||
@@ -653,14 +642,7 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
(_, currentIndex) => currentIndex !== index,
|
||||
);
|
||||
if (!nextMaterials.some((material) => material.isDefault)) {
|
||||
nextMaterials[0] = {
|
||||
...nextMaterials[0],
|
||||
isDefault: true,
|
||||
defaultColorKey: this.resolveMaterialDefaultColorKey(
|
||||
nextMaterials[0].materialCode,
|
||||
nextMaterials[0].defaultColorKey,
|
||||
),
|
||||
};
|
||||
nextMaterials[0].isDefault = true;
|
||||
}
|
||||
this.productForm.materials = nextMaterials;
|
||||
}
|
||||
@@ -670,34 +652,10 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
(material, currentIndex) => ({
|
||||
...material,
|
||||
isDefault: currentIndex === index,
|
||||
defaultColorKey: this.resolveMaterialDefaultColorKey(
|
||||
material.materialCode,
|
||||
material.defaultColorKey,
|
||||
),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
onMaterialCodeChange(index: number, nextMaterialCode: string): void {
|
||||
const normalizedMaterialCode = nextMaterialCode.trim().toUpperCase();
|
||||
this.productForm.materials = this.productForm.materials.map(
|
||||
(material, currentIndex) => {
|
||||
if (currentIndex !== index) {
|
||||
return material;
|
||||
}
|
||||
|
||||
return {
|
||||
...material,
|
||||
materialCode: normalizedMaterialCode,
|
||||
defaultColorKey: this.resolveMaterialDefaultColorKey(
|
||||
normalizedMaterialCode,
|
||||
material.defaultColorKey,
|
||||
),
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
availableMaterialChoices(currentMaterialCode: string): string[] {
|
||||
const normalizedCurrentMaterialCode = currentMaterialCode
|
||||
.trim()
|
||||
@@ -735,22 +693,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
.slice(0, 6);
|
||||
}
|
||||
|
||||
materialColorOptions(
|
||||
materialCode: string,
|
||||
): Array<{ key: string; label: string }> {
|
||||
const normalizedMaterialCode = materialCode.trim().toUpperCase();
|
||||
return this.stockVariantsForMaterial(normalizedMaterialCode).map(
|
||||
(variant) => ({
|
||||
key: this.variantKey(
|
||||
normalizedMaterialCode,
|
||||
variant.colorName,
|
||||
variant.colorHex,
|
||||
),
|
||||
label: this.stockVariantLabel(variant),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
onModelFileSelected(event: Event): void {
|
||||
const input = event.target as HTMLInputElement | null;
|
||||
const file = input?.files?.[0] ?? null;
|
||||
@@ -818,9 +760,7 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
if (
|
||||
!this.confirmBrowser(
|
||||
'Rimuovere il modello 3D associato a questo prodotto?',
|
||||
)
|
||||
!window.confirm('Rimuovere il modello 3D associato a questo prodotto?')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -892,7 +832,7 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
this.imageUploadState = {
|
||||
...this.imageUploadState,
|
||||
file,
|
||||
previewUrl: this.isBrowser ? URL.createObjectURL(file) : null,
|
||||
previewUrl: URL.createObjectURL(file),
|
||||
translations: nextTranslations,
|
||||
};
|
||||
}
|
||||
@@ -1068,7 +1008,7 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.confirmBrowser('Rimuovere questa immagine dal prodotto?')) {
|
||||
if (!window.confirm('Rimuovere questa immagine dal prodotto?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1180,9 +1120,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private restoreListPanelWidth(): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const storedValue = window.localStorage.getItem(
|
||||
SHOP_LIST_PANEL_WIDTH_STORAGE_KEY,
|
||||
);
|
||||
@@ -1197,9 +1134,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private persistListPanelWidth(): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
window.localStorage.setItem(
|
||||
SHOP_LIST_PANEL_WIDTH_STORAGE_KEY,
|
||||
String(this.listPanelWidthPercent),
|
||||
@@ -1348,7 +1282,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
): ProductMaterialFormState {
|
||||
return {
|
||||
materialCode,
|
||||
defaultColorKey: this.resolveMaterialDefaultColorKey(materialCode),
|
||||
priceChf: '0.00',
|
||||
isDefault,
|
||||
isActive: true,
|
||||
@@ -1428,21 +1361,8 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
(left, right) => (left.sortOrder ?? 0) - (right.sortOrder ?? 0),
|
||||
);
|
||||
const firstVariant = sortedVariants[0];
|
||||
const defaultVariantForMaterial =
|
||||
materialVariants.find((variant) => variant.isDefault) ?? null;
|
||||
const persistedDefaultColorKey = defaultVariantForMaterial
|
||||
? this.variantKey(
|
||||
materialCode,
|
||||
defaultVariantForMaterial.colorName,
|
||||
defaultVariantForMaterial.colorHex,
|
||||
)
|
||||
: null;
|
||||
return {
|
||||
materialCode,
|
||||
defaultColorKey: this.resolveMaterialDefaultColorKey(
|
||||
materialCode,
|
||||
persistedDefaultColorKey,
|
||||
),
|
||||
priceChf: Number(firstVariant?.priceChf ?? 0).toFixed(2),
|
||||
isDefault: materialVariants.some((variant) => variant.isDefault),
|
||||
isActive: materialVariants.some((variant) => variant.isActive),
|
||||
@@ -1574,6 +1494,9 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private buildVariantsFromMaterials(): AdminUpsertShopProductVariantPayload[] {
|
||||
const persistedDefaultVariant = this.selectedProduct?.variants.find(
|
||||
(variant) => variant.isDefault,
|
||||
);
|
||||
const existingVariantsByKey = new Map(
|
||||
(this.selectedProduct?.variants ?? []).map((variant) => [
|
||||
this.variantKey(
|
||||
@@ -1584,6 +1507,14 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
variant,
|
||||
]),
|
||||
);
|
||||
const persistedDefaultKey = persistedDefaultVariant
|
||||
? this.variantKey(
|
||||
persistedDefaultVariant.internalMaterialCode,
|
||||
persistedDefaultVariant.colorName,
|
||||
persistedDefaultVariant.colorHex,
|
||||
)
|
||||
: null;
|
||||
|
||||
const variants: AdminUpsertShopProductVariantPayload[] = [];
|
||||
let defaultAssigned = false;
|
||||
|
||||
@@ -1594,10 +1525,20 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
for (const material of sortedMaterials) {
|
||||
const materialCode = material.materialCode.trim().toUpperCase();
|
||||
const stockVariants = this.stockVariantsForMaterial(materialCode);
|
||||
const selectedDefaultColorKey = this.resolveMaterialDefaultColorKey(
|
||||
materialCode,
|
||||
material.defaultColorKey,
|
||||
);
|
||||
let defaultVariantKeyForMaterial: string | null = null;
|
||||
|
||||
if (material.isDefault && persistedDefaultKey) {
|
||||
defaultVariantKeyForMaterial =
|
||||
stockVariants
|
||||
.map((variant) =>
|
||||
this.variantKey(
|
||||
materialCode,
|
||||
variant.colorName,
|
||||
variant.colorHex,
|
||||
),
|
||||
)
|
||||
.find((variantKey) => variantKey === persistedDefaultKey) ?? null;
|
||||
}
|
||||
|
||||
stockVariants.forEach((stockVariant, colorIndex) => {
|
||||
const variantKey = this.variantKey(
|
||||
@@ -1609,7 +1550,9 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
const isDefault =
|
||||
material.isDefault &&
|
||||
!defaultAssigned &&
|
||||
variantKey === selectedDefaultColorKey;
|
||||
(defaultVariantKeyForMaterial
|
||||
? variantKey === defaultVariantKeyForMaterial
|
||||
: colorIndex === 0);
|
||||
|
||||
variants.push({
|
||||
id: existingVariant?.id,
|
||||
@@ -1680,51 +1623,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
private resolveMaterialDefaultColorKey(
|
||||
materialCode: string,
|
||||
preferredKey?: string | null,
|
||||
): string {
|
||||
const normalizedMaterialCode = materialCode.trim().toUpperCase();
|
||||
const stockVariants = this.stockVariantsForMaterial(normalizedMaterialCode);
|
||||
if (stockVariants.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const normalizedPreferredKey = (preferredKey ?? '').trim();
|
||||
if (
|
||||
normalizedPreferredKey &&
|
||||
stockVariants.some(
|
||||
(variant) =>
|
||||
this.variantKey(
|
||||
normalizedMaterialCode,
|
||||
variant.colorName,
|
||||
variant.colorHex,
|
||||
) === normalizedPreferredKey,
|
||||
)
|
||||
) {
|
||||
return normalizedPreferredKey;
|
||||
}
|
||||
|
||||
const firstVariant = stockVariants[0];
|
||||
return this.variantKey(
|
||||
normalizedMaterialCode,
|
||||
firstVariant.colorName,
|
||||
firstVariant.colorHex,
|
||||
);
|
||||
}
|
||||
|
||||
private stockVariantLabel(variant: AdminFilamentVariant): string {
|
||||
const colorName = variant.colorName.trim();
|
||||
const variantDisplayName = variant.variantDisplayName.trim();
|
||||
if (
|
||||
variantDisplayName &&
|
||||
variantDisplayName.toLowerCase() !== colorName.toLowerCase()
|
||||
) {
|
||||
return `${colorName} (${variantDisplayName})`;
|
||||
}
|
||||
return colorName;
|
||||
}
|
||||
|
||||
private nextAvailableMaterialCode(): string | null {
|
||||
const selectedCodes = new Set(
|
||||
this.productForm.materials
|
||||
@@ -1843,9 +1741,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private revokeImagePreviewUrl(previewUrl: string | null): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
if (previewUrl?.startsWith('blob:')) {
|
||||
URL.revokeObjectURL(previewUrl);
|
||||
}
|
||||
@@ -1968,15 +1863,12 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private applyDescriptionExecCommand(command: string): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const editor = this.descriptionEditorElement;
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
editor.focus();
|
||||
this.documentRef.execCommand(command, false);
|
||||
document.execCommand(command, false);
|
||||
this.syncDescriptionFromEditor(editor, false);
|
||||
}
|
||||
|
||||
@@ -2020,10 +1912,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private sanitizeRichTextHtml(value: string): string {
|
||||
if (!this.isBrowser) {
|
||||
return this.stripPotentiallyUnsafeHtml(value);
|
||||
}
|
||||
|
||||
const parser = new DOMParser();
|
||||
const sourceDocument = parser.parseFromString(
|
||||
`<body>${value}</body>`,
|
||||
@@ -2129,18 +2017,12 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private extractTextFromHtml(value: string): string {
|
||||
if (!this.isBrowser) {
|
||||
return value.replace(/<[^>]+>/g, ' ');
|
||||
}
|
||||
const parser = new DOMParser();
|
||||
const parsed = parser.parseFromString(`<body>${value}</body>`, 'text/html');
|
||||
return parsed.body.textContent ?? '';
|
||||
}
|
||||
|
||||
private serializeNodeChildren(node: Node): string {
|
||||
if (!this.isBrowser) {
|
||||
return node.textContent ?? '';
|
||||
}
|
||||
const serializer = new XMLSerializer();
|
||||
let html = '';
|
||||
for (const child of Array.from(node.childNodes)) {
|
||||
@@ -2153,10 +2035,6 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
element: HTMLElement,
|
||||
html: string,
|
||||
): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!html) {
|
||||
element.replaceChildren();
|
||||
return;
|
||||
@@ -2165,21 +2043,11 @@ export class AdminShopComponent implements OnInit, OnDestroy {
|
||||
const parser = new DOMParser();
|
||||
const parsed = parser.parseFromString(`<body>${html}</body>`, 'text/html');
|
||||
const nodes = Array.from(parsed.body.childNodes).map((child) =>
|
||||
this.documentRef.importNode(child, true),
|
||||
document.importNode(child, true),
|
||||
);
|
||||
element.replaceChildren(...nodes);
|
||||
}
|
||||
|
||||
private confirmBrowser(message: string): boolean {
|
||||
return this.isBrowser ? window.confirm(message) : false;
|
||||
}
|
||||
|
||||
private stripPotentiallyUnsafeHtml(value: string): string {
|
||||
return value
|
||||
.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, '')
|
||||
.replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi, '');
|
||||
}
|
||||
|
||||
private escapeHtml(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
|
||||
@@ -4,12 +4,9 @@ import {
|
||||
signal,
|
||||
ViewChild,
|
||||
ElementRef,
|
||||
Inject,
|
||||
OnInit,
|
||||
Optional,
|
||||
PLATFORM_ID,
|
||||
} from '@angular/core';
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { forkJoin, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
@@ -56,7 +53,6 @@ type TrackedPrintSettings = {
|
||||
styleUrl: './calculator-page.component.scss',
|
||||
})
|
||||
export class CalculatorPageComponent implements OnInit {
|
||||
private readonly isBrowser: boolean;
|
||||
mode = signal<'easy' | 'advanced'>('easy');
|
||||
step = signal<'upload' | 'quote' | 'details' | 'success'>('upload');
|
||||
|
||||
@@ -89,10 +85,7 @@ export class CalculatorPageComponent implements OnInit {
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private languageService: LanguageService,
|
||||
@Optional() @Inject(PLATFORM_ID) platformId?: Object,
|
||||
) {
|
||||
this.isBrowser = isPlatformBrowser(platformId ?? 'browser');
|
||||
}
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data) => {
|
||||
@@ -267,7 +260,7 @@ export class CalculatorPageComponent implements OnInit {
|
||||
|
||||
// Auto-scroll on mobile to make analysis visible
|
||||
setTimeout(() => {
|
||||
if (this.isBrowser && this.resultCol && window.innerWidth < 768) {
|
||||
if (this.resultCol && window.innerWidth < 768) {
|
||||
this.resultCol.nativeElement.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'start',
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
import {
|
||||
Component,
|
||||
signal,
|
||||
effect,
|
||||
inject,
|
||||
OnDestroy,
|
||||
PLATFORM_ID,
|
||||
} from '@angular/core';
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { Component, signal, effect, inject, OnDestroy } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import {
|
||||
ReactiveFormsModule,
|
||||
FormBuilder,
|
||||
@@ -23,7 +16,6 @@ import {
|
||||
import { QuoteEstimatorService } from '../../../calculator/services/quote-estimator.service';
|
||||
import { QuoteRequestService } from '../../../../core/services/quote-request.service';
|
||||
import { LanguageService } from '../../../../core/services/language.service';
|
||||
import { SuccessStateComponent } from '../../../../shared/components/success-state/success-state.component';
|
||||
|
||||
interface FilePreview {
|
||||
file: File;
|
||||
@@ -31,6 +23,8 @@ interface FilePreview {
|
||||
type: 'image' | 'video' | 'pdf' | '3d' | 'document' | 'other';
|
||||
}
|
||||
|
||||
import { SuccessStateComponent } from '../../../../shared/components/success-state/success-state.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-contact-form',
|
||||
standalone: true,
|
||||
@@ -47,7 +41,6 @@ interface FilePreview {
|
||||
styleUrl: './contact-form.component.scss',
|
||||
})
|
||||
export class ContactFormComponent implements OnDestroy {
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
form: FormGroup;
|
||||
sent = signal(false);
|
||||
files = signal<FilePreview[]>([]);
|
||||
@@ -134,10 +127,9 @@ export class ContactFormComponent implements OnDestroy {
|
||||
return {
|
||||
file: f,
|
||||
type,
|
||||
url:
|
||||
this.isBrowser && this.shouldCreatePreview(type)
|
||||
? URL.createObjectURL(f)
|
||||
: undefined,
|
||||
url: this.shouldCreatePreview(type)
|
||||
? URL.createObjectURL(f)
|
||||
: undefined,
|
||||
};
|
||||
});
|
||||
this.files.set(filePreviews);
|
||||
@@ -193,10 +185,9 @@ export class ContactFormComponent implements OnDestroy {
|
||||
const preview: FilePreview = {
|
||||
file,
|
||||
type,
|
||||
url:
|
||||
this.isBrowser && this.shouldCreatePreview(type)
|
||||
? URL.createObjectURL(file)
|
||||
: undefined,
|
||||
url: this.shouldCreatePreview(type)
|
||||
? URL.createObjectURL(file)
|
||||
: undefined,
|
||||
};
|
||||
this.files.update((files) => [...files, preview]);
|
||||
});
|
||||
@@ -363,9 +354,6 @@ export class ContactFormComponent implements OnDestroy {
|
||||
}
|
||||
|
||||
private revokePreviewUrl(file: FilePreview): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
if (file.url?.startsWith('blob:')) {
|
||||
URL.revokeObjectURL(file.url);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, OnInit, PLATFORM_ID, inject, signal } from '@angular/core';
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { Component, OnInit, inject, signal } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { AppButtonComponent } from '../../shared/components/app-button/app-button.component';
|
||||
import { AppCardComponent } from '../../shared/components/app-card/app-card.component';
|
||||
@@ -75,7 +75,6 @@ export class OrderComponent implements OnInit {
|
||||
private router = inject(Router);
|
||||
private quoteService = inject(QuoteEstimatorService);
|
||||
private translate = inject(TranslateService);
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
|
||||
orderId: string | null = null;
|
||||
selectedPaymentMethod: 'twint' | 'bill' | null = 'twint';
|
||||
@@ -116,9 +115,6 @@ export class OrderComponent implements OnInit {
|
||||
}
|
||||
|
||||
downloadQrInvoice() {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
const orderId = this.orderId;
|
||||
if (!orderId) return;
|
||||
this.quoteService.getOrderConfirmation(orderId).subscribe({
|
||||
@@ -157,7 +153,7 @@ export class OrderComponent implements OnInit {
|
||||
|
||||
openTwintPayment(): void {
|
||||
const openUrl = this.twintOpenUrl();
|
||||
if (this.isBrowser && openUrl) {
|
||||
if (typeof window !== 'undefined' && openUrl) {
|
||||
window.open(openUrl, '_blank');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import {
|
||||
Component,
|
||||
DestroyRef,
|
||||
Injector,
|
||||
PLATFORM_ID,
|
||||
computed,
|
||||
inject,
|
||||
input,
|
||||
@@ -63,7 +62,6 @@ export class ProductDetailComponent {
|
||||
private readonly seoService = inject(SeoService);
|
||||
private readonly languageService = inject(LanguageService);
|
||||
private readonly shopRouteService = inject(ShopRouteService);
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
readonly shopService = inject(ShopService);
|
||||
|
||||
readonly categorySlug = input<string | undefined>();
|
||||
@@ -446,7 +444,7 @@ export class ProductDetailComponent {
|
||||
|
||||
goBackToShop(): void {
|
||||
const returnUrl =
|
||||
this.isBrowser && typeof history.state?.shopReturnUrl === 'string'
|
||||
typeof history.state?.shopReturnUrl === 'string'
|
||||
? history.state.shopReturnUrl
|
||||
: null;
|
||||
|
||||
@@ -673,15 +671,6 @@ export class ProductDetailComponent {
|
||||
if (!this.containsHtmlMarkup(normalized)) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
if (!this.isBrowser) {
|
||||
const text = normalized
|
||||
.replace(/<[^>]+>/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
return text || null;
|
||||
}
|
||||
|
||||
const parser = new DOMParser();
|
||||
const parsed = parser.parseFromString(
|
||||
`<body>${normalized}</body>`,
|
||||
@@ -705,10 +694,6 @@ export class ProductDetailComponent {
|
||||
}
|
||||
|
||||
private syncPublicUrl(product: ShopProductDetail): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentProductSlug = this.productSlug()?.trim().toLowerCase() ?? '';
|
||||
const targetProductSlug = this.shopRouteService.productPathSegment(product);
|
||||
if (currentProductSlug === targetProductSlug) {
|
||||
|
||||
@@ -5,12 +5,10 @@ import {
|
||||
OnChanges,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
PLATFORM_ID,
|
||||
ViewChild,
|
||||
SimpleChanges,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import * as THREE from 'three';
|
||||
// @ts-ignore
|
||||
@@ -26,9 +24,6 @@ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
||||
styleUrl: './stl-viewer.component.scss',
|
||||
})
|
||||
export class StlViewerComponent implements OnInit, OnDestroy, OnChanges {
|
||||
private readonly platformId = inject(PLATFORM_ID);
|
||||
private readonly isBrowser = isPlatformBrowser(this.platformId);
|
||||
|
||||
@Input() file: File | null = null;
|
||||
@Input() color: string = '#facf0a'; // Default Brand Color
|
||||
@Input() height = 300;
|
||||
@@ -44,22 +39,14 @@ export class StlViewerComponent implements OnInit, OnDestroy, OnChanges {
|
||||
private animationId: number | null = null;
|
||||
private currentMesh: THREE.Mesh | null = null;
|
||||
private autoRotate = true;
|
||||
private resizeObserver: ResizeObserver | null = null;
|
||||
|
||||
loading = false;
|
||||
|
||||
ngOnInit() {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
this.initThree();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (changes['file'] && this.file) {
|
||||
this.loadFile(this.file);
|
||||
}
|
||||
@@ -70,9 +57,6 @@ export class StlViewerComponent implements OnInit, OnDestroy, OnChanges {
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.resizeObserver?.disconnect();
|
||||
this.resizeObserver = null;
|
||||
|
||||
if (this.animationId) cancelAnimationFrame(this.animationId);
|
||||
this.clearCurrentMesh();
|
||||
if (this.controls) this.controls.dispose();
|
||||
@@ -137,7 +121,7 @@ export class StlViewerComponent implements OnInit, OnDestroy, OnChanges {
|
||||
this.animate();
|
||||
|
||||
// Handle resize
|
||||
this.resizeObserver = new ResizeObserver(() => {
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
if (!this.rendererContainer) return;
|
||||
const w = this.rendererContainer.nativeElement.clientWidth;
|
||||
const h = this.rendererContainer.nativeElement.clientHeight;
|
||||
@@ -145,7 +129,7 @@ export class StlViewerComponent implements OnInit, OnDestroy, OnChanges {
|
||||
this.camera.updateProjectionMatrix();
|
||||
this.renderer.setSize(w, h);
|
||||
});
|
||||
this.resizeObserver.observe(this.rendererContainer.nativeElement);
|
||||
resizeObserver.observe(this.rendererContainer.nativeElement);
|
||||
}
|
||||
|
||||
dimensions = { x: 0, y: 0, z: 0 };
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import {
|
||||
Directive,
|
||||
HostBinding,
|
||||
HostListener,
|
||||
Input,
|
||||
PLATFORM_ID,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
import { Directive, HostBinding, HostListener, Input } from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appCopyOnClick]',
|
||||
standalone: true,
|
||||
})
|
||||
export class CopyOnClickDirective {
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
|
||||
@Input('appCopyOnClick') value: string | null | undefined;
|
||||
|
||||
@HostBinding('style.cursor') readonly cursor = 'pointer';
|
||||
@@ -31,10 +21,6 @@ export class CopyOnClickDirective {
|
||||
}
|
||||
|
||||
private async copy(text: string): Promise<void> {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (navigator.clipboard?.writeText) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import {
|
||||
BootstrapContext,
|
||||
bootstrapApplication,
|
||||
} from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { config } from './app/app.config.server';
|
||||
|
||||
const bootstrap = (context: BootstrapContext) =>
|
||||
bootstrapApplication(AppComponent, config, context);
|
||||
|
||||
export default bootstrap;
|
||||
@@ -1,67 +0,0 @@
|
||||
import { APP_BASE_HREF } from '@angular/common';
|
||||
import { CommonEngine, isMainModule } from '@angular/ssr/node';
|
||||
import express from 'express';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import bootstrap from './main.server';
|
||||
|
||||
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
||||
const browserDistFolder = resolve(serverDistFolder, '../browser');
|
||||
const indexHtml = join(serverDistFolder, 'index.server.html');
|
||||
|
||||
const app = express();
|
||||
const commonEngine = new CommonEngine();
|
||||
|
||||
/**
|
||||
* Example Express Rest API endpoints can be defined here.
|
||||
* Uncomment and define endpoints as necessary.
|
||||
*
|
||||
* Example:
|
||||
* ```ts
|
||||
* app.get('/api/**', (req, res) => {
|
||||
* // Handle API request
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
|
||||
/**
|
||||
* Serve static files from /browser
|
||||
*/
|
||||
app.get(
|
||||
'**',
|
||||
express.static(browserDistFolder, {
|
||||
maxAge: '1y',
|
||||
index: false,
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* Handle all other requests by rendering the Angular application.
|
||||
*/
|
||||
app.get('**', (req, res, next) => {
|
||||
const { protocol, originalUrl, baseUrl, headers } = req;
|
||||
|
||||
commonEngine
|
||||
.render({
|
||||
bootstrap,
|
||||
documentFilePath: indexHtml,
|
||||
url: `${protocol}://${headers.host}${originalUrl}`,
|
||||
publicPath: browserDistFolder,
|
||||
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
|
||||
})
|
||||
.then((html) => res.send(html))
|
||||
.catch((err) => next(err));
|
||||
});
|
||||
|
||||
/**
|
||||
* Start the server if this module is the main entry point.
|
||||
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
||||
*/
|
||||
if (isMainModule(import.meta.url)) {
|
||||
const port = process.env['PORT'] || 4000;
|
||||
app.listen(port, () => {
|
||||
console.log(`Node Express server listening on http://localhost:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
export default app;
|
||||
@@ -4,14 +4,10 @@
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
"types": []
|
||||
},
|
||||
"files": [
|
||||
"src/main.ts",
|
||||
"src/main.server.ts",
|
||||
"src/server.ts"
|
||||
"src/main.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.d.ts"
|
||||
|
||||
Reference in New Issue
Block a user