17 changed files with 538 additions and 159 deletions
@ -0,0 +1,94 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2023 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. |
||||
|
|
||||
|
--> |
||||
|
<ng-container [formGroup]="timeseriesTableWidgetConfigForm"> |
||||
|
<tb-timewindow-config-panel formControlName="timewindowConfig"> |
||||
|
</tb-timewindow-config-panel> |
||||
|
<tb-datasources |
||||
|
[configMode]="basicMode" |
||||
|
hideDataKeys |
||||
|
formControlName="datasources"> |
||||
|
</tb-datasources> |
||||
|
<tb-data-keys-panel |
||||
|
panelTitle="{{ 'widgets.table.columns' | translate }}" |
||||
|
addKeyTitle="{{ 'widgets.table.add-column' | translate }}" |
||||
|
keySettingsTitle="{{ 'widgets.table.column-settings' | translate }}" |
||||
|
removeKeyTitle="{{ 'widgets.table.remove-column' | translate }}" |
||||
|
noKeysText="{{ 'widgets.table.no-columns' | translate }}" |
||||
|
requiredKeysText="{{ 'widgets.table.timeseries-column-error' | translate }}" |
||||
|
hideDataKeyColor |
||||
|
[datasourceType]="datasource?.type" |
||||
|
[deviceId]="datasource?.deviceId" |
||||
|
[entityAliasId]="datasource?.entityAliasId" |
||||
|
formControlName="columns"> |
||||
|
</tb-data-keys-panel> |
||||
|
<div class="tb-widget-config-panel"> |
||||
|
<div class="tb-widget-config-panel-title" translate>widget-config.appearance</div> |
||||
|
<div class="tb-widget-config-row"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="showTitle"> |
||||
|
{{ 'widget-config.card-title' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="title" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-widget-config-row space-between same-padding"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="showTitleIcon"> |
||||
|
{{ 'widget-config.card-icon' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px"> |
||||
|
<tb-material-icon-select asBoxInput |
||||
|
[color]="timeseriesTableWidgetConfigForm.get('iconColor').value" |
||||
|
formControlName="titleIcon"> |
||||
|
</tb-material-icon-select> |
||||
|
<mat-divider vertical></mat-divider> |
||||
|
<tb-color-input asBoxInput |
||||
|
formControlName="iconColor"> |
||||
|
</tb-color-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-widget-config-row space-between"> |
||||
|
<div translate>widgets.table.show-card-buttons</div> |
||||
|
<mat-chip-listbox multiple formControlName="cardButtons"> |
||||
|
<mat-chip-option value="search">{{ 'action.search' | translate }}</mat-chip-option> |
||||
|
<mat-chip-option value="columnsToDisplay">{{ 'widgets.table.columns-to-display' | translate }}</mat-chip-option> |
||||
|
<mat-chip-option value="fullscreen">{{ 'fullscreen.fullscreen' | translate }}</mat-chip-option> |
||||
|
</mat-chip-listbox> |
||||
|
</div> |
||||
|
<div class="tb-widget-config-row space-between same-padding"> |
||||
|
<div>{{ 'widget-config.text-color' | translate }}</div> |
||||
|
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px"> |
||||
|
<mat-divider vertical></mat-divider> |
||||
|
<tb-color-input asBoxInput |
||||
|
formControlName="color"> |
||||
|
</tb-color-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-widget-config-row space-between same-padding"> |
||||
|
<div>{{ 'widget-config.background-color' | translate }}</div> |
||||
|
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px"> |
||||
|
<mat-divider vertical></mat-divider> |
||||
|
<tb-color-input asBoxInput |
||||
|
formControlName="backgroundColor"> |
||||
|
</tb-color-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<tb-widget-actions-panel |
||||
|
formControlName="actions"> |
||||
|
</tb-widget-actions-panel> |
||||
|
</ng-container> |
||||
@ -0,0 +1,181 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2023 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 } from '@angular/core'; |
||||
|
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { BasicWidgetConfigComponent } from '@home/components/widget/config/widget-config.component.models'; |
||||
|
import { WidgetConfigComponentData } from '@home/models/widget-component.models'; |
||||
|
import { |
||||
|
DataKey, |
||||
|
Datasource, |
||||
|
datasourcesHasAggregation, |
||||
|
datasourcesHasOnlyComparisonAggregation, WidgetConfig |
||||
|
} from '@shared/models/widget.models'; |
||||
|
import { WidgetConfigComponent } from '@home/components/widget/widget-config.component'; |
||||
|
import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; |
||||
|
import { deepClone, isUndefined } from '@core/utils'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-timeseries-table-basic-config', |
||||
|
templateUrl: './timeseries-table-basic-config.component.html', |
||||
|
styleUrls: ['../basic-config.scss'] |
||||
|
}) |
||||
|
export class TimeseriesTableBasicConfigComponent extends BasicWidgetConfigComponent { |
||||
|
|
||||
|
public get datasource(): Datasource { |
||||
|
const datasources: Datasource[] = this.timeseriesTableWidgetConfigForm.get('datasources').value; |
||||
|
if (datasources && datasources.length) { |
||||
|
return datasources[0]; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
timeseriesTableWidgetConfigForm: UntypedFormGroup; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected widgetConfigComponent: WidgetConfigComponent, |
||||
|
private fb: UntypedFormBuilder) { |
||||
|
super(store, widgetConfigComponent); |
||||
|
} |
||||
|
|
||||
|
protected configForm(): UntypedFormGroup { |
||||
|
return this.timeseriesTableWidgetConfigForm; |
||||
|
} |
||||
|
|
||||
|
protected setupDefaults(configData: WidgetConfigComponentData) { |
||||
|
this.setupDefaultDatasource(configData, |
||||
|
[{ name: 'temperature', label: 'Temperature', type: DataKeyType.timeseries, units: '°C', decimals: 0 }]); |
||||
|
} |
||||
|
|
||||
|
protected onConfigSet(configData: WidgetConfigComponentData) { |
||||
|
this.timeseriesTableWidgetConfigForm = this.fb.group({ |
||||
|
timewindowConfig: [{ |
||||
|
useDashboardTimewindow: configData.config.useDashboardTimewindow, |
||||
|
displayTimewindow: configData.config.displayTimewindow, |
||||
|
timewindow: configData.config.timewindow |
||||
|
}, []], |
||||
|
datasources: [configData.config.datasources, []], |
||||
|
columns: [this.getColumns(configData.config.datasources), []], |
||||
|
showTitle: [configData.config.showTitle, []], |
||||
|
title: [configData.config.title, []], |
||||
|
showTitleIcon: [configData.config.showTitleIcon, []], |
||||
|
titleIcon: [configData.config.titleIcon, []], |
||||
|
iconColor: [configData.config.iconColor, []], |
||||
|
cardButtons: [this.getCardButtons(configData.config), []], |
||||
|
color: [configData.config.color, []], |
||||
|
backgroundColor: [configData.config.backgroundColor, []], |
||||
|
actions: [configData.config.actions || {}, []] |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
protected prepareOutputConfig(config: any): WidgetConfigComponentData { |
||||
|
this.widgetConfig.config.useDashboardTimewindow = config.timewindowConfig.useDashboardTimewindow; |
||||
|
this.widgetConfig.config.displayTimewindow = config.timewindowConfig.displayTimewindow; |
||||
|
this.widgetConfig.config.timewindow = config.timewindowConfig.timewindow; |
||||
|
this.widgetConfig.config.datasources = config.datasources; |
||||
|
this.setColumns(config.columns, this.widgetConfig.config.datasources); |
||||
|
this.widgetConfig.config.actions = config.actions; |
||||
|
this.widgetConfig.config.showTitle = config.showTitle; |
||||
|
this.widgetConfig.config.settings = this.widgetConfig.config.settings || {}; |
||||
|
this.widgetConfig.config.settings.entitiesTitle = config.title; |
||||
|
this.widgetConfig.config.showTitleIcon = config.showTitleIcon; |
||||
|
this.widgetConfig.config.titleIcon = config.titleIcon; |
||||
|
this.widgetConfig.config.iconColor = config.iconColor; |
||||
|
this.setCardButtons(config.cardButtons, this.widgetConfig.config); |
||||
|
this.widgetConfig.config.color = config.color; |
||||
|
this.widgetConfig.config.backgroundColor = config.backgroundColor; |
||||
|
return this.widgetConfig; |
||||
|
} |
||||
|
|
||||
|
protected validatorTriggers(): string[] { |
||||
|
return ['showTitle', 'showTitleIcon']; |
||||
|
} |
||||
|
|
||||
|
protected updateValidators(emitEvent: boolean, trigger?: string) { |
||||
|
const showTitle: boolean = this.timeseriesTableWidgetConfigForm.get('showTitle').value; |
||||
|
const showTitleIcon: boolean = this.timeseriesTableWidgetConfigForm.get('showTitleIcon').value; |
||||
|
if (showTitle) { |
||||
|
this.timeseriesTableWidgetConfigForm.get('title').enable(); |
||||
|
this.timeseriesTableWidgetConfigForm.get('showTitleIcon').enable({emitEvent: false}); |
||||
|
if (showTitleIcon) { |
||||
|
this.timeseriesTableWidgetConfigForm.get('titleIcon').enable(); |
||||
|
this.timeseriesTableWidgetConfigForm.get('iconColor').enable(); |
||||
|
} else { |
||||
|
this.timeseriesTableWidgetConfigForm.get('titleIcon').disable(); |
||||
|
this.timeseriesTableWidgetConfigForm.get('iconColor').disable(); |
||||
|
} |
||||
|
} else { |
||||
|
this.timeseriesTableWidgetConfigForm.get('title').disable(); |
||||
|
this.timeseriesTableWidgetConfigForm.get('showTitleIcon').disable({emitEvent: false}); |
||||
|
this.timeseriesTableWidgetConfigForm.get('titleIcon').disable(); |
||||
|
this.timeseriesTableWidgetConfigForm.get('iconColor').disable(); |
||||
|
} |
||||
|
this.timeseriesTableWidgetConfigForm.get('title').updateValueAndValidity({emitEvent}); |
||||
|
this.timeseriesTableWidgetConfigForm.get('showTitleIcon').updateValueAndValidity({emitEvent: false}); |
||||
|
this.timeseriesTableWidgetConfigForm.get('titleIcon').updateValueAndValidity({emitEvent}); |
||||
|
this.timeseriesTableWidgetConfigForm.get('iconColor').updateValueAndValidity({emitEvent}); |
||||
|
} |
||||
|
|
||||
|
private getColumns(datasources?: Datasource[]): DataKey[] { |
||||
|
if (datasources && datasources.length) { |
||||
|
const dataKeys = deepClone(datasources[0].dataKeys) || []; |
||||
|
dataKeys.forEach(k => { |
||||
|
(k as any).latest = false; |
||||
|
}); |
||||
|
const latestDataKeys = deepClone(datasources[0].latestDataKeys) || []; |
||||
|
latestDataKeys.forEach(k => { |
||||
|
(k as any).latest = true; |
||||
|
}); |
||||
|
return dataKeys.concat(latestDataKeys); |
||||
|
} |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
private setColumns(columns: DataKey[], datasources?: Datasource[]) { |
||||
|
if (datasources && datasources.length) { |
||||
|
const dataKeys = deepClone(columns.filter(c => !(c as any).latest)); |
||||
|
dataKeys.forEach(k => delete (k as any).latest); |
||||
|
const latestDataKeys = deepClone(columns.filter(c => (c as any).latest)); |
||||
|
latestDataKeys.forEach(k => delete (k as any).latest); |
||||
|
datasources[0].dataKeys = dataKeys; |
||||
|
datasources[0].latestDataKeys = latestDataKeys; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private getCardButtons(config: WidgetConfig): string[] { |
||||
|
const buttons: string[] = []; |
||||
|
if (isUndefined(config.settings?.enableSearch) || config.settings?.enableSearch) { |
||||
|
buttons.push('search'); |
||||
|
} |
||||
|
if (isUndefined(config.settings?.enableSelectColumnDisplay) || config.settings?.enableSelectColumnDisplay) { |
||||
|
buttons.push('columnsToDisplay'); |
||||
|
} |
||||
|
if (isUndefined(config.enableFullscreen) || config.enableFullscreen) { |
||||
|
buttons.push('fullscreen'); |
||||
|
} |
||||
|
return buttons; |
||||
|
} |
||||
|
|
||||
|
private setCardButtons(buttons: string[], config: WidgetConfig) { |
||||
|
config.settings.enableSearch = buttons.includes('search'); |
||||
|
config.settings.enableSelectColumnDisplay = buttons.includes('columnsToDisplay'); |
||||
|
config.enableFullscreen = buttons.includes('fullscreen'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue