add location and location format

This commit is contained in:
einhornimmond 2024-02-26 18:49:42 +01:00
parent 03c566919c
commit e69f345226
11 changed files with 211 additions and 42 deletions

View File

@ -1,6 +1,7 @@
import { IsBoolean, IsEnum, IsInt, IsString } from 'class-validator'
import { ArgsType, Field, InputType, Int } from 'type-graphql'
import { GmsPublishLocationType } from '@enum/GmsPublishLocationType'
import { GmsPublishNameType } from '@enum/GmsPublishNameType'
import { Location } from '@model/Location'
@ -49,10 +50,7 @@ export class UpdateUserInfosArgs {
@IsBoolean()
gmsAllowed?: boolean
@Field(() => GmsPublishNameType, {
nullable: true,
defaultValue: GmsPublishNameType.GMS_PUBLISH_NAME_ALIAS_OR_INITALS,
})
@Field(() => GmsPublishNameType, { nullable: true })
@IsEnum(GmsPublishNameType)
gmsPublishName?: GmsPublishNameType | null
@ -60,7 +58,7 @@ export class UpdateUserInfosArgs {
@isValidLocation()
gmsLocation?: Location | null
@Field(() => Int, { nullable: true, defaultValue: 2 })
@IsInt()
gmsPublishLocation?: number | null
@Field(() => GmsPublishLocationType, { nullable: true })
@IsEnum(GmsPublishLocationType)
gmsPublishLocation?: GmsPublishLocationType | null
}

View File

@ -1,6 +1,9 @@
import { User as dbUser } from '@entity/User'
import { ObjectType, Field, Int } from 'type-graphql'
import { GmsPublishLocationType } from '@enum/GmsPublishLocationType'
import { GmsPublishNameType } from '@enum/GmsPublishNameType'
import { KlickTipp } from './KlickTipp'
@ObjectType()
@ -31,6 +34,7 @@ export class User {
this.hideAmountGDT = user.hideAmountGDT
this.gmsAllowed = user.gmsAllowed
this.gmsPublishName = user.gmsPublishName
this.gmsPublishLocation = user.gmsPublishLocation
}
}
@ -79,8 +83,11 @@ export class User {
@Field(() => Boolean)
gmsAllowed: boolean
@Field(() => Int, { nullable: true })
gmsPublishName: number | null
@Field(() => GmsPublishNameType, { nullable: true })
gmsPublishName: GmsPublishNameType | null
@Field(() => GmsPublishLocationType, { nullable: true })
gmsPublishLocation: GmsPublishLocationType | null
// This is not the users publisherId, but the one of the users who recommend him
@Field(() => Int, { nullable: true })

View File

@ -0,0 +1,8 @@
<template>
<b-button>{{ $t('settings.GMS.location.button') }}</b-button>
</template>
<script>
export default {
name: 'UserGMSLocation',
}
</script>

View File

@ -0,0 +1,85 @@
<template>
<div class="user-gms-location-format">
<b-dropdown v-model="selectedOption">
<template slot="button-content">{{ selectedOptionLabel }}</template>
<b-dropdown-item
v-for="option in dropdownOptions"
@click.prevent="update(option)"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</b-dropdown-item>
</b-dropdown>
</div>
</template>
<script>
import { updateUserInfos } from '@/graphql/mutations'
export default {
name: 'UserGMSLocationFormat',
data() {
return {
selectedOption: this.$store.state.gmsPublishLocation ?? 'GMS_LOCATION_TYPE_RANDOM',
dropdownOptions: [
{
label: this.$t('settings.GMS.publish-location.exact'),
value: 'GMS_LOCATION_TYPE_EXACT',
},
{
label: this.$t('settings.GMS.publish-location.approximate'),
value: 'GMS_LOCATION_TYPE_APPROXIMATE',
},
{
label: this.$t('settings.GMS.publish-location.random'),
value: 'GMS_LOCATION_TYPE_RANDOM',
},
],
}
},
computed: {
selectedOptionLabel() {
const selected = this.dropdownOptions.find((option) => option.value === this.selectedOption)
return selected ? selected.label : this.selectedOption
},
},
methods: {
async update(option) {
if (option === this.selectedOption) {
return
}
try {
await this.$apollo.mutate({
mutation: updateUserInfos,
variables: {
gmsPublishLocation: option.value,
},
})
this.toastSuccess(this.$t('settings.GMS.publish-location.updated'))
this.selectedOption = option.value
this.$store.commit('gmsPublishLocation', option.value)
this.$emit('gmsPublishLocation', option.value)
} catch (error) {
this.toastError(error.message)
}
},
},
}
</script>
<style>
.user-gms-location-format > div,
.user-gms-location-format ul.dropdown-menu {
width: 100%;
}
.user-gms-location-format > div > button {
border-radius: 17px;
height: 50px;
text-align: left;
}
.user-gms-location-format .dropdown-toggle::after {
float: right;
top: 50%;
transform: translateY(-50%);
position: relative;
}
</style>

View File

@ -7,6 +7,7 @@
@click.prevent="update(option)"
:key="option.value"
:value="option.value"
:title="option.title"
>
{{ option.label }}
</b-dropdown-item>
@ -24,29 +25,43 @@ export default {
dropdownOptions: [
{
label: this.$t('settings.GMS.publish-name.alias-or-initials'),
title: this.$t('settings.GMS.publish-name.alias-or-initials-tooltip'),
value: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS',
},
{
label: this.$t('settings.GMS.publish-name.initials'),
title: this.$t('settings.GMS.publish-name.initials-tooltip'),
value: 'GMS_PUBLISH_NAME_INITIALS',
},
{ label: this.$t('settings.GMS.publish-name.first'), value: 'GMS_PUBLISH_NAME_FIRST' },
{
label: this.$t('settings.GMS.publish-name.first'),
title: this.$t('settings.GMS.publish-name.first-tooltip'),
value: 'GMS_PUBLISH_NAME_FIRST',
},
{
label: this.$t('settings.GMS.publish-name.first-initial'),
title: this.$t('settings.GMS.publish-name.first-initial-tooltip'),
value: 'GMS_PUBLISH_NAME_FIRST_INITIAL',
},
{ label: this.$t('settings.GMS.publish-name.name-full'), value: 'GMS_PUBLISH_NAME_FULL' },
{
label: this.$t('settings.GMS.publish-name.name-full'),
title: this.$t('settings.GMS.publish-name.name-full-tooltip'),
value: 'GMS_PUBLISH_NAME_FULL',
},
],
}
},
computed: {
selectedOptionLabel() {
const selected = this.dropdownOptions.find((option) => option.value === this.selectedOption)
return selected ? selected.label : 'Select Option'
return selected ? selected.label : this.selectedOption
},
},
methods: {
async update(option) {
if (option === this.selectedOption) {
return
}
try {
await this.$apollo.mutate({
mutation: updateUserInfos,

View File

@ -2,7 +2,7 @@
<div class="form-user-gms-switch">
<b-form-checkbox
test="BFormCheckbox"
v-model="gmsState"
v-model="gmsAllowed"
name="check-button"
switch
@change="onSubmit"
@ -16,7 +16,7 @@ export default {
name: 'UserGMSSwitch',
data() {
return {
gmsState: this.$store.state.gmsState,
gmsAllowed: this.$store.state.gmsAllowed,
}
},
methods: {
@ -25,18 +25,18 @@ export default {
.mutate({
mutation: updateUserInfos,
variables: {
gmsAllowed: this.gmsState,
gmsAllowed: this.gmsAllowed,
},
})
.then(() => {
this.$store.commit('gmsState', this.gmsState)
this.$emit('gmsStateSwitch', this.gmsState)
this.$store.commit('gmsState', this.gmsAllowed)
this.$emit('gmsStateSwitch', this.gmsAllowed)
this.toastSuccess(
this.gmsState ? this.$t('settings.GMS.enabled') : this.$t('settings.GMS.disabled'),
this.gmsAllowed ? this.$t('settings.GMS.enabled') : this.$t('settings.GMS.disabled'),
)
})
.catch((error) => {
this.gmsState = this.$store.state.gmsState
this.gmsAllowed = this.$store.state.gmsAllowed
this.toastError(error.message)
})
},

View File

@ -37,7 +37,7 @@ export const updateUserInfos = gql`
$gmsAllowed: Boolean
$gmsPublishName: GmsPublishNameType
$gmsLocation: Location
$gmsPublishLocation: Int
$gmsPublishLocation: GmsPublishLocationType
) {
updateUserInfos(
firstName: $firstName
@ -174,6 +174,7 @@ export const login = gql`
}
gmsAllowed
gmsPublishName
gmsPublishLocation
hasElopage
publisherId
roles

View File

@ -295,13 +295,29 @@
"GMS": {
"disabled": "Daten werden nicht nach GMS exportiert",
"enabled": "Daten werden nach GMS exportiert",
"location": {
"label": "Positionsbestimmung",
"button": "Klick mich!"
},
"location-format": "Positionstyp",
"naming-format": "Namensformat im GMS",
"publish-location": {
"exact": "Genaue Position",
"approximate": "Ungefähre Position",
"random": "Zufallsposition",
"updated":"Positionstyp für GMS aktualisiert"
},
"publish-name": {
"alias-or-initials": "Benutzername, falls vorhanden, oder die Initialen von Vorname und Nachname",
"first": "nur Vornamen",
"first-initial": "Vorname plus Anfangsbuchstabe des Nachnamens",
"initials": "Initialen von Vor- und Nachname unabhängig von der Existenz des Benutzernamens",
"name-full": "vollständiger Name: Vorname plus Nachname",
"alias-or-initials": "Benutzername oder Initialen",
"alias-or-initials-tooltip": "Benutzername, falls vorhanden, oder die Initialen von Vorname und Nachname",
"first": "Vorname",
"first-tooltip": "Nur der Vornamen",
"first-initial": "Vorname und Initiale",
"first-initial-tooltip": "Vornamen plus Anfangsbuchstabe des Nachnamens",
"initials": "Initialen",
"initials-tooltip": "Initialen von Vor- und Nachname unabhängig von der Existenz des Benutzernamens",
"name-full": "Ganzer Name",
"name-full-tooltip": "Vollständiger Name: Vorname plus Nachname",
"updated": "Namensformat für GMS aktualisiert"
},
"switch": "Erlaubnis Daten nach GMS zu exportieren."

View File

@ -295,13 +295,28 @@
"GMS": {
"disabled": "Data not exported to GMS",
"enabled": "Data exported to GMS",
"location": {
"label": "pinpoint location",
"button": "click me!"
},
"location-format": "location type",
"naming-format": "Format of name in GMS",
"publish-location": {
"exact": "exact position",
"approximate": "approximate position",
"random": "random position"
},
"publish-name": {
"alias-or-initials": "username if exists or Initials of firstname and lastname",
"first": "firstname only",
"first-initial": "firstname plus initial of lastname",
"alias-or-initials": "Username or initials",
"alias-or-initials-tooltip": "username if exists or Initials of firstname and lastname",
"first": "firstname",
"first-tooltip": "the firstname only",
"first-initial": "firstname and initial",
"first-initial-tooltip": "firstname plus initial of lastname",
"initials": "Initials of firstname and lastname independent if username exists",
"name-full": "fullname: firstname plus lastname",
"initials-tooltip": "Initials of firstname and lastname independent if username exists",
"name-full": "fullname",
"name-full-tooltip": "fullname: firstname plus lastname",
"updated": "format of name for GMS updated"
},
"switch": "Allow data export to GMS"

View File

@ -86,24 +86,38 @@
<b-col cols="12" md="6" lg="6">
{{ $t('settings.GMS.switch') }}
<div class="text-small">
{{ gmsState ? $t('settings.GMS.enabled') : $t('settings.GMS.disabled') }}
{{ gmsAllowed ? $t('settings.GMS.enabled') : $t('settings.GMS.disabled') }}
</div>
</b-col>
<b-col cols="12" md="6" lg="6" class="text-right">
<user-g-m-s-switch @gmsStateSwitch="gmsStateSwitch" />
</b-col>
</b-row>
<div v-if="gmsState">
<b-row class="mb-2">
<div v-if="gmsAllowed">
<b-row class="mb-4">
<b-col cols="12" md="6" lg="6">
{{ $t('settings.GMS.naming-format') }}
</b-col>
</b-row>
<b-row :style="{ marginBottom: '200px' }">
<b-col cols="24" md="12" lg="12">
<b-col cols="12" md="6" lg="6">
<user-g-m-s-naming-format />
</b-col>
</b-row>
<b-row class="mb-4">
<b-col cols="12" md="6" lg="6">
{{ $t('settings.GMS.location-format') }}
</b-col>
<b-col cols="12" md="6" lg="6">
<user-g-m-s-location-format />
</b-col>
</b-row>
<b-row class="mb-5">
<b-col cols="12" md="6" lg="6">
{{ $t('settings.GMS.location.label') }}
</b-col>
<b-col cols="12" md="6" lg="6">
<user-g-m-s-location />
</b-col>
</b-row>
</div>
</b-tab>
</b-tabs>
@ -119,6 +133,8 @@
<script>
import UserGMSSwitch from '@/components/UserSettings/UserGMSSwitch'
import UserGMSNamingFormat from '@/components/UserSettings/UserGMSNamingFormat'
import UserGMSLocationFormat from '@/components/UserSettings/UserGMSLocationFormat'
import UserGMSLocation from '@/components/UserSettings/UserGMSLocation'
import UserName from '@/components/UserSettings/UserName.vue'
import UserPassword from '@/components/UserSettings/UserPassword'
import UserLanguage from '@/components/LanguageSwitch2.vue'
@ -130,6 +146,8 @@ export default {
components: {
UserGMSSwitch,
UserGMSNamingFormat,
UserGMSLocationFormat,
UserGMSLocation,
UserName,
UserPassword,
UserLanguage,
@ -142,7 +160,7 @@ export default {
data() {
const { state } = this.$store
const { darkMode, firstName, lastName, email, newsletterState, gmsState } = state
const { darkMode, firstName, lastName, email, newsletterState, gmsAllowed } = state
return {
darkMode,
@ -151,7 +169,7 @@ export default {
lastName,
email,
newsletterState,
gmsState,
gmsAllowed,
mutation: '',
variables: {},
}

View File

@ -35,12 +35,15 @@ export const mutations = {
newsletterState: (state, newsletterState) => {
state.newsletterState = newsletterState
},
gmsState: (state, gmsState) => {
state.gmsState = gmsState
gmsAllowed: (state, gmsAllowed) => {
state.gmsAllowed = gmsAllowed
},
gmsPublishName: (state, gmsPublishName) => {
state.gmsPublishName = gmsPublishName
},
gmsPublishLocation: (state, gmsPublishLocation) => {
state.gmsPublishLocation = gmsPublishLocation
},
publisherId: (state, publisherId) => {
let pubId = parseInt(publisherId)
if (isNaN(pubId)) pubId = null
@ -77,8 +80,9 @@ export const actions = {
commit('firstName', data.firstName)
commit('lastName', data.lastName)
commit('newsletterState', data.klickTipp.newsletterState)
commit('gmsState', data.gmsAllowed)
commit('gmsAllowed', data.gmsAllowed)
commit('gmsPublishName', data.gmsPublishName)
commit('gmsPublishLocation', data.gmsPublishLocation)
commit('hasElopage', data.hasElopage)
commit('publisherId', data.publisherId)
commit('roles', data.roles)
@ -93,8 +97,9 @@ export const actions = {
commit('firstName', '')
commit('lastName', '')
commit('newsletterState', null)
commit('gmsState', null)
commit('gmsAllowed', null)
commit('gmsPublishName', null)
commit('gmsPublishLocation', null)
commit('hasElopage', false)
commit('publisherId', null)
commit('roles', null)
@ -129,6 +134,7 @@ try {
newsletterState: null,
gmsAllowed: null,
gmsPublishName: null,
gmsPublishLocation: null,
hasElopage: false,
publisherId: null,
hideAmountGDD: null,
@ -138,7 +144,7 @@ try {
redirectPath: '/overview',
},
getters: {},
// Syncronous mutation of the state
// Synchronous mutation of the state
mutations,
actions,
})