Extracted actions into seperate mappers function

This commit is contained in:
Angelina Filippova 2019-05-14 16:18:11 +03:00
parent 932d728b8e
commit 90553ba75c

View file

@ -113,80 +113,91 @@ export default {
}
},
methods: {
grantRightToMultipleUsers(right) {
const mapSelectedUsers = () => this.selectedUsers
mappers() {
return {
grantRight: (right) => () => this.selectedUsers
.filter(user => user.local && !user.roles[right] && this.$store.state.user.id !== user.id)
.map(user => this.$store.dispatch('ToggleRight', { user, right }))
this.confirmMessage(
'Are you sure you want to grant ' + right + ' rights to all selected users?',
mapSelectedUsers
)
},
revokeRightToMultipleUsers(right) {
const mapSelectedUsers = () => this.selectedUsers
.map(user => this.$store.dispatch('ToggleRight', { user, right })),
revokeRight: (right) => () => this.selectedUsers
.filter(user => user.local && user.roles[right] && this.$store.state.user.id !== user.id)
.map(user => this.$store.dispatch('ToggleRight', { user, right }))
this.confirmMessage(
'Are you sure you want to revoke ' + right + ' rights from all selected users?',
mapSelectedUsers
)
},
activateMultipleUsers() {
const mapSelectedUsers = () => this.selectedUsers
.map(user => this.$store.dispatch('ToggleRight', { user, right })),
activate: () => this.selectedUsers
.filter(user => user.deactivated && this.$store.state.user.id !== user.id)
.map(user => this.$store.dispatch('ToggleUserActivation', user.nickname))
this.confirmMessage(
'Are you sure you want to activate accounts of all selected users?',
mapSelectedUsers
)
},
deactivateMultipleUsers() {
const mapSelectedUsers = () => this.selectedUsers
.map(user => this.$store.dispatch('ToggleUserActivation', user.nickname)),
deactivate: () => this.selectedUsers
.filter(user => !user.deactivated && this.$store.state.user.id !== user.id)
.map(user => this.$store.dispatch('ToggleUserActivation', user.nickname))
this.confirmMessage(
'Are you sure you want to deactivate accounts of all selected users?',
mapSelectedUsers
)
},
deleteMultipleUsers() {
const mapSelectedUsers = () => this.selectedUsers
.map(user => this.$store.dispatch('ToggleUserActivation', user.nickname)),
remove: () => this.selectedUsers
.filter(user => this.$store.state.user.id !== user.id)
.map(user => this.$store.dispatch('DeleteUser', user))
this.confirmMessage(
'Are you sure you want to delete accounts of all selected users?',
mapSelectedUsers
)
},
addTagForMultipleUsers(tag) {
const mapSelectedUsers = () => this.selectedUsers
.map(user => this.$store.dispatch('DeleteUser', user)),
addTag: (tag) => () => this.selectedUsers
.filter(user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
? user.local && !user.tags.includes(tag)
: !user.tags.includes(tag)
).map(user => this.$store.dispatch('ToggleTag', { user, tag }))
this.confirmMessage(
'Are you sure you want to apply tag to all selected users?',
mapSelectedUsers
)
},
removeTagFromMultipleUsers(tag) {
const mapSelectedUsers = () => this.selectedUsers
).map(user => this.$store.dispatch('ToggleTag', { user, tag })),
removeTag: (tag) => () => this.selectedUsers
.filter(user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
? user.local && user.tags.includes(tag)
: user.tags.includes(tag)
).map(user => this.$store.dispatch('ToggleTag', { user, tag }))
}
},
grantRightToMultipleUsers(right) {
const { grantRight } = this.mappers()
this.confirmMessage(
'Are you sure you want to remove tag from all selected users?',
mapSelectedUsers
`Are you sure you want to grant ${right} rights to all selected users?`,
grantRight(right)
)
},
confirmMessage(message, mapSelectedUsers) {
revokeRightToMultipleUsers(right) {
const { revokeRight } = this.mappers()
this.confirmMessage(
`Are you sure you want to revoke ${right} rights from all selected users?`,
revokeRight(right)
)
},
activateMultipleUsers() {
const { activate } = this.mappers()
this.confirmMessage(
'Are you sure you want to activate accounts of all selected users?',
activate
)
},
deactivateMultipleUsers() {
const { deactivate } = this.mappers()
this.confirmMessage(
'Are you sure you want to deactivate accounts of all selected users?',
deactivate
)
},
deleteMultipleUsers() {
const { remove } = this.mappers()
this.confirmMessage(
'Are you sure you want to delete accounts of all selected users?',
remove
)
},
addTagForMultipleUsers(tag) {
const { addTag } = this.mappers()
this.confirmMessage(
'Are you sure you want to apply tag to all selected users?',
addTag(tag)
)
},
removeTagFromMultipleUsers(tag) {
const { removeTag } = this.mappers()
this.confirmMessage(
'Are you sure you want to remove tag from all selected users?',
removeTag(tag)
)
},
confirmMessage(message, applyAction) {
this.$confirm(message, {
confirmButtonText: 'OK',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
mapSelectedUsers()
applyAction()
this.$emit('apply-action')
this.$message({
type: 'success',