mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 20:43:08 +00:00
fixed issue where the search results would reload when the search method was triggered from somewhere else
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { flatMap, map, tap, } from 'rxjs/operators';
|
import { flatMap, } from 'rxjs/operators';
|
||||||
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
||||||
import { CommunityDataService } from '../core/data/community-data.service';
|
|
||||||
import { PaginatedList } from '../core/data/paginated-list';
|
import { PaginatedList } from '../core/data/paginated-list';
|
||||||
import { RemoteData } from '../core/data/remote-data';
|
import { RemoteData } from '../core/data/remote-data';
|
||||||
import { Community } from '../core/shared/community.model';
|
|
||||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
||||||
import { pushInOut } from '../shared/animations/push';
|
import { pushInOut } from '../shared/animations/push';
|
||||||
import { HostWindowService } from '../shared/host-window.service';
|
import { HostWindowService } from '../shared/host-window.service';
|
||||||
@@ -14,6 +12,9 @@ import { SearchFilterService } from './search-filters/search-filter/search-filte
|
|||||||
import { SearchResult } from './search-result.model';
|
import { SearchResult } from './search-result.model';
|
||||||
import { SearchService } from './search-service/search.service';
|
import { SearchService } from './search-service/search.service';
|
||||||
import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
|
import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
|
||||||
|
import { Subject } from 'rxjs/Subject';
|
||||||
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
import { hasValue } from '../shared/empty.util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component renders a simple item page.
|
* This component renders a simple item page.
|
||||||
@@ -30,7 +31,7 @@ import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
|
|||||||
})
|
})
|
||||||
export class SearchPageComponent implements OnInit {
|
export class SearchPageComponent implements OnInit {
|
||||||
|
|
||||||
resultsRD$: Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>;
|
resultsRD$: Subject<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> = new Subject();
|
||||||
searchOptions$: Observable<PaginatedSearchOptions>;
|
searchOptions$: Observable<PaginatedSearchOptions>;
|
||||||
sortConfig: SortOptions;
|
sortConfig: SortOptions;
|
||||||
scopeListRD$: Observable<DSpaceObject[]>;
|
scopeListRD$: Observable<DSpaceObject[]>;
|
||||||
@@ -46,6 +47,7 @@ export class SearchPageComponent implements OnInit {
|
|||||||
query: '',
|
query: '',
|
||||||
scope: ''
|
scope: ''
|
||||||
};
|
};
|
||||||
|
sub: Subscription;
|
||||||
|
|
||||||
constructor(private service: SearchService,
|
constructor(private service: SearchService,
|
||||||
private sidebarService: SearchSidebarService,
|
private sidebarService: SearchSidebarService,
|
||||||
@@ -56,11 +58,10 @@ export class SearchPageComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.searchOptions$ = this.filterService.getPaginatedSearchOptions(this.defaults);
|
this.searchOptions$ = this.filterService.getPaginatedSearchOptions(this.defaults);
|
||||||
this.resultsRD$ = this.searchOptions$.pipe(
|
this.sub = this.searchOptions$.subscribe((searchOptions) =>
|
||||||
flatMap((searchOptions) =>
|
this.service.search(searchOptions).first().subscribe((results) => this.resultsRD$.next(results))
|
||||||
this.service.search(searchOptions)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scopeListRD$ = this.filterService.getCurrentScope().pipe(
|
this.scopeListRD$ = this.filterService.getCurrentScope().pipe(
|
||||||
flatMap((scopeId) => this.service.getScopes(scopeId))
|
flatMap((scopeId) => this.service.getScopes(scopeId))
|
||||||
);
|
);
|
||||||
@@ -81,4 +82,10 @@ export class SearchPageComponent implements OnInit {
|
|||||||
public getSearchLink(): string {
|
public getSearchLink(): string {
|
||||||
return this.service.getSearchLink();
|
return this.service.getSearchLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
if (hasValue(this.sub)) {
|
||||||
|
this.sub.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user