Skip to content

Commit 999da6a

Browse files
Andrea Barbassovins01-4science
authored andcommitted
Merged in task/dspace-cris-2025_02_x/DSC-395 (pull request DSpace#4291)
[DSC-395] add configuration to open bitstreams in new tabs Approved-by: Francesco Molinaro Approved-by: Vincenzo Mecca
2 parents baa0c30 + 15b126d commit 999da6a

6 files changed

Lines changed: 46 additions & 6 deletions

File tree

config/config.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ item:
410410
pageSize: 5
411411
# Show the bitstream access status label on the item page
412412
showAccessStatuses: false
413+
# Open bitstream download links in a new browser tab by default
414+
openDownloadLinksInNewTab: true
413415
# The maximum number of metadata values to add to the metatag list of the item page
414416
metatagLimit: 20
415417
# The maximum number of values for repeatable metadata to show in the full item
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
@if (!hasNoDownload) {
22
@if (bitstreamPath$ | async; as bitstreamLink) {
33
@if (canDownload$ | async) {
4-
<button [routerLink]="bitstreamLink?.routerLink" [queryParams]="bitstreamLink?.queryParams" class="btn btn-outline-primary"
4+
<a [routerLink]="bitstreamLink?.routerLink" [queryParams]="bitstreamLink?.queryParams"
5+
[target]="isBlank ? '_blank' : '_self'"
6+
class="btn btn-outline-primary"
57
data-test="download">
68
<i class="fas fa-download"></i> {{ 'cris-layout.advanced-attachment.download' | translate }}
7-
</button>
9+
</a>
810
} @else {
9-
<button [routerLink]="bitstreamLink?.routerLink"
11+
<a [routerLink]="bitstreamLink?.routerLink"
1012
[queryParams]="bitstreamLink?.queryParams"
13+
[target]="isBlank ? '_blank' : '_self'"
1114
[dsBtnDisabled]="(canRequestItemCopy$ | async) !== true"
1215
class="btn btn-outline-primary"
1316
data-test="requestACopy">
1417
{{ 'cris-layout.advanced-attachment.requestACopy' | translate }}
15-
</button>
18+
</a>
1619
}
1720
}
1821
}

src/app/shared/file-download-link/file-download-link.component.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
getTestScheduler,
1616
} from 'jasmine-marbles';
1717
import { of } from 'rxjs';
18-
import { APP_DATA_SERVICES_MAP } from 'src/config/app-config.interface';
18+
import {
19+
APP_CONFIG,
20+
APP_DATA_SERVICES_MAP,
21+
} from 'src/config/app-config.interface';
1922

2023
import { getBitstreamModuleRoute } from '../../app-routing-paths';
2124
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
@@ -44,6 +47,14 @@ describe('FileDownloadLinkComponent', () => {
4447
let configurationDataService: ConfigurationDataService;
4548
let storeMock: any;
4649

50+
const mockAppConfig = {
51+
item: {
52+
bitstream: {
53+
openDownloadLinksInNewTab: true,
54+
},
55+
},
56+
};
57+
4758
const itemRequestStub = Object.assign(new ItemRequest(), {
4859
token: 'item-request-token',
4960
requestName: 'requester name',
@@ -95,6 +106,7 @@ describe('FileDownloadLinkComponent', () => {
95106
{ provide: ActivatedRoute, useValue: activatedRoute },
96107
{ provide: Store, useValue: storeMock },
97108
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
109+
{ provide: APP_CONFIG, useValue: mockAppConfig },
98110
{ provide: ConfigurationDataService, useValue: configurationDataService },
99111
],
100112
})
@@ -135,9 +147,19 @@ describe('FileDownloadLinkComponent', () => {
135147
fixture.detectChanges();
136148
const link = fixture.debugElement.query(By.css('a'));
137149
expect(link.injector.get(RouterLinkDirectiveStub).routerLink).toContain(new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString());
150+
expect(link.nativeElement.getAttribute('target')).toBe('_blank');
138151
const lock = fixture.debugElement.query(By.css('.fa-lock'));
139152
expect(lock).toBeNull();
140153
});
154+
155+
it('should keep an explicit isBlank input over the config default', () => {
156+
component.isBlank = false;
157+
component.ngOnInit();
158+
scheduler.flush();
159+
fixture.detectChanges();
160+
const link = fixture.debugElement.query(By.css('a'));
161+
expect(link.nativeElement.getAttribute('target')).toBe('_self');
162+
});
141163
});
142164

143165
describe('when the user has no download rights but has the right to request a copy', () => {

src/app/shared/file-download-link/file-download-link.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
} from '@angular/common';
66
import {
77
Component,
8+
Inject,
89
Input,
910
OnInit,
11+
Optional,
1012
} from '@angular/core';
1113
import {
1214
ActivatedRoute,
@@ -27,6 +29,10 @@ import {
2729
shareReplay,
2830
} from 'rxjs/operators';
2931

32+
import {
33+
APP_CONFIG,
34+
AppConfig,
35+
} from '../../../config/app-config.interface';
3036
import {
3137
getBitstreamDownloadRoute,
3238
getBitstreamDownloadWithAccessTokenRoute,
@@ -85,7 +91,7 @@ export class FileDownloadLinkComponent implements OnInit {
8591
/**
8692
* A boolean representing if link is shown in same tab or in a new one.
8793
*/
88-
@Input() isBlank = false;
94+
@Input() isBlank: boolean;
8995

9096
@Input() enableRequestACopy = true;
9197

@@ -122,10 +128,13 @@ export class FileDownloadLinkComponent implements OnInit {
122128
public dsoNameService: DSONameService,
123129
private route: ActivatedRoute,
124130
private translateService: TranslateService,
131+
@Optional() @Inject(APP_CONFIG) private appConfig?: AppConfig,
125132
) {
126133
}
127134

128135
ngOnInit() {
136+
this.isBlank = this.isBlank ?? this.appConfig?.item?.bitstream?.openDownloadLinksInNewTab ?? true;
137+
129138
if (this.enableRequestACopy) {
130139
// Obtain item request data from the route snapshot
131140
this.itemRequest = this.route.snapshot.data.itemRequest;

src/config/default-app-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ export class DefaultAppConfig implements AppConfig {
419419
pageSize: 5,
420420
// Show the bitstream access status label
421421
showAccessStatuses: false,
422+
// Open bitstream download links in a new browser tab by default
423+
openDownloadLinksInNewTab: true,
422424
},
423425
// The maximum number of metadata values to add to the metatag list of the item page
424426
metatagLimit: 20,

src/config/item-config.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface ItemConfig extends Config {
1414
pageSize: number;
1515
// Show the bitstream access status label
1616
showAccessStatuses: boolean;
17+
// Open bitstream download links in a new browser tab by default
18+
openDownloadLinksInNewTab?: boolean;
1719
}
1820

1921
// The maximum number of metadata values to add to the metatag list of the item page

0 commit comments

Comments
 (0)