|
|
|
@ -17,16 +17,20 @@ |
|
|
|
import { Component, Input, OnInit } from '@angular/core'; |
|
|
|
import { |
|
|
|
HistoryWindowType, |
|
|
|
QuickTimeInterval, |
|
|
|
QuickTimeInterval, quickTimeIntervalPeriod, |
|
|
|
QuickTimeIntervalTranslationMap, |
|
|
|
RealtimeWindowType, |
|
|
|
TimewindowAllowedAggIntervalOption, |
|
|
|
TimewindowAllowedAggIntervalsConfig, |
|
|
|
TimewindowInterval, |
|
|
|
TimewindowIntervalOption, |
|
|
|
TimewindowType |
|
|
|
} from '@shared/models/time/time.models'; |
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms'; |
|
|
|
import { AbstractControl, FormBuilder, FormGroup, UntypedFormArray } from '@angular/forms'; |
|
|
|
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|
|
|
import { TimeService } from '@core/services/time.service'; |
|
|
|
import { coerceBoolean } from '@shared/decorators/coercion'; |
|
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-interval-options-config-panel', |
|
|
|
@ -40,7 +44,10 @@ export class IntervalOptionsConfigPanelComponent implements OnInit { |
|
|
|
aggregation = false; |
|
|
|
|
|
|
|
@Input() |
|
|
|
allowedIntervals: Array<any>; |
|
|
|
allowedIntervals: Array<TimewindowInterval>; |
|
|
|
|
|
|
|
@Input() |
|
|
|
allowedAggIntervals: TimewindowAllowedAggIntervalsConfig; |
|
|
|
|
|
|
|
@Input() |
|
|
|
intervalType: RealtimeWindowType | HistoryWindowType; |
|
|
|
@ -57,27 +64,72 @@ export class IntervalOptionsConfigPanelComponent implements OnInit { |
|
|
|
intervalOptionsConfigForm: FormGroup; |
|
|
|
|
|
|
|
allIntervals: Array<TimewindowIntervalOption>; |
|
|
|
allIntervalValues: Array<TimewindowInterval> |
|
|
|
|
|
|
|
private timeIntervalTranslationMap = QuickTimeIntervalTranslationMap; |
|
|
|
|
|
|
|
constructor(private fb: FormBuilder, |
|
|
|
private timeService: TimeService) {} |
|
|
|
private timeService: TimeService, |
|
|
|
private translate: TranslateService) {} |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
if (this.intervalType === RealtimeWindowType.LAST_INTERVAL || |
|
|
|
this.intervalType === HistoryWindowType.LAST_INTERVAL) { |
|
|
|
this.allIntervals = this.timeService.getIntervals(undefined, undefined, false); |
|
|
|
this.allIntervalValues = this.allIntervals.map(interval => interval.value); |
|
|
|
} else { |
|
|
|
const quickIntervals = this.getQuickIntervals(); |
|
|
|
this.allIntervals = quickIntervals.map(interval => ({ |
|
|
|
name: this.timeIntervalTranslationMap.get(interval), |
|
|
|
this.allIntervalValues = this.getQuickIntervals(); |
|
|
|
this.allIntervals = this.allIntervalValues.map(interval => ({ |
|
|
|
name: this.timeIntervalTranslationMap.get(interval as QuickTimeInterval), |
|
|
|
value: interval |
|
|
|
})); |
|
|
|
} |
|
|
|
|
|
|
|
this.intervalOptionsConfigForm = this.fb.group({ |
|
|
|
allowedIntervals: [this.allowedIntervals] |
|
|
|
allowedIntervals: [this.allowedIntervals?.length ? this.allowedIntervals : this.allIntervalValues], |
|
|
|
intervals: this.fb.array([]) |
|
|
|
}); |
|
|
|
|
|
|
|
if (this.aggregation) { |
|
|
|
const intervalControls: Array<AbstractControl> = []; |
|
|
|
for (const interval of this.allIntervals) { |
|
|
|
const intervalConfig: TimewindowAllowedAggIntervalOption = this.allowedAggIntervals?.hasOwnProperty(interval.value) |
|
|
|
? this.allIntervalValues[interval.value] |
|
|
|
: null; |
|
|
|
intervalControls.push(this.fb.group({ |
|
|
|
name: [this.translate.instant(interval.name, interval.translateParams)], |
|
|
|
value: [interval.value], |
|
|
|
enabled: [this.allowedIntervals?.length ? this.allowedIntervals.includes(interval.value) : true], |
|
|
|
aggIntervals: [intervalConfig ? intervalConfig.aggIntervals : []], |
|
|
|
preferredAggInterval: [intervalConfig ? intervalConfig.preferredAggInterval : null] |
|
|
|
})); |
|
|
|
} |
|
|
|
this.intervalOptionsConfigForm.setControl('intervals', this.fb.array(intervalControls), {emitEvent: false}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
get intervalsFormArray(): UntypedFormArray { |
|
|
|
return this.intervalOptionsConfigForm.get('intervals') as UntypedFormArray; |
|
|
|
} |
|
|
|
|
|
|
|
minAggInterval(interval: TimewindowInterval) { |
|
|
|
return this.timeService.minIntervalLimit(this.getIntervalMs(interval)); |
|
|
|
} |
|
|
|
|
|
|
|
maxAggInterval(interval: TimewindowInterval) { |
|
|
|
return this.timeService.maxIntervalLimit(this.getIntervalMs(interval)); |
|
|
|
} |
|
|
|
|
|
|
|
private getIntervalMs(interval: TimewindowInterval): number { |
|
|
|
if (this.intervalType === RealtimeWindowType.INTERVAL || |
|
|
|
this.intervalType === HistoryWindowType.INTERVAL) { |
|
|
|
return quickTimeIntervalPeriod(interval as QuickTimeInterval); |
|
|
|
} |
|
|
|
return interval as number; |
|
|
|
} |
|
|
|
|
|
|
|
trackByElement(i: number, item: any) { |
|
|
|
return item; |
|
|
|
} |
|
|
|
|
|
|
|
update() { |
|
|
|
|