|
|
@ -14,7 +14,7 @@ |
|
|
/// limitations under the License.
|
|
|
/// limitations under the License.
|
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
import { Component, Inject, InjectionToken, OnInit, ViewContainerRef } from '@angular/core'; |
|
|
import { Component, Input, OnInit, ViewContainerRef } from '@angular/core'; |
|
|
import { |
|
|
import { |
|
|
aggregationTranslations, |
|
|
aggregationTranslations, |
|
|
AggregationType, |
|
|
AggregationType, |
|
|
@ -25,14 +25,12 @@ import { |
|
|
Timewindow, |
|
|
Timewindow, |
|
|
TimewindowType |
|
|
TimewindowType |
|
|
} from '@shared/models/time/time.models'; |
|
|
} from '@shared/models/time/time.models'; |
|
|
import { OverlayRef } from '@angular/cdk/overlay'; |
|
|
|
|
|
import { PageComponent } from '@shared/components/page.component'; |
|
|
import { PageComponent } from '@shared/components/page.component'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
import { AppState } from '@core/core.state'; |
|
|
import { AppState } from '@core/core.state'; |
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
import { TimeService } from '@core/services/time.service'; |
|
|
import { TimeService } from '@core/services/time.service'; |
|
|
|
|
|
import { isDefined } from '@core/utils'; |
|
|
export const TIMEWINDOW_PANEL_DATA = new InjectionToken<any>('TimewindowPanelData'); |
|
|
|
|
|
|
|
|
|
|
|
export interface TimewindowPanelData { |
|
|
export interface TimewindowPanelData { |
|
|
historyOnly: boolean; |
|
|
historyOnly: boolean; |
|
|
@ -50,6 +48,12 @@ export interface TimewindowPanelData { |
|
|
}) |
|
|
}) |
|
|
export class TimewindowPanelComponent extends PageComponent implements OnInit { |
|
|
export class TimewindowPanelComponent extends PageComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
data: any; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
onClose: (result: Timewindow | null) => void; |
|
|
|
|
|
|
|
|
historyOnly = false; |
|
|
historyOnly = false; |
|
|
|
|
|
|
|
|
quickIntervalOnly = false; |
|
|
quickIntervalOnly = false; |
|
|
@ -62,8 +66,6 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit { |
|
|
|
|
|
|
|
|
timewindow: Timewindow; |
|
|
timewindow: Timewindow; |
|
|
|
|
|
|
|
|
result: Timewindow; |
|
|
|
|
|
|
|
|
|
|
|
timewindowForm: FormGroup; |
|
|
timewindowForm: FormGroup; |
|
|
|
|
|
|
|
|
historyTypes = HistoryWindowType; |
|
|
historyTypes = HistoryWindowType; |
|
|
@ -78,22 +80,23 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit { |
|
|
|
|
|
|
|
|
aggregationTypesTranslations = aggregationTranslations; |
|
|
aggregationTypesTranslations = aggregationTranslations; |
|
|
|
|
|
|
|
|
constructor(@Inject(TIMEWINDOW_PANEL_DATA) public data: TimewindowPanelData, |
|
|
private result: Timewindow; |
|
|
public overlayRef: OverlayRef, |
|
|
|
|
|
protected store: Store<AppState>, |
|
|
constructor(protected store: Store<AppState>, |
|
|
public fb: FormBuilder, |
|
|
public fb: FormBuilder, |
|
|
private timeService: TimeService, |
|
|
private timeService: TimeService, |
|
|
public viewContainerRef: ViewContainerRef) { |
|
|
public viewContainerRef: ViewContainerRef) { |
|
|
super(store); |
|
|
super(store); |
|
|
this.historyOnly = data.historyOnly; |
|
|
|
|
|
this.quickIntervalOnly = data.quickIntervalOnly; |
|
|
|
|
|
this.timewindow = data.timewindow; |
|
|
|
|
|
this.aggregation = data.aggregation; |
|
|
|
|
|
this.timezone = data.timezone; |
|
|
|
|
|
this.isEdit = data.isEdit; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
ngOnInit(): void { |
|
|
|
|
|
this.historyOnly = this.data.historyOnly; |
|
|
|
|
|
this.quickIntervalOnly = this.data.quickIntervalOnly; |
|
|
|
|
|
this.timewindow = this.data.timewindow; |
|
|
|
|
|
this.aggregation = this.data.aggregation; |
|
|
|
|
|
this.timezone = this.data.timezone; |
|
|
|
|
|
this.isEdit = this.data.isEdit; |
|
|
|
|
|
|
|
|
const hideInterval = this.timewindow.hideInterval || false; |
|
|
const hideInterval = this.timewindow.hideInterval || false; |
|
|
const hideLastInterval = this.timewindow.hideLastInterval || false; |
|
|
const hideLastInterval = this.timewindow.hideLastInterval || false; |
|
|
const hideQuickInterval = this.timewindow.hideQuickInterval || false; |
|
|
const hideQuickInterval = this.timewindow.hideQuickInterval || false; |
|
|
@ -101,77 +104,60 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit { |
|
|
const hideAggInterval = this.timewindow.hideAggInterval || false; |
|
|
const hideAggInterval = this.timewindow.hideAggInterval || false; |
|
|
const hideTimezone = this.timewindow.hideTimezone || false; |
|
|
const hideTimezone = this.timewindow.hideTimezone || false; |
|
|
|
|
|
|
|
|
|
|
|
const realtime = this.timewindow.realtime; |
|
|
|
|
|
const history = this.timewindow.history; |
|
|
|
|
|
const aggregation = this.timewindow.aggregation; |
|
|
|
|
|
|
|
|
this.timewindowForm = this.fb.group({ |
|
|
this.timewindowForm = this.fb.group({ |
|
|
realtime: this.fb.group( |
|
|
realtime: this.fb.group({ |
|
|
{ |
|
|
realtimeType: [{ |
|
|
realtimeType: this.fb.control({ |
|
|
value: this.defined(realtime, realtime.realtimeType) ? this.timewindow.realtime.realtimeType : RealtimeWindowType.LAST_INTERVAL, |
|
|
value: this.timewindow.realtime && typeof this.timewindow.realtime.realtimeType !== 'undefined' |
|
|
disabled: hideInterval |
|
|
? this.timewindow.realtime.realtimeType : RealtimeWindowType.LAST_INTERVAL, |
|
|
}], |
|
|
disabled: hideInterval |
|
|
timewindowMs: [{ |
|
|
}), |
|
|
value: this.defined(realtime, realtime.timewindowMs) ? this.timewindow.realtime.timewindowMs : null, |
|
|
timewindowMs: this.fb.control({ |
|
|
disabled: hideInterval || hideLastInterval |
|
|
value: this.timewindow.realtime && typeof this.timewindow.realtime.timewindowMs !== 'undefined' |
|
|
}], |
|
|
? this.timewindow.realtime.timewindowMs : null, |
|
|
interval: [this.defined(realtime, realtime.interval) ? this.timewindow.realtime.interval : null], |
|
|
disabled: hideInterval || hideLastInterval |
|
|
quickInterval: [{ |
|
|
}), |
|
|
value: this.defined(realtime, realtime.quickInterval) ? this.timewindow.realtime.quickInterval : null, |
|
|
interval: [ |
|
|
disabled: hideInterval || hideQuickInterval |
|
|
this.timewindow.realtime && typeof this.timewindow.realtime.interval !== 'undefined' |
|
|
}] |
|
|
? this.timewindow.realtime.interval : null |
|
|
}), |
|
|
], |
|
|
history: this.fb.group({ |
|
|
quickInterval: this.fb.control({ |
|
|
historyType: [{ |
|
|
value: this.timewindow.realtime && typeof this.timewindow.realtime.quickInterval !== 'undefined' |
|
|
value: this.defined(history, history.historyType) ? this.timewindow.history.historyType : HistoryWindowType.LAST_INTERVAL, |
|
|
? this.timewindow.realtime.quickInterval : null, |
|
|
disabled: hideInterval |
|
|
disabled: hideInterval || hideQuickInterval |
|
|
}], |
|
|
}) |
|
|
timewindowMs: [{ |
|
|
} |
|
|
value: this.defined(history, history.timewindowMs) ? this.timewindow.history.timewindowMs : null, |
|
|
), |
|
|
disabled: hideInterval |
|
|
history: this.fb.group( |
|
|
}], |
|
|
{ |
|
|
interval: [ this.defined(history, history.interval) ? this.timewindow.history.interval : null |
|
|
historyType: this.fb.control({ |
|
|
], |
|
|
value: this.timewindow.history && typeof this.timewindow.history.historyType !== 'undefined' |
|
|
fixedTimewindow: [{ |
|
|
? this.timewindow.history.historyType : HistoryWindowType.LAST_INTERVAL, |
|
|
value: this.defined(history, history.fixedTimewindow) ? this.timewindow.history.fixedTimewindow : null, |
|
|
disabled: hideInterval |
|
|
disabled: hideInterval |
|
|
}), |
|
|
}], |
|
|
timewindowMs: this.fb.control({ |
|
|
quickInterval: [{ |
|
|
value: this.timewindow.history && typeof this.timewindow.history.timewindowMs !== 'undefined' |
|
|
value: this.defined(history, history.quickInterval) ? this.timewindow.history.quickInterval : null, |
|
|
? this.timewindow.history.timewindowMs : null, |
|
|
disabled: hideInterval |
|
|
disabled: hideInterval |
|
|
}] |
|
|
}), |
|
|
}), |
|
|
interval: [ |
|
|
aggregation: this.fb.group({ |
|
|
this.timewindow.history && typeof this.timewindow.history.interval !== 'undefined' |
|
|
type: [{ |
|
|
? this.timewindow.history.interval : null |
|
|
value: this.defined(aggregation, aggregation.type) ? this.timewindow.aggregation.type : null, |
|
|
], |
|
|
disabled: hideAggregation |
|
|
fixedTimewindow: this.fb.control({ |
|
|
}], |
|
|
value: this.timewindow.history && typeof this.timewindow.history.fixedTimewindow !== 'undefined' |
|
|
limit: [{ |
|
|
? this.timewindow.history.fixedTimewindow : null, |
|
|
value: this.defined(aggregation, aggregation.limit) ? this.checkLimit(this.timewindow.aggregation.limit) : null, |
|
|
disabled: hideInterval |
|
|
disabled: hideAggInterval |
|
|
}), |
|
|
}, []] |
|
|
quickInterval: this.fb.control({ |
|
|
}), |
|
|
value: this.timewindow.history && typeof this.timewindow.history.quickInterval !== 'undefined' |
|
|
timezone: [{ |
|
|
? this.timewindow.history.quickInterval : null, |
|
|
value: isDefined(this.timewindow.timezone) ? this.timewindow.timezone : null, |
|
|
disabled: hideInterval |
|
|
disabled: hideTimezone |
|
|
}) |
|
|
}] |
|
|
} |
|
|
|
|
|
), |
|
|
|
|
|
aggregation: this.fb.group( |
|
|
|
|
|
{ |
|
|
|
|
|
type: this.fb.control({ |
|
|
|
|
|
value: this.timewindow.aggregation && typeof this.timewindow.aggregation.type !== 'undefined' |
|
|
|
|
|
? this.timewindow.aggregation.type : null, |
|
|
|
|
|
disabled: hideAggregation |
|
|
|
|
|
}), |
|
|
|
|
|
limit: this.fb.control({ |
|
|
|
|
|
value: this.timewindow.aggregation && typeof this.timewindow.aggregation.limit !== 'undefined' |
|
|
|
|
|
? this.checkLimit(this.timewindow.aggregation.limit) : null, |
|
|
|
|
|
disabled: hideAggInterval |
|
|
|
|
|
}, []) |
|
|
|
|
|
} |
|
|
|
|
|
), |
|
|
|
|
|
timezone: this.fb.control({ |
|
|
|
|
|
value: this.timewindow.timezone !== 'undefined' |
|
|
|
|
|
? this.timewindow.timezone : null, |
|
|
|
|
|
disabled: hideTimezone |
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
}); |
|
|
this.updateValidators(); |
|
|
this.updateValidators(); |
|
|
this.timewindowForm.get('aggregation.type').valueChanges.subscribe(() => { |
|
|
this.timewindowForm.get('aggregation.type').valueChanges.subscribe(() => { |
|
|
@ -179,6 +165,10 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private defined(arg1, arg2) { |
|
|
|
|
|
return arg1 && isDefined(arg2); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private checkLimit(limit?: number): number { |
|
|
private checkLimit(limit?: number): number { |
|
|
if (!limit || limit < this.minDatapointsLimit()) { |
|
|
if (!limit || limit < this.minDatapointsLimit()) { |
|
|
return this.minDatapointsLimit(); |
|
|
return this.minDatapointsLimit(); |
|
|
@ -224,11 +214,13 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit { |
|
|
this.timewindow.timezone = timewindowFormValue.timezone; |
|
|
this.timewindow.timezone = timewindowFormValue.timezone; |
|
|
} |
|
|
} |
|
|
this.result = this.timewindow; |
|
|
this.result = this.timewindow; |
|
|
this.overlayRef.dispose(); |
|
|
this.cancel(this.result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cancel() { |
|
|
cancel(result: Timewindow | null = null) { |
|
|
this.overlayRef.dispose(); |
|
|
if (this.onClose) { |
|
|
|
|
|
this.onClose(result); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
minDatapointsLimit() { |
|
|
minDatapointsLimit() { |
|
|
|