mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
change Point to nullable and validate return only true if two coordinates exist
This commit is contained in:
parent
d6f58ef7d9
commit
e1edec5678
@ -33,9 +33,15 @@
|
||||
<template #view>
|
||||
<label>{{ $t('federation.gmsApiKey') }} {{ gmsApiKey }}</label>
|
||||
<b-form-group>
|
||||
{{ $t('federation.coordinates') }} {{ item.location.coordinates[1] }} {{
|
||||
item.location.coordinates[0]
|
||||
}}
|
||||
{{ $t('federation.coordinates') }}
|
||||
<span v-if="isValidLocation">
|
||||
{{
|
||||
$t('geo-coordinates.format', {
|
||||
latitude: location.coordinates[1],
|
||||
longitude: location.coordinates[0],
|
||||
})
|
||||
}}
|
||||
</span>
|
||||
</b-form-group>
|
||||
</template>
|
||||
<template #edit>
|
||||
@ -95,16 +101,12 @@ export default {
|
||||
formatDistanceToNow,
|
||||
locale: this.$i18n.locale,
|
||||
details: false,
|
||||
gmsApiKey: '',
|
||||
location: () => ({
|
||||
type: 'Point',
|
||||
coordinates: [],
|
||||
}),
|
||||
gmsApiKey: this.item.gmsApiKey,
|
||||
location: this.item.location,
|
||||
originalGmsApiKey: this.item.gmsApiKey,
|
||||
originalLocation: this.item.location,
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.resetHomeCommunityEditable()
|
||||
},
|
||||
computed: {
|
||||
verified() {
|
||||
if (!this.item.federatedCommunities || this.item.federatedCommunities.length === 0) {
|
||||
@ -153,6 +155,15 @@ export default {
|
||||
}
|
||||
return ''
|
||||
},
|
||||
isLocationChanged() {
|
||||
return this.originalLocation !== this.location
|
||||
},
|
||||
isGMSApiKeyChanged() {
|
||||
return this.originalGmsApiKey !== this.gmsApiKey
|
||||
},
|
||||
isValidLocation() {
|
||||
return this.location && this.location.coordinates.length === 2
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
toggleDetails() {
|
||||
@ -169,15 +180,23 @@ export default {
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
this.toastSuccess(this.$t('federation.toast_gmsApiKeyUpdated'))
|
||||
if (this.isLocationChanged && this.isGMSApiKeyChanged) {
|
||||
this.toastSuccess(this.$t('federation.toast_gmsApiKeyAndLocationUpdated'))
|
||||
} else if (this.isGMSApiKeyChanged) {
|
||||
this.toastSuccess(this.$t('federation.toast_gmsApiKeyUpdated'))
|
||||
} else if (this.isLocationChanged) {
|
||||
this.toastSuccess(this.$t('federation.toast_gmsLocationUpdated'))
|
||||
}
|
||||
this.originalLocation = this.location
|
||||
this.originalGmsApiKey = this.gmsApiKey
|
||||
})
|
||||
.catch((error) => {
|
||||
this.toastError(error.message)
|
||||
})
|
||||
},
|
||||
resetHomeCommunityEditable() {
|
||||
this.gmsApiKey = this.item.gmsApiKey
|
||||
this.location = this.item.location
|
||||
this.location = this.originalLocation
|
||||
this.gmsApiKey = this.originalGmsApiKey
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ export default {
|
||||
value: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: '',
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
|
||||
@ -41,23 +41,23 @@
|
||||
export default {
|
||||
props: {
|
||||
value: Object,
|
||||
default: () => ({
|
||||
type: 'Point',
|
||||
coordinates: [],
|
||||
}),
|
||||
default: null,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
inputValue: this.value,
|
||||
originalValueString: this.getLatitudeLongitudeString(this.value),
|
||||
longitude: this.value.coordinates[0],
|
||||
latitude: this.value.coordinates[1],
|
||||
longitude: this.value ? this.value.coordinates[0] : '',
|
||||
latitude: this.value ? this.value.coordinates[1] : '',
|
||||
latitudeLongitude: this.getLatitudeLongitudeString(this.value),
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isValid() {
|
||||
return this.inputValue.coordinates.length === 0 || this.inputValue.coordinates.length === 2
|
||||
return (
|
||||
(!isNaN(parseFloat(this.longitude)) && !isNaN(parseFloat(this.latitude))) ||
|
||||
(this.longitude === '' && this.latitude === '')
|
||||
)
|
||||
},
|
||||
isChanged() {
|
||||
return this.getLatitudeLongitudeString(this.inputValue) !== this.originalValueString
|
||||
@ -80,20 +80,35 @@ export default {
|
||||
this.valueUpdated()
|
||||
},
|
||||
getLatitudeLongitudeString(geoJSONPoint) {
|
||||
if (geoJSONPoint.coordinates.length !== 2) {
|
||||
if (!geoJSONPoint || geoJSONPoint.coordinates.length !== 2) {
|
||||
return ''
|
||||
}
|
||||
return `${geoJSONPoint.coordinates[1] ?? '0'}, ${geoJSONPoint.coordinates[0] ?? '0'}`
|
||||
return this.$t('geo-coordinates.format', {
|
||||
latitude: geoJSONPoint.coordinates[1],
|
||||
longitude: geoJSONPoint.coordinates[0],
|
||||
})
|
||||
},
|
||||
valueUpdated() {
|
||||
this.inputValue.coordinates = [this.longitude, this.latitude]
|
||||
if (this.longitude && this.latitude) {
|
||||
this.inputValue = {
|
||||
type: 'Point',
|
||||
coordinates: [this.longitude, this.latitude],
|
||||
}
|
||||
} else {
|
||||
this.inputValue = null
|
||||
}
|
||||
this.latitudeLongitude = this.getLatitudeLongitudeString(this.inputValue)
|
||||
|
||||
// make sure all coordinates are numbers
|
||||
this.inputValue.coordinates = this.inputValue.coordinates
|
||||
.map((coord) => parseFloat(coord))
|
||||
// Remove null and NaN values
|
||||
.filter((coord) => coord !== null && !isNaN(coord))
|
||||
if (this.inputValue) {
|
||||
// make sure all coordinates are numbers
|
||||
this.inputValue.coordinates = this.inputValue.coordinates
|
||||
.map((coord) => parseFloat(coord))
|
||||
// Remove null and NaN values
|
||||
.filter((coord) => coord !== null && !isNaN(coord))
|
||||
if (this.inputValue.coordinates.length === 0) {
|
||||
this.inputValue = null
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isValid && this.isChanged) {
|
||||
if (this.$parent.valueChanged) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export const updateHomeCommunity = gql`
|
||||
mutation ($uuid: String!, $gmsApiKey: String!, $location: Point!) {
|
||||
mutation ($uuid: String!, $gmsApiKey: String, $location: Point) {
|
||||
updateHomeCommunity(uuid: $uuid, gmsApiKey: $gmsApiKey, location: $location) {
|
||||
id
|
||||
}
|
||||
|
||||
@ -80,7 +80,9 @@
|
||||
"coordinates": "Koordinaten:",
|
||||
"createdAt": "Erstellt am",
|
||||
"gmsApiKey": "GMS API Key:",
|
||||
"toast_gmsApiKeyAndLocationUpdated": "Der GMS Api Key und die Location wurden erfolgreich aktualisiert!",
|
||||
"toast_gmsApiKeyUpdated": "Der GMS Api Key wurde erfolgreich aktualisiert!",
|
||||
"toast_gmsLocationUpdated": "Die GMS Location wurde erfolgreich aktualisiert!",
|
||||
"gradidoInstances": "Gradido Instanzen",
|
||||
"lastAnnouncedAt": "letzte Bekanntgabe",
|
||||
"lastErrorAt": "Letzer Fehler am",
|
||||
@ -104,6 +106,7 @@
|
||||
},
|
||||
"geo-coordinates": {
|
||||
"both-or-none": "Bitte beide oder keine eingeben!",
|
||||
"format": "{latitude}, {longitude}",
|
||||
"label": "Geo-Koordinaten",
|
||||
"latitude-longitude-smart": {
|
||||
"describe": "Teilt Koordinaten im Format 'Breitengrad, Längengrad' automatisch auf. Fügen sie hier einfach z.B. ihre Koordinaten von Google Maps, zum Beispiel: 49.28187664243721, 9.740672183943639, ein."
|
||||
|
||||
@ -80,7 +80,9 @@
|
||||
"coordinates": "Coordinates:",
|
||||
"createdAt": "Created At ",
|
||||
"gmsApiKey": "GMS API Key:",
|
||||
"toast_gmsApiKeyAndLocationUpdated": "The GMS Api Key and the location have been successfully updated!",
|
||||
"toast_gmsApiKeyUpdated": "The GMS Api Key has been successfully updated!",
|
||||
"toast_gmsLocationUpdated": "The GMS location has been successfully updated!",
|
||||
"gradidoInstances": "Gradido Instances",
|
||||
"lastAnnouncedAt": "Last Announced",
|
||||
"lastErrorAt": "last error at",
|
||||
@ -105,6 +107,7 @@
|
||||
"geo-coordinates": {
|
||||
"both-or-none": "Please enter both or none!",
|
||||
"label": "geo-coordinates",
|
||||
"format": "{latitude}, {longitude}",
|
||||
"latitude-longitude-smart": {
|
||||
"describe": "Automatically splits coordinates in the format 'latitude, longitude'. Simply enter your coordinates from Google Maps here, for example: 49.28187664243721, 9.740672183943639."
|
||||
}
|
||||
|
||||
@ -11,11 +11,11 @@ export class EditCommunityInput {
|
||||
@IsUUID('4')
|
||||
uuid: string
|
||||
|
||||
@Field(() => String)
|
||||
@Field(() => String, {nullable: true})
|
||||
@IsString()
|
||||
gmsApiKey: string
|
||||
gmsApiKey: string | null
|
||||
|
||||
@Field(() => Point)
|
||||
@Field(() => Point, {nullable: true})
|
||||
@isValidPoint()
|
||||
location: Point
|
||||
location: Point | null
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ export class AdminCommunityView {
|
||||
this.uuid = dbCom.communityUuid
|
||||
this.authenticatedAt = dbCom.authenticatedAt
|
||||
this.gmsApiKey = dbCom.gmsApiKey
|
||||
this.location = dbCom.location ? dbCom.location as Point : new Point()
|
||||
this.location = dbCom.location
|
||||
}
|
||||
|
||||
@Field(() => Boolean)
|
||||
@ -64,8 +64,8 @@ export class AdminCommunityView {
|
||||
@Field(() => String, { nullable: true })
|
||||
gmsApiKey: string | null
|
||||
|
||||
@Field(() => Point)
|
||||
location: Point
|
||||
@Field(() => Point, { nullable: true })
|
||||
location: Point | null
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
creationDate: Date | null
|
||||
|
||||
@ -14,8 +14,6 @@ export function isValidPoint(validationOptions?: ValidationOptions) {
|
||||
if (value.type === 'Point') {
|
||||
if (value.coordinates.length === 2) {
|
||||
return value.coordinates.every((coord) => typeof coord === 'number')
|
||||
} else if(value.coordinates.length === 0) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
UpdateDateColumn,
|
||||
OneToMany,
|
||||
JoinColumn,
|
||||
Geometry,
|
||||
Point,
|
||||
} from 'typeorm'
|
||||
import { FederatedCommunity } from '../FederatedCommunity'
|
||||
import { GeometryTransformer } from '../../src/typeorm/GeometryTransformer'
|
||||
@ -56,12 +56,12 @@ export class Community extends BaseEntity {
|
||||
|
||||
@Column({
|
||||
name: 'location',
|
||||
type: 'geometry',
|
||||
type: 'point',
|
||||
default: null,
|
||||
nullable: true,
|
||||
transformer: GeometryTransformer,
|
||||
})
|
||||
location: Geometry | null
|
||||
location: Point | null
|
||||
|
||||
@CreateDateColumn({
|
||||
name: 'created_at',
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN IF NOT EXISTS `location` geometry DEFAULT NULL NULL AFTER `gms_api_key`;',
|
||||
'ALTER TABLE `communities` ADD COLUMN IF NOT EXISTS `location` POINT DEFAULT NULL NULL AFTER `gms_api_key`;',
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user