Skip to content

Commit

Permalink
feat: allow owners and moderators to export poll to JSON file
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Oct 18, 2024
1 parent 99c91ea commit 5962ae0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/components/NewMessage/NewMessagePollEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
</template>
{{ t('spreed', 'Save as draft') }}
</NcActionButton>
<NcActionLink :href="exportPollBlob" :download="exportPollFileName">
<template #icon>
<IconFileDownload :size="20" />
</template>
{{ t('spreed', 'Export draft to file') }}
</NcActionLink>
</NcActions>
<NcButton type="primary" :disabled="!isFilled" @click="createPoll">
{{ t('spreed', 'Create poll') }}
Expand All @@ -95,12 +101,14 @@ import { computed, nextTick, reactive, ref } from 'vue'

import IconArrowLeft from 'vue-material-design-icons/ArrowLeft.vue'
import Close from 'vue-material-design-icons/Close.vue'
import IconFileDownload from 'vue-material-design-icons/FileDownload.vue'
import IconFileEdit from 'vue-material-design-icons/FileEdit.vue'
import Plus from 'vue-material-design-icons/Plus.vue'

import { t } from '@nextcloud/l10n'

import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
Expand Down Expand Up @@ -160,6 +168,15 @@ const isMultipleAnswer = computed({
})

const isModerator = computed(() => (store.getters as unknown).isModerator)

const exportPollBlob = () => {
const jsonString = JSON.stringify(pollForm, null, 2)
const blob = new Blob([jsonString], { type: 'application/json' })

return URL.createObjectURL(blob)
}
const exportPollFileName = `Talk Poll ${new Date().toISOString().slice(0, 10)}`

/**
* Remove a previously added option
* @param index option index
Expand Down
48 changes: 40 additions & 8 deletions src/components/PollViewer/PollViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
</template>
{{ t('spreed', 'Save as draft') }}
</NcActionButton>
<NcActionLink v-if="supportPollDrafts" :href="exportPollBlob" :download="exportPollFileName">
<template #icon>
<IconFileDownload :size="20" />
</template>
{{ t('spreed', 'Export draft to file') }}
</NcActionLink>
<NcActionButton class="critical" @click="endPoll">
{{ t('spreed', 'End poll') }}
<template #icon>
Expand All @@ -86,13 +92,21 @@
</NcActionButton>
</NcActions>
</div>
<div v-else-if="supportPollDrafts && isModerator" class="poll-modal__actions">
<NcButton type="tertiary" @click="createPollDraft">
<template #icon>
<IconFileEdit :size="20" />
</template>
{{ t('spreed', 'Save as draft') }}
</NcButton>
<div v-else-if="supportPollDrafts && selfIsOwnerOrModerator" class="poll-modal__actions">
<NcActions force-menu>
<NcActionButton v-if="isModerator" @click="createPollDraft">
<template #icon>
<IconFileEdit :size="20" />
</template>
{{ t('spreed', 'Save as draft') }}
</NcActionButton>
<NcActionLink :href="exportPollBlob" :download="exportPollFileName">
<template #icon>
<IconFileDownload :size="20" />
</template>
{{ t('spreed', 'Export draft to file') }}
</NcActionLink>
</NcActions>
</div>
</div>
<NcLoadingIcon v-else class="poll-modal__loading" />
Expand All @@ -102,14 +116,15 @@
<script>
import { computed, ref } from 'vue'

import IconFileDownload from 'vue-material-design-icons/FileDownload.vue'
import IconFileEdit from 'vue-material-design-icons/FileEdit.vue'
import FileLock from 'vue-material-design-icons/FileLock.vue'
import PollIcon from 'vue-material-design-icons/Poll.vue'

import { showSuccess } from '@nextcloud/dialogs'
import { t, n } from '@nextcloud/l10n'

import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
Expand All @@ -132,6 +147,7 @@ export default {
components: {
NcActions,
NcActionButton,
NcActionLink,
NcCheckboxRadioSwitch,
NcLoadingIcon,
NcModal,
Expand All @@ -140,6 +156,7 @@ export default {
PollVotersDetails,
// icons
FileLock,
IconFileDownload,
IconFileEdit,
PollIcon,
},
Expand All @@ -159,6 +176,19 @@ export default {
const poll = computed(() => pollsStore.getPoll(token.value, id.value))
const supportPollDrafts = computed(() => hasTalkFeature(token.value, 'talk-polls-drafts'))

const exportPollBlob = computed(() => {
const jsonString = JSON.stringify({
question: poll.value.question,
options: poll.value.options,
resultMode: poll.value.resultMode,
maxVotes: poll.value.maxVotes,
}, null, 2)
const blob = new Blob([jsonString], { type: 'application/json' })

return URL.createObjectURL(blob)
})
const exportPollFileName = `Talk Poll ${new Date().toISOString().slice(0, 10)}`

return {
isInCall: useIsInCall(),
pollsStore,
Expand All @@ -171,6 +201,8 @@ export default {
token,
poll,
supportPollDrafts,
exportPollBlob,
exportPollFileName,
}
},

Expand Down

0 comments on commit 5962ae0

Please sign in to comment.