Added label parsing in select entity dialog

This commit is contained in:
kalytka 2023-03-31 11:30:33 +03:00
parent 75e9e45321
commit bcfab48a79
3 changed files with 45 additions and 3 deletions

View File

@ -31,7 +31,7 @@
<mat-label translate>entity.entity</mat-label> <mat-label translate>entity.entity</mat-label>
<mat-select formControlName="entity"> <mat-select formControlName="entity">
<mat-option *ngFor="let entity of data.entities" [value]="entity"> <mat-option *ngFor="let entity of data.entities" [value]="entity">
{{ entity.entityName }} {{ parseName(entity) }}
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>

View File

@ -22,9 +22,18 @@ import { Router } from '@angular/router';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { FormattedData } from '@shared/models/widget.models'; import { FormattedData } from '@shared/models/widget.models';
import { GenericFunction } from '@home/components/widget/lib/maps/map-models';
import { fillDataPattern, processDataPattern, safeExecute } from '@core/utils';
import { parseWithTranslation } from '@home/components/widget/lib/maps/common-maps-utils';
export interface SelectEntityDialogData { export interface SelectEntityDialogData {
entities: FormattedData[]; entities: FormattedData[];
labelSettings: {
showLabel: boolean;
useLabelFunction: boolean;
parsedLabelFunction: GenericFunction;
label: string;
};
} }
@Component({ @Component({
@ -33,7 +42,6 @@ export interface SelectEntityDialogData {
styleUrls: ['./select-entity-dialog.component.scss'] styleUrls: ['./select-entity-dialog.component.scss']
}) })
export class SelectEntityDialogComponent extends DialogComponent<SelectEntityDialogComponent, FormattedData> { export class SelectEntityDialogComponent extends DialogComponent<SelectEntityDialogComponent, FormattedData> {
selectEntityFormGroup: UntypedFormGroup; selectEntityFormGroup: UntypedFormGroup;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
@ -50,6 +58,20 @@ export class SelectEntityDialogComponent extends DialogComponent<SelectEntityDia
); );
} }
public parseName(entity) {
let name;
if (this.data.labelSettings?.showLabel) {
const pattern = this.data.labelSettings.useLabelFunction ? safeExecute(this.data.labelSettings.parsedLabelFunction,
[entity, this.data.entities, entity.dsIndex]) : this.data.labelSettings.label;
const markerLabelText = parseWithTranslation.prepareProcessPattern(pattern, true);
const replaceInfoLabelMarker = processDataPattern(pattern, entity);
name = fillDataPattern(markerLabelText, replaceInfoLabelMarker, entity);
} else {
name = entity.entityName;
}
return name;
}
save(): void { save(): void {
this.dialogRef.close(this.selectEntityFormGroup.value.entity); this.dialogRef.close(this.selectEntityFormGroup.value.entity);
} }

View File

@ -182,16 +182,35 @@ export default abstract class LeafletMap {
private selectEntityWithoutLocationDialog(shapes: L.PM.SUPPORTED_SHAPES): Observable<FormattedData> { private selectEntityWithoutLocationDialog(shapes: L.PM.SUPPORTED_SHAPES): Observable<FormattedData> {
let entities; let entities;
let labelSettings;
switch (shapes) { switch (shapes) {
case 'Polygon': case 'Polygon':
case 'Rectangle': case 'Rectangle':
entities = this.datasources.filter(pData => !this.isValidPolygonPosition(pData)); entities = this.datasources.filter(pData => !this.isValidPolygonPosition(pData));
labelSettings = {
showLabel: this.options.showPolygonLabel,
useLabelFunction: this.options.usePolygonLabelFunction,
parsedLabelFunction: this.options.parsedPolygonLabelFunction,
label: this.options.polygonLabel
};
break; break;
case 'Marker': case 'Marker':
entities = this.datasources.filter(mData => !this.extractPosition(mData)); entities = this.datasources.filter(mData => !this.extractPosition(mData));
labelSettings = {
showLabel: this.options.showLabel,
useLabelFunction: this.options.useLabelFunction,
parsedLabelFunction: this.options.parsedLabelFunction,
label: this.options.label
};
break; break;
case 'Circle': case 'Circle':
entities = this.datasources.filter(mData => !this.isValidCircle(mData)); entities = this.datasources.filter(mData => !this.isValidCircle(mData));
labelSettings = {
showLabel: this.options.showCircleLabel,
useLabelFunction: this.options.useCircleLabelFunction,
parsedLabelFunction: this.options.parsedCircleLabelFunction,
label: this.options.circleLabel
};
break; break;
default: default:
return of(null); return of(null);
@ -205,7 +224,8 @@ export default abstract class LeafletMap {
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
entities entities,
labelSettings
} }
}).afterClosed(); }).afterClosed();
} }