mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
feature(ui-modal): add QR code display for URLs in dialog modals Add automatic URL detection and QR code rendering in dialog modals: - Parse dialog content to extract URLs (http/https) - Display extracted URLs as QR codes using angularx-qrcode library - Split content around URL to show text before and after the QR code - Auto-detect URLs by default, with optional showUrlAsQrCode override - Add comprehensive unit tests for URL parsing helpers Ref: #5511
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { ParsedDialogContent } from './dialog.model';
|
|
|
|
/**
|
|
* Regular expression to match URLs in text.
|
|
* Matches http:// and https:// URLs.
|
|
*/
|
|
const URL_REGEX = /https?:\/\/[^\s]+/i;
|
|
|
|
/**
|
|
* Parses the dialog content and extracts the first URL.
|
|
* Splits the content into text before the URL, the URL itself, and text after.
|
|
*
|
|
* @param content - The dialog content string to parse
|
|
* @returns ParsedDialogContent with the split content
|
|
*/
|
|
export const parseDialogContentForUrl = (
|
|
content: string | undefined,
|
|
): ParsedDialogContent => {
|
|
if (!content) {
|
|
return { textBefore: '', url: null, textAfter: '' };
|
|
}
|
|
|
|
const match = content.match(URL_REGEX);
|
|
|
|
if (!match || match.index === undefined) {
|
|
return { textBefore: content, url: null, textAfter: '' };
|
|
}
|
|
|
|
const url = match[0];
|
|
const urlIndex = match.index;
|
|
const textBefore = content.substring(0, urlIndex).trim();
|
|
const textAfter = content.substring(urlIndex + url.length).trim();
|
|
|
|
return { textBefore, url, textAfter };
|
|
};
|
|
|
|
/**
|
|
* Checks if the given content contains a URL.
|
|
*
|
|
* @param content - The content string to check
|
|
* @returns true if a URL is found, false otherwise
|
|
*/
|
|
export const contentHasUrl = (content: string | undefined): boolean => {
|
|
if (!content) {
|
|
return false;
|
|
}
|
|
return URL_REGEX.test(content);
|
|
};
|