Added label parsing in select entity dialog
This commit is contained in:
parent
75e9e45321
commit
bcfab48a79
@ -31,7 +31,7 @@
|
||||
<mat-label translate>entity.entity</mat-label>
|
||||
<mat-select formControlName="entity">
|
||||
<mat-option *ngFor="let entity of data.entities" [value]="entity">
|
||||
{{ entity.entityName }}
|
||||
{{ parseName(entity) }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
@ -22,9 +22,18 @@ import { Router } from '@angular/router';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||
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 {
|
||||
entities: FormattedData[];
|
||||
labelSettings: {
|
||||
showLabel: boolean;
|
||||
useLabelFunction: boolean;
|
||||
parsedLabelFunction: GenericFunction;
|
||||
label: string;
|
||||
};
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -33,7 +42,6 @@ export interface SelectEntityDialogData {
|
||||
styleUrls: ['./select-entity-dialog.component.scss']
|
||||
})
|
||||
export class SelectEntityDialogComponent extends DialogComponent<SelectEntityDialogComponent, FormattedData> {
|
||||
|
||||
selectEntityFormGroup: UntypedFormGroup;
|
||||
|
||||
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 {
|
||||
this.dialogRef.close(this.selectEntityFormGroup.value.entity);
|
||||
}
|
||||
|
||||
@ -182,16 +182,35 @@ export default abstract class LeafletMap {
|
||||
|
||||
private selectEntityWithoutLocationDialog(shapes: L.PM.SUPPORTED_SHAPES): Observable<FormattedData> {
|
||||
let entities;
|
||||
let labelSettings;
|
||||
switch (shapes) {
|
||||
case 'Polygon':
|
||||
case 'Rectangle':
|
||||
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;
|
||||
case 'Marker':
|
||||
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;
|
||||
case 'Circle':
|
||||
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;
|
||||
default:
|
||||
return of(null);
|
||||
@ -205,7 +224,8 @@ export default abstract class LeafletMap {
|
||||
disableClose: true,
|
||||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
||||
data: {
|
||||
entities
|
||||
entities,
|
||||
labelSettings
|
||||
}
|
||||
}).afterClosed();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user