Related entity thumbnails.

This commit is contained in:
Michael Spalti
2022-09-14 16:33:25 -07:00
parent 84ad250de6
commit abe19b12bb
21 changed files with 71 additions and 48 deletions

View File

@@ -48,7 +48,7 @@ describe('BrowseByMetadataPageComponent', () => {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const mockEntries = [ const mockEntries = [
{ {

View File

@@ -62,13 +62,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('JournalIssueSearchResultListElementComponent', () => { describe('JournalIssueSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@@ -61,13 +61,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('JournalVolumeSearchResultListElementComponent', () => { describe('JournalVolumeSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@@ -57,13 +57,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('JournalSearchResultListElementComponent', () => { describe('JournalSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@@ -55,13 +55,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('OrgUnitSearchResultListElementComponent', () => { describe('OrgUnitSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@@ -55,13 +55,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('PersonSearchResultListElementComponent', () => { describe('PersonSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@@ -56,13 +56,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('ProjectSearchResultListElementComponent', () => { describe('ProjectSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@@ -42,13 +42,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
function init() { function init() {
mockItemWithMetadata = Object.assign( mockItemWithMetadata = Object.assign(

View File

@@ -10,6 +10,7 @@ import { hasValue, isNotEmpty } from '../../../shared/empty.util';
* An abstract component for displaying an incremental list of objects * An abstract component for displaying an incremental list of objects
*/ */
export class AbstractIncrementalListComponent<T> implements OnInit, OnDestroy { export class AbstractIncrementalListComponent<T> implements OnInit, OnDestroy {
/** /**
* The amount to increment the list by * The amount to increment the list by
* Define this amount in the child component overriding this component * Define this amount in the child component overriding this component
@@ -21,6 +22,11 @@ export class AbstractIncrementalListComponent<T> implements OnInit, OnDestroy {
*/ */
objects: T[]; objects: T[];
/**
* Placeholder css class (defined in global-styles)
*/
placeholderFontClass: string;
/** /**
* A list of open subscriptions * A list of open subscriptions
*/ */

View File

@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core'; import { Component, ElementRef, Input } from '@angular/core';
import { Item } from '../../../core/shared/item.model'; import { Item } from '../../../core/shared/item.model';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
@@ -7,6 +7,7 @@ import { ViewMode } from '../../../core/shared/view-mode.model';
import { RelationshipService } from '../../../core/data/relationship.service'; import { RelationshipService } from '../../../core/data/relationship.service';
import { AbstractIncrementalListComponent } from '../abstract-incremental-list/abstract-incremental-list.component'; import { AbstractIncrementalListComponent } from '../abstract-incremental-list/abstract-incremental-list.component';
import { FindListOptions } from '../../../core/data/find-list-options.model'; import { FindListOptions } from '../../../core/data/find-list-options.model';
import { setPlaceHolderFontSize } from '../../../shared/utils/object-list-utils';
@Component({ @Component({
selector: 'ds-related-items', selector: 'ds-related-items',
@@ -18,6 +19,7 @@ import { FindListOptions } from '../../../core/data/find-list-options.model';
* It expects a parent item and relationship type, as well as a label to display on top * It expects a parent item and relationship type, as well as a label to display on top
*/ */
export class RelatedItemsComponent extends AbstractIncrementalListComponent<Observable<RemoteData<PaginatedList<Item>>>> { export class RelatedItemsComponent extends AbstractIncrementalListComponent<Observable<RemoteData<PaginatedList<Item>>>> {
/** /**
* The parent of the list of related items to display * The parent of the list of related items to display
*/ */
@@ -53,9 +55,14 @@ export class RelatedItemsComponent extends AbstractIncrementalListComponent<Obse
*/ */
viewMode = ViewMode.ListElement; viewMode = ViewMode.ListElement;
constructor(public relationshipService: RelationshipService) { constructor(public relationshipService: RelationshipService, protected elementRef: ElementRef) {
super(); super();
} }
ngOnInit(): void {
const width = this.elementRef.nativeElement.offsetWidth;
this.placeholderFontClass = setPlaceHolderFontSize(width);
super.ngOnInit();
}
/** /**
* Get a specific page * Get a specific page

View File

@@ -1,4 +1,5 @@
<ds-metadata-field-wrapper [label]="label"> <ds-metadata-field-wrapper [label]="label" [ngClass]="placeholderFontClass">
<div #relatedItems>
<ng-container *ngFor="let objectPage of objects; let i = index"> <ng-container *ngFor="let objectPage of objects; let i = index">
<ng-container *ngVar="(objectPage | async) as itemsRD"> <ng-container *ngVar="(objectPage | async) as itemsRD">
<ds-listable-object-component-loader *ngFor="let item of itemsRD?.payload?.page" <ds-listable-object-component-loader *ngFor="let item of itemsRD?.payload?.page"
@@ -17,4 +18,5 @@
</div> </div>
</ng-container> </ng-container>
</ng-container> </ng-container>
</div>
</ds-metadata-field-wrapper> </ds-metadata-field-wrapper>

View File

@@ -0,0 +1,6 @@
ds-listable-object-component-loader {
margin-bottom: 10px;
display: block;
}

View File

@@ -21,6 +21,7 @@ import { ViewMode } from '../../core/shared/view-mode.model';
import { CollectionElementLinkType } from './collection-element-link.type'; import { CollectionElementLinkType } from './collection-element-link.type';
import { PaginatedList } from '../../core/data/paginated-list.model'; import { PaginatedList } from '../../core/data/paginated-list.model';
import { Context } from '../../core/shared/context.model'; import { Context } from '../../core/shared/context.model';
import { setPlaceHolderFontSize } from '../utils/object-list-utils';
/** /**
* Component that can render a list of listable objects in different view modes * Component that can render a list of listable objects in different view modes
@@ -167,7 +168,9 @@ export class ObjectCollectionComponent implements OnInit {
map((params) => isEmpty(params?.view) ? ViewMode.ListElement : params.view), map((params) => isEmpty(params?.view) ? ViewMode.ListElement : params.view),
distinctUntilChanged() distinctUntilChanged()
); );
this.setPlaceHolderFontSize(); const width = this.elementRef.nativeElement.offsetWidth;
this.placeholderFontClass = setPlaceHolderFontSize(width);
} }
/** /**
@@ -177,6 +180,8 @@ export class ObjectCollectionComponent implements OnInit {
* Route is a singleton service provided by Angular. * Route is a singleton service provided by Angular.
* @param router * @param router
* Router is a singleton service provided by Angular. * Router is a singleton service provided by Angular.
* @param elementRef
* Used only to read DOM for the element width
*/ */
constructor( constructor(
private cdRef: ChangeDetectorRef, private cdRef: ChangeDetectorRef,
@@ -236,19 +241,4 @@ export class ObjectCollectionComponent implements OnInit {
this.next.emit(true); this.next.emit(true);
} }
/**
* Sets the class to be used for the "no thumbnail"
* placeholder font size.
*/
setPlaceHolderFontSize() {
const width = this.elementRef.nativeElement.offsetWidth;
if (width < 750) {
this.placeholderFontClass = 'thumb-font-1';
} else if (width < 1000) {
this.placeholderFontClass = 'thumb-font-2';
} else {
this.placeholderFontClass = 'thumb-font-3';
}
}
} }

View File

@@ -71,13 +71,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('ItemListPreviewComponent', () => { describe('ItemListPreviewComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
@@ -226,6 +226,6 @@ describe('ItemListPreviewComponent', () => {
it('should add the ds-thumbnail element', () => { it('should add the ds-thumbnail element', () => {
const thumbnail = fixture.debugElement.query(By.css('ds-thumbnail')); const thumbnail = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnail).toBeFalsy(); expect(thumbnail).toBeFalsy();
}) });
}) });
}); });

View File

@@ -60,7 +60,7 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const rdItem = createSuccessfulRemoteDataObject(item); const rdItem = createSuccessfulRemoteDataObject(item);
const workflowitem = Object.assign(new WorkflowItem(), { item: observableOf(rdItem) }); const workflowitem = Object.assign(new WorkflowItem(), { item: observableOf(rdItem) });

View File

@@ -60,7 +60,7 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const rd = createSuccessfulRemoteDataObject(item); const rd = createSuccessfulRemoteDataObject(item);
mockResultObject.indexableObject = Object.assign(new WorkflowItem(), { item: observableOf(rd) }); mockResultObject.indexableObject = Object.assign(new WorkflowItem(), { item: observableOf(rd) });
@@ -120,7 +120,6 @@ describe('WorkflowItemSearchResultListElementComponent', () => {
})); }));
it('should add an offset to the actions element', () => { it('should add an offset to the actions element', () => {
const thumbnail = fixture.debugElement.query(By.css('.offset-3')); const thumbnail = fixture.debugElement.query(By.css('.offset-3'));
expect(thumbnail).toBeTruthy(); expect(thumbnail).toBeTruthy();

View File

@@ -60,7 +60,7 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const rd = createSuccessfulRemoteDataObject(item); const rd = createSuccessfulRemoteDataObject(item);
mockResultObject.indexableObject = Object.assign(new WorkspaceItem(), { item: observableOf(rd) }); mockResultObject.indexableObject = Object.assign(new WorkspaceItem(), { item: observableOf(rd) });

View File

@@ -48,7 +48,7 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
describe('CollectionSearchResultListElementComponent', () => { describe('CollectionSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
@@ -98,7 +98,7 @@ describe('CollectionSearchResultListElementComponent', () => {
describe('when environment is set to show thumbnail images', () => { describe('when environment is set to show thumbnail images', () => {
it('should offset content', () => { it('should offset content', () => {
const offset = fixture.debugElement.query(By.css('offset-md-2')) const offset = fixture.debugElement.query(By.css('offset-md-2'));
}); });
}); });

View File

@@ -48,7 +48,7 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
describe('CommunitySearchResultListElementComponent', () => { describe('CommunitySearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
@@ -99,7 +99,7 @@ describe('CommunitySearchResultListElementComponent', () => {
describe('when environment is set to show thumbnail images', () => { describe('when environment is set to show thumbnail images', () => {
it('should offset content', () => { it('should offset content', () => {
const offset = fixture.debugElement.query(By.css('offset-md-2')) const offset = fixture.debugElement.query(By.css('offset-md-2'));
}); });
}); });
}); });

View File

@@ -64,13 +64,13 @@ const environmentUseThumbs = {
browseBy: { browseBy: {
showThumbnails: true showThumbnails: true
} }
} };
const enviromentNoThumbs = { const enviromentNoThumbs = {
browseBy: { browseBy: {
showThumbnails: false showThumbnails: false
} }
} };
describe('ItemSearchResultListElementComponent', () => { describe('ItemSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@@ -0,0 +1,13 @@
/**
* Sets the class to be used for the "no thumbnail"
* placeholder font size in lists.
*/
export function setPlaceHolderFontSize(width: number): string {
if (width < 750) {
return 'thumb-font-1';
} else if (width < 1000) {
return 'thumb-font-2';
} else {
return 'thumb-font-3';
}
}