diff --git a/src/app/+search-page/search.component.ts b/src/app/+search-page/search.component.ts index 4e50a82827..999d703dd5 100644 --- a/src/app/+search-page/search.component.ts +++ b/src/app/+search-page/search.component.ts @@ -123,7 +123,7 @@ export class SearchComponent implements OnInit { this.searchLink = this.getSearchLink(); this.searchOptions$ = this.getSearchOptions(); this.sub = this.searchOptions$.pipe( - switchMap((options) => this.service.search(options, null, followLink('logo')).pipe(getSucceededRemoteData(), startWith(undefined)))) + switchMap((options) => this.service.search(options).pipe(getSucceededRemoteData(), startWith(undefined)))) .subscribe((results) => { this.resultsRD$.next(results); }); diff --git a/src/app/core/cache/builders/link.service.spec.ts b/src/app/core/cache/builders/link.service.spec.ts index 6b7c154137..95a7570207 100644 --- a/src/app/core/cache/builders/link.service.spec.ts +++ b/src/app/core/cache/builders/link.service.spec.ts @@ -139,10 +139,13 @@ describe('LinkService', () => { }); describe(`when the specified link doesn't exist on the model's class`, () => { - it('should return with the same model', () => { - expect( + beforeEach(() => { + spyOnFunction(decorators, 'getLinkDefinition').and.returnValue(undefined); + }); + it('should throw an error', () => { + expect(() => { service.resolveLink(testModel, followLink('predecessor', {}, true, followLink('successor'))) - ).toEqual(testModel); + }).toThrow(); }); }); diff --git a/src/app/core/cache/builders/link.service.ts b/src/app/core/cache/builders/link.service.ts index 35c2fbac9c..8d0def71fc 100644 --- a/src/app/core/cache/builders/link.service.ts +++ b/src/app/core/cache/builders/link.service.ts @@ -42,8 +42,7 @@ export class LinkService { const matchingLinkDef = getLinkDefinition(model.constructor, linkToFollow.name); if (hasNoValue(matchingLinkDef)) { - console.error(`followLink('${linkToFollow.name}') was used for a ${model.constructor.name}, but there is no property on ${model.constructor.name} models with an @link() for ${linkToFollow.name}`); - return model; + throw new Error(`followLink('${linkToFollow.name}') was used for a ${model.constructor.name}, but there is no property on ${model.constructor.name} models with an @link() for ${linkToFollow.name}`); } else { const provider = getDataServiceFor(matchingLinkDef.resourceType); diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts index 6f8bf5264e..4ffaafa0f3 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -1,9 +1,12 @@ -import { Component, Inject } from '@angular/core'; +import { Component, Inject, Input } from '@angular/core'; import { Collection } from '../../../core/shared/collection.model'; import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { ViewMode } from '../../../core/shared/view-mode.model'; import { listableObjectComponent } from '../../object-collection/shared/listable-object/listable-object.decorator'; +import { hasNoValue, hasValue } from '../../empty.util'; +import { followLink } from '../../utils/follow-link-config.model'; +import { LinkService } from '../../../core/cache/builders/link.service'; /** * Component representing a grid element for collection @@ -15,4 +18,21 @@ import { listableObjectComponent } from '../../object-collection/shared/listable }) @listableObjectComponent(Collection, ViewMode.GridElement) -export class CollectionGridElementComponent extends AbstractListableElementComponent {} +export class CollectionGridElementComponent extends AbstractListableElementComponent { + private _object: Collection; + + constructor( private linkService: LinkService){ + super(); + } + + @Input() set object(object: Collection) { + this._object = object; + if (hasValue(this._object) && hasNoValue(this._object.logo)) { + this.linkService.resolveLink(this._object, followLink('logo')) + } + } + + get object(): Collection { + return this._object; + } +} diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts index 05c84b683b..47ab77de5f 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts @@ -1,9 +1,12 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { Community } from '../../../core/shared/community.model'; import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { ViewMode } from '../../../core/shared/view-mode.model'; import { listableObjectComponent } from '../../object-collection/shared/listable-object/listable-object.decorator'; +import { followLink } from '../../utils/follow-link-config.model'; +import { LinkService } from '../../../core/cache/builders/link.service'; +import { hasNoValue, hasValue } from '../../empty.util'; /** * Component representing a grid element for a community @@ -15,4 +18,21 @@ import { listableObjectComponent } from '../../object-collection/shared/listable }) @listableObjectComponent(Community, ViewMode.GridElement) -export class CommunityGridElementComponent extends AbstractListableElementComponent {} +export class CommunityGridElementComponent extends AbstractListableElementComponent { + private _object: Community; + + constructor( private linkService: LinkService){ + super(); + } + + @Input() set object(object: Community) { + this._object = object; + if (hasValue(this._object) && hasNoValue(this._object.logo)) { + this.linkService.resolveLink(this._object, followLink('logo')) + } + } + + get object(): Community { + return this._object; + } +} diff --git a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts index 92d93686dc..8e6af1e1a7 100644 --- a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts @@ -53,6 +53,7 @@ export class GridThumbnailComponent implements OnInit, OnChanges { !hasValue(changes.thumbnail.previousValue) && hasValue(changes.thumbnail.currentValue) ) { + console.log('this.thumbnail', changes.thumbnail.currentValue); this.checkThumbnail(changes.thumbnail.currentValue); } } diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts index a834327736..cf5a93aa56 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts @@ -1,10 +1,15 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; import { Collection } from '../../../../core/shared/collection.model'; import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model'; import { ViewMode } from '../../../../core/shared/view-mode.model'; import { listableObjectComponent } from '../../../object-collection/shared/listable-object/listable-object.decorator'; +import { hasNoValue, hasValue } from '../../../empty.util'; +import { followLink } from '../../../utils/follow-link-config.model'; +import { LinkService } from '../../../../core/cache/builders/link.service'; +import { TruncatableService } from '../../../truncatable/truncatable.service'; +import { BitstreamDataService } from '../../../../core/data/bitstream-data.service'; @Component({ selector: 'ds-collection-search-result-grid-element', @@ -15,4 +20,29 @@ import { listableObjectComponent } from '../../../object-collection/shared/lista * Component representing a grid element for a collection search result */ @listableObjectComponent(CollectionSearchResult, ViewMode.GridElement) -export class CollectionSearchResultGridElementComponent extends SearchResultGridElementComponent {} +export class CollectionSearchResultGridElementComponent extends SearchResultGridElementComponent< CollectionSearchResult, Collection > { + private _dso: Collection; + + constructor( + private linkService: LinkService, + protected truncatableService: TruncatableService, + protected bitstreamDataService: BitstreamDataService + ) { + super(truncatableService, bitstreamDataService); + } + + @Input() set dso(dso: Collection) { + this._dso = dso; + console.log('aaasdasd') + if (hasValue(this._dso) && hasNoValue(this._dso.logo)) { + this.linkService.resolveLink( + this._dso, + followLink('logo') + ); + } + } + + get dso(): Collection { + return this._dso; + } +} diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts index e726c3e803..b622651e10 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts @@ -1,18 +1,47 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { Community } from '../../../../core/shared/community.model'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; import { CommunitySearchResult } from '../../../object-collection/shared/community-search-result.model'; import { ViewMode } from '../../../../core/shared/view-mode.model'; import { listableObjectComponent } from '../../../object-collection/shared/listable-object/listable-object.decorator'; +import { LinkService } from '../../../../core/cache/builders/link.service'; +import { TruncatableService } from '../../../truncatable/truncatable.service'; +import { BitstreamDataService } from '../../../../core/data/bitstream-data.service'; +import { hasNoValue, hasValue } from '../../../empty.util'; +import { followLink } from '../../../utils/follow-link-config.model'; @Component({ selector: 'ds-community-search-result-grid-element', - styleUrls: ['../search-result-grid-element.component.scss', 'community-search-result-grid-element.component.scss'], - templateUrl: 'community-search-result-grid-element.component.html' + styleUrls: [ + '../search-result-grid-element.component.scss', + 'community-search-result-grid-element.component.scss', + ], + templateUrl: 'community-search-result-grid-element.component.html', }) /** * Component representing a grid element for a community search result */ @listableObjectComponent(CommunitySearchResult, ViewMode.GridElement) -export class CommunitySearchResultGridElementComponent extends SearchResultGridElementComponent { +export class CommunitySearchResultGridElementComponent extends SearchResultGridElementComponent { + private _dso: Community; + + constructor( + private linkService: LinkService, + protected truncatableService: TruncatableService, + protected bitstreamDataService: BitstreamDataService + ) { + super(truncatableService, bitstreamDataService); + } + + @Input() set dso(dso: Community) { + this._dso = dso; + console.log('aaasdasd'); + if (hasValue(this._dso) && hasNoValue(this._dso.logo)) { + this.linkService.resolveLink(this._dso, followLink('logo')); + } + } + + get dso(): Community { + return this._dso; + } }