mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #3766 from tdonohue/port_3322_to_7x
[Port dspace-7_x] fix #3241: Configuring the URI link target
This commit is contained in:
@@ -18,7 +18,10 @@
|
|||||||
|
|
||||||
<!-- Render value as a link (href and label) -->
|
<!-- Render value as a link (href and label) -->
|
||||||
<ng-template #link let-value="value">
|
<ng-template #link let-value="value">
|
||||||
<a class="dont-break-out ds-simple-metadata-link" target="_blank" [href]="value">
|
<a class="dont-break-out ds-simple-metadata-link"
|
||||||
|
[href]="value"
|
||||||
|
[attr.target]="getLinkAttributes(value).target"
|
||||||
|
[attr.rel]="getLinkAttributes(value).rel">
|
||||||
{{value}}
|
{{value}}
|
||||||
</a>
|
</a>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
@@ -73,4 +73,20 @@ describe('MetadataValuesComponent', () => {
|
|||||||
expect(comp.hasLink(mdValue)).toBe(true);
|
expect(comp.hasLink(mdValue)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return correct target and rel for internal links', () => {
|
||||||
|
spyOn(comp, 'hasInternalLink').and.returnValue(true);
|
||||||
|
const urlValue = '/internal-link';
|
||||||
|
const result = comp.getLinkAttributes(urlValue);
|
||||||
|
expect(result.target).toBe('_self');
|
||||||
|
expect(result.rel).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct target and rel for external links', () => {
|
||||||
|
spyOn(comp, 'hasInternalLink').and.returnValue(false);
|
||||||
|
const urlValue = 'https://www.dspace.org';
|
||||||
|
const result = comp.getLinkAttributes(urlValue);
|
||||||
|
expect(result.target).toBe('_blank');
|
||||||
|
expect(result.rel).toBe('noopener noreferrer');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -4,6 +4,7 @@ import { APP_CONFIG, AppConfig } from '../../../../config/app-config.interface';
|
|||||||
import { BrowseDefinition } from '../../../core/shared/browse-definition.model';
|
import { BrowseDefinition } from '../../../core/shared/browse-definition.model';
|
||||||
import { hasValue } from '../../../shared/empty.util';
|
import { hasValue } from '../../../shared/empty.util';
|
||||||
import { VALUE_LIST_BROWSE_DEFINITION } from '../../../core/shared/value-list-browse-definition.resource-type';
|
import { VALUE_LIST_BROWSE_DEFINITION } from '../../../core/shared/value-list-browse-definition.resource-type';
|
||||||
|
import { environment } from '../../../../environments/environment';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component renders the configured 'values' into the ds-metadata-field-wrapper component.
|
* This component renders the configured 'values' into the ds-metadata-field-wrapper component.
|
||||||
@@ -90,4 +91,25 @@ export class MetadataValuesComponent implements OnChanges {
|
|||||||
}
|
}
|
||||||
return queryParams;
|
return queryParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given link value is an internal link.
|
||||||
|
* @param linkValue - The link value to check.
|
||||||
|
* @returns True if the link value starts with the base URL defined in the environment configuration, false otherwise.
|
||||||
|
*/
|
||||||
|
hasInternalLink(linkValue: string): boolean {
|
||||||
|
return linkValue.startsWith(environment.ui.baseUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method performs a validation and determines the target of the url.
|
||||||
|
* @returns - Returns the target url.
|
||||||
|
*/
|
||||||
|
getLinkAttributes(urlValue: string): { target: string, rel: string } {
|
||||||
|
if (this.hasInternalLink(urlValue)) {
|
||||||
|
return { target: '_self', rel: '' };
|
||||||
|
} else {
|
||||||
|
return { target: '_blank', rel: 'noopener noreferrer' };
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user