Skip to content

Commit

Permalink
feat: use SyntehseDataPagination/Sort in home discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Jan 15, 2025
1 parent 04240f5 commit f690530
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[count]="pagination.totalItems"
(page)="onChangePage($event)"
[externalSorting]="true"
[sorts]="[{ prop: sort.sort, dir: sort.orderby }]"
[sorts]="[{ prop: sort.sortBy, dir: sort.sortOrder }]"
(sort)="onColumnSort($event)"
>
<ngx-datatable-column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ import { GN2CommonModule } from '@geonature_common/GN2Common.module';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { HomeDiscussionsService } from '../home-discussions.service';

interface PaginationItem {
totalItems: number;
currentPage: number;
perPage: number;
}

interface SortingItem {
sort: 'asc' | 'desc';
orderby: string;
}
import { SyntheseDataPaginationItem } from '@geonature_common/form/synthese-form/synthese-data-pagination-item';
import {
SORT_ORDER,
SyntheseDataSortItem,
} from '@geonature_common/form/synthese-form/synthese-data-sort-item';

@Component({
standalone: true,
Expand All @@ -32,19 +26,19 @@ export class HomeDiscussionsTableComponent implements OnInit, OnDestroy {
readonly PROP_CONTENT = 'content';
readonly PROP_OBSERVATION = 'observation';

readonly DEFAULT_PAGINATION: PaginationItem = {
readonly DEFAULT_PAGINATION: SyntheseDataPaginationItem = {
totalItems: 0,
currentPage: 1,
perPage: 4,
};
readonly DEFAULT_SORTING: SortingItem = {
sort: 'desc',
orderby: this.PROP_CREATION_DATE,
readonly DEFAULT_SORTING: SyntheseDataSortItem = {
sortOrder: SORT_ORDER.ASC,
sortBy: this.PROP_CREATION_DATE,
};

discussions = [];
pagination: PaginationItem = this.DEFAULT_PAGINATION;
sort: SortingItem = this.DEFAULT_SORTING;
pagination: SyntheseDataPaginationItem = this.DEFAULT_PAGINATION;
sort: SyntheseDataSortItem = this.DEFAULT_SORTING;

private destroy$ = new Subject<void>();

Expand Down Expand Up @@ -78,8 +72,8 @@ export class HomeDiscussionsTableComponent implements OnInit, OnDestroy {

onColumnSort(event: any) {
this.sort = {
sort: event.newValue,
orderby: event.column.prop,
sortBy: event.newValue,
sortOrder: event.column.prop,
};
this.pagination.currentPage = 1;
this._fetchDiscussions();
Expand All @@ -106,8 +100,8 @@ export class HomeDiscussionsTableComponent implements OnInit, OnDestroy {
private _buildQueryParams(): URLSearchParams {
const params = new URLSearchParams();
params.set('type', 'discussion');
params.set('sort', this.sort.sort);
params.set('orderby', this.sort.orderby);
params.set('sort', this.sort.sortBy);
params.set('orderby', this.sort.sortOrder);
params.set('page', this.pagination.currentPage.toString());
params.set('per_page', this.pagination.perPage.toString());
params.set('my_reports', this._myReportsOnly.toString());
Expand Down

0 comments on commit f690530

Please sign in to comment.