mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-16 14:33:03 +00:00
Merge pull request #387 from atmire/configurable_entities_feedback_2
61947: atarix83 feedback changes 19-04-2019
This commit is contained in:
@@ -13,9 +13,7 @@ import { MetadataService } from '../../core/metadata/metadata.service';
|
||||
|
||||
import { fadeInOut } from '../../shared/animations/fade';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
import * as viewMode from '../../shared/view-mode';
|
||||
|
||||
export const VIEW_MODE_FULL = 'full';
|
||||
import { ItemViewMode } from '../../shared/items/item-type-decorator';
|
||||
|
||||
/**
|
||||
* This component renders a simple item page.
|
||||
@@ -49,7 +47,7 @@ export class ItemPageComponent implements OnInit {
|
||||
/**
|
||||
* The view-mode we're currently on
|
||||
*/
|
||||
viewMode = VIEW_MODE_FULL;
|
||||
viewMode = ItemViewMode.Full;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
|
@@ -2,13 +2,13 @@ import { Component, Inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent, filterRelationsByTypeLabel, relationsToItems } from '../shared/item.component';
|
||||
import { VIEW_MODE_FULL } from '../../item-page.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
|
||||
@rendersItemType('JournalIssue', VIEW_MODE_FULL)
|
||||
@rendersItemType('JournalIssue', ItemViewMode.Full)
|
||||
@Component({
|
||||
selector: 'ds-journal-issue',
|
||||
styleUrls: ['./journal-issue.component.scss'],
|
||||
|
@@ -2,13 +2,13 @@ import { Component, Inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent, filterRelationsByTypeLabel, relationsToItems } from '../shared/item.component';
|
||||
import { VIEW_MODE_FULL } from '../../item-page.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
|
||||
@rendersItemType('JournalVolume', VIEW_MODE_FULL)
|
||||
@rendersItemType('JournalVolume', ItemViewMode.Full)
|
||||
@Component({
|
||||
selector: 'ds-journal-volume',
|
||||
styleUrls: ['./journal-volume.component.scss'],
|
||||
|
@@ -2,13 +2,13 @@ import { Component, Inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent, filterRelationsByTypeLabel, relationsToItems } from '../shared/item.component';
|
||||
import { VIEW_MODE_FULL } from '../../item-page.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
|
||||
@rendersItemType('Journal', VIEW_MODE_FULL)
|
||||
@rendersItemType('Journal', ItemViewMode.Full)
|
||||
@Component({
|
||||
selector: 'ds-journal',
|
||||
styleUrls: ['./journal.component.scss'],
|
||||
|
@@ -2,13 +2,13 @@ import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent, filterRelationsByTypeLabel, relationsToItems } from '../shared/item.component';
|
||||
import { VIEW_MODE_FULL } from '../../item-page.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
|
||||
@rendersItemType('OrgUnit', VIEW_MODE_FULL)
|
||||
@rendersItemType('OrgUnit', ItemViewMode.Full)
|
||||
@Component({
|
||||
selector: 'ds-orgunit',
|
||||
styleUrls: ['./orgunit.component.scss'],
|
||||
|
@@ -2,14 +2,14 @@ import { Component, Inject } from '@angular/core';
|
||||
import { Observable , of as observableOf } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { SearchFixedFilterService } from '../../../../+search-page/search-filters/search-filter/search-fixed-filter.service';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent, filterRelationsByTypeLabel, relationsToItems } from '../shared/item.component';
|
||||
import { VIEW_MODE_FULL } from '../../item-page.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
|
||||
@rendersItemType('Person', VIEW_MODE_FULL)
|
||||
@rendersItemType('Person', ItemViewMode.Full)
|
||||
@Component({
|
||||
selector: 'ds-person',
|
||||
styleUrls: ['./person.component.scss'],
|
||||
|
@@ -2,13 +2,13 @@ import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent, filterRelationsByTypeLabel, relationsToItems } from '../shared/item.component';
|
||||
import { VIEW_MODE_FULL } from '../../item-page.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
|
||||
@rendersItemType('Project', VIEW_MODE_FULL)
|
||||
@rendersItemType('Project', ItemViewMode.Full)
|
||||
@Component({
|
||||
selector: 'ds-project',
|
||||
styleUrls: ['./project.component.scss'],
|
||||
|
@@ -3,16 +3,16 @@ import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import {
|
||||
DEFAULT_ITEM_TYPE,
|
||||
DEFAULT_ITEM_TYPE, ItemViewMode,
|
||||
rendersItemType
|
||||
} from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { ItemComponent, filterRelationsByTypeLabel, relationsToItems } from '../shared/item.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { VIEW_MODE_FULL } from '../../item-page.component';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
|
||||
@rendersItemType('Publication', VIEW_MODE_FULL)
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, VIEW_MODE_FULL)
|
||||
@rendersItemType('Publication', ItemViewMode.Full)
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, ItemViewMode.Full)
|
||||
@Component({
|
||||
selector: 'ds-publication',
|
||||
styleUrls: ['./publication.component.scss'],
|
||||
|
@@ -0,0 +1,80 @@
|
||||
import { hasValue } from '../../../../shared/empty.util';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||
import { RelationshipType } from '../../../../core/shared/item-relationships/relationship-type.model';
|
||||
import { distinctUntilChanged, flatMap, map } from 'rxjs/operators';
|
||||
import { zip as observableZip } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
|
||||
/**
|
||||
* Operator for comparing arrays using a mapping function
|
||||
* The mapping function should turn the source array into an array of basic types, so that the array can
|
||||
* be compared using these basic types.
|
||||
* For example: "(o) => o.id" will compare the two arrays by comparing their content by id.
|
||||
* @param mapFn Function for mapping the arrays
|
||||
*/
|
||||
export const compareArraysUsing = <T>(mapFn: (t: T) => any) =>
|
||||
(a: T[], b: T[]): boolean => {
|
||||
if (!Array.isArray(a) || ! Array.isArray(b)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const aIds = a.map(mapFn);
|
||||
const bIds = b.map(mapFn);
|
||||
|
||||
return aIds.length === bIds.length &&
|
||||
aIds.every((e) => bIds.includes(e)) &&
|
||||
bIds.every((e) => aIds.includes(e));
|
||||
};
|
||||
|
||||
/**
|
||||
* Operator for comparing arrays using the object's ids
|
||||
*/
|
||||
export const compareArraysUsingIds = <T extends { id: string }>() =>
|
||||
compareArraysUsing((t: T) => hasValue(t) ? t.id : undefined);
|
||||
|
||||
/**
|
||||
* Fetch the relationships which match the type label given
|
||||
* @param {string} label Type label
|
||||
* @returns {(source: Observable<[Relationship[] , RelationshipType[]]>) => Observable<Relationship[]>}
|
||||
*/
|
||||
export const filterRelationsByTypeLabel = (label: string) =>
|
||||
(source: Observable<[Relationship[], RelationshipType[]]>): Observable<Relationship[]> =>
|
||||
source.pipe(
|
||||
map(([relsCurrentPage, relTypesCurrentPage]) =>
|
||||
relsCurrentPage.filter((rel: Relationship, idx: number) =>
|
||||
hasValue(relTypesCurrentPage[idx]) && (relTypesCurrentPage[idx].leftLabel === label ||
|
||||
relTypesCurrentPage[idx].rightLabel === label)
|
||||
)
|
||||
),
|
||||
distinctUntilChanged(compareArraysUsingIds())
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator for turning a list of relationships into a list of the relevant items
|
||||
* @param {string} thisId The item's id of which the relations belong to
|
||||
* @param {ItemDataService} ids The ItemDataService to fetch items from the REST API
|
||||
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
|
||||
*/
|
||||
export const relationsToItems = (thisId: string, ids: ItemDataService) =>
|
||||
(source: Observable<Relationship[]>): Observable<Item[]> =>
|
||||
source.pipe(
|
||||
flatMap((rels: Relationship[]) =>
|
||||
observableZip(
|
||||
...rels.map((rel: Relationship) => {
|
||||
let queryId = rel.leftId;
|
||||
if (rel.leftId === thisId) {
|
||||
queryId = rel.rightId;
|
||||
}
|
||||
return ids.findById(queryId);
|
||||
})
|
||||
)
|
||||
),
|
||||
map((arr: Array<RemoteData<Item>>) =>
|
||||
arr
|
||||
.filter((d: RemoteData<Item>) => d.hasSucceeded)
|
||||
.map((d: RemoteData<Item>) => d.payload)),
|
||||
distinctUntilChanged(compareArraysUsingIds()),
|
||||
);
|
@@ -16,19 +16,16 @@ import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||
import { compareArraysUsing, compareArraysUsingIds, ItemComponent } from './item.component';
|
||||
import { ItemComponent } from './item.component';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { ItemPageComponent } from '../../item-page.component';
|
||||
import { VarDirective } from '../../../../shared/utils/var.directive';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { MetadataService } from '../../../../core/metadata/metadata.service';
|
||||
import { of } from 'rxjs/internal/observable/of';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
|
||||
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
|
||||
import { MetadataMap, MetadataValue } from '../../../../core/shared/metadata.models';
|
||||
import { compareArraysUsing, compareArraysUsingIds } from './item-relationships-utils';
|
||||
|
||||
/**
|
||||
* Create a generic test for an item-page-fields component using a mockItem and the type of component
|
||||
|
@@ -8,84 +8,13 @@ import { RelationshipType } from '../../../../core/shared/item-relationships/rel
|
||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators';
|
||||
import { hasNoValue, hasValue } from '../../../../shared/empty.util';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
|
||||
import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
|
||||
import { of } from 'rxjs/internal/observable/of';
|
||||
import { MetadataValue } from '../../../../core/shared/metadata.models';
|
||||
|
||||
/**
|
||||
* Operator for comparing arrays using a mapping function
|
||||
* The mapping function should turn the source array into an array of basic types, so that the array can
|
||||
* be compared using these basic types.
|
||||
* For example: "(o) => o.id" will compare the two arrays by comparing their content by id.
|
||||
* @param mapFn Function for mapping the arrays
|
||||
*/
|
||||
export const compareArraysUsing = <T>(mapFn: (t: T) => any) =>
|
||||
(a: T[], b: T[]): boolean => {
|
||||
if (!Array.isArray(a) || ! Array.isArray(b)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const aIds = a.map(mapFn);
|
||||
const bIds = b.map(mapFn);
|
||||
|
||||
return aIds.length === bIds.length &&
|
||||
aIds.every((e) => bIds.includes(e)) &&
|
||||
bIds.every((e) => aIds.includes(e));
|
||||
};
|
||||
|
||||
/**
|
||||
* Operator for comparing arrays using the object's ids
|
||||
*/
|
||||
export const compareArraysUsingIds = <T extends { id: string }>() =>
|
||||
compareArraysUsing((t: T) => hasValue(t) ? t.id : undefined);
|
||||
|
||||
/**
|
||||
* Fetch the relationships which match the type label given
|
||||
* @param {string} label Type label
|
||||
* @returns {(source: Observable<[Relationship[] , RelationshipType[]]>) => Observable<Relationship[]>}
|
||||
*/
|
||||
export const filterRelationsByTypeLabel = (label: string) =>
|
||||
(source: Observable<[Relationship[], RelationshipType[]]>): Observable<Relationship[]> =>
|
||||
source.pipe(
|
||||
map(([relsCurrentPage, relTypesCurrentPage]) =>
|
||||
relsCurrentPage.filter((rel: Relationship, idx: number) =>
|
||||
hasValue(relTypesCurrentPage[idx]) && (relTypesCurrentPage[idx].leftLabel === label ||
|
||||
relTypesCurrentPage[idx].rightLabel === label)
|
||||
)
|
||||
),
|
||||
distinctUntilChanged(compareArraysUsingIds())
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator for turning a list of relationships into a list of the relevant items
|
||||
* @param {string} thisId The item's id of which the relations belong to
|
||||
* @param {ItemDataService} ids The ItemDataService to fetch items from the REST API
|
||||
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
|
||||
*/
|
||||
export const relationsToItems = (thisId: string, ids: ItemDataService) =>
|
||||
(source: Observable<Relationship[]>): Observable<Item[]> =>
|
||||
source.pipe(
|
||||
flatMap((rels: Relationship[]) =>
|
||||
observableZip(
|
||||
...rels.map((rel: Relationship) => {
|
||||
let queryId = rel.leftId;
|
||||
if (rel.leftId === thisId) {
|
||||
queryId = rel.rightId;
|
||||
}
|
||||
return ids.findById(queryId);
|
||||
})
|
||||
)
|
||||
),
|
||||
map((arr: Array<RemoteData<Item>>) =>
|
||||
arr
|
||||
.filter((d: RemoteData<Item>) => d.hasSucceeded)
|
||||
.map((d: RemoteData<Item>) => d.payload)),
|
||||
distinctUntilChanged(compareArraysUsingIds()),
|
||||
);
|
||||
import { compareArraysUsingIds } from './item-relationships-utils';
|
||||
|
||||
/**
|
||||
* Operator for turning a list of relationships into a list of metadatarepresentations given the original metadata
|
||||
|
@@ -1,8 +1,6 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import * as viewMode from '../../../shared/view-mode';
|
||||
import { MetadataRepresentation } from '../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
|
||||
export const VIEW_MODE_METADATA = 'metadata';
|
||||
import { ItemViewMode } from '../../../shared/items/item-type-decorator';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-metadata-representation-list',
|
||||
@@ -27,5 +25,5 @@ export class MetadataRepresentationListComponent {
|
||||
* The view-mode we're currently on
|
||||
* @type {ElementViewMode}
|
||||
*/
|
||||
viewMode = VIEW_MODE_METADATA;
|
||||
viewMode = ItemViewMode.Metadata;
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
|
||||
export const VIEW_MODE_ELEMENT = 'element';
|
||||
import { ItemViewMode } from '../../../shared/items/item-type-decorator';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-related-items',
|
||||
@@ -27,5 +26,5 @@ export class RelatedItemsComponent {
|
||||
* The view-mode we're currently on
|
||||
* @type {ElementViewMode}
|
||||
*/
|
||||
viewMode = VIEW_MODE_ELEMENT;
|
||||
viewMode = ItemViewMode.Element;
|
||||
}
|
||||
|
@@ -3,7 +3,13 @@ import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angul
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
|
||||
/**
|
||||
* Assemble the correct i18n key for the filtered search page's title depending on the current route's filter parameter
|
||||
* and title data.
|
||||
* The format of the key will be "{title}{filter}.title" with:
|
||||
* - title: The prefix of the key stored in route.data
|
||||
* - filter: The current filter stored in route.params
|
||||
*/
|
||||
export class FilteredSearchPageGuard implements CanActivate {
|
||||
canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
|
@@ -289,76 +289,4 @@ describe('SearchFilterService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the getPaginatedSearchOptions method is called', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getCurrentPagination');
|
||||
spyOn(service, 'getCurrentSort');
|
||||
spyOn(service, 'getCurrentView');
|
||||
spyOn(service, 'getCurrentScope');
|
||||
spyOn(service, 'getCurrentQuery');
|
||||
spyOn(service, 'getCurrentFilters');
|
||||
spyOn(service, 'getCurrentFixedFilter');
|
||||
service.getPaginatedSearchOptions();
|
||||
});
|
||||
|
||||
it('should call getCurrentPagination to build the paginated search options', () => {
|
||||
expect(service.getCurrentPagination).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentSort to build the paginated search options', () => {
|
||||
expect(service.getCurrentSort).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentView to build the paginated search options', () => {
|
||||
expect(service.getCurrentView).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentScope to build the paginated search options', () => {
|
||||
expect(service.getCurrentScope).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentQuery to build the paginated search options', () => {
|
||||
expect(service.getCurrentQuery).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentFilters to build the paginated search options', () => {
|
||||
expect(service.getCurrentFilters).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentFixedFilter to build the paginated search options', () => {
|
||||
expect(service.getCurrentFixedFilter).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the getSearchOptions method is called', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getCurrentView');
|
||||
spyOn(service, 'getCurrentScope');
|
||||
spyOn(service, 'getCurrentQuery');
|
||||
spyOn(service, 'getCurrentFilters');
|
||||
spyOn(service, 'getCurrentFixedFilter');
|
||||
service.getPaginatedSearchOptions();
|
||||
});
|
||||
|
||||
it('should call getCurrentView to build the search options', () => {
|
||||
expect(service.getCurrentView).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentScope to build the search options', () => {
|
||||
expect(service.getCurrentScope).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentQuery to build the search options', () => {
|
||||
expect(service.getCurrentQuery).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentFilters to build the search options', () => {
|
||||
expect(service.getCurrentFilters).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call getCurrentFixedFilter to build the search options', () => {
|
||||
expect(service.getCurrentFixedFilter).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -131,63 +131,6 @@ export class SearchFilterService {
|
||||
return this.routeService.getQueryParameterValue('view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current paginated search options using the getters from above
|
||||
* and combining them with given defaults
|
||||
* @param defaults Default paginated search options
|
||||
* @returns {Observable<PaginatedSearchOptions>}
|
||||
*/
|
||||
getPaginatedSearchOptions(defaults: any = {}): Observable<PaginatedSearchOptions> {
|
||||
return observableCombineLatest(
|
||||
this.getCurrentPagination(defaults.pagination),
|
||||
this.getCurrentSort(defaults.sort),
|
||||
this.getCurrentView(),
|
||||
this.getCurrentScope(),
|
||||
this.getCurrentQuery(),
|
||||
this.getCurrentFilters(),
|
||||
this.getCurrentFixedFilter()).pipe(
|
||||
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
|
||||
map(([pagination, sort, view, scope, query, filters, fixedFilter]) => {
|
||||
return Object.assign(new PaginatedSearchOptions(defaults),
|
||||
{
|
||||
pagination: pagination,
|
||||
sort: sort,
|
||||
view: view,
|
||||
scope: scope || defaults.scope,
|
||||
query: query,
|
||||
filters: filters,
|
||||
fixedFilter: fixedFilter
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current search options (not paginated) using the getters from above
|
||||
* and combining them with given defaults
|
||||
* @param defaults Default search options
|
||||
* @returns {Observable<SearchOptions>}
|
||||
*/
|
||||
getSearchOptions(defaults: any = {}): Observable<SearchOptions> {
|
||||
return observableCombineLatest(
|
||||
this.getCurrentView(),
|
||||
this.getCurrentScope(),
|
||||
this.getCurrentQuery(),
|
||||
this.getCurrentFilters(),
|
||||
this.getCurrentFixedFilter(),
|
||||
(view, scope, query, filters, fixedFilter) => {
|
||||
return Object.assign(new SearchOptions(defaults),
|
||||
{
|
||||
view: view,
|
||||
scope: scope || defaults.scope,
|
||||
query: query,
|
||||
filters: filters,
|
||||
fixedFilter: fixedFilter
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the active filter values set for a given filter
|
||||
* @param {SearchFilterConfig} filterConfig The configuration for which the filters are active
|
||||
|
@@ -31,9 +31,26 @@ export class SearchResultsComponent {
|
||||
* The current configuration of the search
|
||||
*/
|
||||
@Input() searchConfig: SearchOptions;
|
||||
|
||||
/**
|
||||
* The current sorting configuration of the search
|
||||
*/
|
||||
@Input() sortConfig: SortOptions;
|
||||
|
||||
/**
|
||||
* The current view-mode of the list
|
||||
*/
|
||||
@Input() viewMode: SetViewMode;
|
||||
|
||||
/**
|
||||
* An optional fixed filter to filter the result on one type
|
||||
*/
|
||||
@Input() fixedFilter: string;
|
||||
|
||||
/**
|
||||
* Whether or not to hide the header of the results
|
||||
* Defaults to a visible header
|
||||
*/
|
||||
@Input() disableHeader = false;
|
||||
|
||||
/**
|
||||
|
@@ -73,6 +73,7 @@ export class SearchConfigurationService implements OnDestroy {
|
||||
/**
|
||||
* Initialize the search options
|
||||
* @param {RouteService} routeService
|
||||
* @param {SearchFixedFilterService} fixedFilterService
|
||||
* @param {ActivatedRoute} route
|
||||
*/
|
||||
constructor(private routeService: RouteService,
|
||||
|
@@ -1,9 +1,14 @@
|
||||
import { hasNoValue, hasValue } from '../empty.util';
|
||||
import { MetadataRepresentationType } from '../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { VIEW_MODE_ELEMENT } from '../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
export enum ItemViewMode {
|
||||
Element = 'element',
|
||||
Full = 'full',
|
||||
Metadata = 'metadata'
|
||||
}
|
||||
|
||||
export const DEFAULT_ITEM_TYPE = 'Default';
|
||||
export const DEFAULT_VIEW_MODE = VIEW_MODE_ELEMENT;
|
||||
export const DEFAULT_VIEW_MODE = ItemViewMode.Element;
|
||||
export const NO_REPRESENTATION_TYPE = MetadataRepresentationType.None;
|
||||
export const DEFAULT_REPRESENTATION_TYPE = MetadataRepresentationType.PlainText;
|
||||
|
||||
|
@@ -7,11 +7,9 @@ import { Item } from '../../../core/shared/item.model';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import * as decorator from '../item-type-decorator';
|
||||
import { getComponentByItemType } from '../item-type-decorator';
|
||||
import { getComponentByItemType, ItemViewMode } from '../item-type-decorator';
|
||||
import { ItemMetadataRepresentation } from '../../../core/shared/metadata-representation/item/item-metadata-representation.model';
|
||||
import createSpy = jasmine.createSpy;
|
||||
import { VIEW_MODE_FULL } from '../../../+item-page/simple/item-page.component';
|
||||
import { VIEW_MODE_METADATA } from '../../../+item-page/simple/metadata-representation-list/metadata-representation-list.component';
|
||||
|
||||
const relationType = 'type';
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
@@ -32,7 +30,7 @@ const mockItem: Item = Object.assign(new Item(), {
|
||||
}
|
||||
});
|
||||
const mockItemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(relationType), mockItem);
|
||||
let viewMode = VIEW_MODE_FULL;
|
||||
let viewMode = ItemViewMode.Full;
|
||||
|
||||
describe('ItemTypeSwitcherComponent', () => {
|
||||
let comp: ItemTypeSwitcherComponent;
|
||||
@@ -55,7 +53,7 @@ describe('ItemTypeSwitcherComponent', () => {
|
||||
|
||||
describe('when the injected object is of type Item', () => {
|
||||
beforeEach(() => {
|
||||
viewMode = VIEW_MODE_FULL;
|
||||
viewMode = ItemViewMode.Full;
|
||||
comp.object = mockItem;
|
||||
comp.viewMode = viewMode;
|
||||
});
|
||||
@@ -73,7 +71,7 @@ describe('ItemTypeSwitcherComponent', () => {
|
||||
|
||||
describe('when the injected object is of type MetadataRepresentation', () => {
|
||||
beforeEach(() => {
|
||||
viewMode = VIEW_MODE_METADATA;
|
||||
viewMode = ItemViewMode.Metadata;
|
||||
comp.object = mockItemMetadataRepresentation;
|
||||
comp.viewMode = viewMode;
|
||||
});
|
||||
|
@@ -4,7 +4,7 @@ import { Item } from '../../../core/shared/item.model';
|
||||
import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator';
|
||||
import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component';
|
||||
import { SetViewMode } from '../../view-mode';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../+item-page/simple/related-items/related-items-component';
|
||||
import { ItemViewMode } from '../../items/item-type-decorator';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-item-list-element',
|
||||
@@ -18,5 +18,5 @@ import { VIEW_MODE_ELEMENT } from '../../../+item-page/simple/related-items/rela
|
||||
*/
|
||||
@renderElementsFor(Item, SetViewMode.List)
|
||||
export class ItemListElementComponent extends AbstractListableElementComponent<Item> {
|
||||
viewMode = VIEW_MODE_ELEMENT;
|
||||
viewMode = ItemViewMode.Element;
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
@rendersItemType('JournalIssue', VIEW_MODE_ELEMENT)
|
||||
@rendersItemType('JournalIssue', ItemViewMode.Element)
|
||||
@Component({
|
||||
selector: 'ds-journal-issue-list-element',
|
||||
styleUrls: ['./journal-issue-list-element.component.scss'],
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
@rendersItemType('JournalVolume', VIEW_MODE_ELEMENT)
|
||||
@rendersItemType('JournalVolume', ItemViewMode.Element)
|
||||
@Component({
|
||||
selector: 'ds-journal-volume-list-element',
|
||||
styleUrls: ['./journal-volume-list-element.component.scss'],
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
@rendersItemType('Journal', VIEW_MODE_ELEMENT)
|
||||
@rendersItemType('Journal', ItemViewMode.Element)
|
||||
@Component({
|
||||
selector: 'ds-journal-list-element',
|
||||
styleUrls: ['./journal-list-element.component.scss'],
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
@rendersItemType('OrgUnit', VIEW_MODE_ELEMENT)
|
||||
@rendersItemType('OrgUnit', ItemViewMode.Element)
|
||||
@Component({
|
||||
selector: 'ds-orgunit-list-element',
|
||||
styleUrls: ['./orgunit-list-element.component.scss'],
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
@rendersItemType('Person', VIEW_MODE_ELEMENT)
|
||||
@rendersItemType('Person', ItemViewMode.Element)
|
||||
@Component({
|
||||
selector: 'ds-person-list-element',
|
||||
styleUrls: ['./person-list-element.component.scss'],
|
||||
|
@@ -1,10 +1,9 @@
|
||||
import { rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { Component } from '@angular/core';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { MetadataRepresentationType } from '../../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
|
||||
@rendersItemType('Person', VIEW_MODE_ELEMENT, MetadataRepresentationType.Item)
|
||||
@rendersItemType('Person', ItemViewMode.Element, MetadataRepresentationType.Item)
|
||||
@Component({
|
||||
selector: 'ds-person-metadata-list-element',
|
||||
templateUrl: './person-metadata-list-element.component.html'
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
@rendersItemType('Project', VIEW_MODE_ELEMENT)
|
||||
@rendersItemType('Project', ItemViewMode.Element)
|
||||
@Component({
|
||||
selector: 'ds-project-list-element',
|
||||
styleUrls: ['./project-list-element.component.scss'],
|
||||
|
@@ -1,10 +1,9 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { DEFAULT_ITEM_TYPE, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { DEFAULT_ITEM_TYPE, ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
|
||||
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../../+item-page/simple/related-items/related-items-component';
|
||||
|
||||
@rendersItemType('Publication', VIEW_MODE_ELEMENT)
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, VIEW_MODE_ELEMENT)
|
||||
@rendersItemType('Publication', ItemViewMode.Element)
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, ItemViewMode.Element)
|
||||
@Component({
|
||||
selector: 'ds-publication-list-element',
|
||||
styleUrls: ['./publication-list-element.component.scss'],
|
||||
|
@@ -1,12 +1,9 @@
|
||||
import * as viewMode from '../../../view-mode';
|
||||
import { MetadataRepresentationType } from '../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { Component } from '@angular/core';
|
||||
import { MetadataRepresentationListElementComponent } from '../metadata-representation-list-element.component';
|
||||
import { DEFAULT_ITEM_TYPE, rendersItemType } from '../../../items/item-type-decorator';
|
||||
import { VIEW_MODE_METADATA } from '../../../../+item-page/simple/metadata-representation-list/metadata-representation-list.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../+item-page/simple/related-items/related-items-component';
|
||||
import { DEFAULT_ITEM_TYPE, ItemViewMode, rendersItemType } from '../../../items/item-type-decorator';
|
||||
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, VIEW_MODE_METADATA, MetadataRepresentationType.Item)
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, ItemViewMode.Metadata, MetadataRepresentationType.Item)
|
||||
@Component({
|
||||
selector: 'ds-item-metadata-list-element',
|
||||
templateUrl: './item-metadata-list-element.component.html'
|
||||
@@ -21,5 +18,5 @@ export class ItemMetadataListElementComponent extends MetadataRepresentationList
|
||||
* The view-mode we're currently on
|
||||
* @type {ElementViewMode}
|
||||
*/
|
||||
viewMode = VIEW_MODE_ELEMENT;
|
||||
viewMode = ItemViewMode.Element;
|
||||
}
|
||||
|
@@ -1,12 +1,11 @@
|
||||
import { MetadataRepresentationType } from '../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { Component } from '@angular/core';
|
||||
import { MetadataRepresentationListElementComponent } from '../metadata-representation-list-element.component';
|
||||
import { DEFAULT_ITEM_TYPE, rendersItemType } from '../../../items/item-type-decorator';
|
||||
import { VIEW_MODE_METADATA } from '../../../../+item-page/simple/metadata-representation-list/metadata-representation-list.component';
|
||||
import { DEFAULT_ITEM_TYPE, ItemViewMode, rendersItemType } from '../../../items/item-type-decorator';
|
||||
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, VIEW_MODE_METADATA, MetadataRepresentationType.PlainText)
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, ItemViewMode.Metadata, MetadataRepresentationType.PlainText)
|
||||
// For now, authority controlled fields are rendered the same way as plain text fields
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, VIEW_MODE_METADATA, MetadataRepresentationType.AuthorityControlled)
|
||||
@rendersItemType(DEFAULT_ITEM_TYPE, ItemViewMode.Metadata, MetadataRepresentationType.AuthorityControlled)
|
||||
@Component({
|
||||
selector: 'ds-plain-text-metadata-list-element',
|
||||
templateUrl: './plain-text-metadata-list-element.component.html'
|
||||
|
@@ -6,7 +6,7 @@ import { renderElementsFor } from '../../../object-collection/shared/dso-element
|
||||
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
|
||||
import { SetViewMode } from '../../../view-mode';
|
||||
import { SearchResultListElementComponent } from '../search-result-list-element.component';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../../+item-page/simple/related-items/related-items-component';
|
||||
import { ItemViewMode } from '../../../items/item-type-decorator';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-item-search-result-list-element',
|
||||
@@ -18,5 +18,5 @@ import { VIEW_MODE_ELEMENT } from '../../../../+item-page/simple/related-items/r
|
||||
|
||||
@renderElementsFor(ItemSearchResult, SetViewMode.List)
|
||||
export class ItemSearchResultListElementComponent extends SearchResultListElementComponent<ItemSearchResult, Item> {
|
||||
viewMode = VIEW_MODE_ELEMENT;
|
||||
viewMode = ItemViewMode.Element;
|
||||
}
|
||||
|
Reference in New Issue
Block a user