Skip to content

Commit 66fcbdc

Browse files
committed
prefix for images
1 parent 6293a9a commit 66fcbdc

5 files changed

Lines changed: 46 additions & 6 deletions

File tree

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<div class="image-box">
22
<mat-form-field class="image-box__url" appearance="outline">
33
<mat-label>{{normalizedLabel}}</mat-label>
4+
<span *ngIf="prefix" matTextPrefix>{{prefix}}</span>
45
<input matInput type="text" name="{{label}}-{{key}}" #image="ngModel"
56
[required]="required" [disabled]="disabled" [readonly]="readonly"
67
urlValidator
8+
[urlPrefix]="prefix"
79
attr.data-testid="record-{{label}}-image"
810
[(ngModel)]="value" (ngModelChange)="onFieldChange.emit($event)">
911
<mat-error *ngIf="image.errors?.isInvalidURL">URL is invalid.</mat-error>
1012
</mat-form-field>
11-
<img *ngIf="!image.errors?.isInvalidURL" [src]="value" class="image-box__image">
13+
<img *ngIf="!image.errors?.isInvalidURL" [src]="imageUrl" class="image-box__image">
1214
</div>

frontend/src/app/components/ui-components/record-edit-fields/image/image.component.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, OnInit } from '@angular/core';
22

33
import { BaseEditFieldComponent } from '../base-row-field/base-row-field.component';
44
import { CommonModule } from '@angular/common';
@@ -19,6 +19,37 @@ import { UrlValidatorDirective } from 'src/app/directives/url-validator.directiv
1919
UrlValidatorDirective
2020
]
2121
})
22-
export class ImageEditComponent extends BaseEditFieldComponent {
22+
export class ImageEditComponent extends BaseEditFieldComponent implements OnInit {
2323
@Input() value: string;
24+
public prefix: string = '';
25+
26+
ngOnInit(): void {
27+
super.ngOnInit();
28+
this._parseWidgetParams();
29+
}
30+
31+
ngOnChanges(): void {
32+
this._parseWidgetParams();
33+
}
34+
35+
private _parseWidgetParams(): void {
36+
if (this.widgetStructure?.widget_params) {
37+
try {
38+
const params = typeof this.widgetStructure.widget_params === 'string'
39+
? JSON.parse(this.widgetStructure.widget_params)
40+
: this.widgetStructure.widget_params;
41+
42+
if (params.prefix !== undefined) {
43+
this.prefix = params.prefix || '';
44+
}
45+
} catch (e) {
46+
console.error('Error parsing Image widget params:', e);
47+
}
48+
}
49+
}
50+
51+
get imageUrl(): string {
52+
if (!this.value) return '';
53+
return this.prefix + this.value;
54+
}
2455
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<span *ngIf="!isUrl" class="field-view-value">[Image URL]</span>
22
<img *ngIf="isUrl"
33
class="image-preview"
4-
[src]="value" alt="Image">
4+
[src]="srcValue" alt="Image">
55
<span class="field-view-value">{{value || '—'}}</span>

frontend/src/app/components/ui-components/record-view-fields/image/image.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ import { Component, Injectable } from '@angular/core';
1010
imports: [CommonModule]
1111
})
1212
export class ImageRecordViewComponent extends BaseRecordViewFieldComponent {
13+
get srcValue(): string {
14+
if (!this.value) return '';
15+
const prefix = this.widgetStructure?.widget_params?.prefix || '';
16+
return prefix + this.value;
17+
}
18+
1319
get isUrl(): boolean {
1420
if (!this.value) return false;
1521
try {
16-
new URL(this.value);
22+
// Check if the prefixed URL is valid
23+
new URL(this.srcValue);
1724
return true;
1825
} catch {
1926
return false;

frontend/src/app/components/ui-components/table-display-fields/image/image.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<button type="button" mat-icon-button
88
class="field-copy-button"
99
matTooltip="Copy image URL"
10-
[cdkCopyToClipboard]="value"
10+
[cdkCopyToClipboard]="srcValue"
1111
(cdkCopyToClipboardCopied)="onCopyToClipboard.emit('Field value was copied to clipboard.')"
1212
(click)="$event.stopPropagation()">
1313
<mat-icon>content_copy</mat-icon>

0 commit comments

Comments
 (0)