refactoring

This commit is contained in:
Moriz Wahl 2022-02-01 14:01:50 +01:00
parent 932ce8022a
commit bf239b1476

View File

@ -28,7 +28,7 @@
</b-col> </b-col>
<b-col cols="12" lg="6" class="shadow p-3 mb-5 rounded bg-info"> <b-col cols="12" lg="6" class="shadow p-3 mb-5 rounded bg-info">
<user-table <user-table
v-show="$store.state.userSelectedInMassCreation.length > 0" v-show="itemsMassCreation.length > 0"
class="shadow p-3 mb-5 bg-white rounded" class="shadow p-3 mb-5 bg-white rounded"
type="UserListMassCreation" type="UserListMassCreation"
:itemsUser="itemsMassCreationReverse" :itemsUser="itemsMassCreationReverse"
@ -37,14 +37,14 @@
:creation="creation" :creation="creation"
@update-item="updateItem" @update-item="updateItem"
/> />
<div v-if="$store.state.userSelectedInMassCreation.length === 0"> <div v-if="itemsMassCreation.length === 0">
{{ $t('multiple_creation_text') }} {{ $t('multiple_creation_text') }}
</div> </div>
<creation-formular <creation-formular
v-else v-else
type="massCreation" type="massCreation"
:creation="creation" :creation="creation"
:items="$store.state.userSelectedInMassCreation" :items="itemsMassCreation"
@remove-all-bookmark="removeAllBookmark" @remove-all-bookmark="removeAllBookmark"
/> />
</b-col> </b-col>
@ -104,7 +104,7 @@ export default {
{ key: 'bookmark', label: this.$t('remove') }, { key: 'bookmark', label: this.$t('remove') },
], ],
itemsList: [], itemsList: [],
itemsMassCreationReverse: [], itemsMassCreation: this.$store.state.userSelectedInMassCreation,
radioSelectedMass: '', radioSelectedMass: '',
criteria: '', criteria: '',
creation: [null, null, null], creation: [null, null, null],
@ -113,7 +113,7 @@ export default {
perPage: 25, perPage: 25,
} }
}, },
async created() { async mounted() {
await this.getUsers() await this.getUsers()
}, },
methods: { methods: {
@ -136,51 +136,48 @@ export default {
showDetails: false, showDetails: false,
} }
}) })
this.updateItem(this.$store.state.userSelectedInMassCreation, 'mounted') if (this.itemsMassCreation !== []) {
const selectedIndices = this.itemsMassCreation.map((item) => item.userId)
this.itemsList = this.itemsList.filter((item) => !selectedIndices.includes(item.userId))
}
}) })
.catch((error) => { .catch((error) => {
this.$toasted.error(error.message) this.$toasted.error(error.message)
}) })
}, },
updateItem(e, event) { updateItem(selectedItem, event) {
let index = 0
let findArr = {}
const letItemList = this.$store.state.userSelectedInMassCreation
switch (event) { switch (event) {
case 'push': case 'push':
findArr = this.itemsList.find((item) => e.userId === item.userId) this.itemsMassCreation.push(
index = this.itemsList.indexOf(findArr) this.itemsList.find((item) => selectedItem.userId === item.userId),
this.itemsList.splice(index, 1) )
letItemList.push(findArr) this.itemsList = this.itemsList.filter((item) => selectedItem.userId !== item.userId)
break break
case 'remove': case 'remove':
findArr = letItemList.find((item) => e.userId === item.userId) this.itemsList.push(
index = letItemList.indexOf(findArr) this.itemsMassCreation.find((item) => selectedItem.userId === item.userId),
letItemList.splice(index, 1) )
this.itemsList.push(findArr) this.itemsMassCreation = this.itemsMassCreation.filter(
break (item) => selectedItem.userId !== item.userId,
case 'mounted': )
if (this.$store.state.userSelectedInMassCreation === []) return
letItemList.forEach((value, key) => {
findArr = this.itemsList.find((item) => value.userId === item.userId)
index = this.itemsList.indexOf(findArr)
this.itemsList.splice(index, 1)
})
break break
default: default:
throw new Error(event) throw new Error(event)
} }
this.lala = letItemList this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation)
this.itemsMassCreationReverse = letItemList
this.itemsMassCreationReverse.reverse()
this.$store.commit('setUserSelectedInMassCreation', letItemList)
}, },
removeAllBookmark() { removeAllBookmark() {
this.$store.commit('setUserSelectedInMassCreation', []) this.itemsMassCreation = []
this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation)
this.getUsers() this.getUsers()
}, },
}, },
computed: {
itemsMassCreationReverse() {
const array = this.itemsMassCreation
return array.reverse()
},
},
watch: { watch: {
currentPage() { currentPage() {
this.getUsers() this.getUsers()