-
-
+
+
+
+
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts
index 09929f1973..72c026e42e 100644
--- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts
+++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts
@@ -4,7 +4,6 @@ import { DsDynamicLookupRelationSearchTabComponent } from './dynamic-lookup-rela
import { SearchService } from '../../../../../../core/shared/search/search.service';
import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service';
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
-import { RouteService } from '../../../../../../core/services/route.service';
import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { VarDirective } from '../../../../../utils/var.directive';
@@ -15,13 +14,13 @@ import { createSuccessfulRemoteDataObject$ } from '../../../../../remote-data.ut
import { buildPaginatedList } from '../../../../../../core/data/paginated-list.model';
import { ItemSearchResult } from '../../../../../object-collection/shared/item-search-result.model';
import { Item } from '../../../../../../core/shared/item.model';
-import { ActivatedRoute } from '@angular/router';
import { LookupRelationService } from '../../../../../../core/data/lookup-relation.service';
import { PaginationService } from '../../../../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../../../../testing/pagination-service.stub';
import { RelationshipService } from '../../../../../../core/data/relationship.service';
import { relatedRelationships } from '../../../../../testing/related-relationships.mock';
import { RelationshipType } from '../../../../../../core/shared/item-relationships/relationship-type.model';
+import { SearchObjects } from '../../../../../search/models/search-objects.model';
describe('DsDynamicLookupRelationSearchTabComponent', () => {
@@ -41,6 +40,7 @@ describe('DsDynamicLookupRelationSearchTabComponent', () => {
let selection$;
let results;
+ let searchResult;
let selectableListService;
let lookupRelationService;
const relationshipService = jasmine.createSpyObj('searchByItemsAndType',{
@@ -79,6 +79,9 @@ describe('DsDynamicLookupRelationSearchTabComponent', () => {
selection$ = observableOf([searchResult1, searchResult2]);
results = buildPaginatedList(undefined, [searchResult1, searchResult2, searchResult3]);
+ searchResult = Object.assign(new SearchObjects(), {
+ page: [searchResult1, searchResult2, searchResult3]
+ });
selectableListService = jasmine.createSpyObj('selectableListService', ['deselect', 'select', 'deselectAll']);
lookupRelationService = jasmine.createSpyObj('lookupRelationService', {
getLocalResults: createSuccessfulRemoteDataObject$(results)
@@ -101,14 +104,6 @@ describe('DsDynamicLookupRelationSearchTabComponent', () => {
paginatedSearchOptions: observableOf(pSearchOptions)
}
},
- {
- provide: RouteService, useValue: {
- setParameter: () => {
- // do nothing
- }
- }
- },
- { provide: ActivatedRoute, useValue: { snapshot: { queryParams: {} } } },
{ provide: LookupRelationService, useValue: lookupRelationService },
{ provide: PaginationService, useValue: new PaginationServiceStub() },
{ provide: RelationshipService, useValue: relationshipService }
@@ -186,6 +181,7 @@ describe('DsDynamicLookupRelationSearchTabComponent', () => {
describe('check searchByItemsAndType', () => {
it('should call relationshipService.searchByItemsAndType', () => {
+ component.onResultFound(searchResult);
expect(relationshipService.searchByItemsAndType).toHaveBeenCalled();
});
});
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts
index 23dd97601e..5a6b07fd44 100644
--- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts
+++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts
@@ -4,18 +4,15 @@ import { SearchConfigurationService } from '../../../../../../core/shared/search
import { Item } from '../../../../../../core/shared/item.model';
import { SearchResult } from '../../../../../search/models/search-result.model';
import { PaginatedList } from '../../../../../../core/data/paginated-list.model';
-import { RemoteData } from '../../../../../../core/data/remote-data';
import { Observable } from 'rxjs';
import { RelationshipOptions } from '../../../models/relationship-options.model';
import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model';
import { ListableObject } from '../../../../../object-collection/shared/listable-object.model';
import { SearchService } from '../../../../../../core/shared/search/search.service';
-import { ActivatedRoute, Router } from '@angular/router';
import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service';
import { hasValue } from '../../../../../empty.util';
-import { map, mapTo, startWith, switchMap, take, tap } from 'rxjs/operators';
+import { map, mapTo, switchMap, take, tap } from 'rxjs/operators';
import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../../../../core/shared/operators';
-import { RouteService } from '../../../../../../core/services/route.service';
import { CollectionElementLinkType } from '../../../../../object-collection/collection-element-link.type';
import { Context } from '../../../../../../core/shared/context.model';
import { LookupRelationService } from '../../../../../../core/data/lookup-relation.service';
@@ -24,6 +21,9 @@ import { RelationshipService } from '../../../../../../core/data/relationship.se
import { RelationshipType } from '../../../../../../core/shared/item-relationships/relationship-type.model';
import { Relationship } from '../../../../../../core/shared/item-relationships/relationship.model';
+import { SearchObjects } from '../../../../../search/models/search-objects.model';
+import { DSpaceObject } from '../../../../../../core/shared/dspace-object.model';
+import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
@Component({
@@ -107,7 +107,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
/**
* Search results
*/
- resultsRD$: Observable
>>>;
+ resultsRD$: BehaviorSubject> = new BehaviorSubject>(null);
/**
* Are all results selected?
@@ -142,13 +142,15 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
*/
linkTypes = CollectionElementLinkType;
+ /**
+ * Emits an event with the current search result entries
+ */
+ @Output() resultFound: EventEmitter> = new EventEmitter>();
+
constructor(
private searchService: SearchService,
- private router: Router,
- private route: ActivatedRoute,
private selectableListService: SelectableListService,
public searchConfigService: SearchConfigurationService,
- private routeService: RouteService,
public lookupRelationService: LookupRelationService,
private relationshipService: RelationshipService,
private paginationService: PaginationService
@@ -160,21 +162,6 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
*/
ngOnInit(): void {
this.resetRoute();
- this.routeService.setParameter('fixedFilterQuery', this.relationship.filter);
- this.routeService.setParameter('configuration', this.relationship.searchConfiguration);
- this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe(
- switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(
- tap( res => {
- if ( !!res && res.hasSucceeded && this.isEditRelationship ) {
- const idOfItems = res.payload.page.map( itemSearchResult => {
- return itemSearchResult.indexableObject.uuid;
- });
- this.setSelectedIds(idOfItems,res.payload.page);
- }
- }),
- startWith(undefined),
- ))
- );
}
/**
@@ -188,7 +175,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
* Selects a page in the store
* @param page The page to select
*/
- selectPage(page: SearchResult- []) {
+ selectPage(page: SearchResult[]) {
this.selection$
.pipe(take(1))
.subscribe((selection: SearchResult
- []) => {
@@ -202,7 +189,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
* Deselects a page in the store
* @param page the page to deselect
*/
- deselectPage(page: SearchResult
- []) {
+ deselectPage(page: SearchResult[]) {
this.allSelected = false;
this.selection$
.pipe(take(1))
@@ -306,4 +293,16 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
this.subscription.unsubscribe();
}
}
+
+ onResultFound($event: SearchObjects) {
+ console.log($event);
+ this.resultsRD$.next($event);
+ this.resultFound.emit($event);
+ if (this.isEditRelationship ) {
+ const idOfItems = $event.page.map( itemSearchResult => {
+ return itemSearchResult.indexableObject.uuid;
+ });
+ this.setSelectedIds(idOfItems, $event);
+ }
+ }
}