[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=""> [placeholder]="'correction-type.manage-relation.search.placeholder' | translate" aria-label="" aria-describedby="">
<div class="input-group-append"> <div class="input-group-append">
<button type="button" class="btn btn-outline-secondary" [disabled]="projectTitle === ''" <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 === ''" <button type="button" class="btn btn-primary" [disabled]="projectTitle === ''"
(click)="search(projectTitle)">{{('correction-type.manage-relation.search.btn.search' | translate)}}</button> (click)="search(projectTitle)">{{('correction-type.manage-relation.search.btn.search' | translate)}}</button>
</div> </div>
</div> </div>
<ds-loading *ngIf="(isLoading$ | async)" message="{{'loading.search-results' | translate}}"></ds-loading> <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)" <ds-viewable-collection
[sortConfig]="this.searchOptions?.sort" *ngIf="(localEntitiesRD$ | async)?.payload?.page?.length > 0 && !(isLoading$ | async)"
[searchConfig]="this.searchOptions" [config]="pagination"
[sortConfig]="searchOptions?.sort"
[objects]="(localEntitiesRD$ | async)"
[hideGear]="true"
[selectable]="true" [selectable]="true"
[disableHeader]="true"
[hidePaginationDetail]="false"
[selectionConfig]="{ repeatable: false, listId: entityListId }" [selectionConfig]="{ repeatable: false, listId: entityListId }"
[linkType]="linkTypes.ExternalLink" [linkType]="linkTypes.Link"
[context]="context" [context]="context"
[hidePaginationDetail]="false"
(deselectObject)="deselectEntity()" (deselectObject)="deselectEntity()"
(selectObject)="selectEntity($event)"> (selectObject)="selectEntity($event)">
</ds-search-results> </ds-viewable-collection>
<div *ngIf="(localEntitiesRD$ | async)?.payload?.page?.length < 1 && !(isLoading$ | async)"> <div *ngIf="(localEntitiesRD$ | async)?.payload?.page?.length < 1 && !(isLoading$ | async)">
<ds-alert [type]="'alert-info'"> <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 { CorrectionType } from '../../../../core/submission/models/correction-type-mode.model';
import { CorrectionTypeForms } from '../correction-type-forms'; import { CorrectionTypeForms } from '../correction-type-forms';
import { ActivatedRoute, Router } from '@angular/router'; 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 { hasValue, isNotEmpty } from '../../../empty.util';
import { ListableObject } from '../../../object-collection/shared/listable-object.model'; import { ListableObject } from '../../../object-collection/shared/listable-object.model';
import { Item } from '../../../../core/shared/item.model'; import { Item } from '../../../../core/shared/item.model';
@@ -57,7 +57,7 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
*/ */
pagination: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { pagination: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'csmr', id: 'csmr',
pageSize: 3, pageSize: 10,
currentPage: 1 currentPage: 1
}); });
@@ -99,11 +99,11 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
/** /**
* List ID for selecting local entities * List ID for selecting local entities
*/ */
entityListId = 'correction-suggestion-manage-relation'; entityListId = 'csmr';
/** /**
* List ID for selecting local authorities * List ID for selecting local authorities
*/ */
authorityListId = 'correction-suggestion-manage-relation-authority'; authorityListId = 'csmr-authority';
/** /**
* ImportType enum * ImportType enum
@@ -134,23 +134,33 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
* Get the search results * Get the search results
*/ */
ngOnInit(): void { ngOnInit(): void {
this.getData();
}
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( this.searchOptions = Object.assign(new PaginatedSearchOptions(
{ {
configuration: this.correctionType.discoveryConfiguration, configuration: this.correctionType.discoveryConfiguration,
scope: this.itemUuid, scope: this.itemUuid,
pagination: this.pagination pagination: this.pagination,
} }
)); ));
this.localEntitiesRD$ = this.searchService.search(this.searchOptions); return this.searchService.search(this.searchOptions).pipe(
this.subs.push(
this.localEntitiesRD$.pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
).subscribe( finalize(() => this.isLoading$ = observableOf(false))
() => { );
this.isLoading$ = observableOf(false); })
}
)
); );
} }
@@ -169,6 +179,16 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
pagination: this.pagination pagination: this.pagination
} }
)); ));
} 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.localEntitiesRD$ = this.searchService.search(this.searchOptions);
this.subs.push( this.subs.push(
this.localEntitiesRD$.pipe( this.localEntitiesRD$.pipe(
@@ -178,7 +198,6 @@ export class ManageRelationCorrectionTypeComponent implements OnInit, OnDestroy
) )
); );
} }
}
/** /**
* Deselected a local entity * Deselected a local entity