mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
updated merged master to rxjs 6
This commit is contained in:
@@ -3,7 +3,7 @@ import { Item } from '../../shared/item.model';
|
||||
import { PaginatedList } from '../../data/paginated-list';
|
||||
import { PageInfo } from '../../shared/page-info.model';
|
||||
import { RemoteData } from '../../data/remote-data';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
|
||||
const pageInfo = new PageInfo();
|
||||
const array = [
|
||||
@@ -43,14 +43,14 @@ describe('RemoteDataBuildService', () => {
|
||||
});
|
||||
|
||||
it('should return the correct remoteData of a paginatedList when the input is a (remoteData of an) array', () => {
|
||||
const result = (service as any).toPaginatedList(Observable.of(arrayRD), pageInfo);
|
||||
const result = (service as any).toPaginatedList(observableOf(arrayRD), pageInfo);
|
||||
result.subscribe((resultRD) => {
|
||||
expect(resultRD).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the correct remoteData of a paginatedList when the input is a (remoteData of a) paginated list', () => {
|
||||
const result = (service as any).toPaginatedList(Observable.of(paginatedListRD), pageInfo);
|
||||
const result = (service as any).toPaginatedList(observableOf(paginatedListRD), pageInfo);
|
||||
result.subscribe((resultRD) => {
|
||||
expect(resultRD).toEqual(expected);
|
||||
});
|
||||
|
@@ -262,13 +262,15 @@ export class RemoteDataBuildService {
|
||||
}
|
||||
|
||||
private toPaginatedList<T>(input: Observable<RemoteData<T[] | PaginatedList<T>>>, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<T>>> {
|
||||
return input.map((rd: RemoteData<T[] | PaginatedList<T>>) => {
|
||||
if (Array.isArray(rd.payload)) {
|
||||
return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload) })
|
||||
} else {
|
||||
return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload.page) });
|
||||
}
|
||||
});
|
||||
return input.pipe(
|
||||
map((rd: RemoteData<T[] | PaginatedList<T>>) => {
|
||||
if (Array.isArray(rd.payload)) {
|
||||
return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload) })
|
||||
} else {
|
||||
return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload.page) });
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -32,9 +32,7 @@ import { MockItem } from '../../shared/mocks/mock-item';
|
||||
import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader';
|
||||
import { BrowseService } from '../browse/browse.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { PaginatedList } from '../data/paginated-list';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
import { EmptyError } from 'rxjs/util/EmptyError';
|
||||
import { EmptyError } from 'rxjs/internal-compatibility';
|
||||
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
@Component({
|
||||
@@ -185,7 +183,7 @@ describe('MetadataService', () => {
|
||||
describe('when the item has no bitstreams', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(MockItem, 'getFiles').and.returnValue(Observable.of([]));
|
||||
spyOn(MockItem, 'getFiles').and.returnValue(observableOf([]));
|
||||
});
|
||||
|
||||
it('processRemoteData should not produce an EmptyError', fakeAsync(() => {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { distinctUntilKeyChanged, filter, first, map, take } from 'rxjs/operators';
|
||||
import { catchError, distinctUntilKeyChanged, filter, first, map, take } from 'rxjs/operators';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||
|
||||
@@ -52,8 +52,8 @@ export class MetadataService {
|
||||
route = this.getCurrentRoute(route);
|
||||
return { params: route.params, data: route.data };
|
||||
}),).subscribe((routeInfo: any) => {
|
||||
this.processRouteChange(routeInfo);
|
||||
});
|
||||
this.processRouteChange(routeInfo);
|
||||
});
|
||||
}
|
||||
|
||||
public processRemoteData(remoteData: Observable<RemoteData<CacheableObject>>): void {
|
||||
@@ -260,20 +260,25 @@ export class MetadataService {
|
||||
if (this.currentObject.value instanceof Item) {
|
||||
const item = this.currentObject.value as Item;
|
||||
item.getFiles()
|
||||
.first((files) => isNotEmpty(files))
|
||||
.catch((error) => { console.debug(error); return [] })
|
||||
.pipe(
|
||||
first((files) => isNotEmpty(files)),
|
||||
catchError((error) => {
|
||||
console.debug(error);
|
||||
return []
|
||||
}))
|
||||
.subscribe((bitstreams: Bitstream[]) => {
|
||||
for (const bitstream of bitstreams) {
|
||||
bitstream.format.first()
|
||||
.map((rd: RemoteData<BitstreamFormat>) => rd.payload)
|
||||
.filter((format: BitstreamFormat) => hasValue(format))
|
||||
.subscribe((format: BitstreamFormat) => {
|
||||
if (format.mimetype === 'application/pdf') {
|
||||
this.addMetaTag('citation_pdf_url', bitstream.content);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
bitstream.format.pipe(
|
||||
first(),
|
||||
map((rd: RemoteData<BitstreamFormat>) => rd.payload),
|
||||
filter((format: BitstreamFormat) => hasValue(format)))
|
||||
.subscribe((format: BitstreamFormat) => {
|
||||
if (format.mimetype === 'application/pdf') {
|
||||
this.addMetaTag('citation_pdf_url', bitstream.content);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user