Skip to content

Commit 7cb7a4b

Browse files
committed
Merged dspace-cris-7 into dspacecris-7-DSC-1053
2 parents 8795266 + f0c3921 commit 7cb7a4b

22 files changed

Lines changed: 592 additions & 213 deletions

src/app/core/data/bitstream-data.service.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,56 @@ export class BitstreamDataService extends IdentifiableDataService<Bitstream> imp
352352
uuid: string,
353353
bundlename: string,
354354
metadataFilters: MetadataFilter[],
355-
options?: FindListOptions,
355+
options: FindListOptions = {},
356+
useCachedVersionIfAvailable = true,
357+
reRequestOnStale = true,
358+
...linksToFollow: FollowLinkConfig<Bitstream>[]
359+
): Observable<RemoteData<PaginatedList<Bitstream>>> {
360+
const searchParams = [];
361+
searchParams.push(new RequestParam('uuid', uuid));
362+
searchParams.push(new RequestParam('name', bundlename));
363+
364+
metadataFilters.forEach((entry: MetadataFilter) => {
365+
searchParams.push(new RequestParam('filterMetadata', entry.metadataName));
366+
searchParams.push(new RequestParam('filterMetadataValue', entry.metadataValue));
367+
});
368+
369+
const hrefObs = this.getSearchByHref(
370+
'showableByItem',
371+
{ searchParams },
372+
...linksToFollow
373+
);
374+
375+
return this.findListByHref(
376+
hrefObs,
377+
options,
378+
useCachedVersionIfAvailable,
379+
reRequestOnStale,
380+
...linksToFollow
381+
);
382+
}
383+
384+
/**
385+
* Returns an observable of {@link RemoteData} of a {@link Bitstream} that is not marked
386+
* hidden (that hasn't got the metadata `bitstream.hide` or its value is not true/yes).
387+
* resolve {@link HALLink}s of the object
388+
*
389+
* @param uuid The item UUID to retrieve bitstreams from
390+
* @param bundlename Bundle type of the bitstreams
391+
* @param metadataFilters Array of object we want to filter by
392+
* @param options The {@link FindListOptions} for the request
393+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
394+
* no valid cached version. Defaults to true
395+
* @param reRequestOnStale Whether or not the request should automatically be re-
396+
* requested after the response becomes stale
397+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
398+
* {@link HALLink}s should be automatically resolved
399+
*/
400+
showableByItem(
401+
uuid: string,
402+
bundlename: string,
403+
metadataFilters: MetadataFilter[],
404+
options: FindListOptions,
356405
useCachedVersionIfAvailable = true,
357406
reRequestOnStale = true,
358407
...linksToFollow: FollowLinkConfig<Bitstream>[]
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,10 @@
11
<div class="{{valueStyle}}">
22
<ng-container *ngFor="let attachment of (bitstreams$ | async); let last = last;">
3-
<ng-template #tipContent>
4-
<span [innerHTML]="('checksum-tooltip.info.' + attachment.checkSum.checkSumAlgorithm | translate)"></span>
5-
</ng-template>
6-
<div class="row mt-1 mb-2" data-test="attachment-info">
7-
<div class="col-3">
8-
<ds-thumbnail [thumbnail]="attachment.thumbnail | async"></ds-thumbnail>
9-
</div>
10-
<div class="col-5">
11-
12-
<ng-container *ngFor="let attachmentConf of envMetadata">
13-
14-
<div class="content" [attr.data-test]="attachmentConf.name"
15-
*ngIf="attachment.firstMetadataValue(attachmentConf.name) || attachmentConf.type == AdvancedAttachmentElementType.Attribute">
16-
<strong *ngIf="attachmentConf.type != AdvancedAttachmentElementType.Attribute">
17-
{{ 'cris-layout.advanced-attachment.'+attachmentConf.name | translate }}
18-
</strong>
19-
20-
<ng-container *ngIf="attachmentConf.type == AdvancedAttachmentElementType.Metadata">
21-
22-
<p class="text-break m-0" data-test="attachment-name" *ngIf="!attachmentConf.truncatable">
23-
{{attachment.firstMetadataValue(attachmentConf.name)}}
24-
</p>
25-
26-
<ds-truncatable *ngIf="attachmentConf.truncatable" [id]=" attachment.id">
27-
<ds-truncatable-part [id]="attachment.id" [minLines]="1">
28-
{{attachment.firstMetadataValue(attachmentConf.name)}}
29-
</ds-truncatable-part>
30-
</ds-truncatable>
31-
32-
</ng-container>
33-
34-
<ng-container *ngIf="attachmentConf.type == AdvancedAttachmentElementType.Attribute">
35-
<ng-container *ngIf="attachmentConf.name == 'format' && (getFormat(attachment) | async)">
36-
<strong>
37-
{{ 'cris-layout.advanced-attachment.'+attachmentConf.name | translate }}
38-
</strong>
39-
<p class="word-break m-0">{{getFormat(attachment) | async}}</p>
40-
</ng-container>
41-
42-
<ng-container *ngIf="attachmentConf.name == 'size' && getSize(attachment)">
43-
<strong>
44-
{{ 'cris-layout.advanced-attachment.'+attachmentConf.name | translate }}
45-
</strong>
46-
<p class="word-break m-0">{{getSize(attachment) | dsFileSize}}</p>
47-
</ng-container>
48-
49-
<ng-container *ngIf="attachmentConf.name == 'checksum' && getChecksum(attachment)">
50-
<ng-container *ngVar="getChecksum(attachment) as checksum">
51-
<strong>
52-
{{ 'cris-layout.advanced-attachment.'+ attachmentConf.name | translate }}
53-
({{checksum.checkSumAlgorithm}}) <i class="far fa-question-circle text-info hint" #hint="ngbTooltip"
54-
container="body"
55-
placement="top"
56-
[ngbTooltip]="tipContent"
57-
triggers="manual"
58-
[autoClose]="false"
59-
(click)="hint.toggle();$event.preventDefault();"></i>
60-
</strong>
61-
<p class="word-break m-0">{{checksum.value}}</p>
62-
</ng-container>
63-
</ng-container>
64-
</ng-container>
65-
66-
</div>
67-
</ng-container>
68-
69-
</div>
70-
<div class="col-4 text-right">
71-
<ds-file-download-button [bitstream]="attachment" [enableRequestACopy]="true" [item]="item">
72-
</ds-file-download-button>
73-
</div>
74-
</div>
75-
<hr *ngIf="!last">
3+
<ds-bitstream-attachment data-test="attachment-info" [attachment]="attachment"></ds-bitstream-attachment>
764
</ng-container>
775
<div *ngIf="canViewMore" class="w-100 text-center my-3">
786
<button class="btn btn-outline-primary" data-test="view-more" (click)="viewMore()">
797
{{'cris-layout.advanced-attachment.viewMore' | translate}}
808
</button>
819
</div>
8210
</div>
83-
84-

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/advanced-attachment/advanced-attachment.component.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
.img-file {
2-
max-height: var(--ds-advanced-attachment-image-max-height);
3-
object-fit: var(--ds-advanced-attachment-image-object-fit);
4-
object-position: var(--ds-advanced-attachment-image-object-position);
5-
}
61

7-
.thumbnail-placeholder {
8-
border: var(--ds-thumbnail-placeholder-border);
9-
color: var(--ds-thumbnail-placeholder-color);
10-
font-weight: var(--ds-advanced-attachment-thumbnail-placeholder-font-weight);
11-
}
122

133
.hint {
144
cursor: pointer;

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/advanced-attachment/advanced-attachment.component.spec.ts

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -197,43 +197,6 @@ describe('AdvancedAttachmentComponent', () => {
197197
expect(valueFound.length).toBe(3);
198198
}));
199199

200-
it('should show information properly', () => {
201-
const entries = de.queryAll(By.css('[data-test="attachment-info"]'));
202-
expect(entries.length).toBe(3);
203-
expect(entries[0].query(By.css('[data-test="dc.title"]'))).toBeTruthy();
204-
expect(entries[0].query(By.css('[data-test="dc.description"]'))).toBeTruthy();
205-
expect(entries[0].query(By.css('[data-test="dc.type"]'))).toBeTruthy();
206-
expect(entries[0].query(By.css('[data-test="format"]'))).toBeTruthy();
207-
expect(entries[0].query(By.css('[data-test="size"]'))).toBeTruthy();
208-
expect(entries[0].query(By.css('[data-test="checksum"]'))).toBeTruthy();
209-
});
210-
211-
it('should wrap the title', () => {
212-
const titleElement = de.query(By.css('[data-test="attachment-name"]')).nativeElement;
213-
expect(titleElement.classList).toContain('text-break');
214-
});
215-
216-
describe('and the field has metadata key and value set as value', () => {
217-
beforeEach(() => {
218-
// NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
219-
TestBed.resetTestingModule();
220-
TestBed.configureTestingModule(getDefaultTestBedConf());
221-
TestBed.overrideProvider('fieldProvider', { useValue: mockFieldWithMetadata });
222-
fixture = TestBed.createComponent(AdvancedAttachmentComponent);
223-
component = fixture.componentInstance;
224-
de = fixture.debugElement;
225-
let spy = spyOn(component, 'getBitstreamsByItem');
226-
spy.and.returnValue(of(createPaginatedList([attachmentsMock[1]])));
227-
component.item = testItem;
228-
fixture.detectChanges();
229-
});
230-
231-
it('should show main article attachment', () => {
232-
expect(de.query(By.css('[data-test="dc.title"]')).nativeElement.innerHTML).toContain('main.pdf');
233-
});
234-
235-
});
236-
237200
});
238201

