visualisierung

This commit is contained in:
marco committed 2026-10-26 07:34:23 +01:00
1 parent d0655f3638
commit 367c93c93e
84 files changed
+2265 -148

No files matched your search

+34 -8
View File
@@ -1,9 +1,19 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Schema as MongooseSchema, Types } from 'mongoose';
import { VisuAggregate } from './visu-aggregate';
import type { DrawDataDto } from '../../_dto/draw.dto';
export interface GrafikGeneratorDaten {
grafikTyp: 'motor' | 'bandOben' | 'warnung';
config: Record<string, unknown>;
options: Record<string, unknown>;
ergebnis?: DrawDataDto;
}
export interface XamlVariante {
zustand: string;
svg?: string;
xaml?: string;
xamlBase64: string;
}
@@ -17,20 +27,23 @@ export interface ViewElementBasis {
posY: number;
zIndex: number;
show: boolean;
manuell?: boolean;
}
export type ProConViewElement =
| (ViewElementBasis & { darstellung: 'xaml'; typ: string; varianten: XamlVariante[] })
| (ViewElementBasis & { darstellung: 'standard'; typ: 'anfahrzeit' | 'betriebsart' | 'text' });
| (ViewElementBasis & { darstellung: 'xaml'; typ: string; varianten: XamlVariante[]; generator?: GrafikGeneratorDaten })
| (ViewElementBasis & { darstellung: 'standard'; typ: 'anfahrzeit' | 'betriebsart' | 'text' | 'motor' });
const standardTypen = ['anfahrzeit', 'betriebsart', 'text'];
const standardTypen = ['anfahrzeit', 'betriebsart', 'text', 'motor'];
const dateiTeil = /^[a-zA-Z0-9_-]+$/;
const endlich = { validator: Number.isFinite, message: 'Wert muss eine endliche Zahl sein' };
const VarianteSchema = new MongooseSchema<XamlVariante>({
svg: { type: String },
xaml: { type: String },
zustand: { type: String, required: true, match: dateiTeil },
xamlBase64: { type: String, default: '' },
}, { _id: false, strict: 'throw' });
}, { _id: false, strict: 'throw', minimize: false });
const ElementSchema = new MongooseSchema<ViewElementBasis>({
key: { type: String, required: true, match: dateiTeil },
@@ -41,12 +54,16 @@ const ElementSchema = new MongooseSchema<ViewElementBasis>({
posY: { type: Number, required: true, validate: endlich },
zIndex: { type: Number, required: true, validate: { validator: Number.isSafeInteger, message: 'zIndex muss ganzzahlig sein' } },
show: { type: Boolean, default: true },
}, { discriminatorKey: 'darstellung', strict: 'throw' });
manuell: { type: Boolean, default: false },
}, { discriminatorKey: 'darstellung', strict: 'throw', minimize: false });
@Schema({ collection: 'proConViewAggregate', timestamps: true, strict: 'throw' })
@Schema({ collection: 'proConViewAggregate', timestamps: true, strict: 'throw', minimize: false })
export class ProConViewAggregate {
_id!: Types.ObjectId;
@Prop({ type: String, default: null })
positionsMasterId!: string | null;
@Prop({ type: MongooseSchema.Types.ObjectId, ref: VisuAggregate.name, required: true, immutable: true })
visuAggregateId!: Types.ObjectId;
@@ -69,6 +86,15 @@ ProConViewAggregateSchema.index({ visuAggregateId: 1 }, { unique: true });
const elemente = ProConViewAggregateSchema.path<MongooseSchema.Types.DocumentArray>('elemente');
elemente.discriminator('xaml', new MongooseSchema({
generator: {
type: new MongooseSchema({
grafikTyp: { type: String, enum: ['motor', 'bandOben', 'warnung'], required: true },
config: { type: MongooseSchema.Types.Mixed, required: true },
options: { type: MongooseSchema.Types.Mixed, default: () => ({}) },
ergebnis: { type: MongooseSchema.Types.Mixed },
}, { _id: false, strict: 'throw', minimize: false }),
default: undefined,
},
typ: {
type: String, required: true,
validate: { validator: (typ: string) => !standardTypen.includes(typ), message: 'Dieser Elementtyp verwendet keine XAML-Grafiken' },
@@ -80,8 +106,8 @@ elemente.discriminator('xaml', new MongooseSchema({
message: 'Zustände müssen pro Element eindeutig sein',
},
},
}, { _id: false, strict: 'throw' }));
}, { _id: false, strict: 'throw', minimize: false }));
elemente.discriminator('standard', new MongooseSchema({
typ: { type: String, enum: standardTypen, required: true },
}, { _id: false, strict: 'throw' }));
}, { _id: false, strict: 'throw', minimize: false }));