|
|
@ -21,17 +21,18 @@ import { Inject, Injectable, NgZone } from '@angular/core'; |
|
|
import { WINDOW } from '@core/services/window.service'; |
|
|
import { WINDOW } from '@core/services/window.service'; |
|
|
import { ExceptionData } from '@app/shared/models/error.models'; |
|
|
import { ExceptionData } from '@app/shared/models/error.models'; |
|
|
import { |
|
|
import { |
|
|
|
|
|
baseUrl, |
|
|
createLabelFromDatasource, |
|
|
createLabelFromDatasource, |
|
|
deepClone, |
|
|
deepClone, |
|
|
deleteNullProperties, |
|
|
deleteNullProperties, |
|
|
guid, |
|
|
guid, |
|
|
isDefined, |
|
|
isDefined, |
|
|
isDefinedAndNotNull, |
|
|
isDefinedAndNotNull, isString, |
|
|
isUndefined |
|
|
isUndefined |
|
|
} from '@core/utils'; |
|
|
} from '@core/utils'; |
|
|
import { WindowMessage } from '@shared/models/window-message.model'; |
|
|
import { WindowMessage } from '@shared/models/window-message.model'; |
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
import { customTranslationsPrefix } from '@app/shared/models/constants'; |
|
|
import { customTranslationsPrefix, i18nPrefix } from '@app/shared/models/constants'; |
|
|
import { DataKey, Datasource, DatasourceType, KeyInfo } from '@shared/models/widget.models'; |
|
|
import { DataKey, Datasource, DatasourceType, KeyInfo } from '@shared/models/widget.models'; |
|
|
import { EntityType } from '@shared/models/entity-type.models'; |
|
|
import { EntityType } from '@shared/models/entity-type.models'; |
|
|
import { DataKeyType } from '@app/shared/models/telemetry/telemetry.models'; |
|
|
import { DataKeyType } from '@app/shared/models/telemetry/telemetry.models'; |
|
|
@ -42,6 +43,8 @@ import jsonSchemaDefaults from 'json-schema-defaults'; |
|
|
import materialIconsCodepoints from '!raw-loader!material-design-icons/iconfont/codepoints'; |
|
|
import materialIconsCodepoints from '!raw-loader!material-design-icons/iconfont/codepoints'; |
|
|
import { Observable, of, ReplaySubject } from 'rxjs'; |
|
|
import { Observable, of, ReplaySubject } from 'rxjs'; |
|
|
|
|
|
|
|
|
|
|
|
const i18nRegExp = new RegExp(`{${i18nPrefix}:[^{}]+}`, 'g'); |
|
|
|
|
|
|
|
|
const predefinedFunctions: { [func: string]: string } = { |
|
|
const predefinedFunctions: { [func: string]: string } = { |
|
|
Sin: 'return Math.round(1000*Math.sin(time/5000));', |
|
|
Sin: 'return Math.round(1000*Math.sin(time/5000));', |
|
|
Cos: 'return Math.round(1000*Math.cos(time/5000));', |
|
|
Cos: 'return Math.round(1000*Math.cos(time/5000));', |
|
|
@ -107,8 +110,8 @@ export class UtilsService { |
|
|
materialIcons: Array<string> = []; |
|
|
materialIcons: Array<string> = []; |
|
|
|
|
|
|
|
|
constructor(@Inject(WINDOW) private window: Window, |
|
|
constructor(@Inject(WINDOW) private window: Window, |
|
|
private zone: NgZone, |
|
|
private zone: NgZone, |
|
|
private translate: TranslateService) { |
|
|
private translate: TranslateService) { |
|
|
let frame: Element = null; |
|
|
let frame: Element = null; |
|
|
try { |
|
|
try { |
|
|
frame = window.frameElement; |
|
|
frame = window.frameElement; |
|
|
@ -221,8 +224,31 @@ export class UtilsService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public customTranslation(translationValue: string, defaultValue: string): string { |
|
|
public customTranslation(translationValue: string, defaultValue: string): string { |
|
|
|
|
|
if (translationValue && isString(translationValue)) { |
|
|
|
|
|
if (translationValue.includes(`{${i18nPrefix}`)) { |
|
|
|
|
|
const matches = translationValue.match(i18nRegExp); |
|
|
|
|
|
let result = translationValue; |
|
|
|
|
|
for (const match of matches) { |
|
|
|
|
|
const translationId = match.substring(6, match.length - 1); |
|
|
|
|
|
result = result.replace(match, this.doTranslate(translationId, match)); |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} else { |
|
|
|
|
|
return this.doTranslate(translationValue, defaultValue, customTranslationsPrefix); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return translationValue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private doTranslate(translationValue: string, defaultValue: string, prefix?: string): string { |
|
|
let result: string; |
|
|
let result: string; |
|
|
const translationId = customTranslationsPrefix + translationValue; |
|
|
let translationId; |
|
|
|
|
|
if (prefix) { |
|
|
|
|
|
translationId = prefix + translationValue; |
|
|
|
|
|
} else { |
|
|
|
|
|
translationId = translationValue; |
|
|
|
|
|
} |
|
|
const translation = this.translate.instant(translationId); |
|
|
const translation = this.translate.instant(translationId); |
|
|
if (translation !== translationId) { |
|
|
if (translation !== translationId) { |
|
|
result = translation + ''; |
|
|
result = translation + ''; |
|
|
@ -384,7 +410,7 @@ export class UtilsService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public updateQueryParam(name: string, value: string | null) { |
|
|
public updateQueryParam(name: string, value: string | null) { |
|
|
const baseUrl = [this.window.location.protocol, '//', this.window.location.host, this.window.location.pathname].join(''); |
|
|
const baseUrlPart = [baseUrl(), this.window.location.pathname].join(''); |
|
|
const urlQueryString = this.window.location.search; |
|
|
const urlQueryString = this.window.location.search; |
|
|
let newParam = ''; |
|
|
let newParam = ''; |
|
|
let params = ''; |
|
|
let params = ''; |
|
|
@ -404,7 +430,11 @@ export class UtilsService { |
|
|
} else if (newParam) { |
|
|
} else if (newParam) { |
|
|
params = '?' + newParam; |
|
|
params = '?' + newParam; |
|
|
} |
|
|
} |
|
|
this.window.history.replaceState({}, '', baseUrl + params); |
|
|
this.window.history.replaceState({}, '', baseUrlPart + params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public baseUrl(): string { |
|
|
|
|
|
return baseUrl(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public deepClone<T>(target: T, ignoreFields?: string[]): T { |
|
|
public deepClone<T>(target: T, ignoreFields?: string[]): T { |
|
|
|