Browse Source

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

Add to map functions arguments widgetContext
pull/13626/head
Igor Kulikov 12 months ago
committed by GitHub
parent
commit
58cf6b1b71
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/map-data-layer.ts
  2. 2
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/data-layer-pattern-settings.component.html
  3. 2
      ui-ngx/src/assets/help/en_US/widget/lib/map/label_fn.md
  4. 4
      ui-ngx/src/assets/help/en_US/widget/lib/map/map_fn_args.md

4
ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/map-data-layer.ts

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

2
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/data-layer-pattern-settings.component.html

@ -44,7 +44,7 @@
required
withModules
[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 }}"
[helpId]="helpId"
[helpPopupStyle]="{width: '900px'}">

2
ui-ngx/src/assets/help/en_US/widget/lib/map/label_fn.md

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

4
ui-ngx/src/assets/help/en_US/widget/lib/map/map_fn_args.md

@ -5,4 +5,6 @@
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.
</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>

Loading…
Cancel
Save