Skip to content

Commit 5f83139

Browse files
committed
Adding the new embargo badge on the file download component
Fixed lint no-trailing-spaces
1 parent 5b7d246 commit 5f83139

24 files changed

Lines changed: 389 additions & 18 deletions

config/config.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ item:
350350
# Rounded to the nearest size in the list of selectable sizes on the
351351
# settings menu. See pageSizeOptions in 'pagination-component-options.model.ts'.
352352
pageSize: 5
353+
# Show the bitstream access status label
354+
showAccessStatuses: false
353355

354356
# Community Page Config
355357
community:

src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/item-search-result/item-admin-search-result-grid-element.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('ItemAdminSearchResultGridElementComponent', () => {
4545
};
4646

4747
const mockAccessStatusDataService = {
48-
findAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
48+
findItemAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
4949
return createSuccessfulRemoteDataObject$(new AccessStatusObject());
5050
},
5151
};

src/app/core/data/access-status-data.service.spec.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic
1111
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
1212
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
1313
import { ObjectCacheService } from '../cache/object-cache.service';
14+
import { Bitstream } from '../shared/bitstream.model';
1415
import { Item } from '../shared/item.model';
1516
import { AccessStatusDataService } from './access-status-data.service';
1617
import { RemoteData } from './remote-data';
@@ -41,16 +42,44 @@ describe('AccessStatusDataService', () => {
4142
},
4243
});
4344

