Fix adding and removing tags after implementing select

This commit is contained in:
Angelina Filippova 2020-11-05 23:19:37 +03:00
parent 3711248435
commit 4a1c7c2841
2 changed files with 37 additions and 32 deletions

View file

@ -283,7 +283,8 @@ export default {
confirmEnablingTagPolicy: 'Are you sure you want to add TagPolicy to the list of enabled MRF policies?',
enableTagPolicySuccessMessage: 'MRF TagPolicy was enabled',
customTags: 'Custom Tags',
defaultTags: 'Default Tags'
defaultTags: 'Default Tags',
tags: 'Tags'
},
statuses: {
statuses: 'Statuses',

View file

@ -83,36 +83,39 @@
@click.native="disableMfa(user.nickname)">
{{ $t('users.disableMfa') }}
</el-dropdown-item>
<el-dropdown-item
v-if="tagPolicyEnabled">
{{ $t('users.tags') }}:
</el-dropdown-item>
<el-select
v-if="tagPolicyEnabled"
v-model="selectedTags"
:value="selectedTags"
multiple
filterable
allow-create
placeholder="Select Tags"
size="small"
class="select-tags">
class="select-tags"
@change="toggleTag($event, user)">
<el-option-group :label="$t('users.defaultTags')">
<el-option
v-for="(value, name) in defaultTags"
:key="name"
:value="name"
:class="{ 'active-tag': user.tags.includes(name) }"
@click.native="toggleTag(user, name)">
{{ value }}
<i v-if="user.tags.includes(name)" class="el-icon-check"/>
v-for="option in defaultTags"
:value="option.tag"
:key="option.tag"
:label="option.label"
:class="{ 'active-tag': user.tags.includes(option.tag) }">
{{ option.label }}
</el-option>
</el-option-group>
<el-option-group :label="$t('users.customTags')">
<el-option
v-for="item in customTags"
:key="item"
:value="item"
:class="{ 'active-tag': user.tags.includes(item) }"
class="capitalize"
@click.native="toggleTag(user, item)">
{{ item }}
<i v-if="user.tags.includes(item)" class="el-icon-check"/>
v-for="option in customTags"
:value="option.tag"
:key="option.tag"
:label="option.label"
:class="{ 'active-tag': user.tags.includes(option.tag) }"
class="capitalize">
{{ option.label }}
</el-option>
</el-option-group>
</el-select>
@ -146,11 +149,6 @@ export default {
default: ''
}
},
data() {
return {
selectedTags: []
}
},
computed: {
actorType: {
get() {
@ -166,18 +164,21 @@ export default {
}
},
customTags() {
return this.$store.state.users.tags.filter(tag => !Object.keys(this.mapTags).includes(tag))
return this.$store.state.users.tags
.filter(tag => !Object.keys(this.mapTags).includes(tag))
.map(tag => {
return { tag, label: tag.charAt(0).toUpperCase() + tag.slice(1) }
})
},
defaultTags() {
const tagsByType = this.user.local ? Object.keys(this.mapTags) : Object.keys(this.mapRemoteTags)
return tagsByType.filter(tag => this.$store.state.users.tags.includes(tag))
.reduce((acc, el) => {
.map(tag => {
if (this.user.local) {
acc[el] = this.mapTags[el]
return { tag, label: this.mapTags[tag] }
} else {
acc[el] = this.mapRemoteTags[el]
return { tag, label: this.mapRemoteTags[tag] }
}
return acc
}, {})
},
isDesktop() {
@ -203,6 +204,9 @@ export default {
'mrf_tag:disable-any-subscription': 'Disable any subscription'
}
},
selectedTags() {
return this.user.tags
},
tagPolicyEnabled() {
return this.$store.state.users.mrfPolicies.includes('Pleroma.Web.ActivityPub.MRF.TagPolicy')
}
@ -295,10 +299,10 @@ export default {
? this.$store.dispatch('ActivateUsers', { users: [user], _userId: user.id })
: this.$store.dispatch('DeactivateUsers', { users: [user], _userId: user.id })
},
toggleTag(user, tag) {
user.tags.includes(tag)
? this.$store.dispatch('RemoveTag', { users: [user], tag, _userId: user.id, _statusId: this.statusId })
: this.$store.dispatch('AddTag', { users: [user], tag, _userId: user.id, _statusId: this.statusId })
toggleTag(tags, user) {
tags.length > user.tags.length
? this.$store.dispatch('AddTag', { users: [user], tag: tags.filter(tag => !user.tags.includes(tag))[0] })
: this.$store.dispatch('RemoveTag', { users: [user], tag: user.tags.filter(tag => !tags.includes(tag))[0] })
},
toggleUserRight(user, right) {
user.roles[right]