[TLC-380] Support browse links and regex links in metadata display

(resolved conflicts jan 2023)
This commit is contained in:
Kim Shepherd
2022-11-08 16:43:24 +13:00
parent 430b43581a
commit 928157f994
27 changed files with 491 additions and 26 deletions

View File

@@ -1,6 +1,8 @@
import { Component, Inject, Input, OnChanges, SimpleChanges } from '@angular/core';
import { MetadataValue } from '../../../core/shared/metadata.models';
import { APP_CONFIG, AppConfig } from '../../../../config/app-config.interface';
import { BrowseDefinition } from '../../../core/shared/browse-definition.model';
import { hasValue } from '../../../shared/empty.util';
/**
* This component renders the configured 'values' into the ds-metadata-field-wrapper component.
@@ -40,12 +42,38 @@ export class MetadataValuesComponent implements OnChanges {
*/
@Input() enableMarkdown = false;
/**
* Whether any valid HTTP(S) URL should be rendered as a link
*/
@Input() urlRegex?;
/**
* This variable will be true if both {@link environment.markdown.enabled} and {@link enableMarkdown} are true.
*/
renderMarkdown;
@Input() browseDefinition?: BrowseDefinition;
ngOnChanges(changes: SimpleChanges): void {
this.renderMarkdown = !!this.appConfig.markdown.enabled && this.enableMarkdown;
}
/**
* Does this metadata value have a configured link to a browse definition?
*/
hasBrowseDefinition(): boolean {
return hasValue(this.browseDefinition);
}
/**
* Does this metadata value have a valid URL that should be rendered as a link?
* @param value
*/
hasLink(value): boolean {
if (hasValue(this.urlRegex)) {
const pattern: RegExp = new RegExp(this.urlRegex);
return pattern.test(value.value);
}
return false;
}
}