Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
headers="{{ entry.nameStripped }} {{ bundleName }} actions">
<div class="text-center w-100">
<div class="btn-group relationship-action-buttons">
<a [href]="entry.downloadUrl"
<a [routerLink]="entry.downloadUrl"
[attr.aria-label]="'item.edit.bitstreams.edit.buttons.download' | translate"
class="btn btn-outline-primary btn-sm"
title="{{'item.edit.bitstreams.edit.buttons.download' | translate}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
</div>
<div class="float-end w-15">
<ng-container>
<ds-file-download-link [cssClasses]="'btn btn-link-focus'" [isBlank]="true"
[bitstream]="getBitstream()" [enableRequestACopy]="false" [showAccessStatusBadge]="false">
<button class="btn btn-link-focus"
[attr.aria-label]="'submission.sections.upload.download.title' | translate"
title="{{ 'submission.sections.upload.download.title' | translate }}"
(click)="$event.preventDefault(); downloadFile()">
<i class="fa fa-download fa-2x text-normal" aria-hidden="true"></i>
</ds-file-download-link>
</button>
<button class="btn btn-link-focus"
attr.aria-label="{{'submission.sections.upload.edit.title' | translate}} {{fileName}}"
title="{{ 'submission.sections.upload.edit.title' | translate }} {{fileName}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { AuthorizationDataService } from '@dspace/core/data/feature-authorizatio
import { ItemDataService } from '@dspace/core/data/item-data.service';
import { JsonPatchOperationPathCombiner } from '@dspace/core/json-patch/builder/json-patch-operation-path-combiner';
import { JsonPatchOperationsBuilder } from '@dspace/core/json-patch/builder/json-patch-operations-builder';
import { HardRedirectService } from '@dspace/core/services/hard-redirect.service';
import { FileService } from '@dspace/core/shared/file.service';
import { HALEndpointService } from '@dspace/core/shared/hal-endpoint.service';
import { SubmissionJsonPatchOperationsService } from '@dspace/core/submission/submission-json-patch-operations.service';
import { AuthorizationDataServiceStub } from '@dspace/core/testing/authorization-service.stub';
Expand All @@ -37,7 +39,6 @@ import { provideMockStore } from '@ngrx/store/testing';
import { TranslateModule } from '@ngx-translate/core';
import { of } from 'rxjs';

import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component';
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
import { FormService } from '../../../../shared/form/form.service';
import { getMockFormService } from '../../../../shared/form/testing/form-service.mock';
Expand Down Expand Up @@ -117,6 +118,8 @@ describe('SubmissionSectionUploadFileComponent', () => {
{ provide: SubmissionService, useValue: submissionServiceStub },
{ provide: SectionUploadService, useValue: getMockSectionUploadService() },
{ provide: ThemeService, useValue: getMockThemeService() },
{ provide: FileService, useValue: { retrieveFileDownloadLink: jasmine.createSpy('retrieveFileDownloadLink').and.returnValue(of('https://test-url.com/file')) } },
{ provide: HardRedirectService, useValue: { redirect: jasmine.createSpy('redirect') } },
{ provide: Store, useValue: provideMockStore() },
{ provide: ItemDataService, useValue: {} },
ChangeDetectorRef,
Expand All @@ -132,12 +135,9 @@ describe('SubmissionSectionUploadFileComponent', () => {
add: {
schemas: [CUSTOM_ELEMENTS_SCHEMA],
},
remove: {
imports: [
SubmissionSectionUploadFileViewComponent,
ThemedFileDownloadLinkComponent,
],
},
remove: { imports: [
SubmissionSectionUploadFileViewComponent,
] },
})
.compileComponents();
}));
Expand Down Expand Up @@ -288,6 +288,15 @@ describe('SubmissionSectionUploadFileComponent', () => {
expect(compAsAny.editBitstreamData).toHaveBeenCalled();
});

it('should call downloadFile and open link in new tab', () => {
spyOn(window, 'open');
comp.fileData = fileData;

comp.downloadFile();

expect(window.open).toHaveBeenCalledWith('https://test-url.com/file', '_blank');
});

});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { FeatureID } from '@dspace/core/data/feature-authorization/feature-id';
import { ItemDataService } from '@dspace/core/data/item-data.service';
import { JsonPatchOperationPathCombiner } from '@dspace/core/json-patch/builder/json-patch-operation-path-combiner';
import { JsonPatchOperationsBuilder } from '@dspace/core/json-patch/builder/json-patch-operations-builder';
import { Bitstream } from '@dspace/core/shared/bitstream.model';
import { followLink } from '@dspace/core/shared/follow-link-config.model';
import { HALEndpointService } from '@dspace/core/shared/hal-endpoint.service';
import { Item } from '@dspace/core/shared/item.model';
Expand Down Expand Up @@ -47,10 +46,12 @@ import {
filter,
map,
switchMap,
take,
} from 'rxjs/operators';

import { HardRedirectService } from '../../../../core/services/hard-redirect.service';
import { FileService } from '../../../../core/shared/file.service';
import { BtnDisabledDirective } from '../../../../shared/btn-disabled.directive';
import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component';
import { FormService } from '../../../../shared/form/form.service';
import { SubmissionService } from '../../../submission.service';
import { SectionUploadService } from '../section-upload.service';
Expand All @@ -69,7 +70,6 @@ import { SubmissionSectionUploadFileViewComponent } from './view/section-upload-
AsyncPipe,
BtnDisabledDirective,
SubmissionSectionUploadFileViewComponent,
ThemedFileDownloadLinkComponent,
TranslateModule,
],
})
Expand Down Expand Up @@ -229,6 +229,8 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
private operationsService: SubmissionJsonPatchOperationsService,
private submissionService: SubmissionService,
private uploadService: SectionUploadService,
private fileService: FileService,
private hardRedirectService: HardRedirectService,
private authorizationService: AuthorizationDataService,
private halService: HALEndpointService,
private itemDataService: ItemDataService,
Expand Down Expand Up @@ -337,13 +339,11 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
}

/**
* Build a Bitstream object by the current file uuid
*
* @return Bitstream object
* Download the file using a short-lived token
*/
public getBitstream(): Bitstream {
return Object.assign(new Bitstream(), {
uuid: this.fileData.uuid,
public downloadFile() {
this.fileService.retrieveFileDownloadLink(this.fileData.url).pipe(take(1)).subscribe((link) => {
window.open(link, '_blank');
});
}

Expand Down
Loading