Ocelot-Social/webapp/components/ContentMenu.vue
Wolfgang Huß b2e1873ade Refactored to modalData for Delete Comment and Posts
The error is gone with this.
2019-06-07 18:04:12 +02:00

172 lines
4.2 KiB
Vue

<template>
<dropdown class="content-menu" :placement="placement" offset="5">
<template slot="default" slot-scope="{ toggleMenu }">
<slot name="button" :toggleMenu="toggleMenu">
<ds-button class="content-menu-trigger" size="small" ghost @click.prevent="toggleMenu">
<ds-icon name="ellipsis-v" />
</ds-button>
</slot>
</template>
<div slot="popover" slot-scope="{ toggleMenu }" class="content-menu-popover">
<ds-menu :routes="routes">
<ds-menu-item
slot="menuitem"
slot-scope="item"
:route="item.route"
:parents="item.parents"
@click.stop.prevent="openItem(item.route, toggleMenu)"
>
<ds-icon :name="item.route.icon" />
{{ item.route.name }}
</ds-menu-item>
</ds-menu>
</div>
</dropdown>
</template>
<script>
import Dropdown from '~/components/Dropdown'
export default {
name: 'ContentMenu',
components: {
Dropdown,
},
props: {
placement: { type: String, default: 'top-end' },
resource: { type: Object, required: true },
isOwner: { type: Boolean, default: false },
resourceType: {
type: String,
required: true,
validator: value => {
return value.match(/(contribution|comment|organization|user)/)
},
},
modalsData: {
type: Object,
required: false,
// default: () => {
// return {}
// },
},
},
computed: {
routes() {
let routes = []
if (this.isOwner && this.resourceType === 'contribution') {
routes.push({
name: this.$t(`post.menu.edit`),
path: this.$router.resolve({
name: 'post-edit-id',
params: {
id: this.resource.id,
},
}).href,
icon: 'edit',
})
routes.push({
name: this.$t(`post.menu.delete`),
callback: () => {
this.openModal('delete')
},
icon: 'trash',
})
}
if (this.isOwner && this.resourceType === 'comment') {
// routes.push({
// name: this.$t(`comment.menu.edit`),
// callback: () => {
// /* eslint-disable-next-line no-console */
// console.log('EDIT COMMENT')
// },
// icon: 'edit'
// })
routes.push({
name: this.$t(`comment.menu.delete`),
callback: () => {
this.openModal('delete')
},
icon: 'trash',
})
}
if (!this.isOwner) {
routes.push({
name: this.$t(`report.${this.resourceType}.title`),
callback: () => {
this.openModal('report')
},
icon: 'flag',
})
}
if (!this.isOwner && this.isModerator) {
if (!this.resource.disabled) {
routes.push({
name: this.$t(`disable.${this.resourceType}.title`),
callback: () => {
this.openModal('disable')
},
icon: 'eye-slash',
})
} else {
routes.push({
name: this.$t(`release.${this.resourceType}.title`),
callback: () => {
this.openModal('release', this.resource.id)
},
icon: 'eye',
})
}
}
if (this.isOwner && this.resourceType === 'user') {
routes.push({
name: this.$t(`settings.name`),
path: '/settings',
icon: 'edit',
})
}
return routes
},
isModerator() {
return this.$store.getters['auth/isModerator']
},
},
methods: {
openItem(route, toggleMenu) {
if (route.callback) {
route.callback()
} else {
this.$router.push(route.path)
}
toggleMenu()
},
openModal(dialog) {
this.$store.commit('modal/SET_OPEN', {
name: dialog,
data: {
type: this.resourceType,
resource: this.resource,
modalsData: this.modalsData,
},
})
},
},
}
</script>
<style lang="scss">
.content-menu-popover {
nav {
margin-top: -$space-xx-small;
margin-bottom: -$space-xx-small;
margin-left: -$space-x-small;
margin-right: -$space-x-small;
}
}
</style>