fixed listings with versions-mode

This commit is contained in:
CITE\spapacharalampous 2024-08-28 13:41:15 +03:00
parent 83091ee428
commit ee7acec75b
4 changed files with 74 additions and 9 deletions

View File

@ -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<De
descriptionTemplateStatuses = DescriptionTemplateStatus;
mode;
groupId: Guid | null = null;
public permissionEnum = AppPermission;
@ -101,12 +103,14 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
private sumarizeTextPipe: SumarizeTextPipe,
private analyticsService: AnalyticsService,
public routerUtils: RouterUtilsService,
private breadcrumbService: BreadcrumbService,
) {
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
// Lookup setup
// Default lookup values are defined in the user settings class.
this.mode = this.route.snapshot?.data['mode'];
this.lookup = this.initializeLookup();
this.breadcrumbService.addExcludedParam("versions", true);
}
ngOnInit() {
@ -121,9 +125,12 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
lookup.isActive = [IsActive.Active];
lookup.order = { items: [this.toDescSortField(nameof<DescriptionTemplate>(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<De
protected loadListing(): Observable<QueryResult<DescriptionTemplate>> {
this.lookup.onlyCanEdit = true;
return this.descriptionTemplateService.query(this.lookup);
return this.descriptionTemplateService.query(this.lookup).pipe(
takeUntil(this._destroyed),
tap((descriptionTemplates: QueryResult<DescriptionTemplate>) => {
const groupCode = descriptionTemplates.items?.[0]?.code;
if (this.groupId != null && groupCode != null) {
this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), groupCode);
}
})
);
}
public delete(id: Guid) {

View File

@ -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<PlanBlue
isActive = IsActive;
mode;
groupId: Guid | null = null;
@ViewChild('planBlueprintStatus', { static: true }) planBlueprintStatus?: TemplateRef<any>;
@ViewChild('actions', { static: true }) actions?: TemplateRef<any>;
@ViewChild(HybridListingComponent, { static: true }) hybridListingComponent: HybridListingComponent;
@ -80,13 +83,15 @@ export class PlanBlueprintListingComponent extends BaseListingComponent<PlanBlue
private language: TranslateService,
private dialog: MatDialog,
private fileUtils: FileUtils,
private analyticsService: AnalyticsService
private analyticsService: AnalyticsService,
private breadcrumbService: BreadcrumbService,
) {
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
// Lookup setup
// Default lookup values are defined in the user settings class.
this.mode = this.route.snapshot?.data['mode'];
this.lookup = this.initializeLookup();
this.breadcrumbService.addExcludedParam("versions", true);
}
ngOnInit() {
@ -121,9 +126,12 @@ export class PlanBlueprintListingComponent extends BaseListingComponent<PlanBlue
lookup.isActive = [IsActive.Active];
lookup.order = { items: [this.toDescSortField(nameof<PlanBlueprint>(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<PlanBlue
}
protected loadListing(): Observable<QueryResult<PlanBlueprint>> {
return this.planBlueprintService.query(this.lookup);
return this.planBlueprintService.query(this.lookup).pipe(
takeUntil(this._destroyed),
tap((blueprints: QueryResult<PlanBlueprint>) => {
const groupCode = blueprints.items?.[0]?.code;
if (this.groupId != null && groupCode != null) {
this.breadcrumbService.addIdResolvedValue(this.groupId.toString(), groupCode);
}
})
);
}
protected delete(id: Guid) {

View File

@ -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<BasePlan, PlanLoo
@ViewChild(MatPaginator, { static: true }) _paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
lookup: PlanLookup;
groupId: string;
// groupId: string;
totalCount: number;
listingItems: any[] = [];
isPublic: boolean = false;
@ -67,6 +69,9 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
order: new UntypedFormControl()
});
groupId: Guid | null = null;
mode;
scrollbar: boolean;
order = RecentActivityOrder;
@ -113,8 +118,11 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
private guidedTourService: GuidedTourService,
private analyticsService: AnalyticsService,
private principalService: PrincipalService,
private breadcrumbService: BreadcrumbService,
) {
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
this.mode = this.route.snapshot?.data['mode'];
this.breadcrumbService.addExcludedParam("versions", true);
}
ngOnInit() {
@ -195,6 +203,11 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
if (this.isPublic) {
return this.planService.publicQuery(this.lookup).pipe(takeUntil(this._destroyed))
.pipe(tap(result => {
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<BasePlan, PlanLoo
} else {
return this.planService.query(this.lookup).pipe(takeUntil(this._destroyed))
.pipe(tap(result => {
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<BasePlan, PlanLoo
let recentActivityOrder = this.isPublic ? this.toDescSortField(nameof<Description>(x => x.finalizedAt)) : this.toDescSortField(nameof<Description>(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<BasePlan, PlanLoo
[nameof<Plan>(x => x.planDescriptionTemplates), nameof<PlanDescriptionTemplate>(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);
}
}

View File

@ -14,7 +14,8 @@ const routes: Routes = [
path: 'versions/:groupId',
component: PlanListingComponent,
data: {
breadcrumb: true
breadcrumb: true,
mode: 'versions-listing'
},
},
];