Merge pull request #13613 from ArtemDzhereleiko/AD/imp/map/func-ctx

Add to map functions arguments widgetContext
This commit is contained in:
Igor Kulikov 2025-06-20 18:39:29 +03:00 committed by GitHub
commit 58cf6b1b71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 5 deletions

View File

@ -57,7 +57,7 @@ export class DataLayerPatternProcessor {
public setup(): Observable<void> { public setup(): Observable<void> {
if (this.settings.type === DataLayerPatternType.function) { if (this.settings.type === DataLayerPatternType.function) {
return parseTbFunction<MapStringFunction>(this.dataLayer.getCtx().http, this.settings.patternFunction, ['data', 'dsData']).pipe( return parseTbFunction<MapStringFunction>(this.dataLayer.getCtx().http, this.settings.patternFunction, ['data', 'dsData', 'ctx']).pipe(
map((parsed) => { map((parsed) => {
this.patternFunction = parsed; this.patternFunction = parsed;
return null; return null;
@ -72,7 +72,7 @@ export class DataLayerPatternProcessor {
public processPattern(data: FormattedData<TbMapDatasource>, dsData: FormattedData<TbMapDatasource>[]): string { public processPattern(data: FormattedData<TbMapDatasource>, dsData: FormattedData<TbMapDatasource>[]): string {
let pattern: string; let pattern: string;
if (this.settings.type === DataLayerPatternType.function) { if (this.settings.type === DataLayerPatternType.function) {
pattern = safeExecuteTbFunction(this.patternFunction, [data, dsData]); pattern = safeExecuteTbFunction(this.patternFunction, [data, dsData, this.dataLayer.getCtx()]);
} else { } else {
pattern = this.pattern; pattern = this.pattern;
} }

View File

@ -44,7 +44,7 @@
required required
withModules withModules
[globalVariables]="functionScopeVariables" [globalVariables]="functionScopeVariables"
[functionArgs]="['data', 'dsData']" [functionArgs]="['data', 'dsData', 'ctx']"
functionTitle="{{ (patternType === 'label' ? 'widgets.maps.data-layer.label-function' : 'widgets.maps.data-layer.tooltip-function') | translate }}" functionTitle="{{ (patternType === 'label' ? 'widgets.maps.data-layer.label-function' : 'widgets.maps.data-layer.tooltip-function') | translate }}"
[helpId]="helpId" [helpId]="helpId"
[helpPopupStyle]="{width: '900px'}"> [helpPopupStyle]="{width: '900px'}">

View File

@ -3,7 +3,7 @@
<div class="divider"></div> <div class="divider"></div>
<br/> <br/>
*function (data, dsData): string* *function (data, dsData, ctx): string*
A JavaScript function used to compute text or HTML code of the marker label. A JavaScript function used to compute text or HTML code of the marker label.

View File

@ -5,4 +5,6 @@
resolved from configured datasources. Each object represents basic entity properties (ex. <code>entityId</code>, <code>entityName</code>)<br/> resolved from configured datasources. Each object represents basic entity properties (ex. <code>entityId</code>, <code>entityName</code>)<br/>
and provides access to other entity attributes/timeseries declared in datasources of data layers configuration including additional datasources of the map configuration. and provides access to other entity attributes/timeseries declared in datasources of data layers configuration including additional datasources of the map configuration.
</li> </li>
<li><b>ctx:</b> <code><a href="https://github.com/thingsboard/thingsboard/blob/5bb6403407aa4898084832d6698aa9ea6d484889/ui-ngx/src/app/modules/home/models/widget-component.models.ts#L107" target="_blank">WidgetContext</a></code> - A reference to <a href="https://github.com/thingsboard/thingsboard/blob/5bb6403407aa4898084832d6698aa9ea6d484889/ui-ngx/src/app/modules/home/models/widget-component.models.ts#L107" target="_blank">WidgetContext</a> that has all necessary API
and data used by widget instance.
</li>