mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
83635: Keep bitstream param on link
This commit is contained in:
@@ -22,9 +22,14 @@ export function getBitstreamModuleRoute() {
|
||||
export function getBitstreamDownloadRoute(bitstream): string {
|
||||
return new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString();
|
||||
}
|
||||
export function getBitstreamRequestACopyRoute(item, bitstream): string {
|
||||
export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: string, queryParams: any } {
|
||||
const url = new URLCombiner(getItemModuleRoute(), item.uuid, 'request-a-copy').toString();
|
||||
return `${url}?bitstream=${bitstream.uuid}`;
|
||||
return {
|
||||
routerLink: url,
|
||||
queryParams: {
|
||||
bitstream: bitstream.uuid
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const ADMIN_MODULE_PATH = 'admin';
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<a [routerLink]="(bitstreamPath$| async)" [target]="isBlank ? '_blank': '_self'" [ngClass]="cssClasses">
|
||||
<a [routerLink]="(bitstreamPath$| async)?.routerLink" [queryParams]="(bitstreamPath$| async)?.queryParams" [target]="isBlank ? '_blank': '_self'" [ngClass]="cssClasses">
|
||||
<span *ngIf="!(canDownload$ |async)"><i class="fas fa-lock"></i></span>
|
||||
<ng-container *ngTemplateOutlet="content"></ng-container>
|
||||
</a>
|
||||
|
@@ -11,7 +11,7 @@ import { Item } from '../../core/shared/item.model';
|
||||
import { getItemModuleRoute } from '../../item-page/item-page-routing-paths';
|
||||
import { RouterLinkDirectiveStub } from '../testing/router-link-directive.stub';
|
||||
|
||||
describe('FileDownloadLinkComponent', () => {
|
||||
fdescribe('FileDownloadLinkComponent', () => {
|
||||
let component: FileDownloadLinkComponent;
|
||||
let fixture: ComponentFixture<FileDownloadLinkComponent>;
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('FileDownloadLinkComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
it('should return the bitstreamPath based on the input bitstream', () => {
|
||||
expect(component.bitstreamPath$).toBeObservable(cold('-a', {a: new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString()}));
|
||||
expect(component.bitstreamPath$).toBeObservable(cold('-a', {a: { routerLink: new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString(), queryParams: {} }}));
|
||||
expect(component.canDownload$).toBeObservable(cold('--a', {a: true}));
|
||||
|
||||
});
|
||||
@@ -99,7 +99,7 @@ describe('FileDownloadLinkComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
it('should return the bitstreamPath based on the input bitstream', () => {
|
||||
expect(component.bitstreamPath$).toBeObservable(cold('-a', {a: `${new URLCombiner(getItemModuleRoute(), item.uuid, 'request-a-copy').toString()}?bitstream=${bitstream.uuid}`}));
|
||||
expect(component.bitstreamPath$).toBeObservable(cold('-a', {a: { routerLink: new URLCombiner(getItemModuleRoute(), item.uuid, 'request-a-copy').toString(), queryParams: { bitstream: bitstream.uuid } }}));
|
||||
expect(component.canDownload$).toBeObservable(cold('--a', {a: false}));
|
||||
|
||||
});
|
||||
@@ -107,7 +107,7 @@ describe('FileDownloadLinkComponent', () => {
|
||||
scheduler.flush();
|
||||
fixture.detectChanges();
|
||||
const link = fixture.debugElement.query(By.css('a'));
|
||||
expect(link.injector.get(RouterLinkDirectiveStub).routerLink).toContain(`${new URLCombiner(getItemModuleRoute(), item.uuid, 'request-a-copy').toString()}?bitstream=${bitstream.uuid}`);
|
||||
expect(link.injector.get(RouterLinkDirectiveStub).routerLink).toContain(new URLCombiner(getItemModuleRoute(), item.uuid, 'request-a-copy').toString());
|
||||
const lock = fixture.debugElement.query(By.css('.fa-lock')).nativeElement;
|
||||
expect(lock).toBeTruthy();
|
||||
});
|
||||
@@ -127,7 +127,7 @@ describe('FileDownloadLinkComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
it('should return the bitstreamPath based on the input bitstream', () => {
|
||||
expect(component.bitstreamPath$).toBeObservable(cold('-a', {a: new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString()}));
|
||||
expect(component.bitstreamPath$).toBeObservable(cold('-a', {a: { routerLink: new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString(), queryParams: {} }}));
|
||||
expect(component.canDownload$).toBeObservable(cold('--a', {a: false}));
|
||||
|
||||
});
|
||||
|
@@ -39,7 +39,10 @@ export class FileDownloadLinkComponent implements OnInit {
|
||||
|
||||
@Input() enableRequestACopy = true;
|
||||
|
||||
bitstreamPath$: Observable<string>;
|
||||
bitstreamPath$: Observable<{
|
||||
routerLink: string,
|
||||
queryParams: any,
|
||||
}>;
|
||||
|
||||
canDownload$: Observable<boolean>;
|
||||
|
||||
@@ -56,7 +59,7 @@ export class FileDownloadLinkComponent implements OnInit {
|
||||
map(([canDownload, canRequestACopy]) => this.getBitstreamPath(canDownload, canRequestACopy))
|
||||
);
|
||||
} else {
|
||||
this.bitstreamPath$ = observableOf(getBitstreamDownloadRoute(this.bitstream));
|
||||
this.bitstreamPath$ = observableOf(this.getBitstreamDownloadPath());
|
||||
this.canDownload$ = observableOf(true);
|
||||
}
|
||||
}
|
||||
@@ -65,6 +68,13 @@ export class FileDownloadLinkComponent implements OnInit {
|
||||
if (!canDownload && canRequestACopy && hasValue(this.item)) {
|
||||
return getBitstreamRequestACopyRoute(this.item, this.bitstream);
|
||||
}
|
||||
return getBitstreamDownloadRoute(this.bitstream);
|
||||
return this.getBitstreamDownloadPath();
|
||||
}
|
||||
|
||||
getBitstreamDownloadPath() {
|
||||
return {
|
||||
routerLink: getBitstreamDownloadRoute(this.bitstream),
|
||||
queryParams: {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user