45+
const bitstreamId = '3d4c730u-5a4b-438b-9686-be1d5b4a1c5a';
46+
const mockBitstream: Bitstream = Object.assign(new Bitstream(), {
47+
id: bitstreamId,
48+
name: 'test-bitstream',
49+
_links: {
50+
accessStatus: {
51+
href: `https://rest.api/core/bitstreams/${bitstreamId}/accessStatus`,
52+
},
53+
self: {
54+
href: `https://rest.api/core/bitstreams/${bitstreamId}`,
55+
},
56+
},
57+
});
58+
4459
describe('when the requests are successful', () => {
4560
beforeEach(() => {
4661
createService();
4762
});
4863

49-
describe('when calling findAccessStatusFor', () => {
64+
describe('when calling findItemAccessStatusFor', () => {
65+
let contentSource$;
66+
67+
beforeEach(() => {
68+
contentSource$ = service.findItemAccessStatusFor(mockItem);
69+
});
70+
71+
it('should send a new GetRequest', fakeAsync(() => {
72+
contentSource$.subscribe();
73+
tick();
74+
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
75+
}));
76+
});
77+
78+
describe('when calling findBitstreamAccessStatusFor', () => {
5079
let contentSource$;
5180

5281
beforeEach(() => {
53-
contentSource$ = service.findAccessStatusFor(mockItem);
82+
contentSource$ = service.findBitstreamAccessStatusFor(mockBitstream);
5483
});
5584

5685
it('should send a new GetRequest', fakeAsync(() => {

src/app/core/data/access-status-data.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AccessStatusObject } from 'src/app/shared/object-collection/shared/badg
44

55
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
66
import { ObjectCacheService } from '../cache/object-cache.service';
7+
import { Bitstream } from '../shared/bitstream.model';
78
import { HALEndpointService } from '../shared/hal-endpoint.service';
89
import { Item } from '../shared/item.model';
910
import { BaseDataService } from './base/base-data.service';
@@ -29,7 +30,15 @@ export class AccessStatusDataService extends BaseDataService<AccessStatusObject>
2930
* Returns {@link RemoteData} of {@link AccessStatusObject} that is the access status of the given item
3031
* @param item Item we want the access status of
3132
*/
32-
findAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
33+
findItemAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
3334
return this.findByHref(item._links.accessStatus.href);
3435
}
36+
37+
/**
38+
* Returns {@link RemoteData} of {@link AccessStatusObject} that is the access status of the given bitstream
39+
* @param bitstream Bitstream we want the access status of
40+
*/
41+
findBitstreamAccessStatusFor(bitstream: Bitstream): Observable<RemoteData<AccessStatusObject>> {
42+
return this.findByHref(bitstream._links.accessStatus.href);
43+
}
3544
}

src/app/core/provide-core.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ export const models =
176176
ResearcherProfile,
177177
OrcidQueue,
178178
OrcidHistory,
179-
AccessStatusObject,
180179
IdentifierData,
181180
Subscription,
182181
ItemRequest,

src/app/core/shared/bitstream.model.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
inheritSerialization,
55
} from 'cerialize';
66
import { Observable } from 'rxjs';
7+
import { AccessStatusObject } from 'src/app/shared/object-collection/shared/badges/access-status-badge/access-status.model';
8+
import { ACCESS_STATUS } from 'src/app/shared/object-collection/shared/badges/access-status-badge/access-status.resource-type';
79

810
import {
911
link,
@@ -52,6 +54,7 @@ export class Bitstream extends DSpaceObject implements ChildHALResource {
5254
format: HALLink;
5355
content: HALLink;
5456
thumbnail: HALLink;
57+
accessStatus: HALLink;
5558
};
5659

5760
/**
@@ -75,6 +78,13 @@ export class Bitstream extends DSpaceObject implements ChildHALResource {
7578
@link(BUNDLE)
7679
bundle?: Observable<RemoteData<Bundle>>;
7780

81+
/**
82+
* The access status for this Bitstream
83+
* Will be undefined unless the access status {@link HALLink} has been resolved.
84+
*/
85+
@link(ACCESS_STATUS)
86+
accessStatus?: Observable<RemoteData<AccessStatusObject>>;
87+
7888
getParentLinkKey(): keyof this['_links'] {
7989
return 'format';
8090
}

src/app/shared/file-download-link/file-download-link.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
}
99
<ng-container *ngTemplateOutlet="content"></ng-container>
1010
</a>
11+
<ds-embargo-badge [bitstream]="bitstream"></ds-embargo-badge>
1112

1213
<ng-template #content>
1314
<ng-content></ng-content>

src/app/shared/file-download-link/file-download-link.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import {
88
ActivatedRoute,
99
RouterLink,
1010
} from '@angular/router';
11+
import { Store } from '@ngrx/store';
1112
import { TranslateModule } from '@ngx-translate/core';
1213
import {
1314
cold,
1415
getTestScheduler,
1516
} from 'jasmine-marbles';
17+
import { of as observableOf } from 'rxjs';
18+
import { APP_DATA_SERVICES_MAP } from 'src/config/app-config.interface';
1619

1720
import { getBitstreamModuleRoute } from '../../app-routing-paths';
1821
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
@@ -34,6 +37,7 @@ describe('FileDownloadLinkComponent', () => {
3437

3538
let bitstream: Bitstream;
3639
let item: Item;
40+
let storeMock: any;
3741

3842
function init() {
3943
authorizationService = jasmine.createSpyObj('authorizationService', {
@@ -51,6 +55,11 @@ describe('FileDownloadLinkComponent', () => {
5155
self: { href: 'obj-selflink' },
5256
},
5357
});
58+
storeMock = jasmine.createSpyObj('store', {
59+
dispatch: jasmine.createSpy('dispatch'),
60+
select: jasmine.createSpy('select'),
61+
pipe: observableOf(true),
62+
});
5463
}
5564

5665
function initTestbed() {
@@ -63,6 +72,8 @@ describe('FileDownloadLinkComponent', () => {
6372
RouterLinkDirectiveStub,
6473
{ provide: AuthorizationDataService, useValue: authorizationService },
6574
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
75+
{ provide: Store, useValue: storeMock },
76+
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
6677
],
6778
})
6879
.overrideComponent(FileDownloadLinkComponent, {

src/app/shared/file-download-link/file-download-link.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ import {
3030
hasValue,
3131
isNotEmpty,
3232
} from '../empty.util';
33+
import { ThemedEmbargoBadgeComponent } from '../object-collection/shared/badges/embargo-badge/themed-embargo-badge.component';
3334

3435
@Component({
3536
selector: 'ds-base-file-download-link',
3637
templateUrl: './file-download-link.component.html',
3738
styleUrls: ['./file-download-link.component.scss'],
3839
standalone: true,
39-
imports: [RouterLink, NgClass, NgTemplateOutlet, AsyncPipe, TranslateModule],
40+
imports: [RouterLink, NgClass, NgTemplateOutlet, AsyncPipe, TranslateModule, ThemedEmbargoBadgeComponent],
4041
})
4142
/**
4243
* Component displaying a download link

src/app/shared/object-collection/shared/badges/access-status-badge/access-status-badge.component.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('ItemAccessStatusBadgeComponent', () => {
5151
});
5252

5353
accessStatusDataService = jasmine.createSpyObj('accessStatusDataService', {
54-
findAccessStatusFor: createSuccessfulRemoteDataObject$(unknownStatus),
54+
findItemAccessStatusFor: createSuccessfulRemoteDataObject$(unknownStatus),
5555
});
5656

5757
item = Object.assign(new Item(), {
@@ -97,7 +97,7 @@ describe('ItemAccessStatusBadgeComponent', () => {
9797
});
9898
});
9999

100-
describe('When the findAccessStatusFor method returns unknown', () => {
100+
describe('When the findItemAccessStatusFor method returns unknown', () => {
101101
beforeEach(waitForAsync(() => {
102102
init();
103103
initTestBed();
@@ -110,10 +110,10 @@ describe('ItemAccessStatusBadgeComponent', () => {
110110
});
111111
});
112112

113-
describe('When the findAccessStatusFor method returns metadata.only', () => {
113+
describe('When the findItemAccessStatusFor method returns metadata.only', () => {
114114
beforeEach(waitForAsync(() => {
115115
init();
116-
(accessStatusDataService.findAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(metadataOnlyStatus));
116+
(accessStatusDataService.findItemAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(metadataOnlyStatus));
117117
initTestBed();
118118
}));
119119
beforeEach(() => {
@@ -124,10 +124,10 @@ describe('ItemAccessStatusBadgeComponent', () => {
124124
});
125125
});
126126

127-
describe('When the findAccessStatusFor method returns open.access', () => {
127+
describe('When the findItemAccessStatusFor method returns open.access', () => {
128128
beforeEach(waitForAsync(() => {
129129
init();
130-
(accessStatusDataService.findAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(openAccessStatus));
130+
(accessStatusDataService.findItemAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(openAccessStatus));
131131
initTestBed();
132132
}));
133133
beforeEach(() => {
@@ -138,10 +138,10 @@ describe('ItemAccessStatusBadgeComponent', () => {
138138
});
139139
});
140140

141-
describe('When the findAccessStatusFor method returns embargo', () => {
141+
describe('When the findItemAccessStatusFor method returns embargo', () => {
142142
beforeEach(waitForAsync(() => {
143143
init();
144-
(accessStatusDataService.findAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(embargoStatus));
144+
(accessStatusDataService.findItemAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(embargoStatus));
145145
initTestBed();
146146
}));
147147
beforeEach(() => {
@@ -152,10 +152,10 @@ describe('ItemAccessStatusBadgeComponent', () => {
152152
});
153153
});
154154

155-
describe('When the findAccessStatusFor method returns restricted', () => {
155+
describe('When the findItemAccessStatusFor method returns restricted', () => {
156156
beforeEach(waitForAsync(() => {
157157
init();
158-
(accessStatusDataService.findAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(restrictedStatus));
158+
(accessStatusDataService.findItemAccessStatusFor as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(restrictedStatus));
159159
initTestBed();
160160
}));
161161
beforeEach(() => {

0 commit comments

Comments
 (0)