[CST-11178][CST-11179] fixed pagination for relationship management

This commit is contained in:
Alisa Ismailati
2023-09-06 15:54:39 +02:00
committed by Mykhaylo Boychuk
parent 1a525dfbe7
commit 143916c604
2 changed files with 63 additions and 42 deletions

View File

@@ -11,26 +11,28 @@
[placeholder]="'correction-type.manage-relation.search.placeholder' | translate" aria-label="" aria-describedby="">
<div class="input-group-append">
<button type="button" class="btn btn-outline-secondary" [disabled]="projectTitle === ''"
(click)="projectTitle = ''">{{('correction-type.manage-relation.search.btn.clear' | translate)}}</button>
(click)="projectTitle = ''; search('')">{{('correction-type.manage-relation.search.btn.clear' | translate)}}</button>
<button type="button" class="btn btn-primary" [disabled]="projectTitle === ''"
(click)="search(projectTitle)">{{('correction-type.manage-relation.search.btn.search' | translate)}}</button>
</div>
</div>
<ds-loading *ngIf="(isLoading$ | async)" message="{{'loading.search-results' | translate}}"></ds-loading>
<ds-search-results *ngIf="(localEntitiesRD$ | async)?.payload?.page?.length > 0 && !(isLoading$ | async)"
[searchResults]="(localEntitiesRD$ | async)"
[sortConfig]="this.searchOptions?.sort"
[searchConfig]="this.searchOptions"
[selectable]="true"
[disableHeader]="true"
[hidePaginationDetail]="false"
[selectionConfig]="{ repeatable: false, listId: entityListId }"
[linkType]="linkTypes.ExternalLink"
[context]="context"
(deselectObject)="deselectEntity()"
(selectObject)="selectEntity($event)">
</ds-search-results>
<ds-viewable-collection
*ngIf="(localEntitiesRD$ | async)?.payload?.page?.length > 0 && !(isLoading$ | async)"
[config]="pagination"
[sortConfig]="searchOptions?.sort"
[objects]="(localEntitiesRD$ | async)"
[hideGear]="true"
[selectable]="true"
[selectionConfig]="{ repeatable: false, listId: entityListId }"
[linkType]="linkTypes.Link"
[context]="context"
[hidePaginationDetail]="false"
(deselectObject)="deselectEntity()"
(selectObject)="selectEntity($event)">
</ds-viewable-collection>
<div *ngIf="(localEntitiesRD$ | async)?.payload?.page?.length < 1 && !(isLoading$ | async)">
<ds-alert [type]="'alert-info'">

View File

@@ -20,7 +20,7 @@ import { renderCorrectionFor } from '../../correction-suggestion-page.decorator'
import { CorrectionType } from '../../../../core/submission/models/correction-type-mode.model';
import { CorrectionTypeForms } from '../correction-type-forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, of as observableOf, Subscription, switchMap } from 'rxjs';
import { finalize, Observable, of as observableOf, Subscription, switchMap } from 'rxjs';
import { hasValue, isNotEmpty } from '../../../empty.util';
import { ListableObject } from '../../../object-collection/shared/listable-object.model';
import { Item } from '../../../../core/shared/item.model';
@@ -55,9 +55,9 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
/**
* Pagination options
*/
pagination: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
pagination: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'csmr',
pageSize: 3,
pageSize: 10,
currentPage: 1
});
@@ -99,11 +99,11 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
/**
* List ID for selecting local entities
*/
entityListId = 'correction-suggestion-manage-relation';
entityListId = 'csmr';
/**
* List ID for selecting local authorities
*/
authorityListId = 'correction-suggestion-manage-relation-authority';
authorityListId = 'csmr-authority';
/**
* ImportType enum
@@ -134,23 +134,33 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
* Get the search results
*/
ngOnInit(): void {
this.searchOptions = Object.assign(new PaginatedSearchOptions(
{
configuration: this.correctionType.discoveryConfiguration,
scope: this.itemUuid,
pagination: this.pagination
}
));
this.getData();
}
this.localEntitiesRD$ = this.searchService.search(this.searchOptions);
this.subs.push(
this.localEntitiesRD$.pipe(
getFirstCompletedRemoteData(),
).subscribe(
() => {
this.isLoading$ = observableOf(false);
private getData(){
this.localEntitiesRD$ = this.aroute.queryParams
.pipe(
switchMap((params) => {
if (hasValue(params)) {
this.pagination = Object.assign(new PaginationComponentOptions(),{
...this.pagination,
currentPage: params[`${this.pagination.id}.page`] || 1
});
}
)
this.searchOptions = Object.assign(new PaginatedSearchOptions(
{
configuration: this.correctionType.discoveryConfiguration,
scope: this.itemUuid,
pagination: this.pagination,
}
));
return this.searchService.search(this.searchOptions).pipe(
getFirstCompletedRemoteData(),
finalize(() => this.isLoading$ = observableOf(false))
);
})
);
}
@@ -169,15 +179,24 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
pagination: this.pagination
}
));
this.localEntitiesRD$ = this.searchService.search(this.searchOptions);
this.subs.push(
this.localEntitiesRD$.pipe(
getFirstCompletedRemoteData(),
).subscribe(
() => this.isLoading$ = observableOf(false)
)
);
} else {
this.searchOptions = Object.assign(new PaginatedSearchOptions(
{
configuration: this.correctionType.discoveryConfiguration,
scope: this.itemUuid,
pagination: this.pagination
}
));
}
this.localEntitiesRD$ = this.searchService.search(this.searchOptions);
this.subs.push(
this.localEntitiesRD$.pipe(
getFirstCompletedRemoteData(),
).subscribe(
() => this.isLoading$ = observableOf(false)
)
);
}
/**