kopia lustrzana https://github.com/FacilMap/facilmap
Fix handling of marker/line default values
rodzic
e7d17f2469
commit
304b56d9c6
|
@ -173,7 +173,8 @@
|
|||
class="btn-check"
|
||||
:id="`${id}-mode-${mode}`"
|
||||
:name="`${id}-mode`"
|
||||
:checked="decodedMode.mode == mode"
|
||||
v-model="decodedMode.mode"
|
||||
:value="mode"
|
||||
:tabindex="tabindex != null ? tabindex + idx : undefined"
|
||||
v-tooltip:[tooltipPlacement]="`Go ${constants.modeTitle[mode]}`"
|
||||
:disabled="disabled"
|
||||
|
|
|
@ -192,19 +192,16 @@ export default class DatabaseLines {
|
|||
async createLine(padId: PadId, data: Line<CRU.CREATE_VALIDATED>, trackPointsFromRoute?: Route): Promise<Line> {
|
||||
const type = await this._db.types.getType(padId, data.typeId);
|
||||
|
||||
if(type.defaultColour && !data.colour)
|
||||
data.colour = type.defaultColour;
|
||||
if(type.defaultWidth && !data.width)
|
||||
data.width = type.defaultWidth;
|
||||
if(type.defaultMode && !data.mode)
|
||||
data.mode = type.defaultMode;
|
||||
const resolvedData = {
|
||||
...data,
|
||||
colour: data.colour ?? type.defaultColour,
|
||||
width: data.width ?? type.defaultWidth,
|
||||
mode: data.mode ?? type.defaultMode
|
||||
};
|
||||
|
||||
const { trackPoints, ...routeInfo } = await calculateRouteForLine(data, trackPointsFromRoute);
|
||||
const { trackPoints, ...routeInfo } = await calculateRouteForLine(resolvedData, trackPointsFromRoute);
|
||||
|
||||
const dataCopy = { ...data, ...routeInfo };
|
||||
delete dataCopy.trackPoints; // They came if mode is track
|
||||
|
||||
const createdLine = await this._db.helpers._createPadObject<Line>("Line", padId, dataCopy);
|
||||
const createdLine = await this._db.helpers._createPadObject<Line>("Line", padId, omit({ ...resolvedData, ...routeInfo }, "trackPoints" /* Part of data if mode is track */));
|
||||
await this._db.helpers._updateObjectStyles(createdLine);
|
||||
|
||||
// We have to emit this before calling _setLinePoints so that this event is sent to the client first
|
||||
|
|
|
@ -82,20 +82,15 @@ export default class DatabaseMarkers {
|
|||
|
||||
async createMarker(padId: PadId, data: Marker<CRU.CREATE_VALIDATED>): Promise<Marker> {
|
||||
const type = await this._db.types.getType(padId, data.typeId);
|
||||
const elevation = await getElevationForPoint(data);
|
||||
|
||||
if(type.defaultColour)
|
||||
data.colour = type.defaultColour;
|
||||
if(type.defaultSize)
|
||||
data.size = type.defaultSize;
|
||||
if(type.defaultSymbol)
|
||||
data.symbol = type.defaultSymbol;
|
||||
if(type.defaultShape)
|
||||
data.shape = type.defaultShape;
|
||||
|
||||
data.ele = elevation ?? null;
|
||||
|
||||
const result = await this._db.helpers._createPadObject<Marker>("Marker", padId, data);
|
||||
const result = await this._db.helpers._createPadObject<Marker>("Marker", padId, {
|
||||
...data,
|
||||
colour: data.colour ?? type.defaultColour,
|
||||
size: data.size ?? type.defaultSize,
|
||||
symbol: data.symbol ?? type.defaultSymbol,
|
||||
shape: data.shape ?? type.defaultShape,
|
||||
ele: data.ele ?? await getElevationForPoint(data)
|
||||
});
|
||||
|
||||
await this._db.helpers._updateObjectStyles(result);
|
||||
|
||||
|
|
|
@ -175,8 +175,8 @@ export default class DatabaseMigrations {
|
|||
|
||||
// Forbid null defaultSize
|
||||
if (typesAttributes.defaultSize.allowNull) {
|
||||
// 35 is the old default size, now it is 40
|
||||
await this._db.types.TypeModel.update({ defaultSize: 35 }, { where: { defaultSize: null as any } });
|
||||
// 25 is the old default size, now it is 30
|
||||
await this._db.types.TypeModel.update({ defaultSize: 25 }, { where: { defaultSize: null as any } });
|
||||
await queryInterface.changeColumn("Types", "defaultSize", this._db.types.TypeModel.getAttributes().defaultSize);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ export const lineValidator = cruValidator({
|
|||
routePoints: optionalUpdate(z.array(pointValidator).min(2)),
|
||||
typeId: optionalUpdate(idValidator),
|
||||
name: optionalCreate(z.string().trim(), ""),
|
||||
mode: optionalCreate(routeModeValidator, ""),
|
||||
colour: optionalCreate(colourValidator, "0000ff"),
|
||||
width: optionalCreate(z.number(), 4),
|
||||
mode: optionalCreate(routeModeValidator), // defaults to type.defaultMode
|
||||
colour: optionalCreate(colourValidator), // defaults to type.defaultColour
|
||||
width: optionalCreate(z.number()), // defaults to type.defaultWidth
|
||||
data: optionalCreate(z.record(z.string())),
|
||||
extraInfo: optionalCreate(extraInfoValidator.or(z.null()), null),
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ export const markerValidator = cruValidator({
|
|||
...mapValues(pointValidator.shape, optionalUpdate),
|
||||
typeId: optionalUpdate(idValidator),
|
||||
name: optionalCreate(z.string().trim(), ""),
|
||||
symbol: optionalCreate(symbolValidator, ""),
|
||||
shape: optionalCreate(shapeValidator, ""),
|
||||
colour: optionalCreate(colourValidator, "ff0000"),
|
||||
size: optionalCreate(sizeValidator, 30),
|
||||
symbol: optionalCreate(symbolValidator), // defaults to type.defaultSymbol
|
||||
shape: optionalCreate(shapeValidator), // defaults to type.defaultShape
|
||||
colour: optionalCreate(colourValidator), // defaults to type.defaultColour
|
||||
size: optionalCreate(sizeValidator), // defaults to type.defaultSize
|
||||
data: optionalCreate(z.record(z.string())),
|
||||
ele: optionalCreate(z.number().or(z.null()), null)
|
||||
});
|
||||
|
|
|
@ -52,7 +52,7 @@ const rawTypeValidator = cruValidator({
|
|||
|
||||
defaultColour: optionalCreate(colourValidator), // Default value is applied below
|
||||
colourFixed: optionalCreate(z.boolean(), false),
|
||||
defaultSize: optionalCreate(sizeValidator, 40),
|
||||
defaultSize: optionalCreate(sizeValidator, 30),
|
||||
sizeFixed: optionalCreate(z.boolean(), false),
|
||||
defaultSymbol: optionalCreate(symbolValidator, ""),
|
||||
symbolFixed: optionalCreate(z.boolean(), false),
|
||||
|
|
Ładowanie…
Reference in New Issue