Skip to content

Commit 7899e0f

Browse files
custom report name for direct print
1 parent 836b9b2 commit 7899e0f

File tree

10 files changed

+686
-17
lines changed

10 files changed

+686
-17
lines changed

app/frontend/src/components/forms/DirectPrintButton.vue

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ const { isRTL, form } = storeToRefs(formStore);
4040
4141
const formId = computed(() => (properties.f ? properties.f : form.value.id));
4242
43+
async function getReportName(printConfig, formValue, formIdValue) {
44+
// If custom name is specified, use it
45+
if (printConfig.reportNameOption === 'custom' && printConfig.reportName) {
46+
return printConfig.reportName;
47+
}
48+
49+
// Fetch form data if form name is missing
50+
let formData = formValue;
51+
if (!formData?.name) {
52+
await formStore.fetchForm(formIdValue);
53+
formData = form.value;
54+
}
55+
56+
// Default: use form name only
57+
return formData?.name || '';
58+
}
59+
4360
function createBody(content, contentFileType, outputFileName, outputFileType) {
4461
return {
4562
options: {
@@ -55,6 +72,16 @@ function createBody(content, contentFileType, outputFileName, outputFileType) {
5572
};
5673
}
5774
75+
async function generateDocument(submissionId, body, submission) {
76+
if (submissionId?.length > 0) {
77+
return await formService.docGen(submissionId, body);
78+
}
79+
return await utilsService.draftDocGen({
80+
template: body,
81+
submission: submission,
82+
});
83+
}
84+
5885
async function generateDirectPrint() {
5986
try {
6087
loading.value = true;
@@ -67,26 +94,35 @@ async function generateDirectPrint() {
6794
6895
// Extract template content
6996
const temp = templateResponse.data.template.data;
70-
const base64String = temp.map((code) => String.fromCharCode(code)).join('');
97+
const base64String = temp
98+
.map((code) => String.fromCodePoint(code))
99+
.join('');
71100
72-
// Get template filename and extension
73-
const { name, extension } = splitFileName(templateResponse.data.filename);
101+
// Get template extension
102+
const { extension } = splitFileName(templateResponse.data.filename);
74103
const outputFileType = properties.printConfig.outputFileType || 'pdf';
75104
105+
// Build report name based on printConfig options (fetches versions if needed)
106+
const reportName = await getReportName(
107+
properties.printConfig,
108+
form.value,
109+
formId.value
110+
);
111+
76112
// Create the request body
77-
const body = createBody(base64String, extension, name, outputFileType);
113+
const body = createBody(
114+
base64String,
115+
extension,
116+
reportName,
117+
outputFileType
118+
);
78119
79120
// Generate document
80-
let response = null;
81-
if (properties.submissionId?.length > 0) {
82-
response = await formService.docGen(properties.submissionId, body);
83-
} else {
84-
const draftData = {
85-
template: body,
86-
submission: properties.submission,
87-
};
88-
response = await utilsService.draftDocGen(draftData);
89-
}
121+
const response = await generateDocument(
122+
properties.submissionId,
123+
body,
124+
properties.submission
125+
);
90126
91127
// Create file to download
92128
const filename = getDisposition(response.headers['content-disposition']);

app/frontend/src/components/forms/manage/PrintConfig.vue

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const printConfig = ref(null);
1515
const localConfig = ref({
1616
code: 'default',
1717
templateId: null,
18+
reportNameOption: 'formName',
19+
reportName: null,
1820
});
1921
const loading = ref(true);
2022
const saving = ref(false);
@@ -62,12 +64,16 @@ async function fetchPrintConfig() {
6264
localConfig.value = {
6365
code: response.data.code || 'default',
6466
templateId: response.data.templateId || null,
67+
reportNameOption: response.data.reportNameOption || 'formName',
68+
reportName: response.data.reportName || null,
6569
};
6670
} else {
6771
// No config exists, use defaults
6872
localConfig.value = {
6973
code: 'default',
7074
templateId: null,
75+
reportNameOption: 'formName',
76+
reportName: null,
7177
};
7278
}
7379
} catch (e) {
@@ -80,6 +86,8 @@ async function fetchPrintConfig() {
8086
localConfig.value = {
8187
code: 'default',
8288
templateId: null,
89+
reportNameOption: 'formName',
90+
reportName: null,
8391
};
8492
}
8593
}
@@ -125,9 +133,19 @@ async function handleSave() {
125133
if (localConfig.value.code === 'direct') {
126134
data.templateId = localConfig.value.templateId;
127135
data.outputFileType = 'pdf';
136+
// Include reportNameOption and reportName
137+
data.reportNameOption = localConfig.value.reportNameOption || 'formName';
138+
// Only include reportName if custom option is selected
139+
if (localConfig.value.reportNameOption === 'custom') {
140+
data.reportName = localConfig.value.reportName || form.value.name;
141+
} else {
142+
data.reportName = null;
143+
}
128144
} else {
129145
data.templateId = null;
130146
data.outputFileType = null;
147+
data.reportNameOption = null;
148+
data.reportName = null;
131149
}
132150
133151
await printConfigService.upsertPrintConfig(form.value.id, data);
@@ -195,7 +213,7 @@ async function handleSave() {
195213
196214
<!-- Template Selection (when Direct is selected) -->
197215
<v-expand-transition>
198-
<div v-if="isDirectPrint" class="mb-4">
216+
<div v-if="isDirectPrint" class="mb-4 pl-12 pr-12">
199217
<v-alert
200218
v-if="!hasTemplates"
201219
type="warning"
@@ -214,7 +232,70 @@ async function handleSave() {
214232
:lang="locale"
215233
:disabled="!hasTemplates"
216234
clearable
235+
class="mb-4"
217236
/>
237+
238+
<!-- Output File Name Options (when Direct is selected) -->
239+
<div class="mb-4">
240+
<v-radio-group v-model="localConfig.reportNameOption" :lang="locale">
241+
<template #label>
242+
<div class="font-weight-bold">
243+
{{ $t('trans.printConfig.reportNameLabel') }}
244+
</div>
245+
</template>
246+
<v-radio
247+
value="formName"
248+
:label="$t('trans.printConfig.reportNameOptionFormName')"
249+
>
250+
<template #label>
251+
<div>
252+
<div class="font-weight-medium">
253+
{{ $t('trans.printConfig.reportNameOptionFormName') }}
254+
</div>
255+
<div class="text-caption text-medium-emphasis">
256+
{{
257+
$t(
258+
'trans.printConfig.reportNameOptionFormNameDescription'
259+
)
260+
}}
261+
</div>
262+
</div>
263+
</template>
264+
</v-radio>
265+
<v-radio
266+
value="custom"
267+
:label="$t('trans.printConfig.reportNameOptionCustom')"
268+
>
269+
<template #label>
270+
<div>
271+
<div class="font-weight-medium">
272+
{{ $t('trans.printConfig.reportNameOptionCustom') }}
273+
</div>
274+
<div class="text-caption text-medium-emphasis">
275+
{{
276+
$t('trans.printConfig.reportNameOptionCustomDescription')
277+
}}
278+
</div>
279+
</div>
280+
</template>
281+
</v-radio>
282+
</v-radio-group>
283+
284+
<!-- Custom Name Input (shown only when custom option is selected) -->
285+
<v-expand-transition>
286+
<v-text-field
287+
v-if="localConfig.reportNameOption === 'custom'"
288+
v-model="localConfig.reportName"
289+
:label="$t('trans.printConfig.reportNameCustomInput')"
290+
:hint="$t('trans.printConfig.reportNameCustomInputHint')"
291+
:placeholder="form.name"
292+
variant="outlined"
293+
:lang="locale"
294+
persistent-hint
295+
class="mt-2"
296+
/>
297+
</v-expand-transition>
298+
</div>
218299
</div>
219300
</v-expand-transition>
220301

app/frontend/src/internationalization/trans/chefs/en/en.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@
120120
"templateDeleted": "The previously selected template has been deleted. Please select a new template.",
121121
"currentConfig": "Current Configuration",
122122
"type": "Type",
123-
"template": "Template"
123+
"template": "Template",
124+
"reportNameLabel": "Output File Name",
125+
"reportNameOptionFormName": "Use Form Name",
126+
"reportNameOptionFormNameDescription": "Output file will be named using the form name",
127+
"reportNameOptionCustom": "Use Custom Name",
128+
"reportNameOptionCustomDescription": "Enter a custom name for the output file",
129+
"reportNameCustomInput": "Custom File Name",
130+
"reportNameCustomInputHint": "Enter the custom name for the generated document"
124131
},
125132
"encryptionKey": {
126133
"info": "Configure Encryption Keys for your form.",

0 commit comments

Comments
 (0)