diff --git a/admin/src/components/Federation/CommunityVisualizeItem.vue b/admin/src/components/Federation/CommunityVisualizeItem.vue
index 9ec303c34..e72b2a155 100644
--- a/admin/src/components/Federation/CommunityVisualizeItem.vue
+++ b/admin/src/components/Federation/CommunityVisualizeItem.vue
@@ -33,9 +33,15 @@
- {{ $t('federation.coordinates') }} {{ item.location.coordinates[1] }} {{
- item.location.coordinates[0]
- }}
+ {{ $t('federation.coordinates') }}
+
+ {{
+ $t('geo-coordinates.format', {
+ latitude: location.coordinates[1],
+ longitude: location.coordinates[0],
+ })
+ }}
+
@@ -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
},
},
}
diff --git a/admin/src/components/Federation/GMSApiKey.vue b/admin/src/components/Federation/GMSApiKey.vue
index 1e6c22868..a73c47115 100644
--- a/admin/src/components/Federation/GMSApiKey.vue
+++ b/admin/src/components/Federation/GMSApiKey.vue
@@ -11,7 +11,7 @@ export default {
value: {
type: String,
required: false,
- default: '',
+ default: null,
},
},
data() {
diff --git a/admin/src/components/input/Coordinates.vue b/admin/src/components/input/Coordinates.vue
index 28a52971c..ccdcbaff5 100644
--- a/admin/src/components/input/Coordinates.vue
+++ b/admin/src/components/input/Coordinates.vue
@@ -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) {
diff --git a/admin/src/graphql/updateHomeCommunity.js b/admin/src/graphql/updateHomeCommunity.js
index a33e7164c..f38ec9e1f 100644
--- a/admin/src/graphql/updateHomeCommunity.js
+++ b/admin/src/graphql/updateHomeCommunity.js
@@ -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
}
diff --git a/admin/src/locales/de.json b/admin/src/locales/de.json
index 91f4f0a7a..eb540b881 100644
--- a/admin/src/locales/de.json
+++ b/admin/src/locales/de.json
@@ -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."
diff --git a/admin/src/locales/en.json b/admin/src/locales/en.json
index 80c31503b..f534d38a7 100644
--- a/admin/src/locales/en.json
+++ b/admin/src/locales/en.json
@@ -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."
}
diff --git a/backend/src/graphql/input/EditCommunityInput.ts b/backend/src/graphql/input/EditCommunityInput.ts
index b1bfc20fb..d36a6d6b7 100644
--- a/backend/src/graphql/input/EditCommunityInput.ts
+++ b/backend/src/graphql/input/EditCommunityInput.ts
@@ -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
}
diff --git a/backend/src/graphql/model/AdminCommunityView.ts b/backend/src/graphql/model/AdminCommunityView.ts
index c92a41b90..eb9197b73 100644
--- a/backend/src/graphql/model/AdminCommunityView.ts
+++ b/backend/src/graphql/model/AdminCommunityView.ts
@@ -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
diff --git a/backend/src/graphql/validator/Point.ts b/backend/src/graphql/validator/Point.ts
index e82836e67..0e4c90e38 100644
--- a/backend/src/graphql/validator/Point.ts
+++ b/backend/src/graphql/validator/Point.ts
@@ -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
diff --git a/database/entity/0085-add_community_location/Community.ts b/database/entity/0085-add_community_location/Community.ts
index 60410c8ce..2bd4f0ced 100644
--- a/database/entity/0085-add_community_location/Community.ts
+++ b/database/entity/0085-add_community_location/Community.ts
@@ -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',
diff --git a/database/migrations/0085-add_community_location.ts b/database/migrations/0085-add_community_location.ts
index b6f0ea917..1a5b233c7 100644
--- a/database/migrations/0085-add_community_location.ts
+++ b/database/migrations/0085-add_community_location.ts
@@ -4,7 +4,7 @@
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) {
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`;',
)
}