From ee7acec75be98f5daca798dbf7af0cc5752e6665 Mon Sep 17 00:00:00 2001 From: "CITE\\spapacharalampous" Date: Wed, 28 Aug 2024 13:41:15 +0300 Subject: [PATCH] fixed listings with versions-mode --- .../description-template-listing.component.ts | 21 +++++++++-- .../plan-blueprint-listing.component.ts | 24 ++++++++++--- .../ui/plan/listing/plan-listing.component.ts | 35 ++++++++++++++++++- .../ui/plan/listing/plan-listing.routing.ts | 3 +- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts b/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts index 1b839e9c2..516e8c045 100644 --- a/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts +++ b/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts @@ -27,11 +27,12 @@ import { Guid } from '@common/types/guid'; import { TranslateService } from '@ngx-translate/core'; import * as FileSaver from 'file-saver'; import { Observable } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { takeUntil, tap } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; import { ImportDescriptionTemplateDialogComponent } from './import-description-template/import-description-template.dialog.component'; import { RouterUtilsService } from '@app/core/services/router/router-utils.service'; import { AppPermission } from '@app/core/common/enum/permission.enum'; +import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; @Component({ @@ -46,6 +47,7 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent(x => x.createdAt))] }; if (this.mode && this.mode == 'versions-listing') { - lookup.groupIds = [Guid.parse(this.route.snapshot.paramMap.get('groupid'))]; + this.groupId = Guid.parse(this.route.snapshot.paramMap.get('groupid')); + this.breadcrumbService.addExcludedParam(this.groupId.toString(), true); + lookup.groupIds = [this.groupId]; lookup.versionStatuses = null; } else { + this.groupId = null; lookup.versionStatuses = [DescriptionTemplateVersionStatus.Current, DescriptionTemplateVersionStatus.NotFinalized]; } this.updateOrderUiFields(lookup.order); @@ -246,7 +253,15 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent> { this.lookup.onlyCanEdit = true; - return this.descriptionTemplateService.query(this.lookup); + return this.descriptionTemplateService.query(this.lookup).pipe( + takeUntil(this._destroyed), + tap((descriptionTemplates: QueryResult) => { + const groupCode = descriptionTemplates.items?.[0]?.code; + if (this.groupId != null && groupCode != null) { + this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), groupCode); + } + }) + ); } public delete(id: Guid) { diff --git a/frontend/src/app/ui/admin/plan-blueprint/listing/plan-blueprint-listing.component.ts b/frontend/src/app/ui/admin/plan-blueprint/listing/plan-blueprint-listing.component.ts index 2db6cbb87..30e4b5fd0 100644 --- a/frontend/src/app/ui/admin/plan-blueprint/listing/plan-blueprint-listing.component.ts +++ b/frontend/src/app/ui/admin/plan-blueprint/listing/plan-blueprint-listing.component.ts @@ -26,11 +26,12 @@ import { Guid } from '@common/types/guid'; import { TranslateService } from '@ngx-translate/core'; import * as FileSaver from 'file-saver'; import { Observable } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { takeUntil, tap } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; import { ImportPlanBlueprintDialogComponent } from './import-plan-blueprint/import-plan-blueprint.dialog.component'; import { RouterUtilsService } from '@app/core/services/router/router-utils.service'; import { AppPermission } from '@app/core/common/enum/permission.enum'; +import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; @Component({ @@ -46,6 +47,8 @@ export class PlanBlueprintListingComponent extends BaseListingComponent; @ViewChild('actions', { static: true }) actions?: TemplateRef; @ViewChild(HybridListingComponent, { static: true }) hybridListingComponent: HybridListingComponent; @@ -80,13 +83,15 @@ export class PlanBlueprintListingComponent extends BaseListingComponent(x => x.createdAt))] }; if (this.mode && this.mode == 'versions-listing') { - lookup.groupIds = [Guid.parse(this.route.snapshot.paramMap.get('groupid'))]; + this.groupId = Guid.parse(this.route.snapshot.paramMap.get('groupid')); + this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), ""); + lookup.groupIds = [this.groupId]; lookup.versionStatuses = null; } else { + this.groupId = null; lookup.versionStatuses = [PlanBlueprintVersionStatus.Current, PlanBlueprintVersionStatus.NotFinalized]; } this.updateOrderUiFields(lookup.order); @@ -205,7 +213,15 @@ export class PlanBlueprintListingComponent extends BaseListingComponent> { - return this.planBlueprintService.query(this.lookup); + return this.planBlueprintService.query(this.lookup).pipe( + takeUntil(this._destroyed), + tap((blueprints: QueryResult) => { + const groupCode = blueprints.items?.[0]?.code; + if (this.groupId != null && groupCode != null) { + this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), groupCode); + } + }) + ); } protected delete(id: Guid) { 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 d80c85c6e..4b862081b 100644 --- a/frontend/src/app/ui/plan/listing/plan-listing.component.ts +++ b/frontend/src/app/ui/plan/listing/plan-listing.component.ts @@ -40,6 +40,8 @@ import { Tenant } from '@app/core/model/tenant/tenant'; import { BaseHttpParams } from '@common/http/base-http-params'; import { InterceptorType } from '@common/http/interceptors/interceptor-type'; import { PrincipalService } from '@app/core/services/http/principal.service'; +import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; +import { PlanStatusEnum } from '@app/core/common/enum/plan-status'; @Component({ selector: 'app-plan-listing-component', @@ -53,7 +55,7 @@ export class PlanListingComponent extends BaseListingComponent { + if (this.groupId != null) { + const latestVersionPlan: BasePlan = this._getLatestVersion(result.items); + this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), latestVersionPlan.label); + } + if (!result) { return []; } this.totalCount = result.count; if (this.lookup?.page?.offset === 0) this.listingItems = []; @@ -204,6 +217,11 @@ export class PlanListingComponent extends BaseListingComponent { + if (this.groupId != null) { + const latestVersionPlan: BasePlan = this._getLatestVersion(result.items); + this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), latestVersionPlan.label); + } + this.hasLoadedListingItems = true; if (!result) { return []; } this.totalCount = result.count; @@ -224,6 +242,15 @@ export class PlanListingComponent extends BaseListingComponent(x => x.finalizedAt)) : this.toDescSortField(nameof(x => x.updatedAt)); lookup.order = { items: [recentActivityOrder] }; + if (this.mode && this.mode == 'versions-listing') { + this.groupId = Guid.parse(this.route.snapshot.paramMap.get('groupId')); + lookup.groupIds = [this.groupId]; + + this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), ""); + } else { + lookup.groupIds = null; + } + this.updateOrderUiFields(lookup.order); lookup.project = { @@ -522,4 +549,10 @@ export class PlanListingComponent extends BaseListingComponent(x => x.planDescriptionTemplates), nameof(x => x.isActive)].join('.'), ]; } + + private _getLatestVersion(plans: BasePlan[]): BasePlan { + const maxVersion: number = Math.max(...plans.map(p => p.version)); + + return plans.find(p => p.version == maxVersion); + } } diff --git a/frontend/src/app/ui/plan/listing/plan-listing.routing.ts b/frontend/src/app/ui/plan/listing/plan-listing.routing.ts index 41c38e15d..e8d9aae02 100644 --- a/frontend/src/app/ui/plan/listing/plan-listing.routing.ts +++ b/frontend/src/app/ui/plan/listing/plan-listing.routing.ts @@ -14,7 +14,8 @@ const routes: Routes = [ path: 'versions/:groupId', component: PlanListingComponent, data: { - breadcrumb: true + breadcrumb: true, + mode: 'versions-listing' }, }, ];