Browse Source

UI: timewindow configuration dialog introduction

pull/11633/head
Chantsova Ekaterina 2 years ago
parent
commit
9ca85d5cc7
  1. 6
      ui-ngx/src/app/shared/components/time/timeinterval.component.ts
  2. 211
      ui-ngx/src/app/shared/components/time/timewindow-config-dialog.component.html
  3. 70
      ui-ngx/src/app/shared/components/time/timewindow-config-dialog.component.scss
  4. 309
      ui-ngx/src/app/shared/components/time/timewindow-config-dialog.component.ts
  5. 15
      ui-ngx/src/app/shared/components/time/timewindow-panel.component.html
  6. 16
      ui-ngx/src/app/shared/components/time/timewindow-panel.component.scss
  7. 45
      ui-ngx/src/app/shared/components/time/timewindow-panel.component.ts
  8. 3
      ui-ngx/src/app/shared/shared.module.ts
  9. 10
      ui-ngx/src/assets/locale/locale.constant-en_US.json

6
ui-ngx/src/app/shared/components/time/timeinterval.component.ts

@ -190,9 +190,9 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor, OnDe
private setInterval(interval: Interval) {
if (!this.advanced) {
this.timeintervalFormGroup.get('interval').patchValue(interval);
this.timeintervalFormGroup.get('interval').patchValue(interval, {emitEvent: false});
} else {
this.timeintervalFormGroup.get('interval').patchValue(IntervalType.CUSTOM);
this.timeintervalFormGroup.get('interval').patchValue(IntervalType.CUSTOM, {emitEvent: false});
this.setCustomInterval(interval);
}
}
@ -204,7 +204,7 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor, OnDe
hours: Math.floor((intervalSeconds % 86400) / 3600),
mins: Math.floor(((intervalSeconds % 86400) % 3600) / 60),
secs: intervalSeconds % 60
});
}, {emitEvent: false});
}
private boundInterval(updateToPreferred = false) {

211
ui-ngx/src/app/shared/components/time/timewindow-config-dialog.component.html

@ -0,0 +1,211 @@
<!--
Copyright © 2016-2024 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<mat-toolbar color="primary">
<h2>{{ 'timewindow.timewindow-settings' | translate }}</h2>
<span fxFlex></span>
<!-- <div tb-help="#"></div>-->
<button mat-icon-button
(click)="cancel()"
type="button">
<mat-icon class="material-icons">close</mat-icon>
</button>
</mat-toolbar>
<form [formGroup]="timewindowForm" class="mat-content">
<mat-tab-group (selectedTabChange)="onTimewindowTypeChange()" [(selectedIndex)]="timewindow.selectedTab">
<mat-tab label="{{ 'timewindow.realtime' | translate }}">
<div class="tb-flex column">
<section class="tb-form-panel stroked">
<div class="tb-flex space-between"
[ngClass]="{'align-end': realtimeTypeSelectionAvailable, 'align-center': !realtimeTypeSelectionAvailable }">
<div class="tb-flex column no-flex flex-xs">
<div class="tb-form-panel-title">{{ 'timewindow.time-range' | translate }}</div>
<ng-container formGroupName="realtime" *ngIf="realtimeTypeSelectionAvailable">
<tb-toggle-select appearance="fill" [options]="realtimeTimewindowOptions" formControlName="realtimeType">
</tb-toggle-select>
</ng-container>
</div>
<ng-container *ngTemplateOutlet="timezoneSelection">
</ng-container>
</div>
<ng-container formGroupName="realtime">
<ng-container *ngIf="timewindowForm.get('realtime.realtimeType').value === realtimeTypes.LAST_INTERVAL">
<tb-timeinterval
formControlName="timewindowMs"
subscriptSizing="dynamic"
appearance="outline"
[required]="timewindow.selectedTab === timewindowTypes.REALTIME &&
timewindowForm.get('realtime.realtimeType').value === realtimeTypes.LAST_INTERVAL">
</tb-timeinterval>
</ng-container>
<ng-container *ngIf="timewindowForm.get('realtime.realtimeType').value === realtimeTypes.INTERVAL">
<tb-quick-time-interval
displayLabel="false"
formControlName="quickInterval"
onlyCurrentInterval="true"
subscriptSizing="dynamic"
appearance="outline"
[required]="timewindow.selectedTab === timewindowTypes.REALTIME &&
timewindowForm.get('realtime.realtimeType').value === realtimeTypes.INTERVAL">
</tb-quick-time-interval>
</ng-container>
</ng-container>
</section>
<ng-container *ngTemplateOutlet="aggregationConfig">
</ng-container>
</div>
</mat-tab>
<mat-tab label="{{ 'timewindow.history' | translate }}">
<div class="tb-flex column">
<section class="tb-form-panel stroked">
<div class="tb-flex space-between align-end">
<div class="tb-flex column no-flex flex-xs">
<div class="tb-form-panel-title">{{ 'timewindow.time-range' | translate }}</div>
<ng-container formGroupName="history">
<tb-toggle-select appearance="fill" [options]="historyTimewindowOptions" formControlName="historyType">
</tb-toggle-select>
</ng-container>
</div>
<ng-container *ngTemplateOutlet="timezoneSelection">
</ng-container>
</div>
<ng-container formGroupName="history">
<ng-container *ngIf="timewindowForm.get('history.historyType').value === historyTypes.LAST_INTERVAL">
<tb-timeinterval
formControlName="timewindowMs"
subscriptSizing="dynamic"
appearance="outline"
[required]="timewindow.selectedTab === timewindowTypes.HISTORY &&
timewindowForm.get('history.historyType').value === historyTypes.LAST_INTERVAL">
</tb-timeinterval>
</ng-container>
<ng-container *ngIf="timewindowForm.get('history.historyType').value === historyTypes.FIXED">
<tb-datetime-period
formControlName="fixedTimewindow"
subscriptSizing="dynamic"
appearance="outline"
class="history-time-input"
[required]="timewindow.selectedTab === timewindowTypes.HISTORY &&
timewindowForm.get('history.historyType').value === historyTypes.FIXED">
</tb-datetime-period>
</ng-container>
<ng-container *ngIf="timewindowForm.get('history.historyType').value === historyTypes.INTERVAL">
<tb-quick-time-interval
displayLabel="false"
formControlName="quickInterval"
subscriptSizing="dynamic"
appearance="outline"
[required]="timewindow.selectedTab === timewindowTypes.HISTORY &&
timewindowForm.get('history.historyType').value === historyTypes.INTERVAL">
</tb-quick-time-interval>
</ng-container>
</ng-container>
</section>
<ng-container *ngTemplateOutlet="aggregationConfig">
</ng-container>
</div>
</mat-tab>
</mat-tab-group>
<ng-template #aggregationConfig>
<div class="tb-flex column">
<ng-container formGroupName="aggregation">
<section class="tb-form-panel stroked">
<div class="tb-form-panel-title">{{ 'aggregation.aggregation' | translate }}</div>
<mat-form-field subscriptSizing="dynamic" appearance="outline">
<mat-select formControlName="type">
<mat-option *ngFor="let aggregation of aggregations" [value]="aggregation">
{{ aggregationTypesTranslations.get(aggregationTypes[aggregation]) | translate }}
</mat-option>
</mat-select>
</mat-form-field>
</section>
<section class="tb-form-panel stroked"
*ngIf="timewindowForm.get('aggregation.type').value === aggregationTypes.NONE">
<div class="tb-form-panel-title">{{ 'aggregation.limit' | translate }}</div>
<div class="limit-slider-container" fxLayout="row" fxLayoutAlign="start center"
fxLayout.xs="column" fxLayoutAlign.xs="stretch">
<div fxLayout="row" fxLayoutAlign="start center" fxFlex>
<mat-slider fxFlex
min="{{minDatapointsLimit()}}"
max="{{maxDatapointsLimit()}}">
<input matSliderThumb formControlName="limit"/>
</mat-slider>
<mat-form-field class="limit-slider-value" subscriptSizing="dynamic" appearance="outline">
<input matInput formControlName="limit" type="number" step="1"
[value]="timewindowForm.get('aggregation.limit').value"
min="{{minDatapointsLimit()}}"
max="{{maxDatapointsLimit()}}"/>
</mat-form-field>
</div>
</div>
</section>
</ng-container>
<section class="tb-form-panel stroked" [fxShow]="timewindowForm.get('aggregation.type').value !== aggregationTypes.NONE">
<div class="tb-form-panel-title">{{ 'aggregation.group-interval' | translate }}</div>
<ng-container formGroupName="realtime" *ngIf="timewindow.selectedTab === timewindowTypes.REALTIME">
<tb-timeinterval
formControlName="interval"
[min]="minRealtimeAggInterval()" [max]="maxRealtimeAggInterval()"
useCalendarIntervals
subscriptSizing="dynamic"
appearance="outline">
</tb-timeinterval>
</ng-container>
<ng-container formGroupName="history" *ngIf="timewindow.selectedTab === timewindowTypes.HISTORY">
<tb-timeinterval
formControlName="interval"
[min]="minHistoryAggInterval()" [max]="maxHistoryAggInterval()"
useCalendarIntervals
subscriptSizing="dynamic"
appearance="outline">
</tb-timeinterval>
</ng-container>
</section>
</div>
</ng-template>
<ng-template #timezoneSelection>
<tb-timezone asButton strokedButton noMargin
localBrowserTimezonePlaceholderOnEmpty="true"
formControlName="timezone">
</tb-timezone>
</ng-template>
</form>
<mat-divider></mat-divider>
<div mat-dialog-actions class="tb-dialog-actions tb-flex flex-end no-gap">
<button type="button"
mat-button
[disabled]="(isLoading$ | async)"
(click)="cancel()">
{{ 'action.cancel' | translate }}
</button>
<button type="button"
mat-raised-button
color="primary"
(click)="update()"
[disabled]="(isLoading$ | async) || timewindowForm.invalid || !timewindowForm.dirty">
{{ 'action.apply' | translate }}
</button>
</div>

70
ui-ngx/src/app/shared/components/time/timewindow-config-dialog.component.scss

@ -0,0 +1,70 @@
/**
* Copyright © 2016-2024 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@import "../../../../scss/constants";
:host {
display: flex;
flex-direction: column;
max-height: 100%;
max-width: 100%;
background-color: #fff;
.tb-form-panel {
padding: 12px;
gap: 12px;
}
.mat-content {
overflow: hidden;
.tb-flex {
gap: 16px;
}
}
.limit-slider-container {
.limit-slider-value {
margin-left: 16px;
min-width: 25px;
max-width: 100px;
}
mat-form-field input[type=number] {
text-align: center;
}
}
@media #{$mat-gt-sm} {
.limit-slider-container {
> label {
margin-right: 16px;
width: min-content;
max-width: 40%;
}
}
}
}
:host ::ng-deep {
.mat-mdc-tab-group:not(.tb-headless) {
height: 100%;
}
.mat-mdc-tab-body-content {
padding: 12px 16px;
}
}

309
ui-ngx/src/app/shared/components/time/timewindow-config-dialog.component.ts

@ -0,0 +1,309 @@
///
/// Copyright © 2016-2024 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { Component, Inject, OnInit } from '@angular/core';
import {
aggregationTranslations,
AggregationType,
DAY,
HistoryWindowType,
quickTimeIntervalPeriod,
RealtimeWindowType,
Timewindow,
TimewindowType
} from '@shared/models/time/time.models';
import { PageComponent } from '@shared/components/page.component';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { TimeService } from '@core/services/time.service';
import { isDefined, isDefinedAndNotNull } from '@core/utils';
import { ToggleHeaderOption } from '@shared/components/toggle-header.component';
import { TranslateService } from '@ngx-translate/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
export interface TimewindowConfigDialogData {
quickIntervalOnly: boolean;
timewindow: Timewindow;
}
@Component({
selector: 'tb-timewindow-config-dialog',
templateUrl: './timewindow-config-dialog.component.html',
styleUrls: ['./timewindow-config-dialog.component.scss']
})
export class TimewindowConfigDialogComponent extends PageComponent implements OnInit {
quickIntervalOnly = false;
timewindow: Timewindow;
timewindowForm: UntypedFormGroup;
historyTypes = HistoryWindowType;
realtimeTypes = RealtimeWindowType;
timewindowTypes = TimewindowType;
aggregationTypes = AggregationType;
aggregations = Object.keys(AggregationType);
aggregationTypesTranslations = aggregationTranslations;
result: Timewindow;
realtimeTimewindowOptions: ToggleHeaderOption[] = [
{
name: this.translate.instant('timewindow.relative'),
value: this.realtimeTypes.INTERVAL
}
];
historyTimewindowOptions: ToggleHeaderOption[] = [
{
name: this.translate.instant('timewindow.last'),
value: this.historyTypes.LAST_INTERVAL
},
{
name: this.translate.instant('timewindow.fixed'),
value: this.historyTypes.FIXED
},
{
name: this.translate.instant('timewindow.relative'),
value: this.historyTypes.INTERVAL
}
];
realtimeTypeSelectionAvailable: boolean;
constructor(@Inject(MAT_DIALOG_DATA) public data: TimewindowConfigDialogData,
public dialogRef: MatDialogRef<TimewindowConfigDialogComponent, Timewindow>,
protected store: Store<AppState>,
public fb: UntypedFormBuilder,
private timeService: TimeService,
private translate: TranslateService) {
super(store);
this.quickIntervalOnly = data.quickIntervalOnly;
this.timewindow = data.timewindow;
if (!this.quickIntervalOnly) {
this.realtimeTimewindowOptions.unshift({
name: this.translate.instant('timewindow.last'),
value: this.realtimeTypes.LAST_INTERVAL
});
}
this.realtimeTypeSelectionAvailable = this.realtimeTimewindowOptions.length > 1;
}
ngOnInit(): void {
const hideInterval = this.timewindow.hideInterval || false;
const hideLastInterval = this.timewindow.hideLastInterval || false;
const hideQuickInterval = this.timewindow.hideQuickInterval || false;
const hideAggregation = this.timewindow.hideAggregation || false;
const hideAggInterval = this.timewindow.hideAggInterval || 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({
realtime: this.fb.group({
realtimeType: [ isDefined(realtime?.realtimeType) ? this.timewindow.realtime.realtimeType : RealtimeWindowType.LAST_INTERVAL ],
timewindowMs: [ isDefined(realtime?.timewindowMs) ? this.timewindow.realtime.timewindowMs : null ],
interval: [ isDefined(realtime?.interval) ? this.timewindow.realtime.interval : null ],
quickInterval: [ isDefined(realtime?.quickInterval) ? this.timewindow.realtime.quickInterval : null ]
}),
history: this.fb.group({
historyType: [ isDefined(history?.historyType) ? this.timewindow.history.historyType : HistoryWindowType.LAST_INTERVAL ],
timewindowMs: [ isDefined(history?.timewindowMs) ? this.timewindow.history.timewindowMs : null ],
interval: [ isDefined(history?.interval) ? this.timewindow.history.interval : null ],
fixedTimewindow: [ isDefined(history?.fixedTimewindow) ? this.timewindow.history.fixedTimewindow : null ],
quickInterval: [ isDefined(history?.quickInterval) ? this.timewindow.history.quickInterval : null ]
}),
aggregation: this.fb.group({
type: [ isDefined(aggregation?.type) ? this.timewindow.aggregation.type : null ],
limit: [ isDefined(aggregation?.limit) ? this.checkLimit(this.timewindow.aggregation.limit) : null ]
}),
timezone: [ isDefined(this.timewindow.timezone) ? this.timewindow.timezone : null ],
hideInterval: [ isDefinedAndNotNull(this.timewindow.hideInterval)
? this.timewindow.hideInterval : false ],
hideLastInterval: [{
value: isDefinedAndNotNull(this.timewindow.hideLastInterval)
? this.timewindow.hideLastInterval : false,
disabled: this.timewindow.hideInterval
}],
hideQuickInterval: [{
value: isDefinedAndNotNull(this.timewindow.hideQuickInterval)
? this.timewindow.hideQuickInterval : false,
disabled: this.timewindow.hideInterval
}],
hideAggregation: [ isDefinedAndNotNull(this.timewindow.hideAggregation)
? this.timewindow.hideAggregation : false ],
hideAggInterval: [ isDefinedAndNotNull(this.timewindow.hideAggInterval)
? this.timewindow.hideAggInterval : false ],
hideTimezone: [ isDefinedAndNotNull(this.timewindow.hideTimezone)
? this.timewindow.hideTimezone : false ]
});
this.updateValidators(this.timewindowForm.get('aggregation.type').value);
this.timewindowForm.get('aggregation.type').valueChanges.subscribe((aggregationType: AggregationType) => {
this.updateValidators(aggregationType);
});
this.timewindowForm.get('hideInterval').valueChanges.subscribe((value: boolean) => {
if (value) {
this.timewindowForm.get('hideLastInterval').disable();
this.timewindowForm.get('hideQuickInterval').disable();
} else {
this.timewindowForm.get('hideLastInterval').enable();
this.timewindowForm.get('hideQuickInterval').enable();
}
});
}
private checkLimit(limit?: number): number {
if (!limit || limit < this.minDatapointsLimit()) {
return this.minDatapointsLimit();
} else if (limit > this.maxDatapointsLimit()) {
return this.maxDatapointsLimit();
}
return limit;
}
private updateValidators(aggType: AggregationType) {
if (aggType !== AggregationType.NONE) {
this.timewindowForm.get('aggregation.limit').clearValidators();
} else {
this.timewindowForm.get('aggregation.limit').setValidators([Validators.min(this.minDatapointsLimit()),
Validators.max(this.maxDatapointsLimit())]);
}
this.timewindowForm.get('aggregation.limit').updateValueAndValidity({emitEvent: false});
}
onTimewindowTypeChange() {
this.timewindowForm.markAsDirty();
const timewindowFormValue = this.timewindowForm.getRawValue();
if (this.timewindow.selectedTab === TimewindowType.REALTIME) {
if (timewindowFormValue.history.historyType !== HistoryWindowType.FIXED) {
this.timewindowForm.get('realtime').patchValue({
realtimeType: Object.keys(RealtimeWindowType).includes(HistoryWindowType[timewindowFormValue.history.historyType]) ?
RealtimeWindowType[HistoryWindowType[timewindowFormValue.history.historyType]] :
timewindowFormValue.realtime.realtimeType,
timewindowMs: timewindowFormValue.history.timewindowMs,
quickInterval: timewindowFormValue.history.quickInterval.startsWith('CURRENT') ?
timewindowFormValue.history.quickInterval : timewindowFormValue.realtime.quickInterval
});
setTimeout(() => this.timewindowForm.get('realtime.interval').patchValue(timewindowFormValue.history.interval));
}
} else {
this.timewindowForm.get('history').patchValue({
historyType: HistoryWindowType[RealtimeWindowType[timewindowFormValue.realtime.realtimeType]],
timewindowMs: timewindowFormValue.realtime.timewindowMs,
quickInterval: timewindowFormValue.realtime.quickInterval
});
setTimeout(() => this.timewindowForm.get('history.interval').patchValue(timewindowFormValue.realtime.interval));
}
this.timewindowForm.patchValue({
aggregation: {
type: timewindowFormValue.aggregation.type,
limit: timewindowFormValue.aggregation.limit
},
timezone: timewindowFormValue.timezone
});
}
update() {
const timewindowFormValue = this.timewindowForm.getRawValue();
this.timewindow.realtime = {
realtimeType: timewindowFormValue.realtime.realtimeType,
timewindowMs: timewindowFormValue.realtime.timewindowMs,
quickInterval: timewindowFormValue.realtime.quickInterval,
interval: timewindowFormValue.realtime.interval
};
this.timewindow.history = {
historyType: timewindowFormValue.history.historyType,
timewindowMs: timewindowFormValue.history.timewindowMs,
interval: timewindowFormValue.history.interval,
fixedTimewindow: timewindowFormValue.history.fixedTimewindow,
quickInterval: timewindowFormValue.history.quickInterval,
};
this.timewindow.aggregation = {
type: timewindowFormValue.aggregation.type,
limit: timewindowFormValue.aggregation.limit
};
this.timewindow.timezone = timewindowFormValue.timezone;
this.result = this.timewindow;
this.dialogRef.close(this.result);
}
cancel() {
this.dialogRef.close();
}
minDatapointsLimit() {
return this.timeService.getMinDatapointsLimit();
}
maxDatapointsLimit() {
return this.timeService.getMaxDatapointsLimit();
}
minRealtimeAggInterval() {
return this.timeService.minIntervalLimit(this.currentRealtimeTimewindow());
}
maxRealtimeAggInterval() {
return this.timeService.maxIntervalLimit(this.currentRealtimeTimewindow());
}
currentRealtimeTimewindow(): number {
const timeWindowFormValue = this.timewindowForm.getRawValue();
switch (timeWindowFormValue.realtime.realtimeType) {
case RealtimeWindowType.LAST_INTERVAL:
return timeWindowFormValue.realtime.timewindowMs;
case RealtimeWindowType.INTERVAL:
return quickTimeIntervalPeriod(timeWindowFormValue.realtime.quickInterval);
default:
return DAY;
}
}
minHistoryAggInterval() {
return this.timeService.minIntervalLimit(this.currentHistoryTimewindow());
}
maxHistoryAggInterval() {
return this.timeService.maxIntervalLimit(this.currentHistoryTimewindow());
}
currentHistoryTimewindow() {
const timewindowFormValue = this.timewindowForm.getRawValue();
if (timewindowFormValue.history.historyType === HistoryWindowType.LAST_INTERVAL) {
return timewindowFormValue.history.timewindowMs;
} else if (timewindowFormValue.history.historyType === HistoryWindowType.INTERVAL) {
return quickTimeIntervalPeriod(timewindowFormValue.history.quickInterval);
} else if (timewindowFormValue.history.fixedTimewindow) {
return timewindowFormValue.history.fixedTimewindow.endTimeMs -
timewindowFormValue.history.fixedTimewindow.startTimeMs;
} else {
return DAY;
}
}
}

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

@ -80,7 +80,7 @@
</ng-container>
</div>
<ng-container formGroupName="history" *ngIf="isEdit || !timewindow.hideInterval &&
<ng-container formGroupName="history" *ngIf="historyIntervalSelectionAvailable &&
timewindowForm.get('history.historyType').value !== historyTypes.FOR_ALL_TIME">
<ng-container *ngIf="timewindowForm.get('history.historyType').value === historyTypes.LAST_INTERVAL">
<tb-timeinterval
@ -119,6 +119,14 @@
</ng-container>
</div>
</mat-tab>
<mat-tab disabled labelClass="timewindow-config-btn">
<!-- <mat-tab *ngIf="isEdit" disabled>-->
<ng-template mat-tab-label>
<button mat-icon-button (click)="openTimewindowConfig()">
<mat-icon>settings</mat-icon>
</button>
</ng-template>
</mat-tab>
</mat-tab-group>
<ng-template #aggregationConfig>
<div *ngIf="aggregation" class="tb-flex column">
@ -141,9 +149,6 @@
fxLayout.xs="column" fxLayoutAlign.xs="stretch">
<div fxLayout="row" fxLayoutAlign="start center" fxFlex>
<mat-slider fxFlex
discrete
showTickMarks
step="{{datapointsLimitSliderStep()}}"
min="{{minDatapointsLimit()}}"
max="{{maxDatapointsLimit()}}">
<input matSliderThumb formControlName="limit"/>
@ -200,7 +205,7 @@
</ng-template>
</form>
<mat-divider></mat-divider>
<div fxLayout="row" class="tb-panel-actions" fxLayoutAlign="end center">
<div class="tb-panel-actions tb-flex flex-end no-gap">
<button type="button"
mat-button
[disabled]="(isLoading$ | async)"

16
ui-ngx/src/app/shared/components/time/timewindow-panel.component.scss

@ -27,12 +27,12 @@
gap: 12px;
}
.tb-flex {
gap: 16px;
}
.mat-content {
overflow: hidden;
.tb-flex {
gap: 16px;
}
}
.limit-slider-container {
@ -66,4 +66,12 @@
.mat-mdc-tab-body-content {
padding: 12px 16px;
}
.mat-mdc-tab-header .mat-mdc-tab.timewindow-config-btn {
flex-grow: unset;
min-width: 0;
padding: 0 8px;
color: unset;
opacity: unset;
}
}

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

@ -32,9 +32,13 @@ import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms
import { TimeService } from '@core/services/time.service';
import { isDefined } from '@core/utils';
import { OverlayRef } from '@angular/cdk/overlay';
import { WidgetConfigMode } from '@shared/models/widget.models';
import { ToggleHeaderOption } from '@shared/components/toggle-header.component';
import { TranslateService } from '@ngx-translate/core';
import { MatDialog } from '@angular/material/dialog';
import {
TimewindowConfigDialogComponent,
TimewindowConfigDialogData
} from '@shared/components/time/timewindow-config-dialog.component';
export interface TimewindowPanelData {
historyOnly: boolean;
@ -113,7 +117,8 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit {
public fb: UntypedFormBuilder,
private timeService: TimeService,
private translate: TranslateService,
public viewContainerRef: ViewContainerRef) {
public viewContainerRef: ViewContainerRef,
private dialog: MatDialog) {
super(store);
this.historyOnly = data.historyOnly;
this.forAllTimeEnabled = data.forAllTimeEnabled;
@ -277,6 +282,12 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit {
}
update() {
this.prepareTimewindowConfig();
this.result = this.timewindow;
this.overlayRef.dispose();
}
private prepareTimewindowConfig() {
const timewindowFormValue = this.timewindowForm.getRawValue();
this.timewindow.realtime = {
realtimeType: timewindowFormValue.realtime.realtimeType,
@ -300,8 +311,6 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit {
if (this.timezone) {
this.timewindow.timezone = timewindowFormValue.timezone;
}
this.result = this.timewindow;
this.overlayRef.dispose();
}
cancel() {
@ -316,11 +325,6 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit {
return this.timeService.getMaxDatapointsLimit();
}
// TODO: find more accurate step size for slider
datapointsLimitSliderStep() {
return Math.round(this.maxDatapointsLimit() / 10);
}
minRealtimeAggInterval() {
return this.timeService.minIntervalLimit(this.currentRealtimeTimewindow());
}
@ -447,5 +451,26 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit {
this.timewindowForm.markAsDirty();
}
protected readonly WidgetConfigMode = WidgetConfigMode;
openTimewindowConfig() {
this.prepareTimewindowConfig();
console.log(this.timewindow);
this.dialog.open<TimewindowConfigDialogComponent, TimewindowConfigDialogData, Timewindow>(
TimewindowConfigDialogComponent, {
autoFocus: false,
disableClose: false,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
quickIntervalOnly: this.quickIntervalOnly,
timewindow: this.timewindow
}
}).afterClosed()
.subscribe((res) => {
if (res) {
// update timewindow
console.log(res);
// TODO: propagate changes to form
this.timewindow = res;
}
});
}
}

3
ui-ngx/src/app/shared/shared.module.ts

@ -221,6 +221,7 @@ import { WidgetButtonComponent } from '@shared/components/button/widget-button.c
import { HexInputComponent } from '@shared/components/color-picker/hex-input.component';
import { TimezoneComponent } from '@shared/components/time/timezone.component';
import { TimezonePanelComponent } from '@shared/components/time/timezone-panel.component';
import { TimewindowConfigDialogComponent } from '@shared/components/time/timewindow-config-dialog.component';
export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) {
return markedOptionsService;
@ -303,6 +304,7 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService)
UserMenuComponent,
TimewindowComponent,
TimewindowPanelComponent,
TimewindowConfigDialogComponent,
TimeintervalComponent,
TimezoneComponent,
TimezonePanelComponent,
@ -509,6 +511,7 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService)
UserMenuComponent,
TimewindowComponent,
TimewindowPanelComponent,
TimewindowConfigDialogComponent,
TimeintervalComponent,
TimezoneComponent,
TimezonePanelComponent,

10
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -4652,6 +4652,7 @@
},
"timewindow": {
"timewindow": "Timewindow",
"timewindow-settings": "Timewindow settings",
"years": "{ years, plural, =1 { year } other {# years } }",
"years-short": "{{ years }}y",
"months": "{ months, plural, =1 { month } other {# months } }",
@ -4700,7 +4701,14 @@
"preview": "Preview",
"time-range": "Time range",
"relative": "Relative",
"fixed": "Fixed"
"fixed": "Fixed",
"hide-time-range": "Hide time range from end-users",
"hide-last-interval": "Hide last interval from end-users",
"hide-relative-interval": "Hide relative interval from end-users",
"hide-aggregation": "Hide aggregation from end-users",
"hide-group-interval": "Hide grouping interval from end-users",
"hide-timezone": "Hide timezone from end-users",
"disable-custom-interval": "Disable custom interval selection"
},
"tooltip": {
"trigger": "Trigger",

Loading…
Cancel
Save