Skip to content

Commit

Permalink
fix onLinkFile
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
  • Loading branch information
Chartman123 committed Jan 31, 2025
1 parent e739ec6 commit af1b811
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
10 changes: 5 additions & 5 deletions src/components/Results/ResultsSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<meter
:id="`option-${option.questionId}-${option.id}`"
min="0"
:max="submissions.length"
:max="submissions?.length"
:value="option.count" />
</li>
</ol>
Expand Down Expand Up @@ -130,7 +130,7 @@ export default {
})

// Go through submissions to check which options have how many responses
this.submissions.forEach((submission) => {
this.submissions?.forEach((submission) => {
const answers = submission.answers.filter(
(answer) => answer.questionId === this.question.id,
)
Expand Down Expand Up @@ -168,7 +168,7 @@ export default {
questionOptionsStats.forEach((questionOptionsStat) => {
// Fill percentage values
questionOptionsStat.percentage = Math.round(
(100 * questionOptionsStat.count) / this.submissions.length,
(100 * questionOptionsStat.count) / this.submissions?.length,
)
// Mark all best results. First one is best for sure due to sorting
questionOptionsStat.best =
Expand All @@ -186,7 +186,7 @@ export default {
let noResponseCount = 0

// Go through submissions to check which options have how many responses
this.submissions.forEach((submission) => {
this.submissions?.forEach((submission) => {
const answers = submission.answers.filter(
(answer) => answer.questionId === this.question.id,
)
Expand Down Expand Up @@ -216,7 +216,7 @@ export default {

// Calculate no response percentage
const noResponsePercentage = Math.round(
(100 * noResponseCount) / this.submissions.length,
(100 * noResponseCount) / this.submissions?.length,
)
answersModels.unshift({
id: 0,
Expand Down
43 changes: 23 additions & 20 deletions src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<p>
{{
t('forms', '{amount} responses', {
amount: form.submissions.length,
amount: form.submissions?.length ?? 0,
})
}}
</p>
Expand All @@ -125,6 +125,14 @@
@blur="isDownloadActionOpened = false"
@close="isDownloadActionOpened = false">
<template v-if="!isDownloadActionOpened">
<NcActionButton
v-if="canEditForm && !form.fileId"
@click="onLinkFile">
<template #icon>
<IconLink :size="20" />
</template>
{{ t('forms', 'Create spreadsheet') }}
</NcActionButton>
<template v-if="canEditForm && form.fileId">
<NcActionButton
:href="fileUrl"
Expand All @@ -150,16 +158,8 @@
</template>
{{ t('forms', 'Unlink spreadsheet') }}
</NcActionButton>
<NcActionSeparator />
<NcActionSeparator v-if="!noSubmissions" />
</template>
<NcActionButton
v-else-if="canEditForm"
@click="onLinkFile">
<template #icon>
<IconLink :size="20" />
</template>
{{ t('forms', 'Create spreadsheet') }}
</NcActionButton>
<NcActionButton
close-after-click
@click="onStoreToFiles">
Expand Down Expand Up @@ -469,6 +469,7 @@ export default {
async hash() {
await this.fetchFullForm(this.form.id)
this.loadFormResults()
SetWindowTitle(this.formTitle)
},
},

Expand All @@ -492,11 +493,16 @@ export default {
},
)

this.form.fileFormat = null
this.form.fileId = null
this.form.filePath = null
const updatedForm = {
...this.form,
fileFormat: null,
fileId: null,
filePath: null,
}
this.$emit('update:form', updatedForm)
emit('forms:last-updated:set', this.form.id)
},

async loadFormResults() {
this.loadingResults = true
logger.debug(`Loading results for form ${this.form.hash}`)
Expand Down Expand Up @@ -545,7 +551,7 @@ export default {
.pick()
.then(async (path) => {
try {
const response = await axios.patch(
await axios.patch(
generateOcsUrl('apps/forms/api/v3/forms/{id}', {
id: this.form.id,
}),
Expand All @@ -556,15 +562,12 @@ export default {
},
},
)
const responseData = OcsResponse2Data(response)

this.form.fileFormat = responseData.fileFormat
this.form.fileId = responseData.fileId
this.form.filePath = responseData.filePath
await this.fetchFullForm(this.form.id)
await this.loadFormResults()

showSuccess(
t('forms', 'File {file} successfully linked', {
file: responseData.fileName,
file: this.form.filePath.split('/').pop(),
}),
)
emit('forms:last-updated:set', this.form.id)
Expand Down

0 comments on commit af1b811

Please sign in to comment.