Skip to content

Commit 0f84cd8

Browse files
feat: generate document title automatically on the basis file name
1 parent ce671d4 commit 0f84cd8

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

apps/OpenSign/src/constant/Utils.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,3 +2462,45 @@ export const handleRotateWarning = (signerPos, pageNumber) => {
24622462
return false;
24632463
}
24642464
};
2465+
2466+
// `generateTitleFromFilename` to generate Title of document from file name
2467+
export function generateTitleFromFilename(filename) {
2468+
try {
2469+
// Step 1: Trim whitespace
2470+
let title = filename.trim();
2471+
2472+
// Step 2: Remove the file extension (everything after the last '.')
2473+
const lastDotIndex = title.lastIndexOf(".");
2474+
if (lastDotIndex > 0) {
2475+
title = title.substring(0, lastDotIndex);
2476+
}
2477+
2478+
// Step 3: Replace special characters (except Unicode letters, digits, spaces, and hyphens)
2479+
title = title.replace(/[^\p{L}\p{N}\s-]/gu, " ");
2480+
2481+
// Step 4: Replace multiple spaces with a single space
2482+
title = title.replace(/\s+/g, " ");
2483+
2484+
// Step 5: Capitalize first letter of each word (Title Case), handling Unicode characters
2485+
title = title.replace(
2486+
/\p{L}\S*/gu,
2487+
(txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
2488+
);
2489+
2490+
// Step 6: Restrict length of title (optional, let's say 100 characters)
2491+
if (title.length > 100) {
2492+
title = title.substring(0, 100).trim();
2493+
}
2494+
2495+
// Step 7: Handle empty or invalid title by falling back to "Untitled Document"
2496+
if (!title || title.length === 0) {
2497+
return "Untitled Document";
2498+
}
2499+
2500+
return title;
2501+
} catch (error) {
2502+
// Handle unexpected errors gracefully by returning a default title
2503+
console.error("Error generating title from filename:", error);
2504+
return "Untitled Document";
2505+
}
2506+
}

apps/OpenSign/src/json/ReportJson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function reportJson(id) {
1616
"Note",
1717
"Folder",
1818
"File",
19-
"Logs",
19+
"Status",
2020
"Signers"
2121
];
2222
const contactbook = ["Sr.No", "Name", "Email", "Phone"];

apps/OpenSign/src/pages/Form.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import SignersInput from "../components/shared/fields/SignersInput";
99
import Title from "../components/Title";
1010
import PageNotFound from "./PageNotFound";
1111
import { SaveFileSize } from "../constant/saveFileSize";
12-
import { checkIsSubscribed, getFileName, toDataUrl } from "../constant/Utils";
12+
import {
13+
checkIsSubscribed,
14+
generateTitleFromFilename,
15+
getFileName,
16+
toDataUrl
17+
} from "../constant/Utils";
1318
import { PDFDocument } from "pdf-lib";
1419
import axios from "axios";
1520
import { isEnableSubscription } from "../constant/const";
@@ -330,6 +335,8 @@ const Forms = (props) => {
330335
setfileload(false);
331336
if (response.url()) {
332337
const tenantId = localStorage.getItem("TenantId");
338+
const title = generateTitleFromFilename(file.name);
339+
setFormData((obj) => ({ ...obj, Name: title }));
333340
SaveFileSize(size, response.url(), tenantId);
334341
return response.url();
335342
}
@@ -367,9 +374,10 @@ const Forms = (props) => {
367374
});
368375
setFileUpload(response.url());
369376
setfileload(false);
370-
371377
if (response.url()) {
372378
const tenantId = localStorage.getItem("TenantId");
379+
const title = generateTitleFromFilename(file.name);
380+
setFormData((obj) => ({ ...obj, Name: title }));
373381
SaveFileSize(size, response.url(), tenantId);
374382
return response.url();
375383
}

apps/OpenSignServer/cloud/parsefunction/reportsJson.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default function reportJson(id, userId) {
6565
'Folder.Name',
6666
'URL',
6767
'ExtUserPtr.Name',
68+
'ExtUserPtr.Email',
6869
'ExtUserPtr.active_mail_adapter',
6970
'Signers.Name',
7071
'Signers.Email',
@@ -101,6 +102,7 @@ export default function reportJson(id, userId) {
101102
'Folder.Name',
102103
'URL',
103104
'ExtUserPtr.Name',
105+
'ExtUserPtr.Email',
104106
'ExtUserPtr.active_mail_adapter',
105107
'Signers.Name',
106108
'Signers.Email',
@@ -229,6 +231,7 @@ export default function reportJson(id, userId) {
229231
'Folder.Name',
230232
'URL',
231233
'ExtUserPtr.Name',
234+
'ExtUserPtr.Email',
232235
'ExtUserPtr.active_mail_adapter',
233236
'Signers.Name',
234237
'Signers.Email',
@@ -271,6 +274,7 @@ export default function reportJson(id, userId) {
271274
'Name',
272275
'URL',
273276
'ExtUserPtr.Name',
277+
'ExtUserPtr.Email',
274278
'ExtUserPtr.active_mail_adapter',
275279
'Signers.Name',
276280
'Signers.UserId',

0 commit comments

Comments
 (0)