Skip to content

Commit 816a5f8

Browse files
Andrea Barbassovins01-4science
authored andcommitted
Merged in task/dspace-cris-2024_02_x/DSC-395 (pull request DSpace#4292)
[DSC-395] add configuration to open bitstreams in new tabs Approved-by: Francesco Molinaro
2 parents f8aa8fa + 902ef92 commit 816a5f8

6 files changed

Lines changed: 62 additions & 5 deletions

File tree

config/config.example.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ item:
381381
# Rounded to the nearest size in the list of selectable sizes on the
382382
# settings menu. See pageSizeOptions in 'pagination-component-options.model.ts'.
383383
pageSize: 5
384+
# Show the bitstream access status label on the item page
385+
showAccessStatuses: false
386+
# Open bitstream download links in a new browser tab by default
387+
openDownloadLinksInNewTab: true
384388
# The maximum number of metadata values to add to the metatag list of the item page
385389
metatagLimit: 20
386390
# The maximum number of values for repeatable metadata to show in the full item

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/advanced-attachment/bitstream-attachment/attachment-render/types/file-download-button/file-download-button.component.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
<ng-container *ngIf="bitstreamPath$ | async as bitstreamLink">
33
<ng-container *ngIf="canDownload$ | async; then downloadButtonTpl; else requestACopyTpl"></ng-container>
44
<ng-template #downloadButtonTpl>
5-
<button [routerLink]="bitstreamLink?.routerLink" [queryParams]="bitstreamLink?.queryParams" class="btn btn-outline-primary"
5+
<a [routerLink]="bitstreamLink?.routerLink" [queryParams]="bitstreamLink?.queryParams"
6+
[target]="isBlank ? '_blank' : '_self'"
7+
class="btn btn-outline-primary"
68
data-test="download">
79
<i class="fas fa-download"></i> {{ 'cris-layout.advanced-attachment.download' | translate }}
8-
</button>
10+
</a>
911
</ng-template>
1012
<ng-template #requestACopyTpl>
11-
<button [routerLink]="bitstreamLink?.routerLink"
13+
<a [routerLink]="bitstreamLink?.routerLink"
1214
[queryParams]="bitstreamLink?.queryParams"
15+
[target]="isBlank ? '_blank' : '_self'"
1316
[dsBtnDisabled]="(canRequestItemCopy$ | async) !== true"
1417
class="btn btn-outline-primary"
1518
data-test="requestACopy">
1619
{{ 'cris-layout.advanced-attachment.requestACopy' | translate }}
17-
</button>
20+
</a>
1821
</ng-template>
1922
</ng-container>
2023
</ng-container>

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import {
88
ActivatedRoute,
99
RouterLink,
1010
} from '@angular/router';
11+
import { Store } from '@ngrx/store';
1112
import { TranslateModule } from '@ngx-translate/core';
1213
import {
1314
cold,
1415
getTestScheduler,
1516
} from 'jasmine-marbles';
17+
import {
18+
APP_CONFIG,
19+
APP_DATA_SERVICES_MAP,
20+
} from 'src/config/app-config.interface';
1621

1722
import { getBitstreamModuleRoute } from '../../app-routing-paths';
1823
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
@@ -21,6 +26,7 @@ import { FeatureID } from '../../core/data/feature-authorization/feature-id';
2126
import { Bitstream } from '../../core/shared/bitstream.model';
2227
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
2328
import { Item } from '../../core/shared/item.model';
29+
import { ItemRequest } from '../../core/shared/item-request.model';
2430
import { URLCombiner } from '../../core/url-combiner/url-combiner';
2531
import { getItemModuleRoute } from '../../item-page/item-page-routing-paths';
2632
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
@@ -38,6 +44,24 @@ describe('FileDownloadLinkComponent', () => {
3844
let bitstream: Bitstream;
3945
let item: Item;
4046
let configurationDataService: ConfigurationDataService;
47+
let storeMock: any;
48+
49+
const mockAppConfig = {
50+
item: {
51+
bitstream: {
52+
openDownloadLinksInNewTab: true,
53+
},
54+
},
55+
};
56+
57+
const itemRequestStub = Object.assign(new ItemRequest(), {
58+
token: 'item-request-token',
59+
requestName: 'requester name',
60+
accessToken: 'abc123',
61+
acceptRequest: true,
62+
accessExpired: false,
63+
allfiles: true,
64+
});
4165

4266
function init() {
4367
authorizationService = jasmine.createSpyObj('authorizationService', {
@@ -72,6 +96,9 @@ describe('FileDownloadLinkComponent', () => {
7296
providers: [
7397
RouterLinkDirectiveStub,
7498
{ provide: AuthorizationDataService, useValue: authorizationService },
99+
{ provide: Store, useValue: storeMock },
100+
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
101+
{ provide: APP_CONFIG, useValue: mockAppConfig },
75102
{ provide: ConfigurationDataService, useValue: configurationDataService },
76103
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
77104
],
@@ -110,9 +137,19 @@ describe('FileDownloadLinkComponent', () => {
110137
fixture.detectChanges();
111138
const link = fixture.debugElement.query(By.css('a'));
112139
expect(link.injector.get(RouterLinkDirectiveStub).routerLink).toContain(new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString());
140+
expect(link.nativeElement.getAttribute('target')).toBe('_blank');
113141
const lock = fixture.debugElement.query(By.css('.fa-lock'));
114142
expect(lock).toBeNull();
115143
});
144+
145+
it('should keep an explicit isBlank input over the config default', () => {
146+
component.isBlank = false;
147+
component.ngOnInit();
148+
scheduler.flush();
149+
fixture.detectChanges();
150+
const link = fixture.debugElement.query(By.css('a'));
151+
expect(link.nativeElement.getAttribute('target')).toBe('_self');
152+
});
116153
});
117154
describe('when the user has no download rights but has the right to request a copy', () => {
118155
beforeEach(waitForAsync(() => {

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
@@ -6,8 +6,10 @@ import {
66
} from '@angular/common';
77
import {
88
Component,
9+
Inject,
910
Input,
1011
OnInit,
12+
Optional,
1113
} from '@angular/core';
1214
import { RouterLink } from '@angular/router';
1315
import { TranslateModule } from '@ngx-translate/core';
@@ -26,6 +28,10 @@ import {
2628
getRemoteDataPayload,
2729
} from 'src/app/core/shared/operators';
2830

31+
import {
32+
APP_CONFIG,
33+
AppConfig,
34+
} from '../../../config/app-config.interface';
2935
import {
3036
getBitstreamDownloadRoute,
3137
getBitstreamRequestACopyRoute,
@@ -71,7 +77,7 @@ export class FileDownloadLinkComponent implements OnInit {
7177
/**
7278
* A boolean representing if link is shown in same tab or in a new one.
7379
*/
74-
@Input() isBlank = false;
80+
@Input() isBlank: boolean;
7581

7682
@Input() enableRequestACopy = true;
7783

@@ -95,10 +101,13 @@ export class FileDownloadLinkComponent implements OnInit {
95101
private authorizationService: AuthorizationDataService,
96102
private configurationService: ConfigurationDataService,
97103
public dsoNameService: DSONameService,
104+
@Optional() @Inject(APP_CONFIG) private appConfig?: AppConfig,
98105
) {
99106
}
100107

101108
ngOnInit() {
109+
this.isBlank = this.isBlank ?? this.appConfig?.item?.bitstream?.openDownloadLinksInNewTab ?? true;
110+
102111
if (this.enableRequestACopy) {
103112
this.canDownload$ = this.authorizationService.isAuthorized(FeatureID.CanDownload, isNotEmpty(this.bitstream) ? this.bitstream.self : undefined);
104113
const canRequestACopy$ = this.authorizationService.isAuthorized(FeatureID.CanRequestACopy, isNotEmpty(this.bitstream) ? this.bitstream.self : undefined);

src/config/default-app-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ export class DefaultAppConfig implements AppConfig {
411411
// Rounded to the nearest size in the list of selectable sizes on the
412412
// settings menu. See pageSizeOptions in 'pagination-component-options.model.ts'.
413413
pageSize: 5,
414+
// Open bitstream download links in a new browser tab by default
415+
openDownloadLinksInNewTab: true,
414416
},
415417
// The maximum number of metadata values to add to the metatag list of the item page
416418
metatagLimit: 20,

src/config/item-config.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface ItemConfig extends Config {
1212
// Rounded to the nearest size in the list of selectable sizes on the
1313
// settings menu. See pageSizeOptions in 'pagination-component-options.model.ts'.
1414
pageSize: number;
15+
// Open bitstream download links in a new browser tab by default
16+
openDownloadLinksInNewTab?: boolean;
1517
};
1618

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

0 commit comments

Comments
 (0)