239202
describe('when pagination is enabled', () => {
@@ -308,40 +271,6 @@ describe('AdvancedAttachmentComponent', () => {
308271
expect(valueFound.length).toBe(3);
309272
}));
310273

311-
it('should show information properly', () => {
312-
const entries = de.queryAll(By.css('[data-test="attachment-info"]'));
313-
expect(entries.length).toBe(3);
314-
expect(entries[0].query(By.css('[data-test="dc.title"]'))).toBeFalsy();
315-
expect(entries[0].query(By.css('[data-test="dc.description"]'))).toBeFalsy();
316-
expect(entries[0].query(By.css('[data-test="dc.type"]'))).toBeFalsy();
317-
expect(entries[0].query(By.css('[data-test="format"]'))).toBeFalsy();
318-
expect(entries[0].query(By.css('[data-test="size"]'))).toBeFalsy();
319-
expect(entries[0].query(By.css('[data-test="checksum"]'))).toBeFalsy();
320-
});
321-
322-
describe('and the field has metadata key and value set as value', () => {
323-
beforeEach(() => {
324-
// NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
325-
TestBed.resetTestingModule();
326-
TestBed.configureTestingModule(getDefaultTestBedConf());
327-
TestBed.overrideProvider('fieldProvider', { useValue: mockFieldWithMetadata });
328-
fixture = TestBed.createComponent(AdvancedAttachmentComponent);
329-
component = fixture.componentInstance;
330-
component.envMetadata = [];
331-
de = fixture.debugElement;
332-
let spy = spyOn(component, 'getBitstreamsByItem');
333-
spy.and.returnValue(of(createPaginatedList([attachmentsMock[1]])));
334-
component.item = testItem;
335-
fixture.detectChanges();
336-
});
337-
338-
it('should show main article attachment', () => {
339-
expect(de.queryAll(By.css('[data-test="attachment-info"]')).length).toBe(1);
340-
expect(de.query(By.css('[data-test="dc.title"]'))).toBeFalsy();
341-
});
342-
343-
});
344-
345274
});
346275

