Merge pull request #8298 from kalutkaz/selectEntityDialogLabelParsing
Added label parsing in select entity dialog
This commit is contained in:
commit
53dab54a7f
@ -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 }}
|
{{ entity.entityParseName }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import { Store } from '@ngrx/store';
|
|||||||
import { AppState } from '@core/core.state';
|
import { AppState } from '@core/core.state';
|
||||||
import { Router } from '@angular/router';
|
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 { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { FormattedData } from '@shared/models/widget.models';
|
import { FormattedData } from '@shared/models/widget.models';
|
||||||
|
|
||||||
export interface SelectEntityDialogData {
|
export interface SelectEntityDialogData {
|
||||||
@ -33,14 +33,13 @@ 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: FormGroup;
|
||||||
selectEntityFormGroup: UntypedFormGroup;
|
|
||||||
|
|
||||||
constructor(protected store: Store<AppState>,
|
constructor(protected store: Store<AppState>,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: SelectEntityDialogData,
|
@Inject(MAT_DIALOG_DATA) public data: SelectEntityDialogData,
|
||||||
public dialogRef: MatDialogRef<SelectEntityDialogComponent, FormattedData>,
|
public dialogRef: MatDialogRef<SelectEntityDialogComponent, FormattedData>,
|
||||||
public fb: UntypedFormBuilder) {
|
public fb: FormBuilder) {
|
||||||
super(store, router, dialogRef);
|
super(store, router, dialogRef);
|
||||||
|
|
||||||
this.selectEntityFormGroup = this.fb.group(
|
this.selectEntityFormGroup = this.fb.group(
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import { Observable, of } from 'rxjs';
|
|||||||
import { Polyline } from './polyline';
|
import { Polyline } from './polyline';
|
||||||
import { Polygon } from './polygon';
|
import { Polygon } from './polygon';
|
||||||
import { Circle } from './circle';
|
import { Circle } from './circle';
|
||||||
import { createTooltip, isCutPolygon, isJSON } from '@home/components/widget/lib/maps/maps-utils';
|
import { createTooltip, entitiesParseName, isCutPolygon, isJSON } from '@home/components/widget/lib/maps/maps-utils';
|
||||||
import { checkLngLat, createLoadingDiv } from '@home/components/widget/lib/maps/common-maps-utils';
|
import { checkLngLat, createLoadingDiv } from '@home/components/widget/lib/maps/common-maps-utils';
|
||||||
import { WidgetContext } from '@home/models/widget-component.models';
|
import { WidgetContext } from '@home/models/widget-component.models';
|
||||||
import {
|
import {
|
||||||
@ -182,20 +182,40 @@ 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);
|
||||||
}
|
}
|
||||||
|
entities = entitiesParseName(entities, labelSettings);
|
||||||
if (entities.length === 1) {
|
if (entities.length === 1) {
|
||||||
return of(entities[0]);
|
return of(entities[0]);
|
||||||
}
|
}
|
||||||
@ -219,38 +239,38 @@ export default abstract class LeafletMap {
|
|||||||
let customTranslation;
|
let customTranslation;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'tbMarker':
|
case 'tbMarker':
|
||||||
tooltipText = this.translateService.instant('widgets.maps.tooltips.placeMarker', {entityName: data.entityName});
|
tooltipText = this.translateService.instant('widgets.maps.tooltips.placeMarker', {entityName: data.entityParseName});
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.map.pm.Draw.tbMarker._hintMarker.setTooltipContent(tooltipText);
|
this.map.pm.Draw.tbMarker._hintMarker.setTooltipContent(tooltipText);
|
||||||
break;
|
break;
|
||||||
case 'tbCircle':
|
case 'tbCircle':
|
||||||
tooltipText = this.translateService.instant('widgets.maps.tooltips.startCircle', {entityName: data.entityName});
|
tooltipText = this.translateService.instant('widgets.maps.tooltips.startCircle', {entityName: data.entityParseName});
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.map.pm.Draw.tbCircle._hintMarker.setTooltipContent(tooltipText);
|
this.map.pm.Draw.tbCircle._hintMarker.setTooltipContent(tooltipText);
|
||||||
customTranslation = {
|
customTranslation = {
|
||||||
tooltips: {
|
tooltips: {
|
||||||
finishCircle: this.translateService.instant('widgets.maps.tooltips.finishCircle', {entityName: data.entityName})
|
finishCircle: this.translateService.instant('widgets.maps.tooltips.finishCircle', {entityName: data.entityParseName})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case 'tbRectangle':
|
case 'tbRectangle':
|
||||||
tooltipText = this.translateService.instant('widgets.maps.tooltips.firstVertex', {entityName: data.entityName});
|
tooltipText = this.translateService.instant('widgets.maps.tooltips.firstVertex', {entityName: data.entityParseName});
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.map.pm.Draw.tbRectangle._hintMarker.setTooltipContent(tooltipText);
|
this.map.pm.Draw.tbRectangle._hintMarker.setTooltipContent(tooltipText);
|
||||||
customTranslation = {
|
customTranslation = {
|
||||||
tooltips: {
|
tooltips: {
|
||||||
finishRect: this.translateService.instant('widgets.maps.tooltips.finishRect', {entityName: data.entityName})
|
finishRect: this.translateService.instant('widgets.maps.tooltips.finishRect', {entityName: data.entityParseName})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case 'tbPolygon':
|
case 'tbPolygon':
|
||||||
tooltipText = this.translateService.instant('widgets.maps.tooltips.firstVertex', {entityName: data.entityName});
|
tooltipText = this.translateService.instant('widgets.maps.tooltips.firstVertex', {entityName: data.entityParseName});
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.map.pm.Draw.tbPolygon._hintMarker.setTooltipContent(tooltipText);
|
this.map.pm.Draw.tbPolygon._hintMarker.setTooltipContent(tooltipText);
|
||||||
customTranslation = {
|
customTranslation = {
|
||||||
tooltips: {
|
tooltips: {
|
||||||
continueLine: this.translateService.instant('widgets.maps.tooltips.continueLine', {entityName: data.entityName}),
|
continueLine: this.translateService.instant('widgets.maps.tooltips.continueLine', {entityName: data.entityParseName}),
|
||||||
finishPoly: this.translateService.instant('widgets.maps.tooltips.finishPoly', {entityName: data.entityName})
|
finishPoly: this.translateService.instant('widgets.maps.tooltips.finishPoly', {entityName: data.entityParseName})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -16,9 +16,12 @@
|
|||||||
|
|
||||||
import L from 'leaflet';
|
import L from 'leaflet';
|
||||||
import {
|
import {
|
||||||
|
GenericFunction,
|
||||||
ShowTooltipAction, WidgetToolipSettings
|
ShowTooltipAction, WidgetToolipSettings
|
||||||
} from './map-models';
|
} from './map-models';
|
||||||
import { Datasource } from '@app/shared/models/widget.models';
|
import { Datasource, FormattedData } from '@app/shared/models/widget.models';
|
||||||
|
import { fillDataPattern, processDataPattern, safeExecute } from '@core/utils';
|
||||||
|
import { parseWithTranslation } from '@home/components/widget/lib/maps/common-maps-utils';
|
||||||
|
|
||||||
export function createTooltip(target: L.Layer,
|
export function createTooltip(target: L.Layer,
|
||||||
settings: Partial<WidgetToolipSettings>,
|
settings: Partial<WidgetToolipSettings>,
|
||||||
@ -83,3 +86,27 @@ export function isJSON(data: string): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface labelSettings {
|
||||||
|
showLabel: boolean;
|
||||||
|
useLabelFunction: boolean;
|
||||||
|
parsedLabelFunction: GenericFunction;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function entitiesParseName(entities: FormattedData[], labelSettings: labelSettings): FormattedData[] {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
for (const entity of entities) {
|
||||||
|
if (labelSettings?.showLabel) {
|
||||||
|
const pattern = labelSettings.useLabelFunction ? safeExecute(labelSettings.parsedLabelFunction,
|
||||||
|
[entity, entities, entity.dsIndex]) : labelSettings.label;
|
||||||
|
const markerLabelText = parseWithTranslation.prepareProcessPattern(pattern, true);
|
||||||
|
const replaceInfoLabelMarker = processDataPattern(pattern, entity);
|
||||||
|
div.innerHTML = fillDataPattern(markerLabelText, replaceInfoLabelMarker, entity);
|
||||||
|
entity.entityParseName = div.textContent || div.innerText || '';
|
||||||
|
} else {
|
||||||
|
entity.entityParseName = entity.entityName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user