Update logic for markdown and QR code widgets
This commit is contained in:
parent
d330def880
commit
c6dff4145b
@ -25,6 +25,7 @@ import { HttpErrorResponse } from '@angular/common/http';
|
|||||||
import { letterSpacing } from 'html2canvas/dist/types/css/property-descriptors/letter-spacing';
|
import { letterSpacing } from 'html2canvas/dist/types/css/property-descriptors/letter-spacing';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { serverErrorCodesTranslations } from '@shared/models/constants';
|
import { serverErrorCodesTranslations } from '@shared/models/constants';
|
||||||
|
import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined';
|
||||||
|
|
||||||
const varsRegex = /\${([^}]*)}/g;
|
const varsRegex = /\${([^}]*)}/g;
|
||||||
|
|
||||||
@ -479,6 +480,19 @@ export function flatFormattedData(input: FormattedData[]): FormattedData {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function filteringData(data: FormattedData[]): FormattedData {
|
||||||
|
const processingKeyValue = {};
|
||||||
|
for (const deviceData of data) {
|
||||||
|
Object.keys(deviceData).forEach((valueKey) => {
|
||||||
|
if (!isNotNullOrUndefined(processingKeyValue[valueKey]) && isNotNullOrUndefined(deviceData[valueKey]) &&
|
||||||
|
deviceData[valueKey] !== '') {
|
||||||
|
processingKeyValue[valueKey] = deviceData[valueKey];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return processingKeyValue as FormattedData;
|
||||||
|
}
|
||||||
|
|
||||||
export function mergeFormattedData(first: FormattedData[], second: FormattedData[]): FormattedData[] {
|
export function mergeFormattedData(first: FormattedData[], second: FormattedData[]): FormattedData[] {
|
||||||
const merged = first.concat(second);
|
const merged = first.concat(second);
|
||||||
return _(merged).groupBy(el => el.$datasource)
|
return _(merged).groupBy(el => el.$datasource)
|
||||||
|
|||||||
@ -23,12 +23,11 @@ import { DatasourceData, FormattedData } from '@shared/models/widget.models';
|
|||||||
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
|
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
|
||||||
import {
|
import {
|
||||||
createLabelFromPattern,
|
createLabelFromPattern,
|
||||||
fillDataPattern,
|
filteringData,
|
||||||
flatFormattedData,
|
|
||||||
formattedDataFormDatasourceData,
|
formattedDataFormDatasourceData,
|
||||||
hashCode, isDefinedAndNotNull,
|
hashCode, isDefinedAndNotNull,
|
||||||
isNotEmptyStr,
|
isNotEmptyStr,
|
||||||
parseFunction, processDataPattern,
|
parseFunction,
|
||||||
safeExecute
|
safeExecute
|
||||||
} from '@core/utils';
|
} from '@core/utils';
|
||||||
import cssjs from '@core/css/css';
|
import cssjs from '@core/css/css';
|
||||||
@ -119,7 +118,8 @@ export class MarkdownWidgetComponent extends PageComponent implements OnInit {
|
|||||||
const data = formattedDataFormDatasourceData(initialData);
|
const data = formattedDataFormDatasourceData(initialData);
|
||||||
let markdownText = this.settings.useMarkdownTextFunction ?
|
let markdownText = this.settings.useMarkdownTextFunction ?
|
||||||
safeExecute(this.markdownTextFunction, [data]) : this.settings.markdownTextPattern;
|
safeExecute(this.markdownTextFunction, [data]) : this.settings.markdownTextPattern;
|
||||||
markdownText = createLabelFromPattern(markdownText, data[0]);
|
const allData: FormattedData = filteringData(data);
|
||||||
|
markdownText = createLabelFromPattern(markdownText, allData);
|
||||||
if (this.markdownText !== markdownText) {
|
if (this.markdownText !== markdownText) {
|
||||||
this.markdownText = this.utils.customTranslation(markdownText, markdownText);
|
this.markdownText = this.utils.customTranslation(markdownText, markdownText);
|
||||||
this.cd.detectChanges();
|
this.cd.detectChanges();
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import { DatasourceData, FormattedData } from '@shared/models/widget.models';
|
|||||||
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
|
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
|
||||||
import {
|
import {
|
||||||
createLabelFromPattern,
|
createLabelFromPattern,
|
||||||
flatFormattedData,
|
filteringData,
|
||||||
formattedDataFormDatasourceData,
|
formattedDataFormDatasourceData,
|
||||||
isNumber,
|
isNumber,
|
||||||
isObject,
|
isObject,
|
||||||
@ -101,7 +101,7 @@ export class QrCodeWidgetComponent extends PageComponent implements OnInit, Afte
|
|||||||
const data = formattedDataFormDatasourceData(initialData);
|
const data = formattedDataFormDatasourceData(initialData);
|
||||||
const pattern = this.settings.useQrCodeTextFunction ?
|
const pattern = this.settings.useQrCodeTextFunction ?
|
||||||
safeExecute(this.qrCodeTextFunction, [data]) : this.settings.qrCodeTextPattern;
|
safeExecute(this.qrCodeTextFunction, [data]) : this.settings.qrCodeTextPattern;
|
||||||
const allData = flatFormattedData(data);
|
const allData: FormattedData = filteringData(data);
|
||||||
qrCodeText = createLabelFromPattern(pattern, allData);
|
qrCodeText = createLabelFromPattern(pattern, allData);
|
||||||
this.updateQrCodeText(qrCodeText);
|
this.updateQrCodeText(qrCodeText);
|
||||||
}
|
}
|
||||||
@ -132,5 +132,4 @@ export class QrCodeWidgetComponent extends PageComponent implements OnInit, Afte
|
|||||||
this.scheduleUpdateCanvas = true;
|
this.scheduleUpdateCanvas = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
The Markdown template gets keys only from the first entity in the entity alias.
|
The Markdown template displays the value of the first found key in the entities in the entity alias.
|
||||||
|
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
@ -4190,7 +4190,7 @@
|
|||||||
"qr-code": {
|
"qr-code": {
|
||||||
"use-qr-code-text-function": "Use QR code text function",
|
"use-qr-code-text-function": "Use QR code text function",
|
||||||
"qr-code-text-pattern": "QR code text pattern (for ex. '${entityName} | ${keyName} - some text.')",
|
"qr-code-text-pattern": "QR code text pattern (for ex. '${entityName} | ${keyName} - some text.')",
|
||||||
"qr-code-text-pattern-hint": "QR code text pattern get keys only from the first entity in the entity alias.",
|
"qr-code-text-pattern-hint": "QR code text pattern use the value of the first found key in the entities in the entity alias.",
|
||||||
"qr-code-text-pattern-required": "QR code text pattern is required.",
|
"qr-code-text-pattern-required": "QR code text pattern is required.",
|
||||||
"qr-code-text-function": "QR code text function"
|
"qr-code-text-function": "QR code text function"
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user