2019-05-14 01:15:45 +02:00
|
|
|
<!--
|
|
|
|
- @copyright Copyright (c) 2018 René Gieling <github@dartcafe.de>
|
|
|
|
-
|
|
|
|
- @author Ajfar Huq
|
|
|
|
- @author Nick Gallo
|
|
|
|
- @author Affan Hussain
|
|
|
|
-
|
|
|
|
- @license GNU AGPL version 3 or any later version
|
|
|
|
-
|
|
|
|
- This program is free software: you can redistribute it and/or modify
|
|
|
|
- it under the terms of the GNU Affero General Public License as
|
|
|
|
- published by the Free Software Foundation, either version 3 of the
|
|
|
|
- License, or (at your option) any later version.
|
|
|
|
-
|
|
|
|
- This program is distributed in the hope that it will be useful,
|
|
|
|
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
- GNU Affero General Public License for more details.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the GNU Affero General Public License
|
|
|
|
- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
-
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
2020-04-24 15:37:46 +02:00
|
|
|
<AppContent v-if="loadingResults">
|
|
|
|
<EmptyContent icon="icon-loading">
|
2020-04-25 00:31:03 +02:00
|
|
|
{{ t('forms', 'Loading responses …') }}
|
2020-04-24 15:37:46 +02:00
|
|
|
</EmptyContent>
|
|
|
|
</AppContent>
|
|
|
|
|
|
|
|
<AppContent v-else>
|
|
|
|
<TopBar>
|
|
|
|
<button @click="showEdit">
|
|
|
|
<span class="icon-forms" role="img" />
|
2020-05-09 15:56:01 +02:00
|
|
|
{{ t('forms', 'Back to questions') }}
|
2019-05-14 01:15:45 +02:00
|
|
|
</button>
|
2020-04-24 15:37:46 +02:00
|
|
|
</TopBar>
|
|
|
|
|
|
|
|
<header v-if="!noSubmissions">
|
2020-05-09 15:56:01 +02:00
|
|
|
<h2>{{ t('forms', 'Responses for {title}', { title: formTitle }) }}</h2>
|
2020-05-07 09:55:00 +02:00
|
|
|
<div class="response_actions">
|
|
|
|
<button class="response_actions__export" @click="download">
|
2020-05-02 18:36:52 +02:00
|
|
|
<span class="icon-download" role="img" />
|
2020-05-01 01:26:01 +02:00
|
|
|
{{ t('forms', 'Export to CSV') }}
|
2020-05-02 18:36:52 +02:00
|
|
|
</button>
|
|
|
|
<Actions class="results-menu"
|
|
|
|
:aria-label="t('forms', 'Options')"
|
|
|
|
:force-menu="true">
|
|
|
|
<ActionButton icon="icon-delete" @click="deleteAllSubmissions">
|
|
|
|
{{ t('forms', 'Delete all responses') }}
|
|
|
|
</ActionButton>
|
|
|
|
</Actions>
|
|
|
|
</div>
|
2020-04-24 15:37:46 +02:00
|
|
|
</header>
|
|
|
|
|
|
|
|
<!-- No submissions -->
|
|
|
|
<section v-if="noSubmissions">
|
2020-04-25 00:31:03 +02:00
|
|
|
<EmptyContent icon="icon-comment">
|
|
|
|
{{ t('forms', 'No responses yet') }}
|
|
|
|
<template #desc>
|
|
|
|
{{ t('forms', 'Results of submitted forms will show up here') }}
|
|
|
|
</template>
|
2020-05-06 12:48:09 +02:00
|
|
|
<template #action>
|
|
|
|
<button class="primary" @click="copyShareLink">
|
|
|
|
{{ t('forms', 'Copy share link') }}
|
|
|
|
</button>
|
|
|
|
</template>
|
2020-04-24 15:37:46 +02:00
|
|
|
</EmptyContent>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<section v-else>
|
2020-04-20 18:40:15 +02:00
|
|
|
<Submission
|
|
|
|
v-for="submission in submissions"
|
|
|
|
:key="submission.id"
|
|
|
|
:submission="submission"
|
2020-04-30 12:02:23 +02:00
|
|
|
:questions="questions"
|
|
|
|
@delete="deleteSubmission(submission.id)" />
|
2020-04-24 15:37:46 +02:00
|
|
|
</section>
|
2020-03-20 12:22:07 +01:00
|
|
|
</AppContent>
|
2019-05-14 01:15:45 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-04-24 15:37:46 +02:00
|
|
|
import { generateUrl } from '@nextcloud/router'
|
2020-05-01 00:29:38 +02:00
|
|
|
import { Parser } from 'json2csv'
|
2020-05-06 12:48:09 +02:00
|
|
|
import { showError, showSuccess } from '@nextcloud/dialogs'
|
2020-05-01 01:26:01 +02:00
|
|
|
import Actions from '@nextcloud/vue/dist/Components/Actions'
|
|
|
|
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
|
2020-04-24 15:37:46 +02:00
|
|
|
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
|
2020-02-25 20:28:30 +01:00
|
|
|
import axios from '@nextcloud/axios'
|
2020-05-06 12:48:09 +02:00
|
|
|
import Clipboard from 'v-clipboard'
|
2020-05-01 00:29:38 +02:00
|
|
|
import moment from '@nextcloud/moment'
|
2020-05-06 12:48:09 +02:00
|
|
|
import Vue from 'vue'
|
2020-04-24 15:37:46 +02:00
|
|
|
|
|
|
|
import EmptyContent from '../components/EmptyContent'
|
2020-04-20 18:40:15 +02:00
|
|
|
import Submission from '../components/Results/Submission'
|
2020-04-24 15:37:46 +02:00
|
|
|
import TopBar from '../components/TopBar'
|
2020-03-20 12:22:07 +01:00
|
|
|
import ViewsMixin from '../mixins/ViewsMixin'
|
2020-05-10 12:44:56 +02:00
|
|
|
import SetWindowTitle from '../utils/SetWindowTitle'
|
2019-05-14 01:15:45 +02:00
|
|
|
|
2020-05-06 12:48:09 +02:00
|
|
|
Vue.use(Clipboard)
|
|
|
|
|
2019-05-14 01:15:45 +02:00
|
|
|
export default {
|
|
|
|
name: 'Results',
|
|
|
|
|
|
|
|
components: {
|
2020-05-01 01:26:01 +02:00
|
|
|
Actions,
|
|
|
|
ActionButton,
|
2020-03-20 12:22:07 +01:00
|
|
|
AppContent,
|
2020-04-24 15:37:46 +02:00
|
|
|
EmptyContent,
|
2020-04-20 18:40:15 +02:00
|
|
|
Submission,
|
2020-04-24 15:37:46 +02:00
|
|
|
TopBar,
|
2019-05-14 01:15:45 +02:00
|
|
|
},
|
|
|
|
|
2020-05-10 12:44:56 +02:00
|
|
|
mixins: [ViewsMixin],
|
2020-03-20 12:22:07 +01:00
|
|
|
|
2019-05-14 01:15:45 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2020-04-24 15:37:46 +02:00
|
|
|
loadingResults: true,
|
2020-04-20 18:40:15 +02:00
|
|
|
submissions: [],
|
|
|
|
questions: [],
|
2019-05-14 01:15:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-09-03 10:32:32 +02:00
|
|
|
computed: {
|
2020-04-24 15:37:46 +02:00
|
|
|
noSubmissions() {
|
2020-04-20 18:40:15 +02:00
|
|
|
return this.submissions && this.submissions.length === 0
|
2020-04-24 15:37:46 +02:00
|
|
|
},
|
2020-05-09 15:56:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return form title, or placeholder if not set
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
formTitle() {
|
|
|
|
if (this.form.title) {
|
|
|
|
return this.form.title
|
|
|
|
}
|
2020-05-09 18:42:29 +02:00
|
|
|
return t('forms', 'New form')
|
2020-05-09 15:56:01 +02:00
|
|
|
},
|
2019-09-03 10:32:32 +02:00
|
|
|
},
|
|
|
|
|
2020-05-10 14:43:33 +02:00
|
|
|
watch: {
|
|
|
|
// Reload results, when form changes
|
|
|
|
hash() {
|
|
|
|
this.loadFormResults()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-04-24 15:37:46 +02:00
|
|
|
beforeMount() {
|
|
|
|
this.loadFormResults()
|
2020-05-10 12:44:56 +02:00
|
|
|
SetWindowTitle(this.formTitle)
|
2019-05-14 01:15:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-04-24 15:37:46 +02:00
|
|
|
showEdit() {
|
2019-05-14 01:15:45 +02:00
|
|
|
this.$router.push({
|
2020-04-24 15:37:46 +02:00
|
|
|
name: 'edit',
|
2019-05-14 01:15:45 +02:00
|
|
|
params: {
|
2020-04-24 15:37:46 +02:00
|
|
|
hash: this.form.hash,
|
2020-02-26 13:39:50 +01:00
|
|
|
},
|
2019-05-14 01:15:45 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-05-06 12:48:09 +02:00
|
|
|
copyShareLink() {
|
|
|
|
const $formLink = window.location.protocol + '//' + window.location.host + generateUrl(`/apps/forms/${this.form.hash}`)
|
|
|
|
if (this.$clipboard($formLink)) {
|
|
|
|
showSuccess(t('forms', 'Form link copied'))
|
|
|
|
} else {
|
|
|
|
showError(t('forms', 'Cannot copy, please copy the link manually'))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-24 15:37:46 +02:00
|
|
|
async loadFormResults() {
|
|
|
|
this.loadingResults = true
|
|
|
|
console.debug('Loading Results')
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await axios.get(generateUrl('/apps/forms/api/v1/submissions/{hash}', {
|
|
|
|
hash: this.form.hash,
|
|
|
|
}))
|
2020-04-20 18:40:15 +02:00
|
|
|
this.submissions = response.data.submissions
|
|
|
|
this.questions = response.data.questions
|
|
|
|
console.debug(this.submissions)
|
2020-04-24 15:37:46 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
showError(t('forms', 'There was an error while loading results'))
|
|
|
|
} finally {
|
|
|
|
this.loadingResults = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-30 12:02:23 +02:00
|
|
|
async deleteSubmission(id) {
|
|
|
|
this.loadingResults = true
|
|
|
|
|
|
|
|
try {
|
|
|
|
await axios.delete(generateUrl('/apps/forms/api/v1/submission/{id}', { id }))
|
|
|
|
const index = this.submissions.findIndex(search => search.id === id)
|
|
|
|
this.submissions.splice(index, 1)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
2020-05-06 23:08:31 +02:00
|
|
|
showError(t('forms', 'There was an error while removing this response'))
|
2020-04-30 12:02:23 +02:00
|
|
|
} finally {
|
|
|
|
this.loadingResults = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-05-01 01:26:01 +02:00
|
|
|
async deleteAllSubmissions() {
|
2020-05-09 15:56:01 +02:00
|
|
|
if (!confirm(t('forms', 'Are you sure you want to delete all responses of {title}?', { title: this.formTitle }))) {
|
2020-05-01 01:26:01 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loadingResults = true
|
|
|
|
try {
|
|
|
|
await axios.delete(generateUrl('/apps/forms/api/v1/submissions/{formId}', { formId: this.form.id }))
|
|
|
|
this.submissions = []
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
2020-05-06 23:08:31 +02:00
|
|
|
showError(t('forms', 'There was an error while removing responses'))
|
2020-05-01 01:26:01 +02:00
|
|
|
} finally {
|
|
|
|
this.loadingResults = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-05-01 00:29:38 +02:00
|
|
|
download() {
|
|
|
|
this.loadingResults = true
|
|
|
|
|
|
|
|
const parser = new Parser({
|
|
|
|
delimiter: ',',
|
|
|
|
})
|
|
|
|
|
|
|
|
const formattedSubmissions = []
|
|
|
|
this.submissions.forEach(submission => {
|
|
|
|
const formattedSubmission = {
|
2020-05-02 20:30:25 +02:00
|
|
|
userDisplayName: submission.userDisplayName,
|
2020-05-01 00:29:38 +02:00
|
|
|
timestamp: moment(submission.timestamp, 'X').format('L LT'),
|
|
|
|
}
|
|
|
|
|
|
|
|
submission.answers.forEach(answer => {
|
|
|
|
const questionText = this.questions.find(question => question.id === answer.questionId).text
|
|
|
|
if (questionText in formattedSubmission) {
|
|
|
|
formattedSubmission[questionText] = formattedSubmission[questionText].concat('; ').concat(answer.text)
|
|
|
|
} else {
|
|
|
|
formattedSubmission[questionText] = answer.text
|
|
|
|
}
|
2019-05-14 09:03:59 +02:00
|
|
|
})
|
2020-05-01 00:29:38 +02:00
|
|
|
formattedSubmissions.push(formattedSubmission)
|
|
|
|
})
|
|
|
|
|
|
|
|
const element = document.createElement('a')
|
|
|
|
element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(parser.parse(formattedSubmissions)))
|
2020-05-09 15:56:01 +02:00
|
|
|
element.setAttribute('download', this.formTitle + '.csv')
|
2020-05-01 00:29:38 +02:00
|
|
|
element.style.display = 'none'
|
|
|
|
document.body.appendChild(element)
|
|
|
|
element.click()
|
|
|
|
document.body.removeChild(element)
|
|
|
|
|
|
|
|
this.loadingResults = false
|
|
|
|
},
|
2020-02-26 13:39:50 +01:00
|
|
|
},
|
2019-05-14 01:15:45 +02:00
|
|
|
}
|
|
|
|
</script>
|
2020-05-02 18:36:52 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
h2 {
|
|
|
|
font-size: 2em;
|
|
|
|
font-weight: bold;
|
|
|
|
margin-top: 32px;
|
|
|
|
padding-left: 14px;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
|
|
|
|
2020-05-07 09:55:00 +02:00
|
|
|
.response_actions {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
&__export {
|
|
|
|
width: max-content;
|
|
|
|
margin-left: 16px;
|
|
|
|
}
|
2020-05-02 18:36:52 +02:00
|
|
|
}
|
|
|
|
</style>
|