Skip to content

Commit

Permalink
yes
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhorner committed Sep 16, 2024
1 parent 706552a commit 222e24e
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 50 deletions.
3 changes: 3 additions & 0 deletions packages/backend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
68 changes: 66 additions & 2 deletions packages/backend/package-lock.json

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

1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@nestjs/core": "^10.0.0",
"@nestjs/event-emitter": "^2.0.4",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.4.0",
"@nestjs/typeorm": "^10.0.2",
"bullmq": "^5.13.0",
"chokidar": "^3.6.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import { NestFactory } from "@nestjs/core"
import { AppModule } from "./app.module"
import { existsSync } from "fs"
import sirv from "sirv"
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"

async function bootstrap() {
const app = await NestFactory.create(AppModule)

app.setGlobalPrefix("api")

const config = new DocumentBuilder()
.setTitle("Streetlens API")
.setVersion("1.0")
.build()

const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup("swagger", app, document)

if (process.env.FRONTEND_ROOT && existsSync(process.env.FRONTEND_ROOT)) {
console.log(`Serving frontend from ${process.env.FRONTEND_ROOT}`)
app.use(
Expand Down
25 changes: 21 additions & 4 deletions packages/backend/src/tracks/tracks.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Body, Controller, Get, Post, Query } from "@nestjs/common"
import { TracksService } from "./tracks.service"
import { JobType } from "bullmq"

@Controller("tracks")
export class TracksController {
Expand All @@ -26,11 +27,27 @@ export class TracksController {
}))
}

@Post("import")
async import(
@Body("filePath") filePath: string,
@Body("force") force?: boolean,
@Get("imports")
async listImports(
@Query("limit") limit: number = 10,
@Query("state") state?: JobType,
) {
const jobs = await this.tracksService.listImports(limit, state)
return Promise.all(
jobs.map(async (job) => {
return {
id: job.id,
name: job.name,
status: await job.getState(),
createdAt: job.timestamp,
finishedAt: job.finishedOn ?? null,
}
}),
)
}

@Post("imports")
async import(@Body("path") filePath: string, @Body("force") force?: boolean) {
const job = await this.tracksService.startImport(filePath, force)
return job.id
}
Expand Down
10 changes: 9 additions & 1 deletion packages/backend/src/tracks/tracks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TRACK_IMPORT_QUEUE,
TrackImportPayload,
} from "./track-import.processor"
import { Queue } from "bullmq"
import { JobType, Queue } from "bullmq"
import * as fs from "node:fs"
import * as path from "node:path"

Expand Down Expand Up @@ -64,6 +64,14 @@ export class TracksService {
return query.getMany()
}

async listImports(limit: number = 10, state?: JobType) {
return this.trackImportQueue.getJobs(
state ?? ["wait", "waiting", "active", "completed", "failed", "paused"],
0,
limit,
)
}

async get(id: number): Promise<Track> {
return this.tracksRepository.findOneBy({ id })
}
Expand Down
88 changes: 45 additions & 43 deletions packages/frontend/src/lib/components/TrackMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -142,47 +142,49 @@
</div>
</Control>

<GeoJSON id="tracks" data={data}>
<LineLayer
manageHoverState
hoverCursor="pointer"
layout={{ 'line-cap': 'round', 'line-join': 'round' }}
on:click={(e) => selectedTrack = e.detail.features?.[0]?.properties}
paint={{
'line-width': 5,
'line-color': [
'case',
['==', ['get', 'name'], selectedTrack?.name ?? ""],
'#FF0000',
[
'interpolate',
['linear'],
['get', 'captureDate'],
minDate, '#004D00',
maxDate, '#00FF00'
]
],
'line-opacity': 1
}}
>
<Popup openOn="click" closeButton let:data>
<table class="track-props">
<tbody>
<tr>
<th>Name</th>
<td>{selectedTrack?.name}</td>
</tr>
<tr>
<th>Capture Date</th>
<td>{new Date(selectedTrack?.captureDate).toLocaleString()}</td>
</tr>
<tr>
<th>File Path</th>
<td>{selectedTrack?.filePath}</td>
</tr>
</tbody>
</table>
</Popup>
</LineLayer>
</GeoJSON>
{#if data.features.length > 0}
<GeoJSON id="tracks" data={data}>
<LineLayer
manageHoverState
hoverCursor="pointer"
layout={{ 'line-cap': 'round', 'line-join': 'round' }}
on:click={(e) => selectedTrack = e.detail.features?.[0]?.properties}
paint={{
'line-width': 5,
'line-color': [
'case',
['==', ['get', 'name'], selectedTrack?.name ?? ""],
'#FF0000',
[
'interpolate',
['linear'],
['get', 'captureDate'],
minDate, '#004D00',
maxDate, '#00FF00'
]
],
'line-opacity': 1
}}
>
<Popup openOn="click" closeButton let:data>
<table class="track-props">
<tbody>
<tr>
<th>Name</th>
<td>{selectedTrack?.name}</td>
</tr>
<tr>
<th>Capture Date</th>
<td>{new Date(selectedTrack?.captureDate).toLocaleString()}</td>
</tr>
<tr>
<th>File Path</th>
<td>{selectedTrack?.filePath}</td>
</tr>
</tbody>
</table>
</Popup>
</LineLayer>
</GeoJSON>
{/if}
</MapLibre>

0 comments on commit 222e24e

Please sign in to comment.