mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Remove findBitstreamAccessStatusFor and replace it with followLink('accessStatus')
This commit is contained in:
@@ -11,7 +11,6 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic
|
|||||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { Bitstream } from '../shared/bitstream.model';
|
|
||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
import { AccessStatusDataService } from './access-status-data.service';
|
import { AccessStatusDataService } from './access-status-data.service';
|
||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
@@ -42,20 +41,6 @@ describe('AccessStatusDataService', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const bitstreamId = '3d4c730u-5a4b-438b-9686-be1d5b4a1c5a';
|
|
||||||
const mockBitstream: Bitstream = Object.assign(new Bitstream(), {
|
|
||||||
id: bitstreamId,
|
|
||||||
name: 'test-bitstream',
|
|
||||||
_links: {
|
|
||||||
accessStatus: {
|
|
||||||
href: `https://rest.api/core/bitstreams/${bitstreamId}/accessStatus`,
|
|
||||||
},
|
|
||||||
self: {
|
|
||||||
href: `https://rest.api/core/bitstreams/${bitstreamId}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the requests are successful', () => {
|
describe('when the requests are successful', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
createService();
|
createService();
|
||||||
@@ -74,20 +59,6 @@ describe('AccessStatusDataService', () => {
|
|||||||
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
|
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when calling findBitstreamAccessStatusFor', () => {
|
|
||||||
let contentSource$;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
contentSource$ = service.findBitstreamAccessStatusFor(mockBitstream);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should send a new GetRequest', fakeAsync(() => {
|
|
||||||
contentSource$.subscribe();
|
|
||||||
tick();
|
|
||||||
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -4,7 +4,6 @@ import { AccessStatusObject } from 'src/app/shared/object-collection/shared/badg
|
|||||||
|
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { Bitstream } from '../shared/bitstream.model';
|
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
import { BaseDataService } from './base/base-data.service';
|
import { BaseDataService } from './base/base-data.service';
|
||||||
@@ -33,12 +32,4 @@ export class AccessStatusDataService extends BaseDataService<AccessStatusObject>
|
|||||||
findItemAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
|
findItemAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
|
||||||
return this.findByHref(item._links.accessStatus.href);
|
return this.findByHref(item._links.accessStatus.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns {@link RemoteData} of {@link AccessStatusObject} that is the access status of the given bitstream
|
|
||||||
* @param bitstream Bitstream we want the access status of
|
|
||||||
*/
|
|
||||||
findBitstreamAccessStatusFor(bitstream: Bitstream): Observable<RemoteData<AccessStatusObject>> {
|
|
||||||
return this.findByHref(bitstream._links.accessStatus.href);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -109,6 +109,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On
|
|||||||
true,
|
true,
|
||||||
followLink('format'),
|
followLink('format'),
|
||||||
followLink('thumbnail'),
|
followLink('thumbnail'),
|
||||||
|
followLink('accessStatus'),
|
||||||
)),
|
)),
|
||||||
tap((rd: RemoteData<PaginatedList<Bitstream>>) => {
|
tap((rd: RemoteData<PaginatedList<Bitstream>>) => {
|
||||||
if (hasValue(rd.errorMessage)) {
|
if (hasValue(rd.errorMessage)) {
|
||||||
@@ -127,6 +128,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On
|
|||||||
true,
|
true,
|
||||||
followLink('format'),
|
followLink('format'),
|
||||||
followLink('thumbnail'),
|
followLink('thumbnail'),
|
||||||
|
followLink('accessStatus'),
|
||||||
)),
|
)),
|
||||||
tap((rd: RemoteData<PaginatedList<Bitstream>>) => {
|
tap((rd: RemoteData<PaginatedList<Bitstream>>) => {
|
||||||
if (hasValue(rd.errorMessage)) {
|
if (hasValue(rd.errorMessage)) {
|
||||||
|
@@ -29,6 +29,7 @@ import { MetadataFieldWrapperComponent } from '../../../../shared/metadata-field
|
|||||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
import { FileSizePipe } from '../../../../shared/utils/file-size-pipe';
|
import { FileSizePipe } from '../../../../shared/utils/file-size-pipe';
|
||||||
import { VarDirective } from '../../../../shared/utils/var.directive';
|
import { VarDirective } from '../../../../shared/utils/var.directive';
|
||||||
|
import { followLink } from '../../../../shared/utils/follow-link-config.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component renders the file section of the item
|
* This component renders the file section of the item
|
||||||
@@ -109,7 +110,7 @@ export class FileSectionComponent implements OnInit {
|
|||||||
this.bitstreamDataService.findAllByItemAndBundleName(this.item, 'ORIGINAL', {
|
this.bitstreamDataService.findAllByItemAndBundleName(this.item, 'ORIGINAL', {
|
||||||
currentPage: this.currentPage,
|
currentPage: this.currentPage,
|
||||||
elementsPerPage: this.pageSize,
|
elementsPerPage: this.pageSize,
|
||||||
}).pipe(
|
}, true, true, followLink('accessStatus')).pipe(
|
||||||
getFirstCompletedRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
).subscribe((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => {
|
).subscribe((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => {
|
||||||
if (bitstreamsRD.errorMessage) {
|
if (bitstreamsRD.errorMessage) {
|
||||||
|
@@ -14,12 +14,12 @@ import {
|
|||||||
Observable,
|
Observable,
|
||||||
of as observableOf,
|
of as observableOf,
|
||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
import { AccessStatusDataService } from 'src/app/core/data/access-status-data.service';
|
|
||||||
import { Bitstream } from 'src/app/core/shared/bitstream.model';
|
import { Bitstream } from 'src/app/core/shared/bitstream.model';
|
||||||
import { hasValue } from 'src/app/shared/empty.util';
|
import { hasValue } from 'src/app/shared/empty.util';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
import { AccessStatusObject } from '../access-status-badge/access-status.model';
|
import { AccessStatusObject } from '../access-status-badge/access-status.model';
|
||||||
|
import { getFirstSucceededRemoteDataPayload } from 'src/app/core/shared/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-base-embargo-badge',
|
selector: 'ds-base-embargo-badge',
|
||||||
@@ -42,27 +42,14 @@ export class EmbargoBadgeComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
showAccessStatus: boolean;
|
showAccessStatus: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize instance variables
|
|
||||||
*
|
|
||||||
* @param {AccessStatusDataService} accessStatusDataService
|
|
||||||
*/
|
|
||||||
constructor(private accessStatusDataService: AccessStatusDataService) { }
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.showAccessStatus = environment.item.bitstream.showAccessStatuses;
|
this.showAccessStatus = environment.item.bitstream.showAccessStatuses;
|
||||||
if (!this.showAccessStatus || this.bitstream == null) {
|
if (!this.showAccessStatus || this.bitstream == null || this.bitstream.accessStatus == null) {
|
||||||
// Do not show the badge if the feature is inactive or if the bitstream is null.
|
// Do not show the badge if the feature is inactive or if the bitstream is null.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.embargoDate$ = this.accessStatusDataService.findBitstreamAccessStatusFor(this.bitstream).pipe(
|
this.embargoDate$ = this.bitstream.accessStatus.pipe(
|
||||||
map((accessStatusRD) => {
|
getFirstSucceededRemoteDataPayload(),
|
||||||
if (accessStatusRD.statusCode !== 401 && hasValue(accessStatusRD.payload)) {
|
|
||||||
return accessStatusRD.payload;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
map((accessStatus: AccessStatusObject) => hasValue(accessStatus) ? accessStatus.embargoDate : null),
|
map((accessStatus: AccessStatusObject) => hasValue(accessStatus) ? accessStatus.embargoDate : null),
|
||||||
catchError(() => observableOf(null)),
|
catchError(() => observableOf(null)),
|
||||||
);
|
);
|
||||||
|
@@ -6870,5 +6870,5 @@
|
|||||||
|
|
||||||
"metadata-export-filtered-items.columns.warning": "CSV export automatically includes all relevant fields, so selections in this list are not taken into account.",
|
"metadata-export-filtered-items.columns.warning": "CSV export automatically includes all relevant fields, so selections in this list are not taken into account.",
|
||||||
|
|
||||||
"embargo.listelement.badge": "embargo until {{ date }}",
|
"embargo.listelement.badge": "Embargo until {{ date }}",
|
||||||
}
|
}
|
||||||
|
@@ -8597,5 +8597,5 @@
|
|||||||
"metadata-export-filtered-items.columns.warning": "L'exportation CSV inclut automatiquement tous les champs pertinents, sans égard au contenu sélectionné de cette liste.",
|
"metadata-export-filtered-items.columns.warning": "L'exportation CSV inclut automatiquement tous les champs pertinents, sans égard au contenu sélectionné de cette liste.",
|
||||||
|
|
||||||
// "embargo.listelement.badge": "embargo until {{ date }}",
|
// "embargo.listelement.badge": "embargo until {{ date }}",
|
||||||
"embargo.listelement.badge": "embargo jusqu'à {{ date }}",
|
"embargo.listelement.badge": "Embargo jusqu'à {{ date }}",
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user