Skip to content

Commit cb1ca45

Browse files
vNovskiFrancescoMolinaro
authored andcommitted
[UXP-111] feautre: implemented the service into functionality
1 parent 97467da commit cb1ca45

4 files changed

Lines changed: 9 additions & 19 deletions

File tree

src/app/core/core.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ import { ProductDatasetSchemaType } from './metadata/schema-json-ld/schema-types
239239
import { PersonSchemaType } from './metadata/schema-json-ld/schema-types/Person/person-schema-type';
240240
import { InternalLinkService } from './services/internal-link.service';
241241
import { UnpaywallItemService } from './data/unpaywall-item.service';
242+
import { InternalLinkService } from './services/internal-link.service';
242243

243244
/**
244245
* When not in production, endpoint responses can be mocked for testing purposes

src/app/core/services/internal-link.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ describe('InternalLinkService', () => {
4747

4848
describe('transformInternalLink', () => {
4949
it('should transform internal link by removing currentURL', () => {
50-
const result = service.transformInternalLink('https://currentdomain/my-link');
50+
const result = service.getRelativePath('https://currentdomain/my-link');
5151
expect(result).toBe('/my-link');
5252
});
5353

5454
it('should transform internal link by adding leading "/" if missing', () => {
55-
const result = service.transformInternalLink('currentdomain/my-link');
55+
const result = service.getRelativePath('currentdomain/my-link');
5656
expect(result).toBe('/my-link');
5757
});
5858

5959
it('should return unchanged link for external link', () => {
60-
const result = service.transformInternalLink('https://externalDomain/my-link');
60+
const result = service.getRelativePath('https://externalDomain/my-link');
6161
expect(result).toBe('https://externalDomain/my-link');
6262
});
6363

6464
it('should return unchanged link for internal link with leading "/"', () => {
65-
const result = service.transformInternalLink('/my-link');
65+
const result = service.getRelativePath('/my-link');
6666
expect(result).toBe('/my-link');
6767
});
6868
});

src/app/shared/carousel/carousel.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<ngb-carousel #carousel [interval]="2000" (slide)="onSlide($event)" class="ds-carousel">
22
<ng-template ngbSlide *ngFor="let item of items; let i = index; let last = last">
33
<ng-container *ngIf="getItemLink(item.indexableObject); let currentLink; else carouselContent">
4-
<a *ngIf="isLinkInternal(currentLink)" [routerLink]="transformInternalLink(currentLink)">
4+
<a *ngIf="internalLinkService.isLinkInternal(currentLink)" [routerLink]="internalLinkService.getRelativePath(currentLink)">
55
<ng-container *ngTemplateOutlet="carouselContent"></ng-container>
66
</a>
7-
<a *ngIf="!isLinkInternal(currentLink)" [href]="currentLink" [target]="carouselOptions.targetBlank ? '_blank' : null">
7+
<a *ngIf="!internalLinkService.isLinkInternal(currentLink)" [href]="currentLink" [target]="carouselOptions.targetBlank ? '_blank' : null">
88
<ng-container *ngTemplateOutlet="carouselContent"></ng-container>
99
</a>
1010
</ng-container>

src/app/shared/carousel/carousel.component.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {Bitstream} from '../../core/shared/bitstream.model';
88
import {BitstreamDataService} from '../../core/data/bitstream-data.service';
99
import {NativeWindowRef, NativeWindowService} from '../../core/services/window.service';
1010
import {getFirstCompletedRemoteData} from '../../core/shared/operators';
11+
import {InternalLinkService} from '../../core/services/internal-link.service';
1112
import {hasValue} from '../empty.util';
1213
import {ItemSearchResult} from '../object-collection/shared/item-search-result.model';
1314
import {followLink} from '../utils/follow-link-config.model';
@@ -87,6 +88,7 @@ export class CarouselComponent implements OnInit {
8788
isLoading$ = new BehaviorSubject(true);
8889

8990
constructor(
91+
public internalLinkService: InternalLinkService,
9092
protected bitstreamDataService: BitstreamDataService,
9193
@Inject(NativeWindowService) private _window: NativeWindowRef,
9294
) {
@@ -163,19 +165,6 @@ export class CarouselComponent implements OnInit {
163165
return item.firstMetadataValue(this.link);
164166
}
165167

166-
isLinkInternal(link: string) {
167-
return link.startsWith('/') || link.startsWith(this.currentURL);
168-
}
169-
170-
transformInternalLink(link: string) {
171-
if (link.startsWith(this.currentURL)) {
172-
const currentSegments = link.substring(this.currentURL.length);
173-
return currentSegments.startsWith('/') ? currentSegments : `/${currentSegments}`;
174-
} else {
175-
return link;
176-
}
177-
}
178-
179168
/**
180169
* to open a link of an item
181170
*/

0 commit comments

Comments
 (0)