Fixed tsc warnings and errors.

This commit is contained in:
Fabio Manganiello 2025-02-24 22:02:30 +01:00
parent 696bb89e04
commit b7c6ae1f55
Signed by: blacklight
GPG key ID: D90FBA7F76362774
9 changed files with 71 additions and 36 deletions

View file

@ -21,6 +21,7 @@
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node22": "^22.0.0", "@tsconfig/node22": "^22.0.0",
"@types/lodash": "^4.17.15",
"@types/node": "^22.13.4", "@types/node": "^22.13.4",
"@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue": "^5.2.1",
"@vue/eslint-config-prettier": "^10.2.0", "@vue/eslint-config-prettier": "^10.2.0",
@ -1734,6 +1735,13 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-w/P33JFeySuhN6JLkysYUK2gEmy9kHHFN7E8ro0tkfmlDOgxBDzWEZ/J8cWA+fHqFevpswDTFZnDx+R9lbL6xw==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "22.13.4", "version": "22.13.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.4.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.4.tgz",

View file

@ -26,6 +26,7 @@
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node22": "^22.0.0", "@tsconfig/node22": "^22.0.0",
"@types/lodash": "^4.17.15",
"@types/node": "^22.13.4", "@types/node": "^22.13.4",
"@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue": "^5.2.1",
"@vue/eslint-config-prettier": "^10.2.0", "@vue/eslint-config-prettier": "^10.2.0",

View file

