Browse Source

Merge pull request #8641 from vvlladd28/bug/timewindow/incorrect-start-value

Fixed setting time window initialization being called twice
pull/8658/head
Igor Kulikov 3 years ago
committed by GitHub
parent
commit
79ced08ad6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ui-ngx/src/app/core/services/dashboard-utils.service.ts
  2. 13
      ui-ngx/src/app/modules/home/components/event/event-table.component.ts
  3. 2
      ui-ngx/src/app/shared/components/time/timewindow.component.html
  4. 93
      ui-ngx/src/app/shared/components/time/timewindow.component.ts
  5. 6
      ui-ngx/src/app/shared/models/time/time.models.ts

12
ui-ngx/src/app/core/services/dashboard-utils.service.ts

@ -30,7 +30,14 @@ import {
WidgetLayout
} from '@shared/models/dashboard.models';
import { isDefined, isString, isUndefined } from '@core/utils';
import { Datasource, DatasourceType, Widget, WidgetConfig, widgetType } from '@app/shared/models/widget.models';
import {
Datasource,
datasourcesHasOnlyComparisonAggregation,
DatasourceType,
Widget,
WidgetConfig,
widgetType
} from '@app/shared/models/widget.models';
import { EntityType } from '@shared/models/entity-type.models';
import { AliasFilterType, EntityAlias, EntityAliasFilter } from '@app/shared/models/alias.models';
import { EntityId } from '@app/shared/models/id/entity-id';
@ -227,7 +234,8 @@ export class DashboardUtilsService {
}
});
if (type === widgetType.latest) {
widgetConfig.timewindow = initModelFromDefaultTimewindow(widgetConfig.timewindow, true, this.timeService);
const onlyHistoryTimewindow = datasourcesHasOnlyComparisonAggregation(widgetConfig.datasources);
widgetConfig.timewindow = initModelFromDefaultTimewindow(widgetConfig.timewindow, true, onlyHistoryTimewindow, this.timeService);
}
if (type === widgetType.alarm) {
if (!widgetConfig.alarmFilterConfig) {

13
ui-ngx/src/app/modules/home/components/event/event-table.component.ts

@ -14,7 +14,16 @@
/// limitations under the License.
///
import { AfterViewInit, ChangeDetectorRef, Component, Input, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import {
AfterViewInit,
ChangeDetectorRef,
Component,
Input,
OnDestroy,
OnInit,
ViewChild,
ViewContainerRef
} from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '@angular/common';
import { MatDialog } from '@angular/material/dialog';
@ -32,7 +41,7 @@ import { Subscription } from 'rxjs';
templateUrl: './event-table.component.html',
styleUrls: ['./event-table.component.scss']
})
export class EventTableComponent implements OnInit, AfterViewInit {
export class EventTableComponent implements OnInit, AfterViewInit, OnDestroy {
@Input()
tenantId: string;

2
ui-ngx/src/app/shared/components/time/timewindow.component.html

@ -46,7 +46,7 @@
(click)="toggleTimewindow($event)"
matTooltip="{{ 'timewindow.edit' | translate }}"
[matTooltipPosition]="tooltipPosition">
{{innerValue?.displayValue}} <span [fxShow]="innerValue?.displayTimezoneAbbr !== ''">| <span class="timezone-abbr">{{innerValue.displayTimezoneAbbr}}</span></span>
{{innerValue?.displayValue}} <span [fxShow]="innerValue?.displayTimezoneAbbr !== ''">| <span class="timezone-abbr">{{innerValue?.displayTimezoneAbbr}}</span></span>
</span>
<button *ngIf="direction === 'right'" [disabled]="timewindowDisabled" mat-icon-button class="tb-mat-32"
type="button"

93
ui-ngx/src/app/shared/components/time/timewindow.component.ts

@ -21,8 +21,6 @@ import {
forwardRef,
Injector,
Input,
OnDestroy,
OnInit,
StaticProvider,
ViewContainerRef
} from '@angular/core';
@ -68,7 +66,7 @@ import { coerceBoolean } from '@shared/decorators/coercion';
}
]
})
export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAccessor {
export class TimewindowComponent implements ControlValueAccessor {
historyOnlyValue = false;
@ -91,71 +89,29 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
@coerceBoolean()
forAllTimeEnabled = false;
alwaysDisplayTypePrefixValue = false;
@Input()
set alwaysDisplayTypePrefix(val) {
this.alwaysDisplayTypePrefixValue = coerceBooleanProperty(val);
}
get alwaysDisplayTypePrefix() {
return this.alwaysDisplayTypePrefixValue;
}
quickIntervalOnlyValue = false;
@coerceBoolean()
alwaysDisplayTypePrefix = false;
@Input()
set quickIntervalOnly(val) {
this.quickIntervalOnlyValue = coerceBooleanProperty(val);
}
get quickIntervalOnly() {
return this.quickIntervalOnlyValue;
}
aggregationValue = false;
@coerceBoolean()
quickIntervalOnly = false;
@Input()
set aggregation(val) {
this.aggregationValue = coerceBooleanProperty(val);
}
get aggregation() {
return this.aggregationValue;
}
timezoneValue = false;
@coerceBoolean()
aggregation = false;
@Input()
set timezone(val) {
this.timezoneValue = coerceBooleanProperty(val);
}
get timezone() {
return this.timezoneValue;
}
isToolbarValue = false;
@coerceBoolean()
timezone = false;
@Input()
set isToolbar(val) {
this.isToolbarValue = coerceBooleanProperty(val);
}
get isToolbar() {
return this.isToolbarValue;
}
asButtonValue = false;
@coerceBoolean()
isToolbar = false;
@Input()
set asButton(val) {
this.asButtonValue = coerceBooleanProperty(val);
}
get asButton() {
return this.asButtonValue;
}
@coerceBoolean()
asButton = false;
@Input()
@coerceBoolean()
@ -179,7 +135,9 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
@Input()
tooltipPosition: TooltipPosition = 'above';
@Input() disabled: boolean;
@Input()
@coerceBoolean()
disabled: boolean;
innerValue: Timewindow;
@ -198,12 +156,6 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
public breakpointObserver: BreakpointObserver) {
}
ngOnInit(): void {
}
ngOnDestroy(): void {
}
toggleTimewindow($event: Event) {
if ($event) {
$event.stopPropagation();
@ -215,7 +167,6 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
maxHeight: '80vh',
height: 'min-content'
});
config.hasBackdrop = true;
const connectedPosition: ConnectedPosition = {
originX: 'start',
originY: 'bottom',
@ -262,12 +213,10 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
}
private onHistoryOnlyChanged(): boolean {
if (this.historyOnlyValue && this.innerValue) {
if (this.innerValue.selectedTab !== TimewindowType.HISTORY) {
this.innerValue.selectedTab = TimewindowType.HISTORY;
this.updateDisplayValue();
return true;
}
if (this.historyOnlyValue && this.innerValue && this.innerValue.selectedTab !== TimewindowType.HISTORY) {
this.innerValue.selectedTab = TimewindowType.HISTORY;
this.updateDisplayValue();
return true;
}
return false;
}
@ -285,7 +234,7 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
}
writeValue(obj: Timewindow): void {
this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.timeService);
this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.historyOnly, this.timeService);
this.timewindowDisabled = this.isTimewindowDisabled();
if (this.onHistoryOnlyChanged()) {
setTimeout(() => {

6
ui-ngx/src/app/shared/models/time/time.models.ts

@ -245,7 +245,8 @@ const getTimewindowType = (timewindow: Timewindow): TimewindowType => {
}
};
export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalOnly: boolean, timeService: TimeService): Timewindow => {
export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalOnly: boolean,
historyOnly: boolean, timeService: TimeService): Timewindow => {
const model = defaultTimewindow(timeService);
if (value) {
model.hideInterval = value.hideInterval;
@ -316,6 +317,9 @@ export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalO
if (quickIntervalOnly) {
model.realtime.realtimeType = RealtimeWindowType.INTERVAL;
}
if (historyOnly) {
model.selectedTab = TimewindowType.HISTORY;
}
return model;
};

Loading…
Cancel
Save