Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ item:
pageSize: 5
# Show the bitstream access status label on the item page
showAccessStatuses: false
# Open bitstream download links in a new browser tab by default
openDownloadLinksInNewTab: false
# Configuration of metadata to be displayed in the item metadata link view popover
metadataLinkViewPopoverData:
# Metdadata list to be displayed for entities without a specific configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
@if (!hasNoDownload) {
@if (bitstreamPath$ | async; as bitstreamLink) {
@if (canDownload$ | async) {
<button [routerLink]="bitstreamLink?.routerLink" [queryParams]="bitstreamLink?.queryParams" class="btn btn-outline-primary"
<a [routerLink]="bitstreamLink?.routerLink" [queryParams]="bitstreamLink?.queryParams"
[target]="isBlank ? '_blank' : '_self'"
class="btn btn-outline-primary"
data-test="download">
<i class="fas fa-download"></i> {{ 'file-download-button.download' | translate }}
</button>
</a>
} @else {
<button [routerLink]="bitstreamLink?.routerLink"
<a [routerLink]="bitstreamLink?.routerLink"
[queryParams]="bitstreamLink?.queryParams"
[target]="isBlank ? '_blank' : '_self'"
[dsBtnDisabled]="(canRequestACopy$ | async) !== true"
class="btn btn-outline-primary"
data-test="requestACopy">
{{ 'file-download-button.request-copy' | translate }}
</button>
</a>
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ describe('FileDownloadLinkComponent', () => {
let item: Item;
let storeMock: any;

const mockAppConfig = {
cache: {
msToLive: {
default: 15 * 60 * 1000,
},
},
item: {
bitstream: {
openDownloadLinksInNewTab: true,
},
},
};

const itemRequestStub = Object.assign(new ItemRequest(), {
token: 'item-request-token',
requestName: 'requester name',
Expand Down Expand Up @@ -88,7 +101,7 @@ describe('FileDownloadLinkComponent', () => {
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: Store, useValue: storeMock },
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
{ provide: APP_CONFIG, useValue: { cache: { msToLive: { default: 15 * 60 * 1000 } } } },
{ provide: APP_CONFIG, useValue: mockAppConfig },
],
})
.overrideComponent(FileDownloadLinkComponent, {
Expand Down Expand Up @@ -129,9 +142,19 @@ describe('FileDownloadLinkComponent', () => {
fixture.detectChanges();
const link = fixture.debugElement.query(By.css('a'));
expect(link.injector.get(RouterLinkDirectiveStub).routerLink).toContain(new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString());
expect(link.nativeElement.getAttribute('target')).toBe('_blank');
const lock = fixture.debugElement.query(By.css('.fa-lock'));
expect(lock).toBeNull();
});

it('should keep an explicit isBlank input over the config default', () => {
component.isBlank = false;
component.ngOnInit();
scheduler.flush();
fixture.detectChanges();
const link = fixture.debugElement.query(By.css('a'));
expect(link.nativeElement.getAttribute('target')).toBe('_self');
});
});

describe('when the user has no download rights but has the right to request a copy', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import {
} from '@angular/common';
import {
Component,
Inject,
Input,
OnInit,
Optional,
} from '@angular/core';
import {
ActivatedRoute,
RouterLink,
} from '@angular/router';
import {
APP_CONFIG,
AppConfig,
} from '@dspace/config/app-config.interface';
import { DSONameService } from '@dspace/core/breadcrumbs/dso-name.service';
import { AuthorizationDataService } from '@dspace/core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '@dspace/core/data/feature-authorization/feature-id';
Expand Down Expand Up @@ -78,7 +84,7 @@ export class FileDownloadLinkComponent implements OnInit {
/**
* A boolean representing if link is shown in same tab or in a new one.
*/
@Input() isBlank = false;
@Input() isBlank: boolean;

@Input() enableRequestACopy = true;

Expand Down Expand Up @@ -108,10 +114,13 @@ export class FileDownloadLinkComponent implements OnInit {
public dsoNameService: DSONameService,
private route: ActivatedRoute,
private translateService: TranslateService,
@Optional() @Inject(APP_CONFIG) private appConfig?: AppConfig,
) {
}

ngOnInit() {
this.isBlank = this.isBlank ?? this.appConfig?.item?.bitstream?.openDownloadLinksInNewTab;

if (this.enableRequestACopy) {
// Obtain item request data from the route snapshot
this.itemRequest = this.route.snapshot.data.itemRequest;
Expand Down
2 changes: 2 additions & 0 deletions src/config/default-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ export class DefaultAppConfig implements AppConfig {
pageSize: 5,
// Show the bitstream access status label
showAccessStatuses: false,
// Open bitstream download links in a new browser tab by default
openDownloadLinksInNewTab: false,
},
// Configuration for the metadata link view popover
metadataLinkViewPopoverData: {
Expand Down
2 changes: 2 additions & 0 deletions src/config/item-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface ItemConfig extends Config {
pageSize: number;
// Show the bitstream access status label
showAccessStatuses: boolean;
// Open bitstream download links in a new browser tab by default
openDownloadLinksInNewTab?: boolean;
}

metadataLinkViewPopoverData: MetadataLinkViewPopoverDataConfig
Expand Down
Loading