Skip to content

Commit

Permalink
Consolidate Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Sep 25, 2024
1 parent 59a5a92 commit 55c59c6
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 31 deletions.
47 changes: 30 additions & 17 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"@types/busboy": "^1.5.0",
"@types/connect-history-api-fallback": "^1.3.5",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.16",
"@types/express": "^5.0.0",
"@types/geojson": "^7946.0.10",
"@types/jsonwebtoken": "^9.0.1",
"@types/memjs": "^1.3.0",
Expand Down
47 changes: 38 additions & 9 deletions api/routes/basemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import { Basemap } from '../lib/schema.js';
import { toEnum, Basemap_Format, Basemap_Style, Basemap_Type } from '../lib/enums.js';
import * as Default from '../lib/limits.js';

const AugmentedBasemapResponse = Type.Composite([
Type.Omit(BasemapResponse, ['bounds', 'center']),
Type.Object({
bounds: Type.Optional(Type.Array(Type.Number(), { minItems: 4, maxItems: 4 })),
center: Type.Optional(Type.Array(Type.Number()))
})
])

export default async function router(schema: Schema, config: Config) {
await schema.put('/basemap', {
name: 'Import BaseMaps',
Expand Down Expand Up @@ -142,7 +150,7 @@ export default async function router(schema: Schema, config: Config) {
}),
res: Type.Object({
total: Type.Integer(),
items: Type.Array(BasemapResponse)
items: Type.Array(AugmentedBasemapResponse)
})
}, async (req, res) => {
try {
Expand All @@ -166,7 +174,16 @@ export default async function router(schema: Schema, config: Config) {
`
});

return res.json(list);
return res.json({
total: list.total,
items: list.items.map((basemap) => {
return {
...basemap,
bounds: basemap.bounds ? bbox(basemap.bounds) : undefined,
center: basemap.center ? basemap.center.coordinates : undefined,
};
})
});
} catch (err) {
return Err.respond(err, res);
}
Expand All @@ -189,7 +206,7 @@ export default async function router(schema: Schema, config: Config) {
bounds: Type.Optional(Type.Array(Type.Number(), { minItems: 4, maxItems: 4 })),
center: Type.Optional(Type.Array(Type.Number()))
}),
res: BasemapResponse
res: AugmentedBasemapResponse
}, async (req, res) => {
try {
const user = await Auth.as_user(config, req);
Expand Down Expand Up @@ -220,7 +237,11 @@ export default async function router(schema: Schema, config: Config) {
username
});

return res.json(basemap);
return res.json({
...basemap,
bounds: basemap.bounds ? bbox(basemap.bounds) : undefined,
center: basemap.center ? basemap.center.coordinates : undefined,
});
} catch (err) {
return Err.respond(err, res);
}
Expand All @@ -244,7 +265,7 @@ export default async function router(schema: Schema, config: Config) {
bounds: Type.Optional(Type.Array(Type.Number(), { minItems: 4, maxItems: 4 })),
center: Type.Optional(Type.Array(Type.Number()))
}),
res: BasemapResponse
res: AugmentedBasemapResponse
}, async (req, res) => {
try {
const user = await Auth.as_user(config, req);
Expand All @@ -266,13 +287,17 @@ export default async function router(schema: Schema, config: Config) {

const basemap = await config.models.Basemap.commit(Number(req.params.basemapid), {
updated: sql`Now()`,
...req.body,
bounds, center,
...req.body
});

await config.cacher.del(`basemap-${req.params.basemapid}`);

return res.json(basemap);
return res.json({
...basemap,
bounds: basemap.bounds ? bbox(basemap.bounds) : undefined,
center: basemap.center ? basemap.center.coordinates : undefined,
});
} catch (err) {
return Err.respond(err, res);
}
Expand All @@ -290,7 +315,7 @@ export default async function router(schema: Schema, config: Config) {
format: Type.Optional(Type.String()),
token: Type.Optional(Type.String()),
}),
res: Type.Union([BasemapResponse, Type.String()])
res: Type.Union([AugmentedBasemapResponse, Type.String()])
}, async (req, res) => {
try {
const user = await Auth.as_user(config, req, { token: true });
Expand Down Expand Up @@ -326,7 +351,11 @@ export default async function router(schema: Schema, config: Config) {

return res.send(xml);
} else {
return res.json(basemap);
return res.json({
...basemap,
bounds: basemap.bounds ? bbox(basemap.bounds) : undefined,
center: basemap.center ? basemap.center.coordinates : undefined,
});
}
} catch (err) {
return Err.respond(err, res);
Expand Down
47 changes: 43 additions & 4 deletions api/web/src/components/Admin/AdminOverlaysEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
label='MaxZoom'
/>
</div>
<div class='col-12 col-md-6'>
<TablerInput
v-model='overlay.bounds'
label='Bounds'
/>
</div>
<div class='col-12 col-md-6'>
<TablerInput
v-model='overlay.center'
label='Center'
/>
</div>
<div class='col-12 col-md-6'>
<TablerEnum
v-model='overlay.type'
Expand Down Expand Up @@ -100,6 +112,8 @@ export default {
styles: '',
minzoom: 0,
maxzoom: 16,
bounds: '-180, -90, 180, 90',
center: '0, 0',
}
}
},
Expand All @@ -113,27 +127,52 @@ export default {
methods: {
stdclick,
saveOverlay: async function() {
const overlay = JSON.parse(JSON.stringify(this.overlay));
let overlay = JSON.parse(JSON.stringify(this.overlay));
overlay.bounds = overlay.bounds.split(',').map((b) => {
return Number(b);
})
overlay.center = overlay.center.split(',').map((b) => {
return Number(b);
})
this.loading = true;
if (this.$route.params.overlay === 'new') {
this.overlay = await std(`/api/basemap`, {
overlay = await std(`/api/basemap`, {
method: 'POST',
body: overlay
});
} else {
this.overlay = await std(`/api/basemap/${this.overlay.id}`, {
overlay = await std(`/api/basemap/${this.overlay.id}`, {
method: 'PATCH',
body: overlay
});
}
overlay.bounds = overlay.bounds.join(',');
overlay.center = overlay.center.join(',');
this.loading = false;
},
fetchOverlay: async function() {
this.loading = true;
const url = stdurl(`/api/basemap/${this.$route.params.overlay}`);
this.overlay = await std(url);
const overlay = await std(url);
if (!overlay.bounds) {
overlay.bounds = '-180, -90, 180, 90';
} else {
overlay.bounds = overlay.bounds.join(',');
}
if (!overlay.center) {
overlay.center = '0, 0';
} else {
overlay.center = overlay.center.join(',');
}
this.overlay = overlay
this.loading = false;
}
}
Expand Down

0 comments on commit 55c59c6

Please sign in to comment.