Skip to content

Commit

Permalink
Merge pull request #1799 from CSCfi/CSCTTV-3709v2
Browse files Browse the repository at this point in the history
CSCTTV-3709v2
  • Loading branch information
ommann authored Feb 14, 2024
2 parents 17c6f3b + d1c3237 commit 779da61
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
<div class="row links" [class.m-0]="simple" [class.simple]="simple">
<div class="col-12 px-0 link-wrapper">
<div class="link">
<ng-container *ngIf='tag'>
<span class="link-tag"> {{ tag }}</span>

<ng-container *ngIf="tag">
<span class="link-tag">{{ tag }}</span>
</ng-container>

<ng-container *ngIf='icon'>
<ng-container *ngIf="icon">
<span class="link-tag fa fa-link center" style="font-size: 22px; padding: 3px 12px"></span>
</ng-container>

<span class="link-item" [class.p-0]="simple">
<a [href]="fixExternalUrl(url)" target="_blank">

<span class="link-label">
{{ label ? label : (url | trimLinkPrefix) }}
</span>
<a [href]="url | fixExternalUrl" target="_blank">
<span class="link-label">{{ label ? (label | trimLinkPrefix) : (url | trimLinkPrefix) }}</span>

<fa-icon icon="external-link-alt"></fa-icon>
</a>
</span>

</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,17 @@
// :author: CSC - IT Center for Science Ltd., Espoo Finland [email protected]
// :license: MIT

import { Component, Input, OnInit } from '@angular/core';
import { Component, Input } from '@angular/core';

@Component({
selector: 'app-single-result-link',
templateUrl: './single-result-link.component.html',
styleUrls: ['./single-result-link.component.scss'],
})
export class SingleResultLinkComponent implements OnInit {
export class SingleResultLinkComponent {
@Input() tag: string;
@Input() icon: boolean;
@Input() url: string;
@Input() label: string;
@Input() simple: boolean;

constructor() {}

ngOnInit(): void {}

fixExternalUrl(url: string) {
// Fix url address to be handled as external link if prefix missing
return url.startsWith('http')
? url
: url.startsWith('www')
? 'https://' + url
: '//' + url;
}
}
16 changes: 16 additions & 0 deletions src/app/portal/pipes/fix-external-url.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'fixExternalUrl',
standalone: true
})
export class FixExternalUrlPipe implements PipeTransform {
transform(url: string): string {
// Fix url address to be handled as external link if prefix missing
return url.startsWith('http')
? url
: url.startsWith('www')
? 'https://' + url
: '//' + url;
}
}
4 changes: 3 additions & 1 deletion src/app/portal/portal.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ import { CheckEmptyFieldsPipe } from './pipes/check-empty-fields.pipe';
import { PersonGroupComponent } from './components/single/single-person/person-group/person-group.component';
import { PersonGroupAdditionalComponent } from './components/single/single-person/person-group-additional/person-group-additional.component';
import { FooterComponent } from '../layout/footer/footer.component';
import { FixExternalUrlPipe } from '@portal/pipes/fix-external-url.pipe';

@NgModule({
declarations: [
Expand Down Expand Up @@ -287,7 +288,8 @@ import { FooterComponent } from '../layout/footer/footer.component';
TooltipModule.forRoot(),
MatTableModule,
MatSortModule,
FooterComponent
FooterComponent,
FixExternalUrlPipe
],
exports: [DatasetAuthorComponent, FiltersComponent],
providers: [
Expand Down

0 comments on commit 779da61

Please sign in to comment.