Skip to content

Commit 8a1ea05

Browse files
Mattia VianelliMattia Vianelli
authored andcommitted
DSC-2668 Updated link rendering to be able to render plain text values for licenses
(cherry picked from commit 49edf6da7211b70030ed3e7be65b53f87deb479f)
1 parent e35afb1 commit 8a1ea05

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<div [class]="field.styleValue" [attr.lang]="metadataValue.language">
2+
@if (isLink) {
23
<span class="link-value">
34
<a href="{{link.href}}" target="_blank">{{ link.text }}</a>
45
</span>
6+
} @else {
7+
<span class="plain-text-value">{{ link.text }}</span>
8+
}
59
</div>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/link/link.component.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export class LinkComponent extends RenderingTypeValueModelComponent implements O
3838
*/
3939
link: MetadataLinkValue;
4040

41+
/**
42+
* Flag to determine if the value is a valid URL
43+
*/
44+
isLink = false;
45+
4146
isEmail = false;
4247

4348
constructor(
@@ -52,9 +57,25 @@ export class LinkComponent extends RenderingTypeValueModelComponent implements O
5257
}
5358

5459
ngOnInit(): void {
60+
this.isLink = this.isValidUrl();
5561
this.link = this.getLinkFromValue();
5662
}
5763

64+
/**
65+
* Check if the metadata value is a valid URL
66+
*/
67+
isValidUrl(): boolean {
68+
const value = this.metadataValue.value.trim();
69+
70+
// Comprehensive URL regex that matches:
71+
// - URLs with protocols (http, https, ftp, mailto, etc.)
72+
// - URLs without protocols (www.example.com, example.com)
73+
// - URLs with paths, query strings, and fragments
74+
const urlRegex = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/;
75+
76+
return urlRegex.test(value);
77+
}
78+
5879
/**
5980
* Get the link value to render
6081
*/

0 commit comments

Comments
 (0)