From a99bf8efacd140bf932bb6bea4c4d88448ca3d10 Mon Sep 17 00:00:00 2001 From: mchouliara Date: Thu, 29 Aug 2024 15:27:01 +0300 Subject: [PATCH] plan listing > refactor list ordering --- .../plan/listing/plan-listing.component.html | 10 +-- .../ui/plan/listing/plan-listing.component.ts | 75 +++++++++---------- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/frontend/src/app/ui/plan/listing/plan-listing.component.html b/frontend/src/app/ui/plan/listing/plan-listing.component.html index 8cc675b8f..2bc2b7660 100644 --- a/frontend/src/app/ui/plan/listing/plan-listing.component.html +++ b/frontend/src/app/ui/plan/listing/plan-listing.component.html @@ -30,11 +30,11 @@
- - {{enumUtils.toRecentActivityOrderString(order.UpdatedAt)}} - {{enumUtils.toRecentActivityOrderString(order.PublishedAt)}} - {{enumUtils.toRecentActivityOrderString(order.Label)}} - {{enumUtils.toRecentActivityOrderString(order.Status)}} + + {{enumUtils.toRecentActivityOrderString(RecentActivityOrder.UpdatedAt)}} + {{enumUtils.toRecentActivityOrderString(RecentActivityOrder.PublishedAt)}} + {{enumUtils.toRecentActivityOrderString(RecentActivityOrder.Label)}} + {{enumUtils.toRecentActivityOrderString(RecentActivityOrder.Status)}}
diff --git a/frontend/src/app/ui/plan/listing/plan-listing.component.ts b/frontend/src/app/ui/plan/listing/plan-listing.component.ts index ed0839169..fd4cd67ca 100644 --- a/frontend/src/app/ui/plan/listing/plan-listing.component.ts +++ b/frontend/src/app/ui/plan/listing/plan-listing.component.ts @@ -42,6 +42,8 @@ import { PrincipalService } from '@app/core/services/http/principal.service'; import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; import { PlanFilterDialogComponent } from './filtering/plan-filter-dialog/plan-filter-dialog.component'; import { PlanListingFilters } from './filtering/plan-filter.component'; +import { Lookup } from '@common/model/lookup'; +import { MatSelectChange } from '@angular/material/select'; @Component({ selector: 'app-plan-listing-component', @@ -62,33 +64,27 @@ export class PlanListingComponent extends BaseListingComponent 0) { - - let ordering = this.lookup.order.items[0]; - let sortBy = ordering.substring(1, ordering.length); - - this.formGroup.get('order').setValue(this._getRecentActivityOrder(sortBy)); - ordering.charAt(0) == '-' ? this.sortDirection = SortDirection.Descending : this.sortDirection = SortDirection.Ascending; - } - + this.sortBy = this._getRecentActivityOrder(this.lookup.order.items[0]?.substring(1)) this.onPageLoad({ offset: this.lookup.page.offset / this.lookup.page.size } as PageLoadEvent); }); @@ -167,10 +155,6 @@ export class PlanListingComponent extends BaseListingComponent this.controlModified()); } public dashboardTour: GuidedTour = { @@ -286,21 +270,30 @@ export class PlanListingComponent extends BaseListingComponent(x => x.status)] }; - } else if (this.formGroup.get('order').value == RecentActivityOrder.Label) { - this.lookup.order = { items: [this.sortingDirectionPrefix + nameof(x => x.label)] }; - } else if (this.formGroup.get('order').value == RecentActivityOrder.PublishedAt){ - this.lookup.order = { items: [this.sortingDirectionPrefix + nameof(x => x.finalizedAt)] }; - }else { - this.lookup.order = { items: [this.sortingDirectionPrefix + nameof(x => x.updatedAt)] }; - } + orderByChanged($event: MatSelectChange) { + const value = $event.value as RecentActivityOrder; + const directionPrefix = this.isAscending ? '-' : '+'; + switch(value){ + case RecentActivityOrder.Status: { + this.lookup.order = { items: [directionPrefix + nameof(x => x.status)] }; + break; + } + case RecentActivityOrder.Label: { + this.lookup.order = { items: [directionPrefix + nameof(x => x.label)] }; + break; + } + case RecentActivityOrder.PublishedAt: { + this.lookup.order = { items: [directionPrefix + nameof(x => x.finalizedAt)] }; + } + default: { + this.lookup.order = { items: [directionPrefix + nameof(x => x.updatedAt)] }; + break; + } + } this.filterChanged(this.lookup); } controlModified(): void { - //this.lookup.like = this.lookup.like != '' ? this.lookup.like : null; this.lookup.page = { size: this.pageSize, offset: 0 }; this.filterChanged(this.lookup, true); } @@ -367,8 +360,10 @@ export class PlanListingComponent extends BaseListingComponent(x => x.updatedAt); + const sortDirection = this.isAscending ? '+' : '-'; + this.lookup.order.items = [`${sortDirection}${orderBy}`]; + this.filterChanged(this.lookup); } private _loadUserTenants(): Observable> {