83635: Keep bitstream param on link

This commit is contained in:
Kristof De Langhe
2021-10-14 11:25:03 +02:00
parent 881eb92fa1
commit a745468b0c
4 changed files with 26 additions and 11 deletions

View File

@@ -22,9 +22,14 @@ export function getBitstreamModuleRoute() {
export function getBitstreamDownloadRoute(bitstream): string { export function getBitstreamDownloadRoute(bitstream): string {
return new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString(); 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(); 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'; export const ADMIN_MODULE_PATH = 'admin';

View File

@@ -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> <span *ngIf="!(canDownload$ |async)"><i class="fas fa-lock"></i></span>
<ng-container *ngTemplateOutlet="content"></ng-container> <ng-container *ngTemplateOutlet="content"></ng-container>
</a> </a>

View File

@@ -11,7 +11,7 @@ import { Item } from '../../core/shared/item.model';
import { getItemModuleRoute } from '../../item-page/item-page-routing-paths'; import { getItemModuleRoute } from '../../item-page/item-page-routing-paths';
import { RouterLinkDirectiveStub } from '../testing/router-link-directive.stub'; import { RouterLinkDirectiveStub } from '../testing/router-link-directive.stub';
describe('FileDownloadLinkComponent', () => { fdescribe('FileDownloadLinkComponent', () => {
let component: FileDownloadLinkComponent; let component: FileDownloadLinkComponent;
let fixture: ComponentFixture<FileDownloadLinkComponent>; let fixture: ComponentFixture<FileDownloadLinkComponent>;
@@ -66,7 +66,7 @@ describe('FileDownloadLinkComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should return the bitstreamPath based on the input bitstream', () => { 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})); expect(component.canDownload$).toBeObservable(cold('--a', {a: true}));
}); });
@@ -99,7 +99,7 @@ describe('FileDownloadLinkComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should return the bitstreamPath based on the input bitstream', () => { 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})); expect(component.canDownload$).toBeObservable(cold('--a', {a: false}));
}); });
@@ -107,7 +107,7 @@ describe('FileDownloadLinkComponent', () => {
scheduler.flush(); scheduler.flush();
fixture.detectChanges(); fixture.detectChanges();
const link = fixture.debugElement.query(By.css('a')); 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; const lock = fixture.debugElement.query(By.css('.fa-lock')).nativeElement;
expect(lock).toBeTruthy(); expect(lock).toBeTruthy();
}); });
@@ -127,7 +127,7 @@ describe('FileDownloadLinkComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should return the bitstreamPath based on the input bitstream', () => { 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})); expect(component.canDownload$).toBeObservable(cold('--a', {a: false}));
}); });

View File

@@ -39,7 +39,10 @@ export class FileDownloadLinkComponent implements OnInit {
@Input() enableRequestACopy = true; @Input() enableRequestACopy = true;
bitstreamPath$: Observable<string>; bitstreamPath$: Observable<{
routerLink: string,
queryParams: any,
}>;
canDownload$: Observable<boolean>; canDownload$: Observable<boolean>;
@@ -56,7 +59,7 @@ export class FileDownloadLinkComponent implements OnInit {
map(([canDownload, canRequestACopy]) => this.getBitstreamPath(canDownload, canRequestACopy)) map(([canDownload, canRequestACopy]) => this.getBitstreamPath(canDownload, canRequestACopy))
); );
} else { } else {
this.bitstreamPath$ = observableOf(getBitstreamDownloadRoute(this.bitstream)); this.bitstreamPath$ = observableOf(this.getBitstreamDownloadPath());
this.canDownload$ = observableOf(true); this.canDownload$ = observableOf(true);
} }
} }
@@ -65,6 +68,13 @@ export class FileDownloadLinkComponent implements OnInit {
if (!canDownload && canRequestACopy && hasValue(this.item)) { if (!canDownload && canRequestACopy && hasValue(this.item)) {
return getBitstreamRequestACopyRoute(this.item, this.bitstream); return getBitstreamRequestACopyRoute(this.item, this.bitstream);
} }
return getBitstreamDownloadRoute(this.bitstream); return this.getBitstreamDownloadPath();
}
getBitstreamDownloadPath() {
return {
routerLink: getBitstreamDownloadRoute(this.bitstream),
queryParams: {}
};
} }
} }