Skip to content
Snippets Groups Projects
Commit 55e37a63 authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

55946: discovery requests reset and reload and list updates

parent 4307cb0f
Branches
Tags
No related merge requests found
...@@ -8,7 +8,7 @@ import { Collection } from '../../core/shared/collection.model'; ...@@ -8,7 +8,7 @@ import { Collection } from '../../core/shared/collection.model';
import { SearchConfigurationService } from '../../+search-page/search-service/search-configuration.service'; import { SearchConfigurationService } from '../../+search-page/search-service/search-configuration.service';
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model'; import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
import { PaginatedList } from '../../core/data/paginated-list'; import { PaginatedList } from '../../core/data/paginated-list';
import { map, switchMap, take } from 'rxjs/operators'; import { map, switchMap, take, tap } from 'rxjs/operators';
import { getSucceededRemoteData, toDSpaceObjectListRD } from '../../core/shared/operators'; import { getSucceededRemoteData, toDSpaceObjectListRD } from '../../core/shared/operators';
import { SearchService } from '../../+search-page/search-service/search.service'; import { SearchService } from '../../+search-page/search-service/search.service';
import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model';
...@@ -20,6 +20,10 @@ import { TranslateService } from '@ngx-translate/core'; ...@@ -20,6 +20,10 @@ import { TranslateService } from '@ngx-translate/core';
import { CollectionDataService } from '../../core/data/collection-data.service'; import { CollectionDataService } from '../../core/data/collection-data.service';
import { isNotEmpty } from '../../shared/empty.util'; import { isNotEmpty } from '../../shared/empty.util';
import { RestResponse } from '../../core/cache/response.models'; import { RestResponse } from '../../core/cache/response.models';
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
import { Actions, ofType } from '@ngrx/effects';
import { IndexActionTypes } from '../../core/index/index.actions';
import { RequestActionTypes } from '../../core/data/request.actions';
@Component({ @Component({
selector: 'ds-collection-item-mapper', selector: 'ds-collection-item-mapper',
...@@ -64,6 +68,8 @@ export class CollectionItemMapperComponent implements OnInit { ...@@ -64,6 +68,8 @@ export class CollectionItemMapperComponent implements OnInit {
*/ */
defaultSortOptions: SortOptions = new SortOptions('dc.title', SortDirection.ASC); defaultSortOptions: SortOptions = new SortOptions('dc.title', SortDirection.ASC);
shouldUpdate$: BehaviorSubject<boolean>;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private router: Router, private router: Router,
private searchConfigService: SearchConfigurationService, private searchConfigService: SearchConfigurationService,
...@@ -86,25 +92,31 @@ export class CollectionItemMapperComponent implements OnInit { ...@@ -86,25 +92,31 @@ export class CollectionItemMapperComponent implements OnInit {
* TODO: When the API support it, fetch items excluding the collection's scope (currently fetches all items) * TODO: When the API support it, fetch items excluding the collection's scope (currently fetches all items)
*/ */
loadItemLists() { loadItemLists() {
this.shouldUpdate$ = new BehaviorSubject<boolean>(true);
const collectionAndOptions$ = observableCombineLatest( const collectionAndOptions$ = observableCombineLatest(
this.collectionRD$, this.collectionRD$,
this.searchOptions$ this.searchOptions$,
this.shouldUpdate$
); );
this.collectionItemsRD$ = collectionAndOptions$.pipe( this.collectionItemsRD$ = collectionAndOptions$.pipe(
switchMap(([collectionRD, options]) => { switchMap(([collectionRD, options, shouldUpdate]) => {
return this.collectionDataService.getMappedItems(collectionRD.payload.id, Object.assign(options, { if (shouldUpdate) {
sort: this.defaultSortOptions return this.collectionDataService.getMappedItems(collectionRD.payload.id, Object.assign(options, {
})) sort: this.defaultSortOptions
}))
}
}) })
); );
this.mappingItemsRD$ = collectionAndOptions$.pipe( this.mappingItemsRD$ = collectionAndOptions$.pipe(
switchMap(([collectionRD, options]) => { switchMap(([collectionRD, options, shouldUpdate]) => {
return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), { if (shouldUpdate) {
query: this.buildQuery(collectionRD.payload.id, options.query), return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), {
scope: undefined, query: this.buildQuery(collectionRD.payload.id, options.query),
dsoType: DSpaceObjectType.ITEM, scope: undefined,
sort: this.defaultSortOptions dsoType: DSpaceObjectType.ITEM,
})); sort: this.defaultSortOptions
}));
}
}), }),
toDSpaceObjectListRD() toDSpaceObjectListRD()
); );
...@@ -151,10 +163,12 @@ export class CollectionItemMapperComponent implements OnInit { ...@@ -151,10 +163,12 @@ export class CollectionItemMapperComponent implements OnInit {
this.notificationsService.error(head, content); this.notificationsService.error(head, content);
}); });
} }
this.shouldUpdate$.next(true);
}); });
this.collectionRD$.pipe(take(1)).subscribe((collectionRD: RemoteData<Collection>) => { this.collectionRD$.pipe(take(1)).subscribe((collectionRD: RemoteData<Collection>) => {
this.collectionDataService.clearMappingItemsRequests(collectionRD.payload.id); this.collectionDataService.clearMappingItemsRequests(collectionRD.payload.id);
this.searchService.clearDiscoveryRequests();
}); });
} }
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
Router, Router,
UrlSegmentGroup UrlSegmentGroup
} from '@angular/router'; } from '@angular/router';
import { map, switchMap, tap } from 'rxjs/operators'; import { map, switchMap, take, tap } from 'rxjs/operators';
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
import { import {
FacetConfigSuccessResponse, FacetConfigSuccessResponse,
...@@ -47,6 +47,9 @@ import { CommunityDataService } from '../../core/data/community-data.service'; ...@@ -47,6 +47,9 @@ import { CommunityDataService } from '../../core/data/community-data.service';
import { ViewMode } from '../../core/shared/view-mode.model'; import { ViewMode } from '../../core/shared/view-mode.model';
import { ResourceType } from '../../core/shared/resource-type'; import { ResourceType } from '../../core/shared/resource-type';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service'; import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
import { Store } from '@ngrx/store';
import { IndexName, IndexState } from '../../core/index/index.reducer';
import { RemoveFromIndexBySubstringAction } from '../../core/index/index.actions';
/** /**
* Service that performs all general actions that have to do with the search page * Service that performs all general actions that have to do with the search page
...@@ -319,6 +322,12 @@ export class SearchService implements OnDestroy { ...@@ -319,6 +322,12 @@ export class SearchService implements OnDestroy {
return '/' + g.toString(); return '/' + g.toString();
} }
clearDiscoveryRequests() {
this.halService.getEndpoint(this.searchLinkPath).pipe(take(1)).subscribe((href: string) => {
this.requestService.removeByHrefSubstring(href);
});
}
/** /**
* Unsubscribe from the subscription * Unsubscribe from the subscription
*/ */
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
} from 'rxjs'; } from 'rxjs';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { distinctUntilChanged, first, flatMap, map, startWith, switchMap } from 'rxjs/operators'; import { distinctUntilChanged, first, flatMap, map, startWith, switchMap } from 'rxjs/operators';
import { hasValue, hasValueOperator, isEmpty, isNotEmpty } from '../../../shared/empty.util'; import { hasValue, hasValueOperator, isEmpty, isNotEmpty, isNotEmptyOperator } from '../../../shared/empty.util';
import { PaginatedList } from '../../data/paginated-list'; import { PaginatedList } from '../../data/paginated-list';
import { RemoteData } from '../../data/remote-data'; import { RemoteData } from '../../data/remote-data';
import { RemoteDataError } from '../../data/remote-data-error'; import { RemoteDataError } from '../../data/remote-data-error';
...@@ -86,8 +86,8 @@ export class RemoteDataBuildService { ...@@ -86,8 +86,8 @@ export class RemoteDataBuildService {
toRemoteDataObservable<T>(requestEntry$: Observable<RequestEntry>, payload$: Observable<T>) { toRemoteDataObservable<T>(requestEntry$: Observable<RequestEntry>, payload$: Observable<T>) {
return observableCombineLatest(requestEntry$, payload$).pipe( return observableCombineLatest(requestEntry$, payload$).pipe(
map(([reqEntry, payload]) => { map(([reqEntry, payload]) => {
const requestPending = hasValue(reqEntry.requestPending) ? reqEntry.requestPending : true; const requestPending = hasValue(reqEntry) && hasValue(reqEntry.requestPending) ? reqEntry.requestPending : true;
const responsePending = hasValue(reqEntry.responsePending) ? reqEntry.responsePending : false; const responsePending = hasValue(reqEntry) && hasValue(reqEntry.responsePending) ? reqEntry.responsePending : false;
let isSuccessful: boolean; let isSuccessful: boolean;
let error: RemoteDataError; let error: RemoteDataError;
if (hasValue(reqEntry) && hasValue(reqEntry.response)) { if (hasValue(reqEntry) && hasValue(reqEntry.response)) {
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { MemoizedSelector, select, Store } from '@ngrx/store'; import { Action, Store } from '@ngrx/store';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedCollection } from '../cache/models/normalized-collection.model'; import { NormalizedCollection } from '../cache/models/normalized-collection.model';
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { coreSelector, CoreState } from '../core.reducers'; import { CoreState } from '../core.reducers';
import { Collection } from '../shared/collection.model'; import { Collection } from '../shared/collection.model';
import { ComColDataService } from './comcol-data.service'; import { ComColDataService } from './comcol-data.service';
import { CommunityDataService } from './community-data.service'; import { CommunityDataService } from './community-data.service';
...@@ -12,7 +12,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service'; ...@@ -12,7 +12,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { RemoteData } from './remote-data'; import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list'; import { PaginatedList } from './paginated-list';
import { distinctUntilChanged, map, mergeMap, switchMap, take } from 'rxjs/operators'; import { distinctUntilChanged, map, take, tap } from 'rxjs/operators';
import { hasValue, isNotEmptyOperator } from '../../shared/empty.util'; import { hasValue, isNotEmptyOperator } from '../../shared/empty.util';
import { GetRequest } from './request.models'; import { GetRequest } from './request.models';
import { configureRequest } from '../shared/operators'; import { configureRequest } from '../shared/operators';
...@@ -22,9 +22,8 @@ import { ResponseParsingService } from './parsing.service'; ...@@ -22,9 +22,8 @@ import { ResponseParsingService } from './parsing.service';
import { DSpaceObject } from '../shared/dspace-object.model'; import { DSpaceObject } from '../shared/dspace-object.model';
import { DSOResponseParsingService } from './dso-response-parsing.service'; import { DSOResponseParsingService } from './dso-response-parsing.service';
import { IndexName, IndexState } from '../index/index.reducer'; import { IndexName, IndexState } from '../index/index.reducer';
import { RemoveFromIndexBySubstringAction } from '../index/index.actions'; import { IndexActionTypes, RemoveFromIndexBySubstringAction } from '../index/index.actions';
import { pathSelector } from '../shared/selectors'; import { Actions, ofType } from '@ngrx/effects';
import { RequestState } from './request.reducer';
@Injectable() @Injectable()
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> { export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
...@@ -50,6 +49,8 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio ...@@ -50,6 +49,8 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
} }
getMappedItems(collectionId: string, searchOptions?: PaginatedSearchOptions): Observable<RemoteData<PaginatedList<DSpaceObject>>> { getMappedItems(collectionId: string, searchOptions?: PaginatedSearchOptions): Observable<RemoteData<PaginatedList<DSpaceObject>>> {
const requestUuid = this.requestService.generateRequestId();
const href$ = this.getMappingItemsEndpoint(collectionId).pipe( const href$ = this.getMappingItemsEndpoint(collectionId).pipe(
isNotEmptyOperator(), isNotEmptyOperator(),
distinctUntilChanged(), distinctUntilChanged(),
...@@ -58,7 +59,7 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio ...@@ -58,7 +59,7 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
href$.pipe( href$.pipe(
map((endpoint: string) => { map((endpoint: string) => {
const request = new GetRequest(this.requestService.generateRequestId(), endpoint); const request = new GetRequest(requestUuid, endpoint);
return Object.assign(request, { return Object.assign(request, {
getResponseParser(): GenericConstructor<ResponseParsingService> { getResponseParser(): GenericConstructor<ResponseParsingService> {
return DSOResponseParsingService; return DSOResponseParsingService;
...@@ -74,7 +75,6 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio ...@@ -74,7 +75,6 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
clearMappingItemsRequests(collectionId: string) { clearMappingItemsRequests(collectionId: string) {
this.getMappingItemsEndpoint(collectionId).pipe(take(1)).subscribe((href: string) => { this.getMappingItemsEndpoint(collectionId).pipe(take(1)).subscribe((href: string) => {
this.requestService.removeByHrefSubstring(href); this.requestService.removeByHrefSubstring(href);
this.indexStore.dispatch(new RemoveFromIndexBySubstringAction(IndexName.REQUEST, href));
}); });
} }
......
import { distinctUntilChanged, map, filter, switchMap } from 'rxjs/operators'; import { distinctUntilChanged, map, filter, switchMap, tap } from 'rxjs/operators';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
...@@ -21,6 +21,7 @@ import { configureRequest, filterSuccessfulResponses, getResponseFromEntry } fro ...@@ -21,6 +21,7 @@ import { configureRequest, filterSuccessfulResponses, getResponseFromEntry } fro
import { RemoteData } from './remote-data'; import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list'; import { PaginatedList } from './paginated-list';
import { Collection } from '../shared/collection.model'; import { Collection } from '../shared/collection.model';
import { RequestEntry } from './request.reducer';
@Injectable() @Injectable()
export class ItemDataService extends DataService<NormalizedItem, Item> { export class ItemDataService extends DataService<NormalizedItem, Item> {
...@@ -66,7 +67,7 @@ export class ItemDataService extends DataService<NormalizedItem, Item> { ...@@ -66,7 +67,7 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
distinctUntilChanged(), distinctUntilChanged(),
map((endpointURL: string) => new DeleteRequest(this.requestService.generateRequestId(), endpointURL)), map((endpointURL: string) => new DeleteRequest(this.requestService.generateRequestId(), endpointURL)),
configureRequest(this.requestService), configureRequest(this.requestService),
switchMap((request: RestRequest) => this.requestService.getByHref(request.href)), switchMap((request: RestRequest) => this.requestService.getByUUID(request.uuid)),
getResponseFromEntry() getResponseFromEntry()
); );
} }
...@@ -77,7 +78,7 @@ export class ItemDataService extends DataService<NormalizedItem, Item> { ...@@ -77,7 +78,7 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
distinctUntilChanged(), distinctUntilChanged(),
map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL)), map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL)),
configureRequest(this.requestService), configureRequest(this.requestService),
switchMap((request: RestRequest) => this.requestService.getByHref(request.href)), switchMap((request: RestRequest) => this.requestService.getByUUID(request.uuid)),
getResponseFromEntry() getResponseFromEntry()
); );
} }
......
...@@ -31,7 +31,7 @@ import { RequestEntry } from './request.reducer'; ...@@ -31,7 +31,7 @@ import { RequestEntry } from './request.reducer';
import { CommitSSBAction } from '../cache/server-sync-buffer.actions'; import { CommitSSBAction } from '../cache/server-sync-buffer.actions';
import { RestRequestMethod } from './rest-request-method'; import { RestRequestMethod } from './rest-request-method';
import { getResponseFromEntry } from '../shared/operators'; import { getResponseFromEntry } from '../shared/operators';
import { AddToIndexAction } from '../index/index.actions'; import { AddToIndexAction, RemoveFromIndexBySubstringAction } from '../index/index.actions';
@Injectable() @Injectable()
export class RequestService { export class RequestService {
...@@ -39,7 +39,8 @@ export class RequestService { ...@@ -39,7 +39,8 @@ export class RequestService {
constructor(private objectCache: ObjectCacheService, constructor(private objectCache: ObjectCacheService,
private uuidService: UUIDService, private uuidService: UUIDService,
private store: Store<CoreState>) { private store: Store<CoreState>,
private indexStore: Store<IndexState>) {
} }
private entryFromUUIDSelector(uuid: string): MemoizedSelector<CoreState, RequestEntry> { private entryFromUUIDSelector(uuid: string): MemoizedSelector<CoreState, RequestEntry> {
...@@ -138,22 +139,17 @@ export class RequestService { ...@@ -138,22 +139,17 @@ export class RequestService {
} }
} }
removeByHref(href: string) {
this.store.pipe(
select(this.uuidFromHrefSelector(href))
).subscribe((uuid: string) => {
this.removeByUuid(uuid);
});
}
removeByHrefSubstring(href: string) { removeByHrefSubstring(href: string) {
this.store.pipe( this.store.pipe(
select(this.uuidsFromHrefSubstringSelector(pathSelector<CoreState, IndexState>(coreSelector, 'index'), IndexName.REQUEST, href)) select(this.uuidsFromHrefSubstringSelector(pathSelector<CoreState, IndexState>(coreSelector, 'index'), IndexName.REQUEST, href)),
take(1)
).subscribe((uuids: string[]) => { ).subscribe((uuids: string[]) => {
for (const uuid of uuids) { for (const uuid of uuids) {
this.removeByUuid(uuid); this.removeByUuid(uuid);
} }
}); });
this.requestsOnTheirWayToTheStore = this.requestsOnTheirWayToTheStore.filter((reqHref: string) => reqHref.indexOf(href) < 0);
this.indexStore.dispatch(new RemoveFromIndexBySubstringAction(IndexName.REQUEST, href));
} }
removeByUuid(uuid: string) { removeByUuid(uuid: string) {
......
...@@ -77,7 +77,6 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { ...@@ -77,7 +77,6 @@ export class ObjectCollectionComponent implements OnChanges, OnInit {
this.currentMode = params.view; this.currentMode = params.view;
} }
}); });
console.log(this.objects);
} }
/** /**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment