Browse Source

Refactoring

pull/7365/head
Kalutka Zhenya 4 years ago
parent
commit
de0a196d7a
  1. 17
      ui-ngx/src/app/core/utils.ts
  2. 4
      ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts
  3. 4
      ui-ngx/src/app/modules/home/components/widget/lib/qrcode-widget.component.ts

17
ui-ngx/src/app/core/utils.ts

@ -22,10 +22,8 @@ import { EntityId } from '@shared/models/id/entity-id';
import { NULL_UUID } from '@shared/models/id/has-uuid';
import { EntityType, baseDetailsPageByEntityType } from '@shared/models/entity-type.models';
import { HttpErrorResponse } from '@angular/common/http';
import { letterSpacing } from 'html2canvas/dist/types/css/property-descriptors/letter-spacing';
import { TranslateService } from '@ngx-translate/core';
import { serverErrorCodesTranslations } from '@shared/models/constants';
import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined';
const varsRegex = /\${([^}]*)}/g;
@ -480,17 +478,16 @@ export function flatFormattedData(input: FormattedData[]): FormattedData {
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];
export function flatDataWithoutOverride(data: FormattedData[]): FormattedData {
const processingKeyValue = data[0];
for (let i = 1; i < data.length; i++) {
Object.keys(data[i]).forEach((key) => {
if (!isDefinedAndNotNull(processingKeyValue[key]) || isEmptyStr(processingKeyValue[key])) {
processingKeyValue[key] = data[i][key];
}
});
}
return processingKeyValue as FormattedData;
return processingKeyValue;
}
export function mergeFormattedData(first: FormattedData[], second: FormattedData[]): FormattedData[] {

4
ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts

@ -23,7 +23,7 @@ import { DatasourceData, FormattedData } from '@shared/models/widget.models';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
import {
createLabelFromPattern,
filteringData,
flatDataWithoutOverride,
formattedDataFormDatasourceData,
hashCode, isDefinedAndNotNull,
isNotEmptyStr,
@ -118,7 +118,7 @@ export class MarkdownWidgetComponent extends PageComponent implements OnInit {
const data = formattedDataFormDatasourceData(initialData);
let markdownText = this.settings.useMarkdownTextFunction ?
safeExecute(this.markdownTextFunction, [data]) : this.settings.markdownTextPattern;
const allData: FormattedData = filteringData(data);
const allData: FormattedData = flatDataWithoutOverride(data);
markdownText = createLabelFromPattern(markdownText, allData);
if (this.markdownText !== markdownText) {
this.markdownText = this.utils.customTranslation(markdownText, markdownText);

4
ui-ngx/src/app/modules/home/components/widget/lib/qrcode-widget.component.ts

@ -23,7 +23,7 @@ import { DatasourceData, FormattedData } from '@shared/models/widget.models';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
import {
createLabelFromPattern,
filteringData,
flatDataWithoutOverride,
formattedDataFormDatasourceData,
isNumber,
isObject,
@ -101,7 +101,7 @@ export class QrCodeWidgetComponent extends PageComponent implements OnInit, Afte
const data = formattedDataFormDatasourceData(initialData);
const pattern = this.settings.useQrCodeTextFunction ?
safeExecute(this.qrCodeTextFunction, [data]) : this.settings.qrCodeTextPattern;
const allData: FormattedData = filteringData(data);
const allData: FormattedData = flatDataWithoutOverride(data);
qrCodeText = createLabelFromPattern(pattern, allData);
this.updateQrCodeText(qrCodeText);
}

Loading…
Cancel
Save