|
|
|
@ -23,8 +23,8 @@ import { |
|
|
|
telemetryTypeTranslationsShort |
|
|
|
} from '@shared/models/telemetry/telemetry.models'; |
|
|
|
import { WidgetContext } from '@home/models/widget-component.models'; |
|
|
|
import { BehaviorSubject, forkJoin, Observable, Observer, of, throwError } from 'rxjs'; |
|
|
|
import { catchError, delay, map, share, take } from 'rxjs/operators'; |
|
|
|
import { BehaviorSubject, forkJoin, Observable, Observer, of, Subscription, throwError } from 'rxjs'; |
|
|
|
import { catchError, delay, map, share, take, tap } from 'rxjs/operators'; |
|
|
|
import { UtilsService } from '@core/services/utils.service'; |
|
|
|
import { AfterViewInit, ChangeDetectorRef, Directive, Input, OnDestroy, OnInit, TemplateRef } from '@angular/core'; |
|
|
|
import { |
|
|
|
@ -186,8 +186,14 @@ export class DataToValueConverter<V> { |
|
|
|
case DataToValueType.FUNCTION: |
|
|
|
result = data; |
|
|
|
try { |
|
|
|
result = this.dataToValueFunction(!!data ? JSON.parse(data) : data); |
|
|
|
} catch (e) {} |
|
|
|
let input = data; |
|
|
|
if (!!data) { |
|
|
|
try { |
|
|
|
input = JSON.parse(data); |
|
|
|
} catch (_e) {} |
|
|
|
} |
|
|
|
result = this.dataToValueFunction(input); |
|
|
|
} catch (_e) {} |
|
|
|
break; |
|
|
|
case DataToValueType.NONE: |
|
|
|
result = data; |
|
|
|
@ -233,12 +239,16 @@ export abstract class ValueGetter<V> extends ValueAction { |
|
|
|
return new AttributeValueGetter<V>(ctx, settings, valueType, valueObserver); |
|
|
|
case GetValueAction.GET_TIME_SERIES: |
|
|
|
return new TimeSeriesValueGetter<V>(ctx, settings, valueType, valueObserver); |
|
|
|
case GetValueAction.GET_DASHBOARD_STATE: |
|
|
|
return new DashboardStateGetter<V>(ctx, settings, valueType, valueObserver); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private readonly isSimulated: boolean; |
|
|
|
private readonly dataConverter: DataToValueConverter<V>; |
|
|
|
|
|
|
|
private getValueSubscription: Subscription; |
|
|
|
|
|
|
|
protected constructor(protected ctx: WidgetContext, |
|
|
|
protected settings: GetValueSettings<V>, |
|
|
|
protected valueType: ValueType, |
|
|
|
@ -263,7 +273,10 @@ export abstract class ValueGetter<V> extends ValueAction { |
|
|
|
throw this.handleError(err); |
|
|
|
}) |
|
|
|
); |
|
|
|
valueObservable.subscribe({ |
|
|
|
if (this.getValueSubscription) { |
|
|
|
this.getValueSubscription.unsubscribe(); |
|
|
|
} |
|
|
|
this.getValueSubscription = valueObservable.subscribe({ |
|
|
|
next: (value) => { |
|
|
|
this.valueObserver.next(value); |
|
|
|
}, |
|
|
|
@ -277,6 +290,9 @@ export abstract class ValueGetter<V> extends ValueAction { |
|
|
|
} |
|
|
|
|
|
|
|
destroy() { |
|
|
|
if (this.getValueSubscription) { |
|
|
|
this.getValueSubscription.unsubscribe(); |
|
|
|
} |
|
|
|
super.destroy(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -504,6 +520,19 @@ export class TimeSeriesValueGetter<V> extends TelemetryValueGetter<V, TelemetryV |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class DashboardStateGetter<V> extends ValueGetter<V> { |
|
|
|
constructor(protected ctx: WidgetContext, |
|
|
|
protected settings: GetValueSettings<V>, |
|
|
|
protected valueType: ValueType, |
|
|
|
protected valueObserver: Partial<Observer<V>>) { |
|
|
|
super(ctx, settings, valueType, valueObserver); |
|
|
|
} |
|
|
|
|
|
|
|
protected doGetValue(): Observable<string> { |
|
|
|
return this.ctx.stateController.dashboardCtrl.dashboardCtx.stateId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class ExecuteRpcValueSetter<V> extends ValueSetter<V> { |
|
|
|
|
|
|
|
private readonly executeRpcSettings: RpcSettings; |
|
|
|
|