fixed search service remote data pending observables

This commit is contained in:
William Welling
2017-10-04 16:15:39 -05:00
parent 45ca74410c
commit 05a9cb61bd
4 changed files with 26 additions and 14 deletions

View File

@@ -84,7 +84,6 @@ export class SearchPageComponent implements OnInit, OnDestroy {
private updateSearchResults(searchOptions) {
// Resolve search results
this.results = this.service.search(this.query, this.scope, searchOptions);
}
ngOnDestroy() {

View File

@@ -9,12 +9,10 @@ import { SearchOptions } from '../search-options.model';
* The route parameter 'id' is used to request the item it represents.
* All fields of the item that should be displayed, are defined in its template.
*/
@Component({
selector: 'ds-search-results',
templateUrl: './search-results.component.html',
})
export class SearchResultsComponent {
@Input() searchResults: RemoteData<Array<SearchResult<DSpaceObject>>>;
@Input() searchConfig: SearchOptions;

View File

@@ -1,15 +1,20 @@
import { Injectable } from '@angular/core';
import { RemoteData } from '../core/data/remote-data';
import { Observable } from 'rxjs/Observable';
import { SearchResult } from './search-result.model';
import { ItemDataService } from '../core/data/item-data.service';
import { PageInfo } from '../core/shared/page-info.model';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { DSpaceObject } from '../core/shared/dspace-object.model';
import { SearchOptions } from './search-options.model';
import { hasValue, isNotEmpty } from '../shared/empty.util';
import { Metadatum } from '../core/shared/metadatum.model';
import { Item } from '../core/shared/item.model';
import { ItemSearchResult } from '../object-list/search-result-list-element/item-search-result/item-search-result.model';
import { Metadatum } from '../core/shared/metadatum.model';
import { PageInfo } from '../core/shared/page-info.model';
import { RemoteData } from '../core/data/remote-data';
import { SearchOptions } from './search-options.model';
import { SearchResult } from './search-result.model';
import { ItemDataService } from '../core/data/item-data.service';
import { hasValue, isNotEmpty } from '../shared/empty.util';
function shuffle(array: any[]) {
let i = 0;
@@ -63,8 +68,12 @@ export class SearchService {
if (isNotEmpty(searchOptions) && hasValue(searchOptions.sort.field)) {
self += `&sortField=${searchOptions.sort.field}`;
}
const requestPending = Observable.of(false);
const responsePending = Observable.of(false);
const requestPendingSubject = new BehaviorSubject<boolean>(true);
const responsePendingSubject = new BehaviorSubject<boolean>(false);
const requestPending = requestPendingSubject.asObservable();
const responsePending = responsePendingSubject.asObservable();
const errorMessage = Observable.of(undefined);
const statusCode = Observable.of('200');
const returningPageInfo = new PageInfo();
@@ -101,6 +110,11 @@ export class SearchService {
});
});
itemsRD.hasSucceeded.subscribe((success: boolean) => {
requestPendingSubject.next(!success);
responsePendingSubject.next(!success);
});
return new RemoteData(
Observable.of(self),
requestPending,
@@ -112,4 +126,5 @@ export class SearchService {
payload
)
}
}

View File

@@ -14,6 +14,6 @@
<ds-wrapper-list-element [object]="object"></ds-wrapper-list-element>
</li>
</ul>
<ds-error *ngIf="objects.hasFailed | async" message="Error fetching list"></ds-error>
<ds-loading *ngIf="objects.isLoading | async" message="Loading list..."></ds-loading>
<ds-error *ngIf="objects.hasFailed | async" message="Error fetching"></ds-error>
<ds-loading *ngIf="objects.isLoading | async" message="Loading..."></ds-loading>
</ds-pagination>