refactor: Mixin for Creation Labels

This commit is contained in:
Moriz Wahl 2022-02-02 16:30:31 +01:00
parent 0d00c170e5
commit bb86be723b
4 changed files with 13 additions and 28 deletions

View File

@ -195,6 +195,7 @@ export default {
creation: { creation: {
type: Array, type: Array,
required: false, required: false,
default: () => [null, null, null],
}, },
}, },
components: { components: {

View File

@ -1,6 +1,9 @@
export const creationMonths = { export const creationMonths = {
props: { props: {
creation: [1000, 1000, 1000], creation: {
type: Array,
default: () => [1000, 1000, 1000],
},
}, },
computed: { computed: {
creationDates() { creationDates() {
@ -31,5 +34,8 @@ export const creationMonths = {
} }
}) })
}, },
creationLabel() {
return this.creationDates.map((date) => this.$d(date, 'monthShort')).join(' | ')
},
}, },
} }

View File

@ -55,9 +55,11 @@
import CreationFormular from '../components/CreationFormular.vue' import CreationFormular from '../components/CreationFormular.vue'
import UserTable from '../components/UserTable.vue' import UserTable from '../components/UserTable.vue'
import { searchUsers } from '../graphql/searchUsers' import { searchUsers } from '../graphql/searchUsers'
import { creationMonths } from '../mixins/creationMonths'
export default { export default {
name: 'Creation', name: 'Creation',
mixins: [creationMonths],
components: { components: {
CreationFormular, CreationFormular,
UserTable, UserTable,
@ -69,7 +71,6 @@ export default {
itemsMassCreation: this.$store.state.userSelectedInMassCreation, itemsMassCreation: this.$store.state.userSelectedInMassCreation,
radioSelectedMass: '', radioSelectedMass: '',
criteria: '', criteria: '',
creation: [null, null, null],
rows: 0, rows: 0,
currentPage: 1, currentPage: 1,
perPage: 25, perPage: 25,
@ -163,16 +164,6 @@ export default {
{ key: 'bookmark', label: this.$t('remove') }, { key: 'bookmark', label: this.$t('remove') },
] ]
}, },
creationLabel() {
const now = new Date(this.now)
const lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1)
const beforeLastMonth = new Date(now.getFullYear(), now.getMonth() - 2, 1)
return [
this.$d(beforeLastMonth, 'monthShort'),
this.$d(lastMonth, 'monthShort'),
this.$d(now, 'monthShort'),
].join(' | ')
},
}, },
watch: { watch: {
currentPage() { currentPage() {

View File

@ -35,9 +35,11 @@
<script> <script>
import UserTable from '../components/UserTable.vue' import UserTable from '../components/UserTable.vue'
import { searchUsers } from '../graphql/searchUsers' import { searchUsers } from '../graphql/searchUsers'
import { creationMonths } from '../mixins/creationMonths'
export default { export default {
name: 'UserSearch', name: 'UserSearch',
mixins: [creationMonths],
components: { components: {
UserTable, UserTable,
}, },
@ -85,14 +87,6 @@ export default {
}, },
}, },
computed: { computed: {
lastMonthDate() {
const now = new Date(this.now)
return new Date(now.getFullYear(), now.getMonth() - 1, 1)
},
beforeLastMonthDate() {
const now = new Date(this.now)
return new Date(now.getFullYear(), now.getMonth() - 2, 1)
},
fields() { fields() {
return [ return [
{ key: 'email', label: this.$t('e_mail') }, { key: 'email', label: this.$t('e_mail') },
@ -100,14 +94,7 @@ export default {
{ key: 'lastName', label: this.$t('lastname') }, { key: 'lastName', label: this.$t('lastname') },
{ {
key: 'creation', key: 'creation',
label: [ label: this.creationLabel,
this.$d(this.beforeLastMonthDate, 'monthShort'),
this.$d(this.lastMonthDate, 'monthShort'),
this.$d(this.now, 'monthShort'),
].join(' | '),
formatter: (value, key, item) => {
return value.join(' | ')
},
}, },
{ key: 'show_details', label: this.$t('details') }, { key: 'show_details', label: this.$t('details') },
{ key: 'confirm_mail', label: this.$t('confirmed') }, { key: 'confirm_mail', label: this.$t('confirmed') },