Browse Source

UI: Refactoring code after review

pull/8641/head
Vladyslav_Prykhodko 3 years ago
parent
commit
ee91cc3033
  1. 16
      ui-ngx/src/app/core/services/dashboard-utils.service.ts
  2. 1
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html
  3. 2
      ui-ngx/src/app/modules/home/components/entity/entities-table.component.html
  4. 1
      ui-ngx/src/app/modules/home/components/widget/widget-container.component.html
  5. 25
      ui-ngx/src/app/shared/components/time/timewindow.component.ts
  6. 6
      ui-ngx/src/app/shared/models/time/time.models.ts

16
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, this.timeService, onlyHistoryTimewindow);
}
if (type === widgetType.alarm) {
if (!widgetConfig.alarmFilterConfig) {
@ -421,7 +429,7 @@ export class DashboardUtilsService {
targetLayout: DashboardLayoutId,
widget: Widget,
originalColumns?: number,
originalSize?: {sizeX: number, sizeY: number},
originalSize?: {sizeX: number; sizeY: number},
row?: number,
column?: number): void {
const dashboardConfiguration = dashboard.configuration;
@ -494,7 +502,7 @@ export class DashboardUtilsService {
this.removeUnusedWidgets(dashboard);
}
public isSingleLayoutDashboard(dashboard: Dashboard): {state: string, layout: DashboardLayoutId} {
public isSingleLayoutDashboard(dashboard: Dashboard): {state: string; layout: DashboardLayoutId} {
const dashboardConfiguration = dashboard.configuration;
const states = dashboardConfiguration.states;
const stateKeys = Object.keys(states);

1
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html

@ -107,7 +107,6 @@
tooltipPosition="below"
aggregation="true"
timezone="true"
isNgModel
[(ngModel)]="dashboardCtx.dashboardTimewindow">
</tb-timewindow>
<tb-filters-edit [fxShow]="!isEdit && displayFilters()"

2
ui-ngx/src/app/modules/home/components/entity/entities-table.component.html

@ -42,7 +42,7 @@
<tb-anchor #entityTableHeader></tb-anchor>
<tb-timewindow *ngIf="entitiesTableConfig.useTimePageLink"
[(ngModel)]="timewindow" (ngModelChange)="onTimewindowChange()"
asButton strokedButton historyOnly isNgModel
asButton strokedButton historyOnly
[forAllTimeEnabled]="entitiesTableConfig.forAllTimeEnabled">
</tb-timewindow>
</div>

1
ui-ngx/src/app/modules/home/components/widget/widget-container.component.html

@ -50,7 +50,6 @@
historyOnly="{{widget.onlyHistoryTimewindow}}"
alwaysDisplayTypePrefix
timezone="true"
isNgModel
[isEdit]="isEdit"
[(ngModel)]="widgetComponent.widget.config.timewindow"
(ngModelChange)="widgetComponent.onTimewindowChanged($event)">

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

@ -117,10 +117,6 @@ export class TimewindowComponent implements ControlValueAccessor {
@coerceBoolean()
strokedButton = false;
@Input()
@coerceBoolean()
isNgModel = false;
isEditValue = false;
@Input()
@ -149,8 +145,6 @@ export class TimewindowComponent implements ControlValueAccessor {
private propagateChange = (_: any) => {};
private _isControlInitialized = false;
constructor(private overlay: Overlay,
private translate: TranslateService,
private timeService: TimeService,
@ -229,7 +223,6 @@ export class TimewindowComponent implements ControlValueAccessor {
registerOnChange(fn: any): void {
this.propagateChange = fn;
this._isControlInitialized = true;
}
registerOnTouched(fn: any): void {
@ -241,16 +234,14 @@ export class TimewindowComponent implements ControlValueAccessor {
}
writeValue(obj: Timewindow): void {
if (this._isControlInitialized || !this.isNgModel) {
this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.timeService);
this.timewindowDisabled = this.isTimewindowDisabled();
if (this.onHistoryOnlyChanged()) {
setTimeout(() => {
this.notifyChanged();
});
} else {
this.updateDisplayValue();
}
this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.timeService, this.historyOnly);
this.timewindowDisabled = this.isTimewindowDisabled();
if (this.onHistoryOnlyChanged()) {
setTimeout(() => {
this.notifyChanged();
});
} else {
this.updateDisplayValue();
}
}

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,
timeService: TimeService, historyOnly: boolean): 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