38 changed files with 1034 additions and 682 deletions
@ -0,0 +1,113 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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]="flotWidgetConfigForm"> |
||||
|
<tb-timewindow-config-panel formControlName="timewindowConfig"> |
||||
|
</tb-timewindow-config-panel> |
||||
|
<tb-datasources |
||||
|
[configMode]="basicMode" |
||||
|
hideDataKeys |
||||
|
forceSingleDatasource |
||||
|
formControlName="datasources"> |
||||
|
</tb-datasources> |
||||
|
<tb-data-keys-panel |
||||
|
panelTitle="{{ 'widgets.chart.series' | translate }}" |
||||
|
addKeyTitle="{{ 'widgets.chart.add-series' | translate }}" |
||||
|
keySettingsTitle="{{ 'widgets.chart.series-settings' | translate }}" |
||||
|
removeKeyTitle="{{ 'widgets.chart.remove-series' | translate }}" |
||||
|
noKeysText="{{ 'widgets.chart.no-series' | translate }}" |
||||
|
requiredKeysText="{{ 'widgets.chart.no-series-error' | translate }}" |
||||
|
hideSourceSelection |
||||
|
[datasourceType]="datasource?.type" |
||||
|
[deviceId]="datasource?.deviceId" |
||||
|
[entityAliasId]="datasource?.entityAliasId" |
||||
|
formControlName="series"> |
||||
|
</tb-data-keys-panel> |
||||
|
<div class="tb-widget-config-panel"> |
||||
|
<div class="tb-widget-config-panel-title" translate>widget-config.card-appearance</div> |
||||
|
<div class="tb-widget-config-row"> |
||||
|
<mat-slide-toggle class="mat-slide fixed-title-width" 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]="flotWidgetConfigForm.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>widget-config.show-card-buttons</div> |
||||
|
<mat-chip-listbox multiple formControlName="cardButtons"> |
||||
|
<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.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> |
||||
|
<div class="tb-widget-config-panel"> |
||||
|
<div class="tb-widget-config-panel-title" translate>widgets.chart.chart-appearance</div> |
||||
|
<div class="tb-widget-config-row"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="verticalLines"> |
||||
|
{{ 'widgets.chart.vertical-grid-lines' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</div> |
||||
|
<div class="tb-widget-config-row"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="horizontalLines"> |
||||
|
{{ 'widgets.chart.horizontal-grid-lines' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</div> |
||||
|
<div class="tb-widget-config-panel tb-slide-toggle"> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="flotWidgetConfigForm.get('showLegend').value" [disabled]="!flotWidgetConfigForm.get('showLegend').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="showLegend" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widget-config.legend' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<tb-legend-config formControlName="legendConfig"> |
||||
|
</tb-legend-config> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</div> |
||||
|
</div> |
||||
|
<tb-widget-actions-panel |
||||
|
formControlName="actions"> |
||||
|
</tb-widget-actions-panel> |
||||
|
</ng-container> |
||||
@ -0,0 +1,167 @@ |
|||||
|
///
|
||||
|
/// 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, WidgetConfig } from '@shared/models/widget.models'; |
||||
|
import { WidgetConfigComponent } from '@home/components/widget/widget-config.component'; |
||||
|
import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; |
||||
|
import { isUndefined } from '@core/utils'; |
||||
|
import { getTimewindowConfig } from '@home/components/widget/config/timewindow-config-panel.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-flot-basic-config', |
||||
|
templateUrl: './flot-basic-config.component.html', |
||||
|
styleUrls: ['../basic-config.scss'] |
||||
|
}) |
||||
|
export class FlotBasicConfigComponent extends BasicWidgetConfigComponent { |
||||
|
|
||||
|
public get datasource(): Datasource { |
||||
|
const datasources: Datasource[] = this.flotWidgetConfigForm.get('datasources').value; |
||||
|
if (datasources && datasources.length) { |
||||
|
return datasources[0]; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
flotWidgetConfigForm: UntypedFormGroup; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected widgetConfigComponent: WidgetConfigComponent, |
||||
|
private fb: UntypedFormBuilder) { |
||||
|
super(store, widgetConfigComponent); |
||||
|
} |
||||
|
|
||||
|
protected configForm(): UntypedFormGroup { |
||||
|
return this.flotWidgetConfigForm; |
||||
|
} |
||||
|
|
||||
|
protected setupDefaults(configData: WidgetConfigComponentData) { |
||||
|
this.setupDefaultDatasource(configData, |
||||
|
[{ name: 'temperature', label: 'Temperature', type: DataKeyType.timeseries, units: '°C', decimals: 0 }]); |
||||
|
} |
||||
|
|
||||
|
protected onConfigSet(configData: WidgetConfigComponentData) { |
||||
|
this.flotWidgetConfigForm = this.fb.group({ |
||||
|
timewindowConfig: [getTimewindowConfig(configData.config), []], |
||||
|
datasources: [configData.config.datasources, []], |
||||
|
series: [this.getSeries(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, []], |
||||
|
verticalLines: [configData.config.settings?.grid?.verticalLines, []], |
||||
|
horizontalLines: [configData.config.settings?.grid?.horizontalLines, []], |
||||
|
showLegend: [configData.config.settings?.showLegend, []], |
||||
|
legendConfig: [configData.config.settings?.legendConfig, []], |
||||
|
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.setSeries(config.series, this.widgetConfig.config.datasources); |
||||
|
this.widgetConfig.config.actions = config.actions; |
||||
|
this.widgetConfig.config.showTitle = config.showTitle; |
||||
|
this.widgetConfig.config.title = config.title; |
||||
|
this.widgetConfig.config.showTitleIcon = config.showTitleIcon; |
||||
|
this.widgetConfig.config.titleIcon = config.titleIcon; |
||||
|
this.widgetConfig.config.iconColor = config.iconColor; |
||||
|
this.widgetConfig.config.settings = this.widgetConfig.config.settings || {}; |
||||
|
this.setCardButtons(config.cardButtons, this.widgetConfig.config); |
||||
|
this.widgetConfig.config.backgroundColor = config.backgroundColor; |
||||
|
this.widgetConfig.config.settings.grid = this.widgetConfig.config.settings.grid || {}; |
||||
|
this.widgetConfig.config.settings.grid.verticalLines = config.verticalLines; |
||||
|
this.widgetConfig.config.settings.grid.horizontalLines = config.horizontalLines; |
||||
|
this.widgetConfig.config.settings.showLegend = config.showLegend; |
||||
|
this.widgetConfig.config.settings.legendConfig = config.legendConfig; |
||||
|
return this.widgetConfig; |
||||
|
} |
||||
|
|
||||
|
protected validatorTriggers(): string[] { |
||||
|
return ['showTitle', 'showTitleIcon', 'showLegend']; |
||||
|
} |
||||
|
|
||||
|
protected updateValidators(emitEvent: boolean, trigger?: string) { |
||||
|
const showTitle: boolean = this.flotWidgetConfigForm.get('showTitle').value; |
||||
|
const showTitleIcon: boolean = this.flotWidgetConfigForm.get('showTitleIcon').value; |
||||
|
const showLegend: boolean = this.flotWidgetConfigForm.get('showLegend').value; |
||||
|
if (showTitle) { |
||||
|
this.flotWidgetConfigForm.get('title').enable(); |
||||
|
this.flotWidgetConfigForm.get('showTitleIcon').enable({emitEvent: false}); |
||||
|
if (showTitleIcon) { |
||||
|
this.flotWidgetConfigForm.get('titleIcon').enable(); |
||||
|
this.flotWidgetConfigForm.get('iconColor').enable(); |
||||
|
} else { |
||||
|
this.flotWidgetConfigForm.get('titleIcon').disable(); |
||||
|
this.flotWidgetConfigForm.get('iconColor').disable(); |
||||
|
} |
||||
|
} else { |
||||
|
this.flotWidgetConfigForm.get('title').disable(); |
||||
|
this.flotWidgetConfigForm.get('showTitleIcon').disable({emitEvent: false}); |
||||
|
this.flotWidgetConfigForm.get('titleIcon').disable(); |
||||
|
this.flotWidgetConfigForm.get('iconColor').disable(); |
||||
|
} |
||||
|
if (showLegend) { |
||||
|
this.flotWidgetConfigForm.get('legendConfig').enable(); |
||||
|
} else { |
||||
|
this.flotWidgetConfigForm.get('legendConfig').disable(); |
||||
|
} |
||||
|
this.flotWidgetConfigForm.get('title').updateValueAndValidity({emitEvent}); |
||||
|
this.flotWidgetConfigForm.get('showTitleIcon').updateValueAndValidity({emitEvent: false}); |
||||
|
this.flotWidgetConfigForm.get('titleIcon').updateValueAndValidity({emitEvent}); |
||||
|
this.flotWidgetConfigForm.get('iconColor').updateValueAndValidity({emitEvent}); |
||||
|
this.flotWidgetConfigForm.get('legendConfig').updateValueAndValidity({emitEvent}); |
||||
|
} |
||||
|
|
||||
|
private getSeries(datasources?: Datasource[]): DataKey[] { |
||||
|
if (datasources && datasources.length) { |
||||
|
return datasources[0].dataKeys || []; |
||||
|
} |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
private setSeries(series: DataKey[], datasources?: Datasource[]) { |
||||
|
if (datasources && datasources.length) { |
||||
|
datasources[0].dataKeys = series; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private getCardButtons(config: WidgetConfig): string[] { |
||||
|
const buttons: string[] = []; |
||||
|
if (isUndefined(config.enableFullscreen) || config.enableFullscreen) { |
||||
|
buttons.push('fullscreen'); |
||||
|
} |
||||
|
return buttons; |
||||
|
} |
||||
|
|
||||
|
private setCardButtons(buttons: string[], config: WidgetConfig) { |
||||
|
config.enableFullscreen = buttons.includes('fullscreen'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,107 +0,0 @@ |
|||||
/** |
|
||||
* 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 '../../../../../../scss/constants'; |
|
||||
|
|
||||
:host { |
|
||||
.tb-datakey-config { |
|
||||
.fields-group { |
|
||||
padding: 0 16px 8px; |
|
||||
margin-bottom: 10px; |
|
||||
border: 1px groove rgba(0, 0, 0, .25); |
|
||||
border-radius: 4px; |
|
||||
|
|
||||
legend { |
|
||||
color: rgba(0, 0, 0, .7); |
|
||||
width: fit-content; |
|
||||
} |
|
||||
|
|
||||
legend + * { |
|
||||
display: block; |
|
||||
margin-top: 16px; |
|
||||
} |
|
||||
|
|
||||
&.fields-group-slider { |
|
||||
padding: 0; |
|
||||
|
|
||||
legend { |
|
||||
margin-left: 16px; |
|
||||
} |
|
||||
|
|
||||
> .tb-settings { |
|
||||
margin-top: 0; |
|
||||
padding: 0 16px 8px; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
.tb-hint.after-fields { |
|
||||
margin-top: -0.75em; |
|
||||
max-width: fit-content; |
|
||||
line-height: 15px; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
:host ::ng-deep { |
|
||||
.tb-datakey-config { |
|
||||
.mat-expansion-panel { |
|
||||
&.tb-settings { |
|
||||
box-shadow: none; |
|
||||
|
|
||||
.mat-content { |
|
||||
overflow: visible; |
|
||||
} |
|
||||
|
|
||||
.mat-expansion-panel-header { |
|
||||
padding: 0; |
|
||||
color: rgba(0, 0, 0, 0.87); |
|
||||
|
|
||||
&:hover { |
|
||||
background: none; |
|
||||
} |
|
||||
|
|
||||
.mat-expansion-indicator { |
|
||||
padding: 2px; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
&.comparison { |
|
||||
.mat-expansion-panel-header { |
|
||||
height: fit-content; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
.mat-expansion-panel-header-description { |
|
||||
align-items: center; |
|
||||
} |
|
||||
|
|
||||
> .mat-expansion-panel-content { |
|
||||
> .mat-expansion-panel-body { |
|
||||
padding: 0; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
.mat-expansion-panel-content { |
|
||||
font: inherit; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
.mat-slide { |
|
||||
margin: 8px 0; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue