Merge branch '2038-Community-contribution-site-and-form' of github.com:gradido/gradido into 2038-Community-contribution-site-and-form

This commit is contained in:
Moriz Wahl 2022-07-20 15:27:31 +02:00
commit 98ca12d635
8 changed files with 182 additions and 25 deletions

View File

@ -15,6 +15,7 @@ export class Contribution {
this.deletedAt = contribution.deletedAt this.deletedAt = contribution.deletedAt
this.confirmedAt = contribution.confirmedAt this.confirmedAt = contribution.confirmedAt
this.confirmedBy = contribution.confirmedBy this.confirmedBy = contribution.confirmedBy
this.contributionDate = contribution.contributionDate
} }
@Field(() => Number) @Field(() => Number)
@ -43,6 +44,9 @@ export class Contribution {
@Field(() => Number, { nullable: true }) @Field(() => Number, { nullable: true })
confirmedBy: number | null confirmedBy: number | null
@Field(() => Date)
contributionDate: Date
} }
@ObjectType() @ObjectType()

View File

@ -0,0 +1,83 @@
import {
BaseEntity,
Entity,
PrimaryGeneratedColumn,
Column,
DeleteDateColumn,
OneToMany,
JoinColumn,
} from 'typeorm'
import { Contribution } from '../Contribution'
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
export class User extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ name: 'public_key', type: 'binary', length: 32, default: null, nullable: true })
pubKey: Buffer
@Column({ name: 'privkey', type: 'binary', length: 80, default: null, nullable: true })
privKey: Buffer
@Column({ length: 255, unique: true, nullable: false, collation: 'utf8mb4_unicode_ci' })
email: string
@Column({
name: 'first_name',
length: 255,
nullable: true,
default: null,
collation: 'utf8mb4_unicode_ci',
})
firstName: string
@Column({
name: 'last_name',
length: 255,
nullable: true,
default: null,
collation: 'utf8mb4_unicode_ci',
})
lastName: string
@DeleteDateColumn()
deletedAt: Date | null
@Column({ type: 'bigint', default: 0, unsigned: true })
password: BigInt
@Column({ name: 'email_hash', type: 'binary', length: 32, default: null, nullable: true })
emailHash: Buffer
@Column({ name: 'created', default: () => 'CURRENT_TIMESTAMP', nullable: false })
createdAt: Date
@Column({ name: 'email_checked', type: 'bool', nullable: false, default: false })
emailChecked: boolean
@Column({ length: 4, default: 'de', collation: 'utf8mb4_unicode_ci', nullable: false })
language: string
@Column({ name: 'is_admin', type: 'datetime', nullable: true, default: null })
isAdmin: Date | null
@Column({ name: 'referrer_id', type: 'int', unsigned: true, nullable: true, default: null })
referrerId?: number | null
@Column({ name: 'publisher_id', default: 0 })
publisherId: number
@Column({
type: 'text',
name: 'passphrase',
collation: 'utf8mb4_unicode_ci',
nullable: true,
default: null,
})
passphrase: string
@OneToMany(() => Contribution, (contribution) => contribution.user)
@JoinColumn({ name: 'user_id' })
contributions?: Contribution[]
}

View File

@ -74,7 +74,7 @@
</b-col> </b-col>
<b-col class="text-right"> <b-col class="text-right">
<b-button class="test-submit" type="submit" variant="primary" :disabled="disabled"> <b-button class="test-submit" type="submit" variant="primary" :disabled="disabled">
{{ id === null ? $t('contribution.submit') : $t('form.edit') }} {{ value.id ? $t('form.edit') : $t('contribution.submit') }}
</b-button> </b-button>
</b-col> </b-col>
</b-row> </b-row>
@ -89,8 +89,6 @@ export default {
}, },
data() { data() {
return { return {
maxGddLastMonth: this.$store.state.creation[1],
maxGddThisMonth: this.$store.state.creation[2],
minlength: 50, minlength: 50,
maxlength: 255, maxlength: 255,
maximalDate: new Date(), maximalDate: new Date(),
@ -100,10 +98,10 @@ export default {
}, },
methods: { methods: {
submit() { submit() {
if (this.id === null) { if (this.value.id) {
this.$emit('set-contribution', this.form) this.$emit('update-contribution', this.form)
} else { } else {
this.$emit('edit-contribution', this.form) this.$emit('set-contribution', this.form)
} }
this.reset() this.reset()
}, },
@ -137,20 +135,36 @@ export default {
// new Date().getMonth === 1 If the current month is January, then one year must be gone back in the previous month // new Date().getMonth === 1 If the current month is January, then one year must be gone back in the previous month
const obj = { const obj = {
monthAndYear: this.$d(new Date(this.minimalDate), 'monthAndYear'), monthAndYear: this.$d(new Date(this.minimalDate), 'monthAndYear'),
creation: this.$store.state.creation[1], creation: this.id
? this.$store.state.creation[1] + this.form.amount
: this.$store.state.creation[1],
} }
return this.$t('contribution.formText.openAmountForMonth', obj) return this.$t('contribution.formText.openAmountForMonth', obj)
}, },
thisMonthObject() { thisMonthObject() {
const obj = { const obj = {
monthAndYear: this.$d(new Date(), 'monthAndYear'), monthAndYear: this.$d(new Date(), 'monthAndYear'),
creation: this.$store.state.creation[2], creation: this.id
? parseInt(this.$store.state.creation[2]) + parseInt(this.form.amount)
: this.$store.state.creation[2],
} }
return this.$t('contribution.formText.openAmountForMonth', obj) return this.$t('contribution.formText.openAmountForMonth', obj)
}, },
isThisMonth() { isThisMonth() {
return new Date(this.form.date).getMonth() === new Date().getMonth() return new Date(this.form.date).getMonth() === new Date().getMonth()
}, },
maxGddLastMonth() {
// When edited, the amount is added back on top of the amount
return this.id
? parseInt(this.$store.state.creation[1]) + parseInt(this.form.amount)
: this.$store.state.creation[1]
},
maxGddThisMonth() {
// When edited, the amount is added back on top of the amount
return this.id
? parseInt(this.$store.state.creation[2]) + parseInt(this.form.amount)
: this.$store.state.creation[2]
},
}, },
} }
</script> </script>

View File

@ -1,7 +1,11 @@
<template> <template>
<div class="contribution-list container"> <div class="contribution-list container">
<div class="list-group" v-for="item in items" :key="item.id"> <div class="list-group" v-for="item in items" :key="item.id">
<contribution-list-item v-bind="item" @update-contribution-form="updateContributionForm" /> <contribution-list-item
v-bind="item"
@update-contribution-form="updateContributionForm"
@delete-contribution="deleteContribution"
/>
</div> </div>
<b-pagination <b-pagination
v-if="isPaginationVisible" v-if="isPaginationVisible"
@ -53,6 +57,11 @@ export default {
updateContributionForm(item) { updateContributionForm(item) {
this.$emit('update-contribution-form', item) this.$emit('update-contribution-form', item)
}, },
deleteContribution(id) {
this.$emit('delete-contribution', {
id: id,
})
},
}, },
computed: { computed: {
isPaginationVisible() { isPaginationVisible() {

View File

@ -12,19 +12,23 @@
<div class="mx-2">{{ $d(new Date(date), 'short') }}</div> <div class="mx-2">{{ $d(new Date(date), 'short') }}</div>
</div> </div>
<div class="mr-2">{{ memo }}</div> <div class="mr-2">{{ memo }}</div>
<div <div v-if="type === 'pending' && !firstName" class="d-flex flex-row-reverse">
v-if="type === 'pending' && !firstName" <div
class="text-right pointer" class="pointer ml-5"
@click=" @click="
$emit('update-contribution-form', { $emit('update-contribution-form', {
id: id, id: id,
createdAt: createdAt, contributionDate: contributionDate,
memo: memo, memo: memo,
amount: amount, amount: amount,
}) })
" "
> >
<b-icon icon="pencil" class="h2"></b-icon> <b-icon icon="pencil" class="h2"></b-icon>
</div>
<div class="pointer" @click="deleteContribution(id)">
<b-icon icon="trash" class="h2"></b-icon>
</div>
</div> </div>
</div> </div>
</slot> </slot>
@ -54,6 +58,9 @@ export default {
createdAt: { createdAt: {
type: String, type: String,
}, },
contributionDate: {
type: String,
},
deletedAt: { deletedAt: {
type: String, type: String,
}, },
@ -83,13 +90,21 @@ export default {
date() { date() {
if (this.deletedAt) return this.deletedAt if (this.deletedAt) return this.deletedAt
if (this.confirmedAt) return this.confirmedAt if (this.confirmedAt) return this.confirmedAt
return this.createdAt return this.contributionDate
}, },
}, },
methods: { methods: {
updateContributionForm(item) { updateContributionForm(item) {
this.$emit('update-contribution-form', item) this.$emit('update-contribution-form', item)
}, },
deleteContribution(id) {
this.boxOne = ''
this.$bvModal.msgBoxConfirm('Delete Contribution! Are you sure?').then((value) => {
this.$emit('delete-contribution', {
id: id,
})
})
},
}, },
} }
</script> </script>

View File

@ -113,3 +113,9 @@ export const updateContribution = gql`
} }
} }
` `
export const deleteContribution = gql`
mutation($id: Int!) {
deleteContribution(id: $id)
}
`

View File

@ -182,8 +182,10 @@ export const listContributions = gql`
amount amount
memo memo
createdAt createdAt
contributionDate
confirmedAt confirmedAt
confirmedBy confirmedBy
deletedAt
} }
} }
} }
@ -200,6 +202,7 @@ export const listAllContributions = gql`
amount amount
memo memo
createdAt createdAt
contributionDate
confirmedAt confirmedAt
confirmedBy confirmedBy
} }

View File

@ -6,6 +6,7 @@
<contribution-form <contribution-form
@set-contribution="setContribution" @set-contribution="setContribution"
@update-contribution="updateContribution" @update-contribution="updateContribution"
@delete-contribution="deleteContribution"
v-model="form" v-model="form"
/> />
</b-tab> </b-tab>
@ -36,7 +37,7 @@
<script> <script>
import ContributionForm from '@/components/Contributions/ContributionForm.vue' import ContributionForm from '@/components/Contributions/ContributionForm.vue'
import ContributionList from '@/components/Contributions/ContributionList.vue' import ContributionList from '@/components/Contributions/ContributionList.vue'
import { createContribution, updateContribution } from '@/graphql/mutations' import { createContribution, updateContribution, deleteContribution } from '@/graphql/mutations'
import { listContributions, listAllContributions, verifyLogin } from '@/graphql/queries' import { listContributions, listAllContributions, verifyLogin } from '@/graphql/queries'
export default { export default {
@ -111,6 +112,28 @@ export default {
this.toastError(err.message) this.toastError(err.message)
}) })
}, },
deleteContribution(id) {
this.$apollo
.mutate({
fetchPolicy: 'no-cache',
mutation: deleteContribution,
variables: {
id: id,
},
})
.then((result) => {
// console.log('result', result.data)
this.toastSuccess(result.data)
this.updateListContributions({
currentPage: this.currentPage,
pageSize: this.pageSize,
})
this.verifyLogin()
})
.catch((err) => {
this.toastError(err.message)
})
},
updateListAllContributions(pagination) { updateListAllContributions(pagination) {
this.$apollo this.$apollo
.query({ .query({
@ -171,7 +194,7 @@ export default {
}, },
updateContributionForm(item) { updateContributionForm(item) {
this.form.id = item.id this.form.id = item.id
this.form.date = item.createdAt this.form.date = item.contributionDate
this.form.memo = item.memo this.form.memo = item.memo
this.form.amount = item.amount this.form.amount = item.amount
this.tabIndex = 0 this.tabIndex = 0