diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts index 8fca66ea79..1915a8ce64 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts @@ -38,7 +38,7 @@ export class TopLevelCommunityListComponent { } updatePage(data) { - this.communitiesRDObs = this.cds.findAll({ + this.communitiesRDObs = this.cds.findTop({ currentPage: data.page, elementsPerPage: data.pageSize, sort: { field: data.sortField, direction: data.sortDirection } diff --git a/src/app/+search-page/search-page.component.html b/src/app/+search-page/search-page.component.html index 6aa3e92bf3..341bc7ff25 100644 --- a/src/app/+search-page/search-page.component.html +++ b/src/app/+search-page/search-page.component.html @@ -8,7 +8,7 @@ [query]="(searchOptions$ | async)?.query" [scope]="(searchOptions$ | async)?.scope" [currentUrl]="getSearchLink()" - [scopes]="(scopeListRD$ | async)?.payload?.page"> + [scopes]="(scopeListRD$ | async)">
diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 63e72960d8..118a2de071 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { flatMap, } from 'rxjs/operators'; +import { flatMap, map, tap, } from 'rxjs/operators'; 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'; @@ -33,7 +33,7 @@ export class SearchPageComponent implements OnInit { resultsRD$: Observable>>>; searchOptions$: Observable; sortConfig: SortOptions; - scopeListRD$: Observable>>; + scopeListRD$: Observable; isXsOrSm$: Observable; pageSize; pageSizeOptions; @@ -48,19 +48,22 @@ export class SearchPageComponent implements OnInit { }; constructor(private service: SearchService, - private communityService: CommunityDataService, private sidebarService: SearchSidebarService, private windowService: HostWindowService, private filterService: SearchFilterService) { this.isXsOrSm$ = this.windowService.isXsOrSm(); - this.scopeListRD$ = communityService.findAll(); } ngOnInit(): void { this.searchOptions$ = this.filterService.getPaginatedSearchOptions(this.defaults); this.resultsRD$ = this.searchOptions$.pipe( - flatMap((searchOptions) => this.service.search(searchOptions)) + flatMap((searchOptions) => + this.service.search(searchOptions) + ) ); + this.scopeListRD$ = this.filterService.getCurrentScope().pipe( + flatMap((scopeId) => this.service.getScopes(scopeId)) + ) } public closeSidebar(): void { diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index e27b43597b..a2b29e17ca 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -4,7 +4,7 @@ import { UrlSegmentGroup } from '@angular/router'; import { Observable } from 'rxjs/Observable'; -import { flatMap, map, tap } from 'rxjs/operators'; +import { filter, flatMap, map, tap } from 'rxjs/operators'; import { ViewMode } from '../../+search-page/search-options.model'; import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service'; import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; @@ -25,7 +25,7 @@ import { GenericConstructor } from '../../core/shared/generic-constructor'; import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; import { configureRequest } from '../../core/shared/operators'; import { URLCombiner } from '../../core/url-combiner/url-combiner'; -import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; +import { hasNoValue, hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { NormalizedSearchResult } from '../normalized-search-result.model'; import { SearchOptions } from '../search-options.model'; @@ -42,6 +42,10 @@ import { FacetConfigResponseParsingService } from '../../core/data/facet-config- import { PaginatedSearchOptions } from '../paginated-search-options.model'; import { FilterLabel } from './filter-label.model'; import { combineLatest } from 'rxjs/observable/combineLatest'; +import { Community } from '../../core/shared/community.model'; +import { CommunityDataService } from '../../core/data/community-data.service'; +import { CollectionDataService } from '../../core/data/collection-data.service'; +import { Collection } from '../../core/shared/collection.model'; @Injectable() export class SearchService implements OnDestroy { @@ -58,7 +62,9 @@ export class SearchService implements OnDestroy { protected responseCache: ResponseCacheService, protected requestService: RequestService, private rdb: RemoteDataBuildService, - private halService: HALEndpointService) { + private halService: HALEndpointService, + private communityService: CommunityDataService, + private collectionService: CollectionDataService) { const pagination: PaginationComponentOptions = new PaginationComponentOptions(); pagination.id = 'search-results-pagination'; pagination.currentPage = 1; @@ -224,6 +230,38 @@ export class SearchService implements OnDestroy { return this.rdb.toRemoteDataObservable(requestEntryObs, responseCacheObs, payloadObs); } + getScopes(scopeId: string): Observable { + + if (hasNoValue(scopeId)) { + const top: Observable = this.communityService.findTop({ elementsPerPage: 9999 }).pipe( + map( + (communities: RemoteData>) => communities.payload.page + ) + ); + return top; + } + + const communityScope: Observable> = this.communityService.findById(scopeId).filter((communityRD: RemoteData) => !communityRD.isLoading); + const scopeObject: Observable = communityScope.pipe( + flatMap((communityRD: RemoteData) => { + if (hasValue(communityRD.payload)) { + const community: Community = communityRD.payload; + // const subcommunities$ = community.subcommunities.filter((subcommunitiesRD: RemoteData>) => !subcommunitiesRD.isLoading).first(); + // const collections$ = community.subcommunities.filter((subcommunitiesRD: RemoteData>) => !subcommunitiesRD.isLoading).first(); + return Observable.combineLatest(community.subcommunities, community.collections, (subCommunities, collections) => { + /*if this is a community, we also need to show the direct children*/ + return [community, ...subCommunities.payload.page, ...collections.payload.page] + }) + } else { + return this.collectionService.findById(scopeId).pipe(map((collectionRD: RemoteData) => [collectionRD.payload])); + } + } + )); + + return scopeObject; + + } + getFilterLabels(): Observable { return combineLatest(this.getConfig(), this.route.queryParams).pipe( map(([rd, params]) => { diff --git a/src/app/core/cache/models/normalized-community.model.ts b/src/app/core/cache/models/normalized-community.model.ts index 03784e414b..2ade808922 100644 --- a/src/app/core/cache/models/normalized-community.model.ts +++ b/src/app/core/cache/models/normalized-community.model.ts @@ -40,4 +40,8 @@ export class NormalizedCommunity extends NormalizedDSpaceObject { @relationship(ResourceType.Collection, true) collections: string[]; + @autoserialize + @relationship(ResourceType.Community, true) + subcommunities: string[]; + } diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts index 88ad3a5287..3e31c62d25 100644 --- a/src/app/core/data/community-data.service.ts +++ b/src/app/core/data/community-data.service.ts @@ -1,7 +1,6 @@ -import { Inject, Injectable } from '@angular/core'; +import { Injectable } from '@angular/core'; import { Store } from '@ngrx/store'; -import { GLOBAL_CONFIG, GlobalConfig } from '../../../config'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { NormalizedCommunity } from '../cache/models/normalized-community.model'; import { ObjectCacheService } from '../cache/object-cache.service'; @@ -11,10 +10,16 @@ import { Community } from '../shared/community.model'; import { ComColDataService } from './comcol-data.service'; import { RequestService } from './request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { FindAllOptions, FindAllRequest } from './request.models'; +import { RemoteData } from './remote-data'; +import { hasValue, isNotEmpty } from '../../shared/empty.util'; +import { Observable } from 'rxjs/Observable'; +import { PaginatedList } from './paginated-list'; @Injectable() export class CommunityDataService extends ComColDataService { protected linkPath = 'communities'; + protected topLinkPath = 'communities/search/top'; protected cds = this; constructor( @@ -31,4 +36,19 @@ export class CommunityDataService extends ComColDataService>> { + const hrefObs = this.halService.getEndpoint(this.topLinkPath).filter((href: string) => isNotEmpty(href)) + .flatMap((endpoint: string) => this.getFindAllHref(endpoint, options)); + + hrefObs + .filter((href: string) => hasValue(href)) + .take(1) + .subscribe((href: string) => { + const request = new FindAllRequest(this.requestService.generateRequestId(), href, options); + this.requestService.configure(request); + }); + + return this.rdbService.buildList(hrefObs) as Observable>>; + } } diff --git a/src/app/core/shared/community.model.ts b/src/app/core/shared/community.model.ts index 8fd55d312f..20bd50f4a9 100644 --- a/src/app/core/shared/community.model.ts +++ b/src/app/core/shared/community.model.ts @@ -61,4 +61,6 @@ export class Community extends DSpaceObject { collections: Observable>>; + subcommunities: Observable>>; + }