Skip to content

Commit 76f5136

Browse files
Merge pull request #1245 from OpenSignLabs/validation
2 parents adfdf76 + 0f84cd8 commit 76f5136

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
@@ -2474,3 +2474,45 @@ export const handleRotateWarning = (signerPos, pageNumber) => {
24742474
return false;
24752475
}
24762476
};
2477+
2478+
// `generateTitleFromFilename` to generate Title of document from file name
2479+
export function generateTitleFromFilename(filename) {
2480+
try {
2481+
// Step 1: Trim whitespace
2482+
let title = filename.trim();
2483+
2484+
// Step 2: Remove the file extension (everything after the last '.')
2485+
const lastDotIndex = title.lastIndexOf(".");
2486+
if (lastDotIndex > 0) {
2487+
title = title.substring(0, lastDotIndex);
2488+
}
2489+
2490+
// Step 3: Replace special characters (except Unicode letters, digits, spaces, and hyphens)
2491+
title = title.replace(/[^\p{L}\p{N}\s-]/gu, " ");
2492+
2493+
// Step 4: Replace multiple spaces with a single space
2494+
title = title.replace(/\s+/g, " ");
2495+
2496+
// Step 5: Capitalize first letter of each word (Title Case), handling Unicode characters
2497+
title = title.replace(
2498+
/\p{L}\S*/gu,
2499+
(txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
2500+
);
2501+
2502+
// Step 6: Restrict length of title (optional, let's say 100 characters)
2503+
if (title.length > 100) {
2504+
title = title.substring(0, 100).trim();
2505+
}
2506+
2507+
// Step 7: Handle empty or invalid title by falling back to "Untitled Document"
2508+
if (!title || title.length === 0) {
2509+
return "Untitled Document";
2510+
}
2511+
2512+
return title;
2513+
} catch (error) {
2514+
// Handle unexpected errors gracefully by returning a default title
2515+
console.error("Error generating title from filename:", error);
2516+
return "Untitled Document";
2517+
}
2518+
}

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',
@@ -230,6 +232,7 @@ export default function reportJson(id, userId) {
230232
'Folder.Name',
231233
'URL',
232234
'ExtUserPtr.Name',
235+
'ExtUserPtr.Email',
233236
'ExtUserPtr.active_mail_adapter',
234237
'Signers.Name',
235238
'Signers.Email',
@@ -272,6 +275,7 @@ export default function reportJson(id, userId) {
272275
'Name',
273276
'URL',
274277
'ExtUserPtr.Name',
278+
'ExtUserPtr.Email',
275279
'ExtUserPtr.active_mail_adapter',
276280
'Signers.Name',
277281
'Signers.UserId',

0 commit comments

Comments
 (0)