Skip to content

Commit d7372bc

Browse files
authored
Merge pull request DSpace#2239 from alexandrevryghem/fix-community-page-sorting_contribute-main
Fixed community's sub-communities and collections sort
2 parents f276756 + 4449960 commit d7372bc

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/app/community-page/sub-collection-list/community-page-sub-collection-list.component.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
2+
import { ActivatedRoute } from '@angular/router';
23

34
import { BehaviorSubject, combineLatest as observableCombineLatest } from 'rxjs';
45

@@ -49,19 +50,23 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro
4950
*/
5051
subCollectionsRDObs: BehaviorSubject<RemoteData<PaginatedList<Collection>>> = new BehaviorSubject<RemoteData<PaginatedList<Collection>>>({} as any);
5152

52-
constructor(private cds: CollectionDataService,
53-
private paginationService: PaginationService,
54-
55-
) {}
53+
constructor(
54+
protected cds: CollectionDataService,
55+
protected paginationService: PaginationService,
56+
protected route: ActivatedRoute,
57+
) {
58+
}
5659

5760
ngOnInit(): void {
5861
this.config = new PaginationComponentOptions();
5962
this.config.id = this.pageId;
6063
if (hasValue(this.pageSize)) {
6164
this.config.pageSize = this.pageSize;
65+
} else {
66+
this.config.pageSize = this.route.snapshot.queryParams[this.pageId + '.rpp'] ?? this.config.pageSize;
6267
}
63-
this.config.currentPage = 1;
64-
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
68+
this.config.currentPage = this.route.snapshot.queryParams[this.pageId + '.page'] ?? 1;
69+
this.sortConfig = new SortOptions('dc.title', SortDirection[this.route.snapshot.queryParams[this.pageId + '.sd']] ?? SortDirection.ASC);
6570
this.initPage();
6671
}
6772

src/app/community-page/sub-community-list/community-page-sub-community-list.component.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
2+
import { ActivatedRoute } from '@angular/router';
23

34
import { BehaviorSubject, combineLatest as observableCombineLatest } from 'rxjs';
45

@@ -9,7 +10,6 @@ import { PaginatedList } from '../../core/data/paginated-list.model';
910
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
1011
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
1112
import { CommunityDataService } from '../../core/data/community-data.service';
12-
import { takeUntilCompletedRemoteData } from '../../core/shared/operators';
1313
import { switchMap } from 'rxjs/operators';
1414
import { PaginationService } from '../../core/pagination/pagination.service';
1515
import { hasValue } from '../../shared/empty.util';
@@ -52,8 +52,10 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy
5252
*/
5353
subCommunitiesRDObs: BehaviorSubject<RemoteData<PaginatedList<Community>>> = new BehaviorSubject<RemoteData<PaginatedList<Community>>>({} as any);
5454

55-
constructor(private cds: CommunityDataService,
56-
private paginationService: PaginationService
55+
constructor(
56+
protected cds: CommunityDataService,
57+
protected paginationService: PaginationService,
58+
protected route: ActivatedRoute,
5759
) {
5860
}
5961

@@ -62,9 +64,11 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy
6264
this.config.id = this.pageId;
6365
if (hasValue(this.pageSize)) {
6466
this.config.pageSize = this.pageSize;
67+
} else {
68+
this.config.pageSize = this.route.snapshot.queryParams[this.pageId + '.rpp'] ?? this.config.pageSize;
6569
}
66-
this.config.currentPage = 1;
67-
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
70+
this.config.currentPage = this.route.snapshot.queryParams[this.pageId + '.page'] ?? 1;
71+
this.sortConfig = new SortOptions('dc.title', SortDirection[this.route.snapshot.queryParams[this.pageId + '.sd']] ?? SortDirection.ASC);
6872
this.initPage();
6973
}
7074

@@ -86,15 +90,6 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy
8690
).subscribe((results) => {
8791
this.subCommunitiesRDObs.next(results);
8892
});
89-
90-
91-
this.cds.findByParent(this.community.id, {
92-
currentPage: this.config.currentPage,
93-
elementsPerPage: this.config.pageSize,
94-
sort: { field: this.sortConfig.field, direction: this.sortConfig.direction }
95-
}).pipe(takeUntilCompletedRemoteData()).subscribe((results) => {
96-
this.subCommunitiesRDObs.next(results);
97-
});
9893
}
9994

10095
ngOnDestroy(): void {

0 commit comments

Comments
 (0)