mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Refactor subgroups-list component's "search()" to act same as member-list component's "search()". Avoids reloading the page as frequently.
(cherry picked from commit 2eb1a17e4e
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
4a1f2a1b75
commit
8cc36d7056
@@ -3,12 +3,13 @@ import { UntypedFormBuilder } from '@angular/forms';
|
|||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
|
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
|
||||||
import { switchMap, take } from 'rxjs/operators';
|
import { map, switchMap, take } from 'rxjs/operators';
|
||||||
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
||||||
import { RemoteData } from '../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
import { GroupDataService } from '../../../../core/eperson/group-data.service';
|
import { GroupDataService } from '../../../../core/eperson/group-data.service';
|
||||||
import { Group } from '../../../../core/eperson/models/group.model';
|
import { Group } from '../../../../core/eperson/models/group.model';
|
||||||
import {
|
import {
|
||||||
|
getAllCompletedRemoteData,
|
||||||
getFirstCompletedRemoteData
|
getFirstCompletedRemoteData
|
||||||
} from '../../../../core/shared/operators';
|
} from '../../../../core/shared/operators';
|
||||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
@@ -179,24 +180,36 @@ export class SubgroupsListComponent implements OnInit, OnDestroy {
|
|||||||
* @param data Contains query param
|
* @param data Contains query param
|
||||||
*/
|
*/
|
||||||
search(data: any) {
|
search(data: any) {
|
||||||
const query: string = data.query;
|
|
||||||
if (query != null && this.currentSearchQuery !== query) {
|
|
||||||
this.router.navigateByUrl(this.groupDataService.getGroupEditPageRouterLink(this.groupBeingEdited));
|
|
||||||
this.currentSearchQuery = query;
|
|
||||||
this.configSearch.currentPage = 1;
|
|
||||||
}
|
|
||||||
this.searchDone = true;
|
|
||||||
|
|
||||||
this.unsubFrom(SubKey.SearchResults);
|
this.unsubFrom(SubKey.SearchResults);
|
||||||
this.subs.set(SubKey.SearchResults, this.paginationService.getCurrentPagination(this.configSearch.id, this.configSearch).pipe(
|
this.subs.set(SubKey.SearchResults,
|
||||||
switchMap((config) => this.groupDataService.searchNonMemberGroups(this.currentSearchQuery, this.groupBeingEdited.id, {
|
this.paginationService.getCurrentPagination(this.configSearch.id, this.configSearch).pipe(
|
||||||
currentPage: config.currentPage,
|
switchMap((paginationOptions) => {
|
||||||
elementsPerPage: config.pageSize
|
const query: string = data.query;
|
||||||
}, false, true, followLink('object')
|
if (query != null && this.currentSearchQuery !== query && this.groupBeingEdited) {
|
||||||
))
|
this.router.navigate([], {
|
||||||
).subscribe((rd: RemoteData<PaginatedList<Group>>) => {
|
queryParamsHandling: 'merge'
|
||||||
this.searchResults$.next(rd);
|
});
|
||||||
}));
|
this.currentSearchQuery = query;
|
||||||
|
this.paginationService.resetPage(this.configSearch.id);
|
||||||
|
}
|
||||||
|
this.searchDone = true;
|
||||||
|
|
||||||
|
return this.groupDataService.searchNonMemberGroups(this.currentSearchQuery, this.groupBeingEdited.id, {
|
||||||
|
currentPage: paginationOptions.currentPage,
|
||||||
|
elementsPerPage: paginationOptions.pageSize
|
||||||
|
}, false, true, followLink('object'));
|
||||||
|
}),
|
||||||
|
getAllCompletedRemoteData(),
|
||||||
|
map((rd: RemoteData<any>) => {
|
||||||
|
if (rd.hasFailed) {
|
||||||
|
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure', { cause: rd.errorMessage }));
|
||||||
|
} else {
|
||||||
|
return rd;
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.subscribe((rd: RemoteData<PaginatedList<Group>>) => {
|
||||||
|
this.searchResults$.next(rd);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user