mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 21:13:07 +00:00
54348: scope dropdown
This commit is contained in:
@@ -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 }
|
||||
|
@@ -8,7 +8,7 @@
|
||||
[query]="(searchOptions$ | async)?.query"
|
||||
[scope]="(searchOptions$ | async)?.scope"
|
||||
[currentUrl]="getSearchLink()"
|
||||
[scopes]="(scopeListRD$ | async)?.payload?.page">
|
||||
[scopes]="(scopeListRD$ | async)">
|
||||
</ds-search-form>
|
||||
<ds-search-labels></ds-search-labels>
|
||||
<div class="row">
|
||||
|
@@ -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<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>;
|
||||
searchOptions$: Observable<PaginatedSearchOptions>;
|
||||
sortConfig: SortOptions;
|
||||
scopeListRD$: Observable<RemoteData<PaginatedList<Community>>>;
|
||||
scopeListRD$: Observable<DSpaceObject[]>;
|
||||
isXsOrSm$: Observable<boolean>;
|
||||
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 {
|
||||
|
@@ -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<DSpaceObject[]> {
|
||||
|
||||
if (hasNoValue(scopeId)) {
|
||||
const top: Observable<Community[]> = this.communityService.findTop({ elementsPerPage: 9999 }).pipe(
|
||||
map(
|
||||
(communities: RemoteData<PaginatedList<Community>>) => communities.payload.page
|
||||
)
|
||||
);
|
||||
return top;
|
||||
}
|
||||
|
||||
const communityScope: Observable<RemoteData<Community>> = this.communityService.findById(scopeId).filter((communityRD: RemoteData<Community>) => !communityRD.isLoading);
|
||||
const scopeObject: Observable<DSpaceObject[]> = communityScope.pipe(
|
||||
flatMap((communityRD: RemoteData<Community>) => {
|
||||
if (hasValue(communityRD.payload)) {
|
||||
const community: Community = communityRD.payload;
|
||||
// const subcommunities$ = community.subcommunities.filter((subcommunitiesRD: RemoteData<PaginatedList<Community>>) => !subcommunitiesRD.isLoading).first();
|
||||
// const collections$ = community.subcommunities.filter((subcommunitiesRD: RemoteData<PaginatedList<Community>>) => !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<Collection>) => [collectionRD.payload]));
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
return scopeObject;
|
||||
|
||||
}
|
||||
|
||||
getFilterLabels(): Observable<FilterLabel[]> {
|
||||
return combineLatest(this.getConfig(), this.route.queryParams).pipe(
|
||||
map(([rd, params]) => {
|
||||
|
@@ -40,4 +40,8 @@ export class NormalizedCommunity extends NormalizedDSpaceObject {
|
||||
@relationship(ResourceType.Collection, true)
|
||||
collections: string[];
|
||||
|
||||
@autoserialize
|
||||
@relationship(ResourceType.Community, true)
|
||||
subcommunities: string[];
|
||||
|
||||
}
|
||||
|
@@ -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<NormalizedCommunity, Community> {
|
||||
protected linkPath = 'communities';
|
||||
protected topLinkPath = 'communities/search/top';
|
||||
protected cds = this;
|
||||
|
||||
constructor(
|
||||
@@ -31,4 +36,19 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
|
||||
getEndpoint() {
|
||||
return this.halService.getEndpoint(this.linkPath);
|
||||
}
|
||||
|
||||
findTop(options: FindAllOptions = {}): Observable<RemoteData<PaginatedList<Community>>> {
|
||||
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<NormalizedCommunity, Community>(hrefObs) as Observable<RemoteData<PaginatedList<Community>>>;
|
||||
}
|
||||
}
|
||||
|
@@ -61,4 +61,6 @@ export class Community extends DSpaceObject {
|
||||
|
||||
collections: Observable<RemoteData<PaginatedList<Collection>>>;
|
||||
|
||||
subcommunities: Observable<RemoteData<PaginatedList<Collection>>>;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user