Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
<template>

<div>
<ConfirmationDialog
v-model="restoreDialog"
title="Restore channel"
:text="`Are you sure you want to restore ${name} and make it active again?`"
data-test="confirm-restore"
confirmButtonText="Restore"
@confirm="restoreHandler"
/>
<KModal
v-if="activeDialog"
:title="dialogConfig.title"
:submitText="dialogConfig.submitText"
:cancelText="$tr('cancelAction')"
:data-test="dialogConfig.testId"
@submit="handleSubmit"
@cancel="activeDialog = null"
>
<p>{{ dialogConfig.message }}</p>
</KModal>

<ConfirmationDialog
v-model="makePublicDialog"
title="Make channel public"
:text="`All users will be able to view and import content from ${name}.`"
data-test="confirm-public"
confirmButtonText="Make public"
@confirm="makePublicHandler"
/>
<ConfirmationDialog
v-model="makePrivateDialog"
title="Make channel private"
:text="`Only users with view-only or edit permissions will be able to access ${name}.`"
data-test="confirm-private"
confirmButtonText="Make private"
@confirm="makePrivateHandler"
/>
<ConfirmationDialog
v-model="deleteDialog"
title="Permanently delete channel"
:text="`Are you sure you want to permanently delete ${name}? This can not be undone.`"
data-test="confirm-delete"
confirmButtonText="Delete permanently"
@confirm="deleteHandler"
/>
<ConfirmationDialog
v-model="softDeleteDialog"
title="Permanently delete channel"
:text="`Are you sure you want to delete ${name}?`"
data-test="confirm-softdelete"
confirmButtonText="Delete"
@confirm="softDeleteHandler"
/>
<BaseMenu>
<template #activator="{ on }">
<VBtn
Expand All @@ -59,13 +30,13 @@
<template v-if="channel.deleted">
<VListTile
data-test="restore"
@click="restoreDialog = true"
@click="openDialog('restore')"
>
<VListTileTitle>Restore</VListTileTitle>
</VListTile>
<VListTile
data-test="delete"
@click="deleteDialog = true"
@click="openDialog('permanentDelete')"
>
<VListTileTitle>Delete permanently</VListTileTitle>
</VListTile>
Expand All @@ -92,21 +63,21 @@
<VListTile
v-if="channel.public"
data-test="private"
@click="makePrivateDialog = true"
@click="openDialog('makePrivate')"
>
<VListTileTitle>Make private</VListTileTitle>
</VListTile>
<VListTile
v-else
data-test="public"
@click="makePublicDialog = true"
@click="openDialog('makePublic')"
>
<VListTileTitle>Make public</VListTileTitle>
</VListTile>
<VListTile
v-if="!channel.public"
data-test="softdelete"
@click="softDeleteDialog = true"
@click="openDialog('softDelete')"
>
<VListTileTitle>Delete channel</VListTileTitle>
</VListTile>
Expand All @@ -121,15 +92,11 @@
<script>

import { mapActions, mapGetters } from 'vuex';
import ConfirmationDialog from '../../components/ConfirmationDialog';
import { RouteNames } from '../../constants';
import { channelExportMixin } from 'shared/views/channel/mixins';

export default {
name: 'ChannelActionsDropdown',
components: {
ConfirmationDialog,
},
mixins: [channelExportMixin],
props: {
channelId: {
Expand All @@ -138,11 +105,7 @@
},
},
data: () => ({
deleteDialog: false,
makePublicDialog: false,
makePrivateDialog: false,
restoreDialog: false,
softDeleteDialog: false,
activeDialog: null,
}),
computed: {
...mapGetters('channel', ['getChannel']),
Expand All @@ -160,13 +123,62 @@
},
};
},
dialogConfig() {
const configs = {
restore: {
title: this.$tr('restoreChannelTitle'),
submitText: this.$tr('restoreAction'),
message: this.$tr('restoreChannelMessage', { name: this.name }),
testId: 'confirm-restore',
handler: this.restoreHandler,
},
makePublic: {
title: this.$tr('makePublicTitle'),
submitText: this.$tr('makePublicAction'),
message: this.$tr('makePublicMessage', { name: this.name }),
testId: 'confirm-public',
handler: this.makePublicHandler,
},
makePrivate: {
title: this.$tr('makePrivateTitle'),
submitText: this.$tr('makePrivateAction'),
message: this.$tr('makePrivateMessage', { name: this.name }),
testId: 'confirm-private',
handler: this.makePrivateHandler,
},
permanentDelete: {
title: this.$tr('permanentDeleteTitle'),
submitText: this.$tr('permanentDeleteAction'),
message: this.$tr('permanentDeleteMessage', { name: this.name }),
testId: 'confirm-delete',
handler: this.deleteHandler,
},
softDelete: {
title: this.$tr('softDeleteTitle'),
submitText: this.$tr('softDeleteAction'),
message: this.$tr('softDeleteMessage', { name: this.name }),
testId: 'confirm-softdelete',
handler: this.softDeleteHandler,
},
};
return configs[this.activeDialog] || {};
},
},
methods: {
...mapActions('channelAdmin', [
'getAdminChannelListDetails',
'deleteChannel',
'updateChannel',
]),
openDialog(type) {
this.activeDialog = type;
},
handleSubmit() {
if (this.dialogConfig.handler) {
this.dialogConfig.handler();
}
this.activeDialog = null;
},
async downloadPDF() {
this.$store.dispatch('showSnackbarSimple', 'Generating PDF...');
const channelList = await this.getAdminChannelListDetails([this.channel.id]);
Expand All @@ -178,7 +190,6 @@
return this.generateChannelsCSV(channelList);
},
restoreHandler() {
this.restoreDialog = false;
this.updateChannel({
id: this.channelId,
deleted: false,
Expand All @@ -187,7 +198,6 @@
});
},
softDeleteHandler() {
this.softDeleteDialog = false;
this.updateChannel({
id: this.channelId,
deleted: true,
Expand All @@ -196,14 +206,12 @@
});
},
deleteHandler() {
this.deleteDialog = false;
this.$emit('deleted');
return this.deleteChannel(this.channelId).then(() => {
this.$store.dispatch('showSnackbarSimple', 'Channel deleted permanently');
});
},
makePublicHandler() {
this.makePublicDialog = false;
this.updateChannel({
id: this.channelId,
isPublic: true,
Expand All @@ -212,7 +220,6 @@
});
},
makePrivateHandler() {
this.makePrivateDialog = false;
this.updateChannel({
id: this.channelId,
isPublic: false,
Expand All @@ -221,6 +228,30 @@
});
},
},
$trs: {
restoreChannelTitle: 'Restore channel',
restoreAction: 'Restore',
cancelAction: 'Cancel',
restoreChannelMessage: 'Are you sure you want to restore {name} and make it active again?',

makePublicTitle: 'Make channel public',
makePublicAction: 'Make public',
makePublicMessage: 'All users will be able to view and import content from {name}.',

makePrivateTitle: 'Make channel private',
makePrivateAction: 'Make private',
makePrivateMessage:
'Only users with view-only or edit permissions will be able to access {name}.',

permanentDeleteTitle: 'Permanently delete channel',
permanentDeleteAction: 'Delete permanently',
permanentDeleteMessage:
'Are you sure you want to permanently delete {name}? This can not be undone.',

softDeleteTitle: 'Delete channel',
softDeleteAction: 'Delete',
softDeleteMessage: 'Are you sure you want to delete {name}?',
},
};

</script>
Expand Down
Loading