Skip to content

Commit

Permalink
Fix handling of marker/line default values
Browse files Browse the repository at this point in the history
  • Loading branch information
cdauth committed Nov 14, 2023
1 parent e7d17f2 commit 304b56d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
3 changes: 2 additions & 1 deletion frontend/src/lib/components/ui/route-mode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 8 additions & 11 deletions server/src/database/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { trackPoints, ...routeInfo } = await calculateRouteForLine(data, trackPointsFromRoute);
const resolvedData = {
...data,
colour: data.colour ?? type.defaultColour,
width: data.width ?? type.defaultWidth,
mode: data.mode ?? type.defaultMode
};

const dataCopy = { ...data, ...routeInfo };
delete dataCopy.trackPoints; // They came if mode is track
const { trackPoints, ...routeInfo } = await calculateRouteForLine(resolvedData, trackPointsFromRoute);

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
Expand Down
21 changes: 8 additions & 13 deletions server/src/database/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions server/src/database/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions types/src/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
8 changes: 4 additions & 4 deletions types/src/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
2 changes: 1 addition & 1 deletion types/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 304b56d

Please sign in to comment.