forked from hazza/dspace-angular
fixed search service remote data pending observables
This commit is contained in:
@@ -84,7 +84,6 @@ export class SearchPageComponent implements OnInit, OnDestroy {
|
|||||||
private updateSearchResults(searchOptions) {
|
private updateSearchResults(searchOptions) {
|
||||||
// Resolve search results
|
// Resolve search results
|
||||||
this.results = this.service.search(this.query, this.scope, searchOptions);
|
this.results = this.service.search(this.query, this.scope, searchOptions);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
@@ -9,12 +9,10 @@ import { SearchOptions } from '../search-options.model';
|
|||||||
* The route parameter 'id' is used to request the item it represents.
|
* 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.
|
* All fields of the item that should be displayed, are defined in its template.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-search-results',
|
selector: 'ds-search-results',
|
||||||
templateUrl: './search-results.component.html',
|
templateUrl: './search-results.component.html',
|
||||||
})
|
})
|
||||||
|
|
||||||
export class SearchResultsComponent {
|
export class SearchResultsComponent {
|
||||||
@Input() searchResults: RemoteData<Array<SearchResult<DSpaceObject>>>;
|
@Input() searchResults: RemoteData<Array<SearchResult<DSpaceObject>>>;
|
||||||
@Input() searchConfig: SearchOptions;
|
@Input() searchConfig: SearchOptions;
|
||||||
|
@@ -1,15 +1,20 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { RemoteData } from '../core/data/remote-data';
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { SearchResult } from './search-result.model';
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||||
import { ItemDataService } from '../core/data/item-data.service';
|
|
||||||
import { PageInfo } from '../core/shared/page-info.model';
|
|
||||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
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 { Item } from '../core/shared/item.model';
|
||||||
import { ItemSearchResult } from '../object-list/search-result-list-element/item-search-result/item-search-result.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[]) {
|
function shuffle(array: any[]) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
@@ -63,8 +68,12 @@ export class SearchService {
|
|||||||
if (isNotEmpty(searchOptions) && hasValue(searchOptions.sort.field)) {
|
if (isNotEmpty(searchOptions) && hasValue(searchOptions.sort.field)) {
|
||||||
self += `&sortField=${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 errorMessage = Observable.of(undefined);
|
||||||
const statusCode = Observable.of('200');
|
const statusCode = Observable.of('200');
|
||||||
const returningPageInfo = new PageInfo();
|
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(
|
return new RemoteData(
|
||||||
Observable.of(self),
|
Observable.of(self),
|
||||||
requestPending,
|
requestPending,
|
||||||
@@ -112,4 +126,5 @@ export class SearchService {
|
|||||||
payload
|
payload
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,6 @@
|
|||||||
<ds-wrapper-list-element [object]="object"></ds-wrapper-list-element>
|
<ds-wrapper-list-element [object]="object"></ds-wrapper-list-element>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ds-error *ngIf="objects.hasFailed | async" message="Error fetching list"></ds-error>
|
<ds-error *ngIf="objects.hasFailed | async" message="Error fetching"></ds-error>
|
||||||
<ds-loading *ngIf="objects.isLoading | async" message="Loading list..."></ds-loading>
|
<ds-loading *ngIf="objects.isLoading | async" message="Loading..."></ds-loading>
|
||||||
</ds-pagination>
|
</ds-pagination>
|
||||||
|
Reference in New Issue
Block a user