diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index 920bf5633b..570f0f77ca 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -20,8 +20,7 @@ import { DSpaceObject } from '../shared/dspace-object.model'; import { Item } from '../shared/item.model'; import { getFirstCompletedRemoteData, - getFirstSucceededRemoteDataPayload, - getDownloadableBitstream + getFirstSucceededRemoteDataPayload } from '../shared/operators'; import { RootDataService } from '../data/root-data.service'; import { getBitstreamDownloadRoute } from '../../app-routing-paths'; @@ -37,6 +36,7 @@ import { AddMetaTagAction, ClearMetaTagAction } from './meta-tag.actions'; import { coreSelector } from '../core.selectors'; import { CoreState } from '../core-state.model'; import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service'; +import { getDownloadableBitstream } from '../shared/bitstream.operators'; /** * The base selector function to select the metaTag section in the store diff --git a/src/app/core/shared/bitstream.operators.ts b/src/app/core/shared/bitstream.operators.ts new file mode 100644 index 0000000000..73f38d8c00 --- /dev/null +++ b/src/app/core/shared/bitstream.operators.ts @@ -0,0 +1,24 @@ +import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service'; +import { Observable, of as observableOf } from 'rxjs'; +import { Bitstream } from './bitstream.model'; +import { map, switchMap } from 'rxjs/operators'; +import { hasValue } from '../../shared/empty.util'; +import { FeatureID } from '../data/feature-authorization/feature-id'; + +/** + * Operator to check if the given bitstream is downloadable + */ +export const getDownloadableBitstream = (authService: AuthorizationDataService) => + (source: Observable): Observable => + source.pipe( + switchMap((bit: Bitstream) => { + if (hasValue(bit)) { + return authService.isAuthorized(FeatureID.CanDownload, bit.self).pipe( + map((canDownload: boolean) => { + return canDownload ? bit : null; + })); + } else { + return observableOf(null); + } + }) + ); diff --git a/src/app/core/shared/operators.ts b/src/app/core/shared/operators.ts index 1a8b5cbf8f..b2ceaa4964 100644 --- a/src/app/core/shared/operators.ts +++ b/src/app/core/shared/operators.ts @@ -1,4 +1,4 @@ -import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs'; +import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { debounceTime, filter, find, map, switchMap, take, takeWhile } from 'rxjs/operators'; import { hasNoValue, hasValue, hasValueOperator, isNotEmpty } from '../../shared/empty.util'; import { SearchResult } from '../../shared/search/models/search-result.model'; @@ -9,9 +9,6 @@ import { MetadataSchema } from '../metadata/metadata-schema.model'; import { BrowseDefinition } from './browse-definition.model'; import { DSpaceObject } from './dspace-object.model'; import { InjectionToken } from '@angular/core'; -import { Bitstream } from './bitstream.model'; -import { FeatureID } from '../data/feature-authorization/feature-id'; -import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service'; export const DEBOUNCE_TIME_OPERATOR = new InjectionToken<(dueTime: number) => (source: Observable) => Observable>('debounceTime', { providedIn: 'root', @@ -225,20 +222,3 @@ export const metadataFieldsToString = () => }) ); -/** - * Operator to check if the given bitstream is downloadable - */ -export const getDownloadableBitstream = (authService: AuthorizationDataService) => - (source: Observable): Observable => - source.pipe( - switchMap((bit: Bitstream) => { - if (hasValue(bit)) { - return authService.isAuthorized(FeatureID.CanDownload, bit.self).pipe( - map((canDownload: boolean) => { - return canDownload ? bit : null; - })); - } else { - return observableOf(null); - } - }) - );