|
32 | 32 | @openSharing="openSharing" |
33 | 33 | @mobileCloseNavigation="mobileCloseNavigation" |
34 | 34 | @clone="onCloneForm" |
| 35 | + @download="onDownloadForm" |
35 | 36 | @delete="onDeleteForm" /> |
36 | 37 | </ul> |
37 | 38 | </template> |
|
51 | 52 | readOnly |
52 | 53 | @openSharing="openSharing" |
53 | 54 | @clone="onCloneForm" |
| 55 | + @download="onDownloadForm" |
54 | 56 | @mobileCloseNavigation="mobileCloseNavigation" /> |
55 | 57 | </ul> |
56 | 58 | </template> |
@@ -170,6 +172,7 @@ import AppNavigationForm from './components/AppNavigationForm.vue' |
170 | 172 | import ArchivedFormsModal from './components/ArchivedFormsModal.vue' |
171 | 173 | import Sidebar from './views/Sidebar.vue' |
172 | 174 | import FormsIcon from '../img/forms-dark.svg?raw' |
| 175 | +import { version } from '../package.json' |
173 | 176 | import PermissionTypes from './mixins/PermissionTypes.js' |
174 | 177 | import { FormState } from './models/Constants.ts' |
175 | 178 | import logger from './utils/Logger.js' |
@@ -440,6 +443,58 @@ export default { |
440 | 443 | } |
441 | 444 | } |
442 | 445 |
|
| 446 | + const onDownloadForm = async (id) => { |
| 447 | + try { |
| 448 | + const response = await axios.get( |
| 449 | + generateOcsUrl('apps/forms/api/v3/forms/{id}', { |
| 450 | + id, |
| 451 | + }), |
| 452 | + ) |
| 453 | + const form = OcsResponse2Data(response) |
| 454 | +
|
| 455 | + // download only required values |
| 456 | + const download = { |
| 457 | + appVersion: version, |
| 458 | + form: { |
| 459 | + ...form, |
| 460 | + // Remove unused values |
| 461 | + ...[ |
| 462 | + 'hash', |
| 463 | + 'ownerId', |
| 464 | + 'created', |
| 465 | + 'access', |
| 466 | + 'lastUpdated', |
| 467 | + 'lockedBy', |
| 468 | + 'lockedUntil', |
| 469 | + 'shares', |
| 470 | + 'permissions', |
| 471 | + 'canSubmit', |
| 472 | + 'isMaxSubmissionsReached', |
| 473 | + 'submissionCount', |
| 474 | + ].reduce((prev, curr) => { |
| 475 | + prev[curr] = undefined |
| 476 | + return prev |
| 477 | + }, {}), |
| 478 | +
|
| 479 | + id: undefined, |
| 480 | + questions: form.questions, |
| 481 | + }, |
| 482 | + } |
| 483 | + // create blob and download |
| 484 | + const blob = new Blob([JSON.stringify(download)]) |
| 485 | + const url = URL.createObjectURL(blob) |
| 486 | + const a = document.createElement('a') |
| 487 | + a.href = url |
| 488 | + const formTitle = form.title ? form.title : t('forms', 'New form') |
| 489 | + a.download = `${formTitle}.json` |
| 490 | + a.click() |
| 491 | + URL.revokeObjectURL(url) |
| 492 | + } catch (error) { |
| 493 | + logger.error(`Unable to download form ${id}`, { error }) |
| 494 | + showError(t('forms', 'Unable to download form')) |
| 495 | + } |
| 496 | + } |
| 497 | +
|
443 | 498 | const onDeleteForm = async (id) => { |
444 | 499 | const formIndex = forms.value.findIndex((form) => form.id === id) |
445 | 500 | const deletedHash = forms.value[formIndex].hash |
@@ -513,6 +568,7 @@ export default { |
513 | 568 | fetchPartialForm, |
514 | 569 | onNewForm, |
515 | 570 | onCloneForm, |
| 571 | + onDownloadForm, |
516 | 572 | onDeleteForm, |
517 | 573 | onLastUpdatedByEventBus, |
518 | 574 | IconPlus, |
|
0 commit comments