Refactoring
This commit is contained in:
parent
a77e5d93ee
commit
6f5fe7c081
@ -72,10 +72,6 @@ export class TimeService {
|
|||||||
IntervalMath.numberValue(interval.value) >= min && IntervalMath.numberValue(interval.value) <= max);
|
IntervalMath.numberValue(interval.value) >= min && IntervalMath.numberValue(interval.value) <= max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public intervalValuesToTimeIntervals(intervalValues: Array<Interval>): Array<TimeInterval> {
|
|
||||||
return defaultTimeIntervals.filter(interval => intervalValues.includes(interval.value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boundMinInterval(min: number): number {
|
public boundMinInterval(min: number): number {
|
||||||
if (isDefined(min)) {
|
if (isDefined(min)) {
|
||||||
min = Math.ceil(min / 1000) * 1000;
|
min = Math.ceil(min / 1000) * 1000;
|
||||||
|
|||||||
@ -335,8 +335,8 @@ import * as RuleChainSelectComponent from '@shared/components/rule-chain/rule-ch
|
|||||||
import * as TimezoneComponent from '@shared/components/time/timezone.component';
|
import * as TimezoneComponent from '@shared/components/time/timezone.component';
|
||||||
import * as TimezonePanelComponent from '@shared/components/time/timezone-panel.component';
|
import * as TimezonePanelComponent from '@shared/components/time/timezone-panel.component';
|
||||||
import * as DatapointsLimitComponent from '@shared/components/time/datapoints-limit.component';
|
import * as DatapointsLimitComponent from '@shared/components/time/datapoints-limit.component';
|
||||||
import * as AggregationTypeSelectComponent from '@shared/components/aggregation/aggregation-type-select.component';
|
import * as AggregationTypeSelectComponent from '@shared/components/time/aggregation/aggregation-type-select.component';
|
||||||
import * as AggregationOptionsConfigComponent from '@shared/components/aggregation/aggregation-options-config-panel.component';
|
import * as AggregationOptionsConfigComponent from '@shared/components/time/aggregation/aggregation-options-config-panel.component';
|
||||||
import * as IntervalOptionsConfigPanelComponent from '@shared/components/time/interval-options-config-panel.component';
|
import * as IntervalOptionsConfigPanelComponent from '@shared/components/time/interval-options-config-panel.component';
|
||||||
|
|
||||||
import { IModulesMap } from '@modules/common/modules-map.models';
|
import { IModulesMap } from '@modules/common/modules-map.models';
|
||||||
@ -475,8 +475,8 @@ class ModulesMap implements IModulesMap {
|
|||||||
'@shared/components/time/timezone.component': TimezoneComponent,
|
'@shared/components/time/timezone.component': TimezoneComponent,
|
||||||
'@shared/components/time/timezone-panel.component': TimezonePanelComponent,
|
'@shared/components/time/timezone-panel.component': TimezonePanelComponent,
|
||||||
'@shared/components/time/datapoints-limit.component': DatapointsLimitComponent,
|
'@shared/components/time/datapoints-limit.component': DatapointsLimitComponent,
|
||||||
'@shared/components/aggregation/aggregation-type-select.component': AggregationTypeSelectComponent,
|
'@shared/components/time/aggregation/aggregation-type-select.component': AggregationTypeSelectComponent,
|
||||||
'@shared/components/aggregation/aggregation-options-config-panel.component': AggregationOptionsConfigComponent,
|
'@shared/components/time/aggregation/aggregation-options-config-panel.component': AggregationOptionsConfigComponent,
|
||||||
'@shared/components/time/interval-options-config-panel.component': IntervalOptionsConfigPanelComponent,
|
'@shared/components/time/interval-options-config-panel.component': IntervalOptionsConfigPanelComponent,
|
||||||
'@shared/components/value-input.component': ValueInputComponent,
|
'@shared/components/value-input.component': ValueInputComponent,
|
||||||
'@shared/components/dashboard-autocomplete.component': DashboardAutocompleteComponent,
|
'@shared/components/dashboard-autocomplete.component': DashboardAutocompleteComponent,
|
||||||
|
|||||||
@ -14,13 +14,22 @@
|
|||||||
/// limitations under the License.
|
/// limitations under the License.
|
||||||
///
|
///
|
||||||
|
|
||||||
import { Component, forwardRef, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
|
import {
|
||||||
|
booleanAttribute,
|
||||||
|
Component,
|
||||||
|
forwardRef,
|
||||||
|
Input,
|
||||||
|
OnChanges,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
SimpleChanges
|
||||||
|
} from '@angular/core';
|
||||||
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
|
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||||
import { TimeService } from '@core/services/time.service';
|
import { TimeService } from '@core/services/time.service';
|
||||||
import { coerceNumberProperty } from '@angular/cdk/coercion';
|
import { coerceNumberProperty } from '@angular/cdk/coercion';
|
||||||
import { MatFormFieldAppearance, SubscriptSizing } from '@angular/material/form-field';
|
import { MatFormFieldAppearance, SubscriptSizing } from '@angular/material/form-field';
|
||||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||||
import { Interval, IntervalMath, TimeInterval } from '@shared/models/time/time.models';
|
import { Interval, IntervalMath, intervalValuesToTimeIntervals, TimeInterval } from '@shared/models/time/time.models';
|
||||||
import { isDefined, isEqual } from '@core/utils';
|
import { isDefined, isEqual } from '@core/utils';
|
||||||
import { IntervalType } from '@shared/models/telemetry/telemetry.models';
|
import { IntervalType } from '@shared/models/telemetry/telemetry.models';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntil } from 'rxjs/operators';
|
||||||
@ -43,9 +52,6 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor, OnCh
|
|||||||
minValue: number;
|
minValue: number;
|
||||||
maxValue: number;
|
maxValue: number;
|
||||||
|
|
||||||
disabledAdvancedState = false;
|
|
||||||
allowedIntervalsList: Array<Interval>;
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set min(min: number) {
|
set min(min: number) {
|
||||||
const minValueData = coerceNumberProperty(min);
|
const minValueData = coerceNumberProperty(min);
|
||||||
@ -72,23 +78,11 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor, OnCh
|
|||||||
@coerceBoolean()
|
@coerceBoolean()
|
||||||
isEdit = false;
|
isEdit = false;
|
||||||
|
|
||||||
@Input()
|
@Input({transform : booleanAttribute})
|
||||||
@coerceBoolean()
|
disabledAdvanced = false;
|
||||||
set disabledAdvanced(disabledAdvanced: boolean) {
|
|
||||||
if (this.disabledAdvancedState !== disabledAdvanced) {
|
|
||||||
this.disabledAdvancedState = disabledAdvanced;
|
|
||||||
this.updateIntervalValue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set allowedIntervals(allowedIntervals: Array<Interval>) {
|
allowedIntervals: Array<Interval>;
|
||||||
console.log('set', allowedIntervals);
|
|
||||||
if (!this.allowedIntervalsList || !isEqual(allowedIntervals, this.allowedIntervalsList)) {
|
|
||||||
this.allowedIntervalsList = allowedIntervals;
|
|
||||||
this.updateIntervalValue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@coerceBoolean()
|
@coerceBoolean()
|
||||||
@ -165,8 +159,11 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor, OnCh
|
|||||||
this.boundInterval();
|
this.boundInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges({allowedIntervals}: SimpleChanges): void {
|
ngOnChanges({disabledAdvanced, allowedIntervals}: SimpleChanges): void {
|
||||||
console.log('changes', allowedIntervals);
|
if ((disabledAdvanced && !disabledAdvanced.firstChange && disabledAdvanced.currentValue !== disabledAdvanced.previousValue) ||
|
||||||
|
(allowedIntervals && !allowedIntervals.firstChange && !isEqual(allowedIntervals.currentValue, allowedIntervals.previousValue))) {
|
||||||
|
this.updateIntervalValue(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOnChange(fn: any): void {
|
registerOnChange(fn: any): void {
|
||||||
@ -198,13 +195,13 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor, OnCh
|
|||||||
if (typeof this.modelValue !== 'undefined') {
|
if (typeof this.modelValue !== 'undefined') {
|
||||||
const min = this.timeService.boundMinInterval(this.minValue);
|
const min = this.timeService.boundMinInterval(this.minValue);
|
||||||
const max = this.timeService.boundMaxInterval(this.maxValue);
|
const max = this.timeService.boundMaxInterval(this.maxValue);
|
||||||
if (this.allowedIntervalsList?.length ||
|
if (this.allowedIntervals?.length ||
|
||||||
IntervalMath.numberValue(this.modelValue) >= min && IntervalMath.numberValue(this.modelValue) <= max) {
|
IntervalMath.numberValue(this.modelValue) >= min && IntervalMath.numberValue(this.modelValue) <= max) {
|
||||||
const advanced = this.allowedIntervalsList?.length
|
const advanced = this.allowedIntervals?.length
|
||||||
? !this.allowedIntervalsList.includes(this.modelValue)
|
? !this.allowedIntervals.includes(this.modelValue)
|
||||||
: !this.timeService.matchesExistingInterval(this.minValue, this.maxValue, this.modelValue,
|
: !this.timeService.matchesExistingInterval(this.minValue, this.maxValue, this.modelValue,
|
||||||
this.useCalendarIntervals);
|
this.useCalendarIntervals);
|
||||||
if (advanced && this.disabledAdvancedState) {
|
if (advanced && this.disabledAdvanced) {
|
||||||
this.advanced = false;
|
this.advanced = false;
|
||||||
this.boundInterval();
|
this.boundInterval();
|
||||||
} else {
|
} else {
|
||||||
@ -242,17 +239,17 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor, OnCh
|
|||||||
private boundInterval(updateToPreferred = false) {
|
private boundInterval(updateToPreferred = false) {
|
||||||
const min = this.timeService.boundMinInterval(this.minValue);
|
const min = this.timeService.boundMinInterval(this.minValue);
|
||||||
const max = this.timeService.boundMaxInterval(this.maxValue);
|
const max = this.timeService.boundMaxInterval(this.maxValue);
|
||||||
this.intervals = this.allowedIntervalsList?.length
|
this.intervals = this.allowedIntervals?.length
|
||||||
? this.timeService.intervalValuesToTimeIntervals(this.allowedIntervalsList)
|
? intervalValuesToTimeIntervals(this.allowedIntervals)
|
||||||
: this.timeService.getIntervals(this.minValue, this.maxValue, this.useCalendarIntervals);
|
: this.timeService.getIntervals(this.minValue, this.maxValue, this.useCalendarIntervals);
|
||||||
if (!this.disabledAdvancedState) {
|
if (!this.disabledAdvanced) {
|
||||||
this.intervals.push(this.customTimeInterval);
|
this.intervals.push(this.customTimeInterval);
|
||||||
}
|
}
|
||||||
if (this.rendered) {
|
if (this.rendered) {
|
||||||
let newInterval = this.modelValue;
|
let newInterval = this.modelValue;
|
||||||
if (this.allowedIntervalsList?.length) {
|
if (this.allowedIntervals?.length) {
|
||||||
if (!this.allowedIntervalsList.includes(newInterval) && !this.advanced) {
|
if (!this.allowedIntervals.includes(newInterval) && !this.advanced) {
|
||||||
newInterval = this.allowedIntervalsList[0];
|
newInterval = this.allowedIntervals[0];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const newIntervalMs = IntervalMath.numberValue(newInterval);
|
const newIntervalMs = IntervalMath.numberValue(newInterval);
|
||||||
|
|||||||
@ -42,7 +42,7 @@ import { takeUntil } from 'rxjs/operators';
|
|||||||
import { TbPopoverService } from '@shared/components/popover.service';
|
import { TbPopoverService } from '@shared/components/popover.service';
|
||||||
import {
|
import {
|
||||||
AggregationOptionsConfigPanelComponent
|
AggregationOptionsConfigPanelComponent
|
||||||
} from '@shared/components/aggregation/aggregation-options-config-panel.component';
|
} from '@shared/components/time/aggregation/aggregation-options-config-panel.component';
|
||||||
import { IntervalOptionsConfigPanelComponent } from '@shared/components/time/interval-options-config-panel.component';
|
import { IntervalOptionsConfigPanelComponent } from '@shared/components/time/interval-options-config-panel.component';
|
||||||
|
|
||||||
export interface TimewindowConfigDialogData {
|
export interface TimewindowConfigDialogData {
|
||||||
|
|||||||
@ -1054,6 +1054,10 @@ export const defaultTimeIntervals = new Array<TimeInterval>(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const intervalValuesToTimeIntervals = (intervalValues: Array<Interval>): Array<TimeInterval> => {
|
||||||
|
return defaultTimeIntervals.filter(interval => intervalValues.includes(interval.value));
|
||||||
|
}
|
||||||
|
|
||||||
export enum TimeUnit {
|
export enum TimeUnit {
|
||||||
SECONDS = 'SECONDS',
|
SECONDS = 'SECONDS',
|
||||||
MINUTES = 'MINUTES',
|
MINUTES = 'MINUTES',
|
||||||
|
|||||||
@ -218,8 +218,8 @@ import { CountryAutocompleteComponent } from '@shared/components/country-autocom
|
|||||||
import { CountryData } from '@shared/models/country.models';
|
import { CountryData } from '@shared/models/country.models';
|
||||||
import { SvgXmlComponent } from '@shared/components/svg-xml.component';
|
import { SvgXmlComponent } from '@shared/components/svg-xml.component';
|
||||||
import { DatapointsLimitComponent } from '@shared/components/time/datapoints-limit.component';
|
import { DatapointsLimitComponent } from '@shared/components/time/datapoints-limit.component';
|
||||||
import { AggregationTypeSelectComponent } from '@shared/components/aggregation/aggregation-type-select.component';
|
import { AggregationTypeSelectComponent } from '@shared/components/time/aggregation/aggregation-type-select.component';
|
||||||
import { AggregationOptionsConfigPanelComponent } from '@shared/components/aggregation/aggregation-options-config-panel.component';
|
import { AggregationOptionsConfigPanelComponent } from '@shared/components/time/aggregation/aggregation-options-config-panel.component';
|
||||||
import { IntervalOptionsConfigPanelComponent } from '@shared/components/time/interval-options-config-panel.component';
|
import { IntervalOptionsConfigPanelComponent } from '@shared/components/time/interval-options-config-panel.component';
|
||||||
|
|
||||||
export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) {
|
export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user