@ -3,12 +3,12 @@
<div class="loading" v-if="loading">Loading...</div> <div class="loading" v-if="loading">Loading...</div>
<div class="map-wrapper" v-else> <div class="map-wrapper" v-else>
<div id="map"> <div id="map">
<div class="time-range" v-if="gpsPoints?.length"> <div class="time-range" v-if="oldestPoint && newestPoint">
<div class="row"> <div class="row">
<div class="key">From</div> <div class="key">From</div>
<div class="value"> <div class="value">
<a href="#" @click.prevent.stop="onStartDateClick"> <a href="#" @click.prevent.stop="onStartDateClick">
{{ displayDate(oldestPoint?.timestamp) }} {{ displayDate(oldestPoint.timestamp) }}
</a> </a>
</div> </div>
</div> </div>
@ -16,7 +16,7 @@
<div class="key">To</div> <div class="key">To</div>
<div class="value"> <div class="value">
<a href="#" @click.prevent.stop="onEndDateClick"> <a href="#" @click.prevent.stop="onEndDateClick">
{{ displayDate(newestPoint?.timestamp) }} {{ displayDate(newestPoint.timestamp) }}
</a> </a>
</div> </div>
</div> </div>
@ -38,7 +38,7 @@
:has-next-page="hasNextPage" :has-next-page="hasNextPage"
:has-prev-page="hasPrevPage" :has-prev-page="hasPrevPage"
@refresh="locationQuery = $event" @refresh="locationQuery = $event"
@reset-page="locationQuery.minId = locationQuery.maxId = undefined" @reset-page="locationQuery.minId = locationQuery.maxId = null"
@next-page="fetchNextPage" @next-page="fetchNextPage"
@prev-page="fetchPrevPage" /> @prev-page="fetchPrevPage" />
</div> </div>
@ -94,7 +94,6 @@ export default {
data() { data() {
return { return {
loading: false, loading: false,
locationQuery: new LocationQuery({}),
map: null as Nullable<Map>, map: null as Nullable<Map>,
mappedPoints: [] as Point[], mappedPoints: [] as Point[],
mapView: null as Nullable<View>, mapView: null as Nullable<View>,
@ -140,16 +139,19 @@ export default {
createMap(gpsPoints: GPSPoint[]): Map { createMap(gpsPoints: GPSPoint[]): Map {
this.mappedPoints = this.toMappedPoints(gpsPoints) this.mappedPoints = this.toMappedPoints(gpsPoints)
this.pointsLayer = this.createPointsLayer(this.mappedPoints) this.pointsLayer = this.createPointsLayer(this.mappedPoints as Point[])
this.routesLayer = this.createRoutesLayer(this.mappedPoints) this.routesLayer = this.createRoutesLayer(this.mappedPoints as Point[])
this.mapView = this.mapView || this.createMapView(gpsPoints) this.mapView = this.mapView || this.createMapView(gpsPoints)
const map = new Map({ const map = new Map({
target: 'map', target: 'map',
layers: [ layers: [
this.createMapLayer(), this.createMapLayer(),
// @ts-ignore
this.pointsLayer, this.pointsLayer,
// @ts-ignore
this.routesLayer, this.routesLayer,
], ],
// @ts-ignore
view: this.mapView, view: this.mapView,
}) })
@ -194,15 +196,15 @@ export default {
}, },
onStartDateClick() { onStartDateClick() {
this.locationQuery.startDate = this.oldestPoint?.timestamp this.locationQuery.startDate = this.oldestPoint?.timestamp || null
this.locationQuery.minId = undefined this.locationQuery.minId = null
this.locationQuery.maxId = undefined this.locationQuery.maxId = null
}, },
onEndDateClick() { onEndDateClick() {
this.locationQuery.endDate = this.newestPoint?.timestamp this.locationQuery.endDate = this.newestPoint?.timestamp || null
this.locationQuery.minId = undefined this.locationQuery.minId = null
this.locationQuery.maxId = undefined this.locationQuery.maxId = null
}, },
}, },
@ -215,8 +217,8 @@ export default {
if (!isFirstQuery && if (!isFirstQuery &&
(newQuery.startDate !== oldQuery.startDate || newQuery.endDate !== oldQuery.endDate) (newQuery.startDate !== oldQuery.startDate || newQuery.endDate !== oldQuery.endDate)
) { ) {
newQuery.minId = undefined newQuery.minId = null
newQuery.maxId = undefined newQuery.maxId = null
this.hasNextPage = true this.hasNextPage = true
this.hasPrevPage = true this.hasPrevPage = true
} }
@ -254,8 +256,11 @@ export default {
this.mappedPoints = this.toMappedPoints(this.gpsPoints) this.mappedPoints = this.toMappedPoints(this.gpsPoints)
if (this.mapView) { if (this.mapView) {
// @ts-ignore
this.refreshMapView(this.mapView, this.gpsPoints) this.refreshMapView(this.mapView, this.gpsPoints)
// @ts-ignore
this.refreshPointsLayer(this.pointsLayer, this.mappedPoints) this.refreshPointsLayer(this.pointsLayer, this.mappedPoints)
// @ts-ignore
this.refreshRoutesLayer(this.routesLayer, this.mappedPoints) this.refreshRoutesLayer(this.routesLayer, this.mappedPoints)
} }
}, },

View file

@ -8,8 +8,8 @@
<input type="datetime-local" <input type="datetime-local"
id="start-date" id="start-date"
name="start-date" name="start-date"
@input="newFilter.startDate = startPlusHours($event.target.value, 0)" @input="newFilter.startDate = startPlusHours($event, 0)"
@change="newFilter.startDate = startPlusHours($event.target.value, 0)" @change="newFilter.startDate = startPlusHours($event, 0)"
:value="toLocalString(newFilter.startDate)" :value="toLocalString(newFilter.startDate)"
:disabled="disabled" :disabled="disabled"
:max="maxDate" /> :max="maxDate" />
@ -44,8 +44,8 @@
<input type="datetime-local" <input type="datetime-local"
id="end-date" id="end-date"
name="end-date" name="end-date"
@input="newFilter.endDate = endPlusHours($event.target.value, 0)" @input="newFilter.endDate = endPlusHours($event, 0)"
@change="newFilter.endDate = endPlusHours($event.target.value, 0)" @change="newFilter.endDate = endPlusHours($event, 0)"
:value="toLocalString(newFilter.endDate)" :value="toLocalString(newFilter.endDate)"
:disabled="disabled" :disabled="disabled"
:max="maxDate" /> :max="maxDate" />
@ -80,7 +80,7 @@
<div class="page-button-container"> <div class="page-button-container">
<button type="button" <button type="button"
:disabled="disabled" :disabled="disabled"
v-if="value.minId || value.maxId" v-if="value?.minId || value?.maxId"
@click.stop="$emit('reset-page')"> @click.stop="$emit('reset-page')">
<font-awesome-icon icon="fas fa-undo" /> <font-awesome-icon icon="fas fa-undo" />
</button> </button>
@ -99,8 +99,8 @@
<input type="number" <input type="number"
id="limit" id="limit"
name="limit" name="limit"
@input="newFilter.limit = Number($event.target.value)" @input="setLimit"
@change="newFilter.limit = Number($event.target.value)" @change="setLimit"
:value="newFilter.limit" :value="newFilter.limit"
:disabled="disabled" :disabled="disabled"
min="1" /> min="1" />
@ -168,8 +168,8 @@ export default {
return !_.isEqual( return !_.isEqual(
{ {
...oldValue, ...oldValue,
startDate: this.normalizeDate(this.value.startDate), startDate: this.normalizeDate(this.value?.startDate),
endDate: this.normalizeDate(this.value.endDate), endDate: this.normalizeDate(this.value?.endDate),
}, },
{ {
...newValue, ...newValue,
@ -179,7 +179,7 @@ export default {
) )
}, },
normalizeDate(date: Date | number | string | null): Date | null { normalizeDate(date: any): Date | null {
if (!date) { if (!date) {
return null return null
} }
@ -203,7 +203,11 @@ export default {
).toISOString().slice(0, -8) ).toISOString().slice(0, -8)
}, },
startPlusHours(date: Date | number | null, hours: number): Date | null { startPlusHours(date: Date | number | Event | undefined | null, hours: number): Date | null {
if ((date as any)?.target?.value) {
date = (date as any).target.value
}
let d = this.normalizeDate(date) let d = this.normalizeDate(date)
if (!d) { if (!d) {
return null return null
@ -219,11 +223,15 @@ export default {
return d return d
}, },
startPlusDays(date: Date | number | null, days: number): Date | null { startPlusDays(date: Date | number | Event | undefined | null, days: number): Date | null {
return this.startPlusHours(date, days * 24) return this.startPlusHours(date, days * 24)
}, },
endPlusHours(date: Date | number | null, hours: number): Date | null { endPlusHours(date: Date | number | Event | undefined | null, hours: number): Date | null {
if ((date as any)?.target?.value) {
date = (date as any).target.value
}
let d = this.normalizeDate(date) let d = this.normalizeDate(date)
if (!d) { if (!d) {
return null return null
@ -244,13 +252,17 @@ export default {
return d return d
}, },
endPlusDays(date: Date | number | null, days: number): Date | null { endPlusDays(date: Date | number | Event | undefined | null, days: number): Date | null {
return this.endPlusHours(date, days * 24) return this.endPlusHours(date, days * 24)
}, },
handleSubmit() { handleSubmit() {
this.$emit('refresh', this.newFilter) this.$emit('refresh', this.newFilter)
}, },
setLimit(event: Event) {
this.newFilter.limit = Number((event.target as HTMLInputElement).value)
},
}, },
watch: { watch: {

View file

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
export default { export default {
methods: { methods: {
displayDate(date: Date | number | string | null): string { displayDate(date: Date | number | string | null | undefined): string {
if (!date) { if (!date) {
return '-' return '-'
} }

View file

@ -8,16 +8,17 @@ export default {
gpsPoints: [] as GPSPoint[], gpsPoints: [] as GPSPoint[],
hasNextPage: true, hasNextPage: true,
hasPrevPage: true, hasPrevPage: true,
locationQuery: new LocationQuery({}),
} }
}, },
computed: { computed: {
newestPoint(): GPSPoint | undefined { newestPoint(): GPSPoint | null {
return this.gpsPoints[this.gpsPoints.length - 1] || undefined return this.gpsPoints[this.gpsPoints.length - 1] || null
}, },
oldestPoint(): GPSPoint | undefined { oldestPoint(): GPSPoint | null {
return this.gpsPoints[0] || undefined return this.gpsPoints[0] || null
}, },
}, },

View file

@ -83,6 +83,10 @@ export default {
refreshPointsLayer(layer: VectorLayer, points: Point[]) { refreshPointsLayer(layer: VectorLayer, points: Point[]) {
const source = layer.getSource() const source = layer.getSource()
if (!source) {
return
}
source.clear() source.clear()
source.addFeatures(points.map((point: Point) => new Feature(point))) source.addFeatures(points.map((point: Point) => new Feature(point)))
source.changed() source.changed()

View file

@ -27,13 +27,17 @@ export default {
refreshRoutesLayer(layer: VectorLayer, points: Point[]) { refreshRoutesLayer(layer: VectorLayer, points: Point[]) {
const routeFeatures = this.extractRouteFeatures(points) const routeFeatures = this.extractRouteFeatures(points)
const source = layer.getSource() const source = layer.getSource()
if (!source) {
return
}
source.clear() source.clear()
source.addFeatures(routeFeatures) source.addFeatures(routeFeatures)
source.changed() source.changed()
}, },
extractRouteFeatures(points: Point[]): Feature[] { extractRouteFeatures(points: Point[]): Feature[] {
const routeFeatures = [] const routeFeatures: Feature[] = []
points.forEach((point: Point, index: number) => { points.forEach((point: Point, index: number) => {
if (index === 0) { if (index === 0) {
return return

View file

@ -11,7 +11,7 @@ function isDate(key: string, value: string): boolean {
) )
} }
function parseValue(key: string, value: string | null): string | number | boolean | Date { function parseValue(key: string, value: string | null): string | number | boolean | Date | undefined {
value = decodeURI(value?.trim() || '') value = decodeURI(value?.trim() || '')
if (!value.length) { if (!value.length) {
return undefined return undefined