347276
describe('when pagination is enabled', () => {

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/advanced-attachment/advanced-attachment.component.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ import { BitstreamDataService } from '../../../../../../../core/data/bitstream-d
66
import { Item } from '../../../../../../../core/shared/item.model';
77
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
88
import { AttachmentComponent } from '../attachment/attachment.component';
9-
import { AdvancedAttachmentElementType } from '../../../../../../../../config/advanced-attachment-rendering.config';
109
import { environment } from '../../../../../../../../environments/environment';
10+
import { FindListOptions } from '../../../../../../../core/data/find-list-options.model';
11+
import { Observable } from 'rxjs';
12+
import { buildPaginatedList, PaginatedList } from '../../../../../../../core/data/paginated-list.model';
13+
import { Bitstream } from '../../../../../../../core/shared/bitstream.model';
14+
import { followLink } from '../../../../../../../shared/utils/follow-link-config.model';
15+
import { getFirstCompletedRemoteData } from '../../../../../../../core/shared/operators';
16+
import { map } from 'rxjs/operators';
17+
import { RemoteData } from '../../../../../../../core/data/remote-data';
1118

1219
@Component({
1320
selector: 'ds-advanced-attachment',
@@ -30,11 +37,6 @@ export class AdvancedAttachmentComponent extends AttachmentComponent implements
3037
*/
3138
envPagination = environment.advancedAttachmentRendering.pagination;
3239

33-
/**
34-
* Configuration type enum
35-
*/
36-
AdvancedAttachmentElementType = AdvancedAttachmentElementType;
37-
3840
constructor(
3941
@Inject('fieldProvider') public fieldProvider: LayoutField,
4042
@Inject('itemProvider') public itemProvider: Item,
@@ -45,4 +47,14 @@ export class AdvancedAttachmentComponent extends AttachmentComponent implements
4547
super(fieldProvider, itemProvider, renderingSubTypeProvider, bitstreamDataService, translateService);
4648
}
4749

50+
getBitstreamsByItem(options?: FindListOptions): Observable<PaginatedList<Bitstream>> {
51+
return this.bitstreamDataService
52+
.showableByItem(this.item.uuid, this.field.bitstream.bundle, this.getMetadataFilters(), options, false, false, followLink('thumbnail'))
53+
.pipe(
54+
getFirstCompletedRemoteData(),
55+
map((response: RemoteData<PaginatedList<Bitstream>>) => {
56+
return response.hasSucceeded ? response.payload : buildPaginatedList(null, []);
57+
})
58+
);
59+
}
4860
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ng-template #attachmentValue dsCrisLayoutLoader></ng-template>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/advanced-attachment/bitstream-attachment/attachment-render/attachment-render.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { AttachmentRenderComponent } from './attachment-render.component';
4+
import { NO_ERRORS_SCHEMA } from '@angular/core';
5+
import {
6+
AuthorizationDataService
7+
} from '../../../../../../../../../core/data/feature-authorization/authorization-data.service';
8+
import { AuthorizationDataServiceStub } from '../../../../../../../../../shared/testing/authorization-service.stub';
9+
10+
describe('AttachmentRenderComponent', () => {
11+
let component: AttachmentRenderComponent;
12+
let fixture: ComponentFixture<AttachmentRenderComponent>;
13+
14+
beforeEach(async () => {
15+
await TestBed.configureTestingModule({
16+
declarations: [ AttachmentRenderComponent ],
17+
providers: [
18+
{provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub}
19+
],
20+
schemas: [ NO_ERRORS_SCHEMA ]
21+
})
22+
.compileComponents();
23+
});
24+
25+
beforeEach(() => {
26+
fixture = TestBed.createComponent(AttachmentRenderComponent);
27+
component = fixture.componentInstance;
28+
fixture.detectChanges();
29+
});
30+
31+
it('should create', () => {
32+
expect(component).toBeTruthy();
33+
});
34+
});

0 commit comments

Comments
 (0)