mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 05:23:06 +00:00
57557: Refactored EntitySearchResultComponent
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
import { Component, Inject } from '@angular/core';
|
import { Component, Inject } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
import { Item } from '../../../../core/shared/item.model';
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
import { Metadatum } from '../../../../core/shared/metadatum.model';
|
import { hasValue } from '../../../empty.util';
|
||||||
import { hasNoValue, hasValue, isEmpty } from '../../../empty.util';
|
|
||||||
import { ITEM } from '../../../entities/switcher/entity-type-switcher.component';
|
import { ITEM } from '../../../entities/switcher/entity-type-switcher.component';
|
||||||
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
|
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
|
||||||
import { TruncatableService } from '../../../truncatable/truncatable.service';
|
import { TruncatableService } from '../../../truncatable/truncatable.service';
|
||||||
|
import { SearchResultListElementComponent } from '../../search-result-list-element/search-result-list-element.component';
|
||||||
|
|
||||||
// TODO lot of overlap with SearchResultListElementComponent => refactor!
|
|
||||||
/**
|
/**
|
||||||
* A generic component for displaying entity list elements
|
* A generic component for displaying entity list elements
|
||||||
*/
|
*/
|
||||||
@@ -15,77 +13,24 @@ import { TruncatableService } from '../../../truncatable/truncatable.service';
|
|||||||
selector: 'ds-entity-search-result',
|
selector: 'ds-entity-search-result',
|
||||||
template: ''
|
template: ''
|
||||||
})
|
})
|
||||||
export class EntitySearchResultComponent {
|
export class EntitySearchResultComponent extends SearchResultListElementComponent<ItemSearchResult, Item> {
|
||||||
item: Item;
|
item: Item;
|
||||||
searchResult: ItemSearchResult;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private truncatableService: TruncatableService,
|
protected truncatableService: TruncatableService,
|
||||||
@Inject(ITEM) public object: Item | ItemSearchResult,
|
@Inject(ITEM) public obj: Item | ItemSearchResult,
|
||||||
) {
|
) {
|
||||||
|
super(undefined, truncatableService);
|
||||||
if (hasValue((this.object as any).dspaceObject)) {
|
if (hasValue((obj as any).dspaceObject)) {
|
||||||
this.searchResult = this.object as ItemSearchResult;
|
this.object = obj as ItemSearchResult;
|
||||||
this.item = this.searchResult.dspaceObject;
|
this.dso = this.object.dspaceObject;
|
||||||
} else {
|
} else {
|
||||||
this.searchResult = {
|
this.object = {
|
||||||
dspaceObject: this.object as Item,
|
dspaceObject: obj as Item,
|
||||||
hitHighlights: []
|
hitHighlights: []
|
||||||
};
|
};
|
||||||
this.item = this.object as Item;
|
this.dso = obj as Item;
|
||||||
}
|
}
|
||||||
}
|
this.item = this.dso;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the values of metadata by keys
|
|
||||||
* @param {string[]} keys List of metadata keys to get values for
|
|
||||||
* @returns {string[]} List of metadata values
|
|
||||||
*/
|
|
||||||
getValues(keys: string[]): string[] {
|
|
||||||
const results: string[] = new Array<string>();
|
|
||||||
this.searchResult.hitHighlights.forEach(
|
|
||||||
(md: Metadatum) => {
|
|
||||||
if (keys.indexOf(md.key) > -1) {
|
|
||||||
results.push(md.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (isEmpty(results)) {
|
|
||||||
this.item.filterMetadata(keys).forEach(
|
|
||||||
(md: Metadatum) => {
|
|
||||||
results.push(md.value);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the first value of a metadatum by key
|
|
||||||
* @param {string} key Metadatum key
|
|
||||||
* @returns {string} Metadatum value
|
|
||||||
*/
|
|
||||||
getFirstValue(key: string): string {
|
|
||||||
let result: string;
|
|
||||||
this.searchResult.hitHighlights.some(
|
|
||||||
(md: Metadatum) => {
|
|
||||||
if (key === md.key) {
|
|
||||||
result = md.value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (hasNoValue(result)) {
|
|
||||||
result = this.item.findMetadata(key);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not the item's values are collapsed
|
|
||||||
* @returns {Observable<boolean>}
|
|
||||||
*/
|
|
||||||
isCollapsed(): Observable<boolean> {
|
|
||||||
return this.truncatableService.isCollapsed(this.item.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ import { Observable } from 'rxjs/Observable';
|
|||||||
import { SearchResult } from '../../../+search-page/search-result.model';
|
import { SearchResult } from '../../../+search-page/search-result.model';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
import { Metadatum } from '../../../core/shared/metadatum.model';
|
import { Metadatum } from '../../../core/shared/metadatum.model';
|
||||||
import { hasNoValue, isEmpty } from '../../empty.util';
|
import { hasNoValue, hasValue, isEmpty } from '../../empty.util';
|
||||||
import { ListableObject } from '../../object-collection/shared/listable-object.model';
|
import { ListableObject } from '../../object-collection/shared/listable-object.model';
|
||||||
import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component';
|
import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component';
|
||||||
import { TruncatableService } from '../../truncatable/truncatable.service';
|
import { TruncatableService } from '../../truncatable/truncatable.service';
|
||||||
@@ -17,9 +17,11 @@ import { TruncatableService } from '../../truncatable/truncatable.service';
|
|||||||
export class SearchResultListElementComponent<T extends SearchResult<K>, K extends DSpaceObject> extends AbstractListableElementComponent<T> {
|
export class SearchResultListElementComponent<T extends SearchResult<K>, K extends DSpaceObject> extends AbstractListableElementComponent<T> {
|
||||||
dso: K;
|
dso: K;
|
||||||
|
|
||||||
public constructor(@Inject('objectElementProvider') public listable: ListableObject, private truncatableService: TruncatableService) {
|
public constructor(@Inject('objectElementProvider') public listable: ListableObject, protected truncatableService: TruncatableService) {
|
||||||
super(listable);
|
super(listable);
|
||||||
this.dso = this.object.dspaceObject;
|
if (hasValue(this.object)) {
|
||||||
|
this.dso = this.object.dspaceObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getValues(keys: string[]): string[] {
|
getValues(keys: string[]): string[] {
|
||||||
|
Reference in New Issue
Block a user