pfeile
This commit is contained in:
1 parent
367c93c93e
commit
4bfd5d9bf7
34 files changed
+558
-94
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import * as sql from 'mssql';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { Anlage } from '../../_schemas/anlage.schema';
|
||||
@@ -32,6 +32,7 @@ export interface GroupSyncRequest {
|
||||
masterId: string;
|
||||
elementIds?: string[];
|
||||
elements?: { id: string; values: GroupSyncValues; generator?: GrafikGeneratorDaten }[];
|
||||
newArrows?: { key: string; values: GroupSyncValues; generator: GrafikGeneratorDaten }[];
|
||||
}
|
||||
export function validateSyncValues(values: SyncValues) {
|
||||
if (!values || ['x', 'y', 'width', 'height'].some(key => typeof values[key] !== 'number' || !Number.isFinite(values[key])) ||
|
||||
@@ -116,6 +117,11 @@ export class ProConSyncService {
|
||||
const masterId = data.mainId ?? dto.masterId;
|
||||
if (!data.elements.some(item => item.id === masterId)) throw new BadRequestException('Positions-Master auswählen');
|
||||
if (dto.direction === 'saveLocal') {
|
||||
if (dto.newArrows !== undefined && (!Array.isArray(dto.newArrows) || dto.newArrows.length > 100 ||
|
||||
dto.newArrows.some(item => !item || typeof item.key !== 'string' || !/^pfeil_[0-9]+$/.test(item.key) || item.generator?.grafikTyp !== 'pfeil') ||
|
||||
new Set([...data.elements.map(item => item.key), ...dto.newArrows.map(item => item.key)]).size !== data.elements.length + dto.newArrows.length))
|
||||
throw new BadRequestException('Neue Pfeile benötigen eindeutige Schlüssel und einen Pfeilgenerator');
|
||||
dto.newArrows?.forEach(item => validateGroupValues(item.values));
|
||||
if (!Array.isArray(dto.elements) || dto.elements.length !== data.elements.length ||
|
||||
new Set(dto.elements.map(item => item.id)).size !== data.elements.length ||
|
||||
dto.elements.some(item => !data.elements.some(element => element.id === item.id)))
|
||||
@@ -175,6 +181,17 @@ export class ProConSyncService {
|
||||
}));
|
||||
}
|
||||
}
|
||||
if (dto.direction === 'saveLocal') for (const arrow of dto.newArrows ?? []) {
|
||||
const { config, options } = arrow.generator;
|
||||
const ergebnis = this.draw.renderGraphic('pfeil', { config, options });
|
||||
data.document.elemente.push({
|
||||
_id: new Types.ObjectId(), key: arrow.key, name: arrow.key, typ: 'pfeil', darstellung: 'xaml',
|
||||
posX: arrow.values.x, posY: arrow.values.y, zIndex: arrow.values.z, show: arrow.values.show,
|
||||
width: ergebnis.width, height: ergebnis.height, manuell: false,
|
||||
generator: { grafikTyp: 'pfeil', config, options: options ?? {}, ergebnis },
|
||||
varianten: ergebnis.varianten.map(variant => ({ zustand: variant.state, svg: variant.svg, xaml: variant.xaml, xamlBase64: variant.xamlBase64 })),
|
||||
});
|
||||
}
|
||||
data.document.positionsMasterId = masterId;
|
||||
data.document.markModified('elemente');
|
||||
await data.document.validate();
|
||||
|
||||
Reference in new issue
Block a user