175 changed files with 6942 additions and 6893 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,19 @@ |
|||
///
|
|||
/// 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.
|
|||
///
|
|||
|
|||
export * from './notification-websocket.service'; |
|||
export * from './telemetry-websocket.service'; |
|||
export * from './websocket.service'; |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* 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'; |
|||
|
|||
.tb-add-widget-dialog { |
|||
.mat-mdc-dialog-content { |
|||
padding: 0; |
|||
position: relative; |
|||
} |
|||
@media #{$mat-gt-xs} { |
|||
width: 1200px; |
|||
.mat-mdc-dialog-content { |
|||
height: 600px; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
<!-- |
|||
|
|||
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]="valueCardWidgetConfigForm"> |
|||
<tb-timewindow-config-panel *ngIf="displayTimewindowConfig" |
|||
[onlyHistoryTimewindow]="onlyHistoryTimewindow()" |
|||
formControlName="timewindowConfig"> |
|||
</tb-timewindow-config-panel> |
|||
<tb-datasources |
|||
[configMode]="basicMode" |
|||
hideDataKeyLabel |
|||
hideDataKeyColor |
|||
hideDataKeyUnits |
|||
hideDataKeyDecimals |
|||
formControlName="datasources"> |
|||
</tb-datasources> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widget-config.appearance</div> |
|||
<tb-image-cards-select rowHeight="{{ horizontal ? '3:1' : '7:5' }}" |
|||
[cols]="horizontal ? 2 : 4" |
|||
[colsLtMd]="horizontal ? 1 : 2" |
|||
label="{{ 'widgets.value-card.layout' | translate }}" formControlName="layout"> |
|||
<tb-image-cards-select-option *ngFor="let layout of valueCardLayouts" |
|||
[value]="layout" |
|||
[image]="valueCardLayoutImageMap.get(layout)"> |
|||
{{ valueCardLayoutTranslationMap.get(layout) | translate }} |
|||
</tb-image-cards-select-option> |
|||
</tb-image-cards-select> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showLabel"> |
|||
{{ 'widgets.value-card.label' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="label" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-font-settings formControlName="labelFont" |
|||
[previewText]="valueCardWidgetConfigForm.get('label').value"> |
|||
</tb-font-settings> |
|||
<tb-color-settings formControlName="labelColor"> |
|||
</tb-color-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showIcon"> |
|||
{{ 'widgets.value-card.icon' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field fxFlex appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="iconSizeUnit"></tb-css-unit-select> |
|||
<tb-material-icon-select asBoxInput |
|||
[color]="valueCardWidgetConfigForm.get('iconColor').value?.color" |
|||
formControlName="icon"> |
|||
</tb-material-icon-select> |
|||
<tb-color-settings formControlName="iconColor"> |
|||
</tb-color-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" translate>widgets.value-card.value</div> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-unit-input fxFlex formControlName="units"></tb-unit-input> |
|||
<mat-form-field fxFlex appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="decimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<div matSuffix translate>widget-config.decimals-suffix</div> |
|||
</mat-form-field> |
|||
<tb-font-settings formControlName="valueFont" |
|||
[previewText]="valuePreviewFn"> |
|||
</tb-font-settings> |
|||
<tb-color-settings formControlName="valueColor"> |
|||
</tb-color-settings> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showDate"> |
|||
{{ 'widgets.value-card.date' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-date-format-select fxFlex formControlName="dateFormat"></tb-date-format-select> |
|||
<tb-font-settings formControlName="dateFont" |
|||
[previewText]="datePreviewFn"> |
|||
</tb-font-settings> |
|||
<tb-color-settings formControlName="dateColor"> |
|||
</tb-color-settings> |
|||
</div> |
|||
</div> |
|||
</ng-container> |
|||
@ -0,0 +1,276 @@ |
|||
///
|
|||
/// 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 { ChangeDetectorRef, Component, Injector } from '@angular/core'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } 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 { |
|||
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 { getTimewindowConfig } from '@home/components/widget/config/timewindow-config-panel.component'; |
|||
import { formatValue, isDefinedAndNotNull, isUndefined } from '@core/utils'; |
|||
import { |
|||
DateFormatProcessor, |
|||
DateFormatSettings, |
|||
getLabel, |
|||
setLabel |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
import { |
|||
valueCardDefaultSettings, |
|||
ValueCardLayout, |
|||
valueCardLayoutImages, |
|||
valueCardLayouts, |
|||
valueCardLayoutTranslations, |
|||
ValueCardWidgetSettings |
|||
} from '@home/components/widget/lib/cards/value-card-widget.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-value-card-basic-config', |
|||
templateUrl: './value-card-basic-config.component.html', |
|||
styleUrls: ['../basic-config.scss'] |
|||
}) |
|||
export class ValueCardBasicConfigComponent extends BasicWidgetConfigComponent { |
|||
|
|||
public get displayTimewindowConfig(): boolean { |
|||
const datasources = this.valueCardWidgetConfigForm.get('datasources').value; |
|||
return datasourcesHasAggregation(datasources); |
|||
} |
|||
|
|||
public onlyHistoryTimewindow(): boolean { |
|||
const datasources = this.valueCardWidgetConfigForm.get('datasources').value; |
|||
return datasourcesHasOnlyComparisonAggregation(datasources); |
|||
} |
|||
|
|||
valueCardLayouts: ValueCardLayout[] = []; |
|||
|
|||
valueCardLayoutTranslationMap = valueCardLayoutTranslations; |
|||
valueCardLayoutImageMap = valueCardLayoutImages; |
|||
|
|||
horizontal = false; |
|||
|
|||
valueCardWidgetConfigForm: UntypedFormGroup; |
|||
|
|||
valuePreviewFn = this._valuePreviewFn.bind(this); |
|||
|
|||
datePreviewFn = this._datePreviewFn.bind(this); |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected widgetConfigComponent: WidgetConfigComponent, |
|||
private cd: ChangeDetectorRef, |
|||
private $injector: Injector, |
|||
private fb: UntypedFormBuilder) { |
|||
super(store, widgetConfigComponent); |
|||
} |
|||
|
|||
protected configForm(): UntypedFormGroup { |
|||
return this.valueCardWidgetConfigForm; |
|||
} |
|||
|
|||
protected setupConfig(widgetConfig: WidgetConfigComponentData) { |
|||
const params = widgetConfig.typeParameters as any; |
|||
this.horizontal = isDefinedAndNotNull(params.horizontal) ? params.horizontal : false; |
|||
this.valueCardLayouts = valueCardLayouts(this.horizontal); |
|||
super.setupConfig(widgetConfig); |
|||
} |
|||
|
|||
protected setupDefaults(configData: WidgetConfigComponentData) { |
|||
this.setupDefaultDatasource(configData, [{ name: 'temperature', label: 'Temperature', type: DataKeyType.timeseries }]); |
|||
} |
|||
|
|||
protected onConfigSet(configData: WidgetConfigComponentData) { |
|||
const settings: ValueCardWidgetSettings = {...valueCardDefaultSettings(this.horizontal), ...(configData.config.settings || {})}; |
|||
this.valueCardWidgetConfigForm = this.fb.group({ |
|||
timewindowConfig: [getTimewindowConfig(configData.config), []], |
|||
datasources: [configData.config.datasources, []], |
|||
layout: [settings.layout, []], |
|||
|
|||
showLabel: [settings.showLabel, []], |
|||
label: [getLabel(configData.config.datasources), []], |
|||
labelFont: [settings.labelFont, []], |
|||
labelColor: [settings.labelColor, []], |
|||
|
|||
showIcon: [settings.showIcon, []], |
|||
iconSize: [settings.iconSize, [Validators.min(0)]], |
|||
iconSizeUnit: [settings.iconSizeUnit, []], |
|||
icon: [settings.icon, []], |
|||
iconColor: [settings.iconColor, []], |
|||
|
|||
units: [configData.config.units, []], |
|||
decimals: [configData.config.decimals, []], |
|||
valueFont: [settings.valueFont, []], |
|||
valueColor: [settings.valueColor, []], |
|||
|
|||
showDate: [settings.showDate, []], |
|||
dateFormat: [settings.dateFormat, []], |
|||
dateFont: [settings.dateFont, []], |
|||
dateColor: [settings.dateColor, []], |
|||
|
|||
background: [settings.background, []], |
|||
|
|||
cardButtons: [this.getCardButtons(configData.config), []], |
|||
borderRadius: [configData.config.borderRadius, []], |
|||
|
|||
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.widgetConfig.config.settings = this.widgetConfig.config.settings || {}; |
|||
|
|||
this.widgetConfig.config.settings.layout = config.layout; |
|||
|
|||
this.widgetConfig.config.settings.showLabel = config.showLabel; |
|||
setLabel(config.label, this.widgetConfig.config.datasources); |
|||
this.widgetConfig.config.settings.labelFont = config.labelFont; |
|||
this.widgetConfig.config.settings.labelColor = config.labelColor; |
|||
|
|||
this.widgetConfig.config.settings.showIcon = config.showIcon; |
|||
this.widgetConfig.config.settings.iconSize = config.iconSize; |
|||
this.widgetConfig.config.settings.iconSizeUnit = config.iconSizeUnit; |
|||
this.widgetConfig.config.settings.icon = config.icon; |
|||
this.widgetConfig.config.settings.iconColor = config.iconColor; |
|||
|
|||
this.widgetConfig.config.units = config.units; |
|||
this.widgetConfig.config.decimals = config.decimals; |
|||
this.widgetConfig.config.settings.valueFont = config.valueFont; |
|||
this.widgetConfig.config.settings.valueColor = config.valueColor; |
|||
|
|||
this.widgetConfig.config.settings.showDate = config.showDate; |
|||
this.widgetConfig.config.settings.dateFormat = config.dateFormat; |
|||
this.widgetConfig.config.settings.dateFont = config.dateFont; |
|||
this.widgetConfig.config.settings.dateColor = config.dateColor; |
|||
|
|||
this.widgetConfig.config.settings.background = config.background; |
|||
|
|||
this.setCardButtons(config.cardButtons, this.widgetConfig.config); |
|||
this.widgetConfig.config.borderRadius = config.borderRadius; |
|||
|
|||
this.widgetConfig.config.actions = config.actions; |
|||
return this.widgetConfig; |
|||
} |
|||
|
|||
protected validatorTriggers(): string[] { |
|||
return ['layout', 'showLabel', 'showIcon', 'showDate']; |
|||
} |
|||
|
|||
protected updateValidators(emitEvent: boolean, trigger?: string) { |
|||
const layout: ValueCardLayout = this.valueCardWidgetConfigForm.get('layout').value; |
|||
const showLabel: boolean = this.valueCardWidgetConfigForm.get('showLabel').value; |
|||
const showIcon: boolean = this.valueCardWidgetConfigForm.get('showIcon').value; |
|||
const showDate: boolean = this.valueCardWidgetConfigForm.get('showDate').value; |
|||
|
|||
const dateEnabled = ![ValueCardLayout.vertical, ValueCardLayout.simplified].includes(layout); |
|||
const iconEnabled = layout !== ValueCardLayout.simplified; |
|||
|
|||
if (showLabel) { |
|||
this.valueCardWidgetConfigForm.get('label').enable(); |
|||
this.valueCardWidgetConfigForm.get('labelFont').enable(); |
|||
this.valueCardWidgetConfigForm.get('labelColor').enable(); |
|||
} else { |
|||
this.valueCardWidgetConfigForm.get('label').disable(); |
|||
this.valueCardWidgetConfigForm.get('labelFont').disable(); |
|||
this.valueCardWidgetConfigForm.get('labelColor').disable(); |
|||
} |
|||
|
|||
if (iconEnabled) { |
|||
this.valueCardWidgetConfigForm.get('showIcon').enable({emitEvent: false}); |
|||
if (showIcon) { |
|||
this.valueCardWidgetConfigForm.get('iconSize').enable(); |
|||
this.valueCardWidgetConfigForm.get('iconSizeUnit').enable(); |
|||
this.valueCardWidgetConfigForm.get('icon').enable(); |
|||
this.valueCardWidgetConfigForm.get('iconColor').enable(); |
|||
} else { |
|||
this.valueCardWidgetConfigForm.get('iconSize').disable(); |
|||
this.valueCardWidgetConfigForm.get('iconSizeUnit').disable(); |
|||
this.valueCardWidgetConfigForm.get('icon').disable(); |
|||
this.valueCardWidgetConfigForm.get('iconColor').disable(); |
|||
} |
|||
} else { |
|||
this.valueCardWidgetConfigForm.get('showIcon').disable({emitEvent: false}); |
|||
this.valueCardWidgetConfigForm.get('iconSize').disable(); |
|||
this.valueCardWidgetConfigForm.get('iconSizeUnit').disable(); |
|||
this.valueCardWidgetConfigForm.get('icon').disable(); |
|||
this.valueCardWidgetConfigForm.get('iconColor').disable(); |
|||
} |
|||
|
|||
if (dateEnabled) { |
|||
this.valueCardWidgetConfigForm.get('showDate').enable({emitEvent: false}); |
|||
if (showDate) { |
|||
this.valueCardWidgetConfigForm.get('dateFormat').enable(); |
|||
this.valueCardWidgetConfigForm.get('dateFont').enable(); |
|||
this.valueCardWidgetConfigForm.get('dateColor').enable(); |
|||
} else { |
|||
this.valueCardWidgetConfigForm.get('dateFormat').disable(); |
|||
this.valueCardWidgetConfigForm.get('dateFont').disable(); |
|||
this.valueCardWidgetConfigForm.get('dateColor').disable(); |
|||
} |
|||
} else { |
|||
this.valueCardWidgetConfigForm.get('showDate').disable({emitEvent: false}); |
|||
this.valueCardWidgetConfigForm.get('dateFormat').disable(); |
|||
this.valueCardWidgetConfigForm.get('dateFont').disable(); |
|||
this.valueCardWidgetConfigForm.get('dateColor').disable(); |
|||
} |
|||
this.valueCardWidgetConfigForm.get('showIcon').updateValueAndValidity({emitEvent: false}); |
|||
this.valueCardWidgetConfigForm.get('showDate').updateValueAndValidity({emitEvent: false}); |
|||
this.valueCardWidgetConfigForm.get('label').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('labelFont').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('labelColor').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('iconSize').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('iconSizeUnit').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('icon').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('iconColor').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('dateFormat').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('dateFont').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetConfigForm.get('dateColor').updateValueAndValidity({emitEvent}); |
|||
} |
|||
|
|||
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'); |
|||
} |
|||
|
|||
private _valuePreviewFn(): string { |
|||
const units: string = this.valueCardWidgetConfigForm.get('units').value; |
|||
const decimals: number = this.valueCardWidgetConfigForm.get('decimals').value; |
|||
return formatValue(22, decimals, units, true); |
|||
} |
|||
|
|||
private _datePreviewFn(): string { |
|||
const dateFormat: DateFormatSettings = this.valueCardWidgetConfigForm.get('dateFormat').value; |
|||
const processor = DateFormatProcessor.fromSettings(this.$injector, dateFormat); |
|||
processor.update(Date.now()); |
|||
return processor.formatted; |
|||
} |
|||
} |
|||
@ -0,0 +1,365 @@ |
|||
///
|
|||
/// 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 { isDefinedAndNotNull, isNumber, isNumeric, parseFunction } from '@core/utils'; |
|||
import { DataKey, Datasource, DatasourceData } from '@shared/models/widget.models'; |
|||
import { Injector } from '@angular/core'; |
|||
import { DatePipe, formatDate } from '@angular/common'; |
|||
import { DateAgoPipe } from '@shared/pipe/date-ago.pipe'; |
|||
import { TranslateService } from '@ngx-translate/core'; |
|||
|
|||
export type ComponentStyle = {[klass: string]: any}; |
|||
|
|||
export const cssUnits = ['px', 'em', '%', 'rem', 'pt', 'pc', 'in', 'cm', 'mm', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax'] as const; |
|||
type cssUnitTuple = typeof cssUnits; |
|||
export type cssUnit = cssUnitTuple[number]; |
|||
|
|||
export const fontWeights = ['normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900'] as const; |
|||
type fontWeightTuple = typeof fontWeights; |
|||
export type fontWeight = fontWeightTuple[number]; |
|||
|
|||
export const fontWeightTranslations = new Map<fontWeight, string>( |
|||
[ |
|||
['normal', 'widgets.widget-font.font-weight-normal'], |
|||
['bold', 'widgets.widget-font.font-weight-bold'], |
|||
['bolder', 'widgets.widget-font.font-weight-bolder'], |
|||
['lighter', 'widgets.widget-font.font-weight-lighter'] |
|||
] |
|||
); |
|||
|
|||
export const fontStyles = ['normal', 'italic', 'oblique'] as const; |
|||
type fontStyleTuple = typeof fontStyles; |
|||
export type fontStyle = fontStyleTuple[number]; |
|||
|
|||
export const fontStyleTranslations = new Map<fontStyle, string>( |
|||
[ |
|||
['normal', 'widgets.widget-font.font-style-normal'], |
|||
['italic', 'widgets.widget-font.font-style-italic'], |
|||
['oblique', 'widgets.widget-font.font-style-oblique'] |
|||
] |
|||
); |
|||
|
|||
export const commonFonts = ['Roboto', 'monospace', 'sans-serif', 'serif']; |
|||
|
|||
export interface Font { |
|||
size: number; |
|||
sizeUnit: cssUnit; |
|||
family: string; |
|||
weight: fontWeight; |
|||
style: fontStyle; |
|||
} |
|||
|
|||
export enum ColorType { |
|||
constant = 'constant', |
|||
range = 'range', |
|||
function = 'function' |
|||
} |
|||
|
|||
export const colorTypeTranslations = new Map<ColorType, string>( |
|||
[ |
|||
[ColorType.constant, 'widgets.color.color-type-constant'], |
|||
[ColorType.range, 'widgets.color.color-type-range'], |
|||
[ColorType.function, 'widgets.color.color-type-function'] |
|||
] |
|||
); |
|||
|
|||
export interface ColorRange { |
|||
from?: number; |
|||
to?: number; |
|||
color: string; |
|||
} |
|||
|
|||
export interface ColorSettings { |
|||
type: ColorType; |
|||
color: string; |
|||
rangeList?: ColorRange[]; |
|||
colorFunction?: string; |
|||
} |
|||
|
|||
export const constantColor = (color: string): ColorSettings => ({ |
|||
type: ColorType.constant, |
|||
color, |
|||
colorFunction: 'var temperature = value;\n' + |
|||
'if (typeof temperature !== undefined) {\n' + |
|||
' var percent = (temperature + 60)/120 * 100;\n' + |
|||
' return tinycolor.mix(\'blue\', \'red\', percent).toHexString();\n' + |
|||
'}\n' + |
|||
'return \'blue\';' |
|||
}); |
|||
|
|||
type ValueColorFunction = (value: any) => string; |
|||
|
|||
export abstract class ColorProcessor { |
|||
|
|||
static fromSettings(color: ColorSettings): ColorProcessor { |
|||
switch (color.type) { |
|||
case ColorType.constant: |
|||
return new ConstantColorProcessor(color); |
|||
case ColorType.range: |
|||
return new RangeColorProcessor(color); |
|||
case ColorType.function: |
|||
return new FunctionColorProcessor(color); |
|||
} |
|||
} |
|||
|
|||
color: string; |
|||
|
|||
protected constructor(protected settings: ColorSettings) { |
|||
this.color = settings.color; |
|||
} |
|||
|
|||
abstract update(value: any): void; |
|||
|
|||
} |
|||
|
|||
class ConstantColorProcessor extends ColorProcessor { |
|||
constructor(protected settings: ColorSettings) { |
|||
super(settings); |
|||
} |
|||
|
|||
update(value: any): void {} |
|||
} |
|||
|
|||
class RangeColorProcessor extends ColorProcessor { |
|||
|
|||
constructor(protected settings: ColorSettings) { |
|||
super(settings); |
|||
} |
|||
|
|||
update(value: any): void { |
|||
this.color = this.computeFromRange(value); |
|||
} |
|||
|
|||
private computeFromRange(value: any): string { |
|||
if (this.settings.rangeList?.length && isDefinedAndNotNull(value) && isNumeric(value)) { |
|||
const num = Number(value); |
|||
for (const range of this.settings.rangeList) { |
|||
if ((!isNumber(range.from) || num >= range.from) && (!isNumber(range.to) || num < range.to)) { |
|||
return range.color; |
|||
} |
|||
} |
|||
} |
|||
return this.settings.color; |
|||
} |
|||
} |
|||
|
|||
class FunctionColorProcessor extends ColorProcessor { |
|||
|
|||
private readonly colorFunction: ValueColorFunction; |
|||
|
|||
constructor(protected settings: ColorSettings) { |
|||
super(settings); |
|||
this.colorFunction = parseFunction(settings.colorFunction, ['value']); |
|||
} |
|||
|
|||
update(value: any): void { |
|||
if (this.colorFunction) { |
|||
this.color = this.colorFunction(value) || this.settings.color; |
|||
} |
|||
} |
|||
} |
|||
|
|||
export interface DateFormatSettings { |
|||
format?: string; |
|||
lastUpdateAgo?: boolean; |
|||
custom?: boolean; |
|||
} |
|||
|
|||
export const simpleDateFormat = (format: string): DateFormatSettings => ({ |
|||
format, |
|||
lastUpdateAgo: false, |
|||
custom: false |
|||
}); |
|||
|
|||
export const lastUpdateAgoDateFormat = (): DateFormatSettings => ({ |
|||
format: null, |
|||
lastUpdateAgo: true, |
|||
custom: false |
|||
}); |
|||
|
|||
export const customDateFormat = (format: string): DateFormatSettings => ({ |
|||
format, |
|||
lastUpdateAgo: false, |
|||
custom: true |
|||
}); |
|||
|
|||
export const dateFormats = ['MMM dd yyyy HH:mm', 'dd MMM yyyy HH:mm', 'yyyy MMM dd HH:mm', |
|||
'MM/dd/yyyy HH:mm', 'dd/MM/yyyy HH:mm', 'yyyy/MM/dd HH:mm:ss'] |
|||
.map(f => simpleDateFormat(f)).concat([lastUpdateAgoDateFormat(), customDateFormat('EEE, MMMM dd, yyyy')]); |
|||
|
|||
export const compareDateFormats = (df1: DateFormatSettings, df2: DateFormatSettings): boolean => { |
|||
if (df1 === df2) { |
|||
return true; |
|||
} else if (df1 && df2) { |
|||
if (df1.lastUpdateAgo && df2.lastUpdateAgo) { |
|||
return true; |
|||
} else if (df1.custom && df2.custom) { |
|||
return true; |
|||
} else if (!df1.lastUpdateAgo && !df2.lastUpdateAgo && !df1.custom && !df2.custom) { |
|||
return df1.format === df2.format; |
|||
} |
|||
} |
|||
return false; |
|||
}; |
|||
|
|||
export abstract class DateFormatProcessor { |
|||
|
|||
static fromSettings($injector: Injector, settings: DateFormatSettings): DateFormatProcessor { |
|||
if (settings.lastUpdateAgo) { |
|||
return new LastUpdateAgoDateFormatProcessor($injector, settings); |
|||
} else { |
|||
return new SimpleDateFormatProcessor($injector, settings); |
|||
} |
|||
} |
|||
|
|||
formatted = ''; |
|||
|
|||
protected constructor(protected $injector: Injector, |
|||
protected settings: DateFormatSettings) { |
|||
} |
|||
|
|||
abstract update(ts: string | number | Date): void; |
|||
|
|||
} |
|||
|
|||
export class SimpleDateFormatProcessor extends DateFormatProcessor { |
|||
|
|||
private datePipe: DatePipe; |
|||
|
|||
constructor(protected $injector: Injector, |
|||
protected settings: DateFormatSettings) { |
|||
super($injector, settings); |
|||
this.datePipe = $injector.get(DatePipe); |
|||
} |
|||
|
|||
update(ts: string| number | Date): void { |
|||
this.formatted = this.datePipe.transform(ts, this.settings.format); |
|||
} |
|||
|
|||
} |
|||
|
|||
export class LastUpdateAgoDateFormatProcessor extends DateFormatProcessor { |
|||
|
|||
private dateAgoPipe: DateAgoPipe; |
|||
private translate: TranslateService; |
|||
|
|||
constructor(protected $injector: Injector, |
|||
protected settings: DateFormatSettings) { |
|||
super($injector, settings); |
|||
this.dateAgoPipe = $injector.get(DateAgoPipe); |
|||
this.translate = $injector.get(TranslateService); |
|||
} |
|||
|
|||
update(ts: string| number | Date): void { |
|||
this.formatted = this.translate.instant('date.last-update-n-ago-text', |
|||
{agoText: this.dateAgoPipe.transform(ts, {applyAgo: true, short: true, textPart: true})}); |
|||
} |
|||
|
|||
} |
|||
|
|||
export enum BackgroundType { |
|||
image = 'image', |
|||
imageUrl = 'imageUrl', |
|||
color = 'color' |
|||
} |
|||
|
|||
export interface OverlaySettings { |
|||
enabled: boolean; |
|||
color: string; |
|||
blur: number; |
|||
} |
|||
|
|||
export interface BackgroundSettings { |
|||
type: BackgroundType; |
|||
imageBase64?: string; |
|||
imageUrl?: string; |
|||
color?: string; |
|||
overlay: OverlaySettings; |
|||
} |
|||
|
|||
export const iconStyle = (size: number, sizeUnit: cssUnit): ComponentStyle => { |
|||
const iconSize = size + sizeUnit; |
|||
return { |
|||
width: iconSize, |
|||
height: iconSize, |
|||
fontSize: iconSize, |
|||
lineHeight: iconSize |
|||
}; |
|||
}; |
|||
|
|||
export const textStyle = (font: Font, lineHeight = '1.5', letterSpacing = '0.25px'): ComponentStyle => ({ |
|||
font: font.style + ' normal ' + font.weight + ' ' + (font.size+font.sizeUnit) + '/' + lineHeight + ' ' + font.family + |
|||
(font.family !== 'Roboto' ? ', Roboto' : ''), |
|||
letterSpacing |
|||
}); |
|||
|
|||
export const backgroundStyle = (background: BackgroundSettings): ComponentStyle => { |
|||
if (background.type === BackgroundType.color) { |
|||
return { |
|||
background: background.color |
|||
}; |
|||
} else { |
|||
const imageUrl = background.type === BackgroundType.image ? background.imageBase64 : background.imageUrl; |
|||
return { |
|||
background: `url(${imageUrl}) no-repeat`, |
|||
backgroundSize: 'cover', |
|||
backgroundPosition: '50% 50%' |
|||
}; |
|||
} |
|||
}; |
|||
|
|||
export const overlayStyle = (overlay: OverlaySettings): ComponentStyle => ( |
|||
{ |
|||
display: overlay.enabled ? 'block' : 'none', |
|||
background: overlay.color, |
|||
backdropFilter: `blur(${overlay.blur}px)` |
|||
} |
|||
); |
|||
|
|||
export const getDataKey = (datasources?: Datasource[]): DataKey => { |
|||
if (datasources && datasources.length) { |
|||
const dataKeys = datasources[0].dataKeys; |
|||
if (dataKeys && dataKeys.length) { |
|||
return dataKeys[0]; |
|||
} |
|||
} |
|||
return null; |
|||
}; |
|||
|
|||
export const getLabel = (datasources?: Datasource[]): string => { |
|||
const dataKey = getDataKey(datasources); |
|||
if (dataKey) { |
|||
return dataKey.label; |
|||
} |
|||
return ''; |
|||
}; |
|||
|
|||
export const setLabel = (label: string, datasources?: Datasource[]): void => { |
|||
const dataKey = getDataKey(datasources); |
|||
if (dataKey) { |
|||
dataKey.label = label; |
|||
} |
|||
}; |
|||
|
|||
export const getSingleTsValue = (data: Array<DatasourceData>): [number, any] => { |
|||
if (data.length) { |
|||
const dsData = data[0]; |
|||
if (dsData.data.length) { |
|||
return dsData.data[0]; |
|||
} |
|||
} |
|||
return null; |
|||
}; |
|||
@ -0,0 +1,70 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div class="tb-value-card-panel" [class]="this.layout" [style]="backgroundStyle"> |
|||
<div class="tb-value-card-overlay" [style]="overlayStyle"></div> |
|||
<ng-container [ngSwitch]="layout"> |
|||
<ng-template [ngSwitchCase]="valueCardLayout.square"> |
|||
<ng-container *ngTemplateOutlet="iconWithLabelTpl"></ng-container> |
|||
<ng-container *ngTemplateOutlet="valueTpl"></ng-container> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="valueCardLayout.vertical"> |
|||
<ng-container *ngTemplateOutlet="labelTpl"></ng-container> |
|||
<ng-container *ngTemplateOutlet="valueTpl"></ng-container> |
|||
<ng-container *ngTemplateOutlet="iconTpl"></ng-container> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="valueCardLayout.centered"> |
|||
<ng-container *ngTemplateOutlet="labelTpl"></ng-container> |
|||
<div class="tb-value-card-icon-row"> |
|||
<ng-container *ngTemplateOutlet="iconTpl"></ng-container> |
|||
<ng-container *ngTemplateOutlet="valueTpl"></ng-container> |
|||
</div> |
|||
<ng-container *ngTemplateOutlet="dateTpl"></ng-container> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="valueCardLayout.simplified"> |
|||
<ng-container *ngTemplateOutlet="valueTpl"></ng-container> |
|||
<ng-container *ngTemplateOutlet="labelTpl"></ng-container> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="layout === valueCardLayout.horizontal || |
|||
layout === valueCardLayout.horizontal_reversed ? layout : ''"> |
|||
<ng-container *ngTemplateOutlet="iconWithLabelTpl"></ng-container> |
|||
<div fxFlex></div> |
|||
<ng-container *ngTemplateOutlet="valueTpl"></ng-container> |
|||
</ng-template> |
|||
</ng-container> |
|||
</div> |
|||
<ng-template #iconWithLabelTpl> |
|||
<div class="tb-value-card-icon-row"> |
|||
<ng-container *ngTemplateOutlet="iconTpl"></ng-container> |
|||
<div class="tb-value-card-label-row"> |
|||
<ng-container *ngTemplateOutlet="labelTpl"></ng-container> |
|||
<ng-container *ngTemplateOutlet="dateTpl"></ng-container> |
|||
</div> |
|||
</div> |
|||
</ng-template> |
|||
<ng-template #iconTpl> |
|||
<tb-icon *ngIf="showIcon" [style]="iconStyle" [style.color]="iconColor.color">{{ icon }}</tb-icon> |
|||
</ng-template> |
|||
<ng-template #labelTpl> |
|||
<div *ngIf="showLabel" [style]="labelStyle" [style.color]="labelColor.color">{{ label }}</div> |
|||
</ng-template> |
|||
<ng-template #dateTpl> |
|||
<div *ngIf="showDate" [style]="dateStyle" [style.color]="dateColor.color">{{ dateFormat.formatted }}</div> |
|||
</ng-template> |
|||
<ng-template #valueTpl> |
|||
<div class="tb-value-card-value" [style]="valueStyle" [style.color]="valueColor.color">{{ valueText }}</div> |
|||
</ng-template> |
|||
@ -0,0 +1,70 @@ |
|||
/** |
|||
* 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. |
|||
*/ |
|||
:host { |
|||
.tb-value-card-panel { |
|||
width: 100%; |
|||
height: 100%; |
|||
position: relative; |
|||
display: flex; |
|||
flex-direction: column; |
|||
align-items: center; |
|||
justify-content: center; |
|||
gap: 16px; |
|||
padding: 24px; |
|||
> div:not(.tb-value-card-overlay) { |
|||
z-index: 1; |
|||
} |
|||
&.square { |
|||
justify-content: space-evenly; |
|||
gap: 0; |
|||
} |
|||
&.horizontal { |
|||
flex-direction: row; |
|||
} |
|||
&.horizontal_reversed { |
|||
flex-direction: row-reverse; |
|||
} |
|||
.tb-value-card-overlay { |
|||
position: absolute; |
|||
top: 12px; |
|||
left: 12px; |
|||
bottom: 12px; |
|||
right: 12px; |
|||
} |
|||
.tb-value-card-icon-row { |
|||
display: flex; |
|||
flex-direction: row; |
|||
align-items: center; |
|||
gap: 8px; |
|||
} |
|||
&.horizontal_reversed { |
|||
.tb-value-card-icon-row { |
|||
flex-direction: row-reverse; |
|||
} |
|||
.tb-value-card-label-row { |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
.tb-value-card-label-row { |
|||
display: flex; |
|||
flex-direction: column; |
|||
justify-content: center; |
|||
} |
|||
.tb-value-card-value { |
|||
white-space: nowrap; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,144 @@ |
|||
///
|
|||
/// 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 { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'; |
|||
import { WidgetContext } from '@home/models/widget-component.models'; |
|||
import { formatValue, isDefinedAndNotNull } from '@core/utils'; |
|||
import { DatePipe } from '@angular/common'; |
|||
import { |
|||
backgroundStyle, |
|||
ColorProcessor, |
|||
ComponentStyle, DateFormatProcessor, |
|||
getDataKey, |
|||
getLabel, |
|||
getSingleTsValue, |
|||
iconStyle, |
|||
overlayStyle, |
|||
textStyle |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
import { valueCardDefaultSettings, ValueCardLayout, ValueCardWidgetSettings } from './value-card-widget.models'; |
|||
import { WidgetComponent } from '@home/components/widget/widget.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-value-card-widget', |
|||
templateUrl: './value-card-widget.component.html', |
|||
styleUrls: ['./value-card-widget.component.scss'] |
|||
}) |
|||
export class ValueCardWidgetComponent implements OnInit { |
|||
|
|||
settings: ValueCardWidgetSettings; |
|||
|
|||
valueCardLayout = ValueCardLayout; |
|||
|
|||
@Input() |
|||
ctx: WidgetContext; |
|||
|
|||
layout: ValueCardLayout; |
|||
showIcon = true; |
|||
icon = ''; |
|||
iconStyle: ComponentStyle = {}; |
|||
iconColor: ColorProcessor; |
|||
|
|||
showLabel = true; |
|||
label = ''; |
|||
labelStyle: ComponentStyle = {}; |
|||
labelColor: ColorProcessor; |
|||
|
|||
valueText = 'N/A'; |
|||
valueStyle: ComponentStyle = {}; |
|||
valueColor: ColorProcessor; |
|||
|
|||
showDate = true; |
|||
dateFormat: DateFormatProcessor; |
|||
dateStyle: ComponentStyle = {}; |
|||
dateColor: ColorProcessor; |
|||
|
|||
backgroundStyle: ComponentStyle = {}; |
|||
overlayStyle: ComponentStyle = {}; |
|||
|
|||
private horizontal = false; |
|||
private decimals = 0; |
|||
private units = ''; |
|||
|
|||
constructor(private date: DatePipe, |
|||
private widgetComponent: WidgetComponent, |
|||
private cd: ChangeDetectorRef) { |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
const params = this.widgetComponent.typeParameters as any; |
|||
this.horizontal = isDefinedAndNotNull(params.horizontal) ? params.horizontal : false; |
|||
this.ctx.$scope.valueCardWidget = this; |
|||
this.settings = {...valueCardDefaultSettings(this.horizontal), ...this.ctx.settings}; |
|||
|
|||
this.decimals = this.ctx.decimals; |
|||
this.units = this.ctx.units; |
|||
const dataKey = getDataKey(this.ctx.datasources); |
|||
if (isDefinedAndNotNull(dataKey?.decimals)) { |
|||
this.decimals = dataKey.decimals; |
|||
} |
|||
if (dataKey?.units) { |
|||
this.units = dataKey.units; |
|||
} |
|||
|
|||
this.layout = this.settings.layout; |
|||
|
|||
this.showIcon = this.settings.showIcon; |
|||
this.icon = this.settings.icon; |
|||
this.iconStyle = iconStyle(this.settings.iconSize, this.settings.iconSizeUnit ); |
|||
this.iconColor = ColorProcessor.fromSettings(this.settings.iconColor); |
|||
|
|||
this.showLabel = this.settings.showLabel; |
|||
this.label = getLabel(this.ctx.datasources); |
|||
this.labelStyle = textStyle(this.settings.labelFont, '1.5', '0.25px'); |
|||
this.labelColor = ColorProcessor.fromSettings(this.settings.labelColor); |
|||
this.valueStyle = textStyle(this.settings.valueFont, '100%', '0.13px'); |
|||
this.valueColor = ColorProcessor.fromSettings(this.settings.valueColor); |
|||
|
|||
this.showDate = this.settings.showDate; |
|||
this.dateFormat = DateFormatProcessor.fromSettings(this.ctx.$injector, this.settings.dateFormat); |
|||
this.dateStyle = textStyle(this.settings.dateFont, '1.33', '0.25px'); |
|||
this.dateColor = ColorProcessor.fromSettings(this.settings.dateColor); |
|||
|
|||
this.backgroundStyle = backgroundStyle(this.settings.background); |
|||
this.overlayStyle = overlayStyle(this.settings.background.overlay); |
|||
} |
|||
|
|||
public onInit() { |
|||
const borderRadius = this.ctx.$widgetElement.css('borderRadius'); |
|||
this.overlayStyle = {...this.overlayStyle, ...{borderRadius}}; |
|||
this.cd.detectChanges(); |
|||
} |
|||
|
|||
public onDataUpdated() { |
|||
const tsValue = getSingleTsValue(this.ctx.data); |
|||
let ts; |
|||
let value; |
|||
if (tsValue) { |
|||
ts = tsValue[0]; |
|||
value = tsValue[1]; |
|||
this.valueText = formatValue(value, this.decimals, this.units, true); |
|||
} else { |
|||
this.valueText = 'N/A'; |
|||
} |
|||
this.dateFormat.update(ts); |
|||
this.iconColor.update(value); |
|||
this.labelColor.update(value); |
|||
this.valueColor.update(value); |
|||
this.dateColor.update(value); |
|||
this.cd.detectChanges(); |
|||
} |
|||
} |
|||
@ -0,0 +1,127 @@ |
|||
///
|
|||
/// 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 { |
|||
BackgroundSettings, |
|||
BackgroundType, |
|||
ColorSettings, |
|||
constantColor, |
|||
cssUnit, DateFormatSettings, |
|||
Font, lastUpdateAgoDateFormat |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
|
|||
export enum ValueCardLayout { |
|||
square = 'square', |
|||
vertical = 'vertical', |
|||
centered = 'centered', |
|||
simplified = 'simplified', |
|||
horizontal = 'horizontal', |
|||
horizontal_reversed = 'horizontal_reversed' |
|||
} |
|||
|
|||
export const valueCardLayouts = (horizontal: boolean): ValueCardLayout[] => { |
|||
if (horizontal) { |
|||
return [ValueCardLayout.horizontal, ValueCardLayout.horizontal_reversed]; |
|||
} else { |
|||
return [ValueCardLayout.square, ValueCardLayout.vertical, ValueCardLayout.centered, ValueCardLayout.simplified]; |
|||
} |
|||
}; |
|||
|
|||
export const valueCardLayoutTranslations = new Map<ValueCardLayout, string>( |
|||
[ |
|||
[ValueCardLayout.square, 'widgets.value-card.layout-square'], |
|||
[ValueCardLayout.vertical, 'widgets.value-card.layout-vertical'], |
|||
[ValueCardLayout.centered, 'widgets.value-card.layout-centered'], |
|||
[ValueCardLayout.simplified, 'widgets.value-card.layout-simplified'], |
|||
[ValueCardLayout.horizontal, 'widgets.value-card.layout-horizontal'], |
|||
[ValueCardLayout.horizontal_reversed, 'widgets.value-card.layout-horizontal-reversed'] |
|||
] |
|||
); |
|||
|
|||
export const valueCardLayoutImages = new Map<ValueCardLayout, string>( |
|||
[ |
|||
[ValueCardLayout.square, 'assets/widget/value-card/square-layout.svg'], |
|||
[ValueCardLayout.vertical, 'assets/widget/value-card/vertical-layout.svg'], |
|||
[ValueCardLayout.centered, 'assets/widget/value-card/centered-layout.svg'], |
|||
[ValueCardLayout.simplified, 'assets/widget/value-card/simplified-layout.svg'], |
|||
[ValueCardLayout.horizontal, 'assets/widget/value-card/horizontal-layout.svg'], |
|||
[ValueCardLayout.horizontal_reversed, 'assets/widget/value-card/horizontal-reversed-layout.svg'] |
|||
] |
|||
); |
|||
|
|||
export interface ValueCardWidgetSettings { |
|||
layout: ValueCardLayout; |
|||
showLabel: boolean; |
|||
labelFont: Font; |
|||
labelColor: ColorSettings; |
|||
showIcon: boolean; |
|||
icon: string; |
|||
iconSize: number; |
|||
iconSizeUnit: cssUnit; |
|||
iconColor: ColorSettings; |
|||
valueFont: Font; |
|||
valueColor: ColorSettings; |
|||
showDate: boolean; |
|||
dateFormat: DateFormatSettings; |
|||
dateFont: Font; |
|||
dateColor: ColorSettings; |
|||
background: BackgroundSettings; |
|||
} |
|||
|
|||
export const valueCardDefaultSettings = (horizontal: boolean): ValueCardWidgetSettings => ({ |
|||
layout: horizontal ? ValueCardLayout.horizontal : ValueCardLayout.square, |
|||
showLabel: true, |
|||
labelFont: { |
|||
family: 'Roboto', |
|||
size: 16, |
|||
sizeUnit: 'px', |
|||
style: 'normal', |
|||
weight: '500' |
|||
}, |
|||
labelColor: constantColor('rgba(0, 0, 0, 0.87)'), |
|||
showIcon: true, |
|||
icon: 'thermostat', |
|||
iconSize: 40, |
|||
iconSizeUnit: 'px', |
|||
iconColor: constantColor('#5469FF'), |
|||
valueFont: { |
|||
family: 'Roboto', |
|||
size: 52, |
|||
sizeUnit: 'px', |
|||
style: 'normal', |
|||
weight: '500' |
|||
}, |
|||
valueColor: constantColor('rgba(0, 0, 0, 0.87)'), |
|||
showDate: true, |
|||
dateFormat: lastUpdateAgoDateFormat(), |
|||
dateFont: { |
|||
family: 'Roboto', |
|||
size: 12, |
|||
sizeUnit: 'px', |
|||
style: 'normal', |
|||
weight: '500' |
|||
}, |
|||
dateColor: constantColor('rgba(0, 0, 0, 0.38)'), |
|||
background: { |
|||
type: BackgroundType.color, |
|||
color: '#fff', |
|||
overlay: { |
|||
enabled: false, |
|||
color: 'rgba(255,255,255,0.72)', |
|||
blur: 3 |
|||
} |
|||
} |
|||
}); |
|||
@ -0,0 +1,105 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div class="tb-color-settings-panel" [formGroup]="colorSettingsFormGroup"> |
|||
<div class="tb-color-settings-title" translate>widgets.color.color-settings</div> |
|||
<div fxLayout="row"> |
|||
<tb-toggle-select formControlName="type" fxFlex.xs fxFlex="70%"> |
|||
<tb-toggle-option *ngFor="let type of colorTypes" |
|||
[value]="type"> |
|||
{{ colorTypeTranslationsMap.get(type) | translate }} |
|||
</tb-toggle-option> |
|||
</tb-toggle-select> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div translate>widgets.color.color</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="color"> |
|||
</tb-color-input> |
|||
</div> |
|||
<div class="tb-color-settings-panel-body" [fxShow]="colorSettingsFormGroup.get('type').value === colorType.constant"> |
|||
</div> |
|||
<div class="tb-color-settings-panel-body" [fxShow]="colorSettingsFormGroup.get('type').value === colorType.range"> |
|||
<ng-container *ngTemplateOutlet="range"></ng-container> |
|||
</div> |
|||
<div class="tb-color-settings-panel-body" [fxShow]="colorSettingsFormGroup.get('type').value === colorType.function"> |
|||
<ng-container *ngTemplateOutlet="function"></ng-container> |
|||
</div> |
|||
<div class="tb-color-settings-panel-buttons"> |
|||
<button mat-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="cancel()"> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
<button mat-raised-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="applyColorSettings()" |
|||
[disabled]="colorSettingsFormGroup.invalid || !colorSettingsFormGroup.dirty"> |
|||
{{ 'action.apply' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
|
|||
<ng-template #range> |
|||
<div fxFlex class="tb-color-ranges-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.color.value-range</div> |
|||
<div class="tb-color-ranges" [formGroup]="colorSettingsFormGroup"> |
|||
<div class="tb-form-row no-padding no-border" [formGroup]="rangeFormGroup" *ngFor="let rangeFormGroup of rangeListFormGroups; trackBy: trackByRange; let $index = index;"> |
|||
<div fxFlex fxLayout="row" fxLayoutGap="24px"> |
|||
<div fxFlex fxLayout="row" fxLayoutGap="12px" fxLayoutAlign="start center"> |
|||
<div class="tb-value-range-text" translate>widgets.color.from</div> |
|||
<mat-form-field fxFlex appearance="outline" class="center number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" formControlName="from" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<div class="tb-value-range-text tb-value-range-text-to" translate>widgets.color.to</div> |
|||
<mat-form-field fxFlex appearance="outline" class="center number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" formControlName="to" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-color-input asBoxInput |
|||
formControlName="color"> |
|||
</tb-color-input> |
|||
</div> |
|||
<button type="button" |
|||
mat-icon-button |
|||
class="tb-box-button" |
|||
(click)="removeRange($index)" |
|||
matTooltip="{{ 'action.remove' | translate }}" |
|||
matTooltipPosition="above"> |
|||
<mat-icon>delete</mat-icon> |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<button class="tb-add-color-range" |
|||
mat-stroked-button |
|||
(click)="addRange()"> |
|||
<mat-icon>add</mat-icon> |
|||
</button> |
|||
</div> |
|||
</ng-template> |
|||
<ng-template #function> |
|||
<div class="tb-form-panel no-padding no-border" [formGroup]="colorSettingsFormGroup"> |
|||
<tb-js-func formControlName="colorFunction" |
|||
[functionArgs]="['value']" |
|||
[globalVariables]="functionScopeVariables" |
|||
functionTitle="{{ 'widgets.color.color-function' | translate }}" |
|||
helpId="widget/lib/card/value_color_fn"> |
|||
</tb-js-func> |
|||
</div> |
|||
</ng-template> |
|||
@ -0,0 +1,85 @@ |
|||
/** |
|||
* 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'; |
|||
|
|||
.tb-color-settings-panel { |
|||
width: 500px; |
|||
height: 470px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
@media #{$mat-xs} { |
|||
width: 90vw; |
|||
} |
|||
.tb-color-settings-title { |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
letter-spacing: 0.25px; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
.tb-color-ranges-panel { |
|||
flex: 1; |
|||
min-height: 0; |
|||
gap: 16px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
} |
|||
.tb-color-ranges { |
|||
flex: 1; |
|||
gap: 12px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
overflow: auto; |
|||
} |
|||
.tb-form-row { |
|||
height: auto; |
|||
.tb-value-range-text { |
|||
width: 64px; |
|||
font-size: 14px; |
|||
color: rgba(0, 0, 0, 0.38); |
|||
@media #{$mat-xs} { |
|||
width: auto; |
|||
} |
|||
&.tb-value-range-text-to { |
|||
text-align: center; |
|||
} |
|||
} |
|||
} |
|||
button.mat-mdc-button-base.tb-add-color-range { |
|||
&:not(:disabled) { |
|||
color: rgba(0, 0, 0, 0.54); |
|||
} |
|||
&:disabled { |
|||
color: rgba(0, 0, 0, 0.12); |
|||
} |
|||
} |
|||
.tb-color-settings-panel-body { |
|||
flex: 1; |
|||
display: flex; |
|||
flex-direction: column; |
|||
min-height: 0; |
|||
} |
|||
.tb-color-settings-panel-buttons { |
|||
height: 40px; |
|||
display: flex; |
|||
flex-direction: row; |
|||
gap: 16px; |
|||
justify-content: flex-end; |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
@ -0,0 +1,133 @@ |
|||
///
|
|||
/// 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, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { |
|||
ColorRange, |
|||
ColorSettings, |
|||
ColorType, |
|||
colorTypeTranslations |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { |
|||
AbstractControl, |
|||
FormControl, |
|||
FormGroup, |
|||
UntypedFormArray, |
|||
UntypedFormBuilder, |
|||
UntypedFormGroup |
|||
} from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Datasource, DatasourceType } from '@shared/models/widget.models'; |
|||
import { deepClone } from '@core/utils'; |
|||
import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; |
|||
import { WidgetService } from '@core/http/widget.service'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-color-settings-panel', |
|||
templateUrl: './color-settings-panel.component.html', |
|||
providers: [], |
|||
styleUrls: ['./color-settings-panel.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class ColorSettingsPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() |
|||
colorSettings: ColorSettings; |
|||
|
|||
@Input() |
|||
popover: TbPopoverComponent<ColorSettingsPanelComponent>; |
|||
|
|||
@Output() |
|||
colorSettingsApplied = new EventEmitter<ColorSettings>(); |
|||
|
|||
colorType = ColorType; |
|||
|
|||
colorTypes = Object.keys(ColorType) as ColorType[]; |
|||
|
|||
colorTypeTranslationsMap = colorTypeTranslations; |
|||
|
|||
colorSettingsFormGroup: UntypedFormGroup; |
|||
|
|||
functionScopeVariables = this.widgetService.getWidgetScopeVariables(); |
|||
|
|||
constructor(private fb: UntypedFormBuilder, |
|||
private widgetService: WidgetService, |
|||
protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.colorSettingsFormGroup = this.fb.group( |
|||
{ |
|||
type: [this.colorSettings?.type, []], |
|||
color: [this.colorSettings?.color, []], |
|||
rangeList: this.fb.array((this.colorSettings?.rangeList || []).map(r => this.colorRangeControl(r))), |
|||
colorFunction: [this.colorSettings?.colorFunction, []] |
|||
} |
|||
); |
|||
this.colorSettingsFormGroup.get('type').valueChanges.subscribe(() => { |
|||
setTimeout(() => {this.popover?.updatePosition();}, 0); |
|||
}); |
|||
} |
|||
|
|||
private colorRangeControl(range: ColorRange): AbstractControl { |
|||
return this.fb.group({ |
|||
from: [range?.from, []], |
|||
to: [range?.to, []], |
|||
color: [range?.color, []] |
|||
}); |
|||
} |
|||
|
|||
get rangeListFormArray(): UntypedFormArray { |
|||
return this.colorSettingsFormGroup.get('rangeList') as UntypedFormArray; |
|||
} |
|||
|
|||
get rangeListFormGroups(): FormGroup[] { |
|||
return this.rangeListFormArray.controls as FormGroup[]; |
|||
} |
|||
|
|||
trackByRange(index: number, rangeControl: AbstractControl): any { |
|||
return rangeControl; |
|||
} |
|||
|
|||
removeRange(index: number) { |
|||
this.rangeListFormArray.removeAt(index); |
|||
this.colorSettingsFormGroup.markAsDirty(); |
|||
setTimeout(() => {this.popover?.updatePosition();}, 0); |
|||
} |
|||
|
|||
addRange() { |
|||
const newRange: ColorRange = { |
|||
color: 'rgba(0,0,0,0.87)' |
|||
}; |
|||
this.rangeListFormArray.push(this.colorRangeControl(newRange)); |
|||
this.colorSettingsFormGroup.markAsDirty(); |
|||
setTimeout(() => {this.popover?.updatePosition();}, 0); |
|||
} |
|||
|
|||
cancel() { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
applyColorSettings() { |
|||
const colorSettings = this.colorSettingsFormGroup.value; |
|||
this.colorSettingsApplied.emit(colorSettings); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<button type="button" |
|||
mat-stroked-button |
|||
class="tb-box-button" |
|||
[disabled]="disabled" |
|||
#matButton |
|||
(click)="openColorSettingsPopup($event, matButton)"> |
|||
<tb-icon matButtonIcon *ngIf="modelValue.type === colorType.function; else colorPreview">mdi:function-variant</tb-icon> |
|||
</button> |
|||
<ng-template #colorPreview> |
|||
<div class="tb-color-preview box" [ngClass]="{'disabled': disabled}"> |
|||
<div class="tb-color-result" [style]="colorStyle"></div> |
|||
</div> |
|||
</ng-template> |
|||
@ -0,0 +1,124 @@ |
|||
///
|
|||
/// 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, forwardRef, Input, OnInit, Renderer2, ViewContainerRef } from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
import { ColorSettings, ColorType, ComponentStyle } from '@home/components/widget/config/widget-settings.models'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { |
|||
ColorSettingsPanelComponent |
|||
} from '@home/components/widget/lib/settings/common/color-settings-panel.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-color-settings', |
|||
templateUrl: './color-settings.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => ColorSettingsComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class ColorSettingsComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
colorType = ColorType; |
|||
|
|||
modelValue: ColorSettings; |
|||
|
|||
colorStyle: ComponentStyle = {}; |
|||
|
|||
private propagateChange = null; |
|||
|
|||
constructor(private popoverService: TbPopoverService, |
|||
private renderer: Renderer2, |
|||
private viewContainerRef: ViewContainerRef) {} |
|||
|
|||
ngOnInit(): void { |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
this.updateColorStyle(); |
|||
} |
|||
|
|||
writeValue(value: ColorSettings): void { |
|||
this.modelValue = value; |
|||
this.updateColorStyle(); |
|||
} |
|||
|
|||
openColorSettingsPopup($event: Event, matButton: MatButton) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const trigger = matButton._elementRef.nativeElement; |
|||
if (this.popoverService.hasPopover(trigger)) { |
|||
this.popoverService.hidePopover(trigger); |
|||
} else { |
|||
const ctx: any = { |
|||
colorSettings: this.modelValue |
|||
}; |
|||
const colorSettingsPanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, ColorSettingsPanelComponent, 'left', true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
colorSettingsPanelPopover.tbComponentRef.instance.popover = colorSettingsPanelPopover; |
|||
colorSettingsPanelPopover.tbComponentRef.instance.colorSettingsApplied.subscribe((colorSettings) => { |
|||
colorSettingsPanelPopover.hide(); |
|||
this.modelValue = colorSettings; |
|||
this.updateColorStyle(); |
|||
this.propagateChange(this.modelValue); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
private updateColorStyle() { |
|||
if (!this.disabled) { |
|||
let colors: string[] = [this.modelValue.color]; |
|||
if (this.modelValue.type === ColorType.range && this.modelValue.rangeList?.length) { |
|||
const rangeColors = this.modelValue.rangeList.slice(0, Math.min(2, this.modelValue.rangeList.length)).map(r => r.color); |
|||
colors = colors.concat(rangeColors); |
|||
} |
|||
if (colors.length === 1) { |
|||
this.colorStyle = {backgroundColor: colors[0]}; |
|||
} else { |
|||
const gradientValues: string[] = []; |
|||
const step = 100 / colors.length; |
|||
for (let i = 0; i < colors.length; i++) { |
|||
gradientValues.push(`${colors[i]} ${step*i}%`); |
|||
gradientValues.push(`${colors[i]} ${step*(i+1)}%`); |
|||
} |
|||
this.colorStyle = {background: `linear-gradient(90deg, ${gradientValues.join(', ')})`}; |
|||
} |
|||
} else { |
|||
this.colorStyle = {}; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<mat-form-field appearance="outline" subscriptSizing="dynamic" style="width: 100%;"> |
|||
<mat-select [formControl]="cssUnitFormControl"> |
|||
<mat-option *ngFor="let cssUnit of cssUnitsList" [value]="cssUnit">{{ cssUnit }}</mat-option> |
|||
</mat-select> |
|||
</mat-form-field> |
|||
@ -0,0 +1,82 @@ |
|||
///
|
|||
/// 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, forwardRef, Input, OnInit } from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormControl } from '@angular/forms'; |
|||
import { cssUnit, cssUnits } from '@home/components/widget/config/widget-settings.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-css-unit-select', |
|||
templateUrl: './css-unit-select.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => CssUnitSelectComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class CssUnitSelectComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
cssUnitsList = cssUnits; |
|||
|
|||
cssUnitFormControl: UntypedFormControl; |
|||
|
|||
modelValue: cssUnit; |
|||
|
|||
private propagateChange = null; |
|||
|
|||
constructor() {} |
|||
|
|||
ngOnInit(): void { |
|||
this.cssUnitFormControl = new UntypedFormControl(); |
|||
this.cssUnitFormControl.valueChanges.subscribe((value: cssUnit) => { |
|||
this.updateModel(value); |
|||
}); |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
if (this.disabled) { |
|||
this.cssUnitFormControl.disable(); |
|||
} else { |
|||
this.cssUnitFormControl.enable(); |
|||
} |
|||
} |
|||
|
|||
writeValue(value: cssUnit): void { |
|||
this.modelValue = value; |
|||
this.cssUnitFormControl.patchValue(this.modelValue, {emitEvent: false}); |
|||
} |
|||
|
|||
updateModel(value: cssUnit): void { |
|||
if (this.modelValue !== value) { |
|||
this.modelValue = value; |
|||
this.propagateChange(this.modelValue); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<mat-form-field appearance="outline" subscriptSizing="dynamic" style="width: 100%;"> |
|||
<mat-select [formControl]="dateFormatFormControl" [compareWith]="dateFormatsCompare" > |
|||
<mat-option *ngFor="let dateFormat of dateFormatList" [value]="dateFormat">{{ dateFormatDisplayValue(dateFormat) }}</mat-option> |
|||
</mat-select> |
|||
<button #customFormatButton |
|||
*ngIf="dateFormatFormControl.value?.custom" matSuffix mat-icon-button (click)="openDateFormatSettingsPopup($event, customFormatButton)"> |
|||
<tb-icon>edit</tb-icon> |
|||
</button> |
|||
</mat-form-field> |
|||
@ -0,0 +1,148 @@ |
|||
///
|
|||
/// 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, forwardRef, Input, OnInit, Renderer2, ViewChild, ViewContainerRef } from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormControl } from '@angular/forms'; |
|||
import { |
|||
compareDateFormats, |
|||
dateFormats, |
|||
DateFormatSettings |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
import { TranslateService } from '@ngx-translate/core'; |
|||
import { DatePipe } from '@angular/common'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { deepClone } from '@core/utils'; |
|||
import { |
|||
DateFormatSettingsPanelComponent |
|||
} from '@home/components/widget/lib/settings/common/date-format-settings-panel.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-date-format-select', |
|||
templateUrl: './date-format-select.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => DateFormatSelectComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class DateFormatSelectComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@ViewChild('customFormatButton', {static: false}) |
|||
customFormatButton: MatButton; |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
dateFormatList = dateFormats; |
|||
|
|||
dateFormatsCompare = compareDateFormats; |
|||
|
|||
dateFormatFormControl: UntypedFormControl; |
|||
|
|||
modelValue: DateFormatSettings; |
|||
|
|||
private propagateChange = null; |
|||
|
|||
private formatCache: {[format: string]: string} = {}; |
|||
|
|||
constructor(private translate: TranslateService, |
|||
private date: DatePipe, |
|||
private popoverService: TbPopoverService, |
|||
private renderer: Renderer2, |
|||
private viewContainerRef: ViewContainerRef) {} |
|||
|
|||
ngOnInit(): void { |
|||
this.dateFormatFormControl = new UntypedFormControl(); |
|||
this.dateFormatFormControl.valueChanges.subscribe((value: DateFormatSettings) => { |
|||
this.updateModel(value); |
|||
if (value?.custom) { |
|||
setTimeout(() => { |
|||
this.openDateFormatSettingsPopup(null, this.customFormatButton); |
|||
}, 0); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
if (this.disabled) { |
|||
this.dateFormatFormControl.disable(); |
|||
} else { |
|||
this.dateFormatFormControl.enable(); |
|||
} |
|||
} |
|||
|
|||
writeValue(value: DateFormatSettings): void { |
|||
this.modelValue = value; |
|||
this.dateFormatFormControl.patchValue(this.modelValue, {emitEvent: false}); |
|||
} |
|||
|
|||
updateModel(value: DateFormatSettings): void { |
|||
if (!compareDateFormats(this.modelValue, value)) { |
|||
this.modelValue = value; |
|||
this.propagateChange(this.modelValue); |
|||
} |
|||
} |
|||
|
|||
dateFormatDisplayValue(value: DateFormatSettings): string { |
|||
if (value.custom) { |
|||
return this.translate.instant('date.custom-date'); |
|||
} else if (value.lastUpdateAgo) { |
|||
return this.translate.instant('date.last-update-n-ago'); |
|||
} else { |
|||
if (!this.formatCache[value.format]) { |
|||
this.formatCache[value.format] = this.date.transform(Date.now(), value.format); |
|||
} |
|||
return this.formatCache[value.format]; |
|||
} |
|||
} |
|||
|
|||
openDateFormatSettingsPopup($event: Event, matButton: MatButton) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const trigger = matButton._elementRef.nativeElement; |
|||
if (this.popoverService.hasPopover(trigger)) { |
|||
this.popoverService.hidePopover(trigger); |
|||
} else { |
|||
const ctx: any = { |
|||
dateFormat: deepClone(this.modelValue) |
|||
}; |
|||
const dateFormatSettingsPanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, DateFormatSettingsPanelComponent, 'top', true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
dateFormatSettingsPanelPopover.tbComponentRef.instance.popover = dateFormatSettingsPanelPopover; |
|||
dateFormatSettingsPanelPopover.tbComponentRef.instance.dateFormatApplied.subscribe((dateFormat) => { |
|||
dateFormatSettingsPanelPopover.hide(); |
|||
this.modelValue = dateFormat; |
|||
this.propagateChange(this.modelValue); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div class="tb-date-format-settings-panel"> |
|||
<div class="tb-date-format-settings-title" translate>date.custom-date</div> |
|||
<div class="tb-form-row no-border no-padding"> |
|||
<div class="fixed-title-width" translate>date.format</div> |
|||
<mat-form-field class="tb-date-format-input" required fxFlex appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput [formControl]="dateFormatFormControl" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<div matSuffix tb-help-popup="date/date-format" [tb-help-popup-style]="{width: '800px'}"></div> |
|||
</mat-form-field> |
|||
</div> |
|||
<mat-divider></mat-divider> |
|||
<div class="tb-form-row no-border no-padding date-format-preview"> |
|||
<div class="fixed-title-width" translate>date.preview</div> |
|||
<div class="preview-text" fxFlex>{{ previewText }}</div> |
|||
</div> |
|||
<div class="tb-date-format-settings-panel-buttons"> |
|||
<button mat-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="cancel()"> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
<button mat-raised-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="applyDateFormat()" |
|||
[disabled]="dateFormatFormControl.invalid || !dateFormatFormControl.dirty"> |
|||
{{ 'action.apply' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,67 @@ |
|||
/** |
|||
* 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'; |
|||
|
|||
.tb-date-format-settings-panel { |
|||
width: 500px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
@media #{$mat-xs} { |
|||
width: 90vw; |
|||
} |
|||
.tb-date-format-settings-title { |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
letter-spacing: 0.25px; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
.tb-form-row { |
|||
.fixed-title-width { |
|||
min-width: 120px; |
|||
} |
|||
&.date-format-preview { |
|||
align-items: flex-start; |
|||
.preview-text { |
|||
font-size: 14px; |
|||
font-style: normal; |
|||
font-weight: 400; |
|||
line-height: 20px; |
|||
letter-spacing: 0.2px; |
|||
color: rgba(0, 0, 0, 0.38); |
|||
} |
|||
} |
|||
.mat-mdc-form-field.tb-date-format-input { |
|||
.mat-mdc-text-field-wrapper.mdc-text-field--outlined { |
|||
.mat-mdc-form-field-icon-suffix { |
|||
display: flex; |
|||
align-items: center; |
|||
line-height: normal; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
.tb-date-format-settings-panel-buttons { |
|||
height: 60px; |
|||
display: flex; |
|||
flex-direction: row; |
|||
gap: 16px; |
|||
justify-content: flex-end; |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
///
|
|||
/// 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, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { DateFormatSettings } from '@home/components/widget/config/widget-settings.models'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { UntypedFormControl, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { DatePipe } from '@angular/common'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-date-format-settings-panel', |
|||
templateUrl: './date-format-settings-panel.component.html', |
|||
providers: [], |
|||
styleUrls: ['./date-format-settings-panel.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class DateFormatSettingsPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() |
|||
dateFormat: DateFormatSettings; |
|||
|
|||
@Input() |
|||
popover: TbPopoverComponent<DateFormatSettingsPanelComponent>; |
|||
|
|||
@Output() |
|||
dateFormatApplied = new EventEmitter<DateFormatSettings>(); |
|||
|
|||
dateFormatFormControl: UntypedFormControl; |
|||
|
|||
previewText = ''; |
|||
|
|||
constructor(private date: DatePipe, |
|||
protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.dateFormatFormControl = new UntypedFormControl(this.dateFormat.format, [Validators.required]); |
|||
this.dateFormatFormControl.valueChanges.subscribe((value: string) => { |
|||
this.previewText = this.date.transform(Date.now(), value); |
|||
}); |
|||
this.previewText = this.date.transform(Date.now(), this.dateFormat.format); |
|||
} |
|||
|
|||
cancel() { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
applyDateFormat() { |
|||
this.dateFormat.format = this.dateFormatFormControl.value; |
|||
this.dateFormatApplied.emit(this.dateFormat); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div class="tb-font-settings-panel" [formGroup]="fontFormGroup"> |
|||
<div class="tb-font-settings-title" translate>widgets.widget-font.font-settings</div> |
|||
<div class="tb-form-row no-border no-padding"> |
|||
<div class="fixed-title-width" translate>widgets.widget-font.size</div> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<mat-form-field fxFlex appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="size" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="sizeUnit"></tb-css-unit-select> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row no-border no-padding"> |
|||
<div class="fixed-title-width" translate>widgets.widget-font.font-family</div> |
|||
<mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput #familyInput |
|||
formControlName="family" placeholder="{{ 'widget-config.set' | translate }}" |
|||
[matAutocomplete]="familyAutocomplete"> |
|||
<button *ngIf="fontFormGroup.get('family').value" |
|||
type="button" |
|||
matSuffix mat-icon-button aria-label="Clear" |
|||
(click)="clearFamily()"> |
|||
<mat-icon class="material-icons">close</mat-icon> |
|||
</button> |
|||
<mat-autocomplete |
|||
#familyAutocomplete="matAutocomplete" |
|||
class="tb-autocomplete" |
|||
panelWidth="fit-content"> |
|||
<mat-option *ngFor="let family of filteredFontFamilies | async" [value]="family"> |
|||
<span [innerHTML]="family | highlight:familySearchText:true:'ig'"></span> |
|||
</mat-option> |
|||
</mat-autocomplete> |
|||
</mat-form-field> |
|||
</div> |
|||
<div class="tb-form-row no-border no-padding"> |
|||
<div class="fixed-title-width" translate>widgets.widget-font.font-weight</div> |
|||
<mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic"> |
|||
<mat-select formControlName="weight"> |
|||
<mat-option *ngFor="let weight of fontWeightsList" [value]="weight"> |
|||
{{ fontWeightTranslationsMap.has(weight) ? (fontWeightTranslationsMap.get(weight) | translate) : weight }} |
|||
</mat-option> |
|||
</mat-select> |
|||
</mat-form-field> |
|||
</div> |
|||
<div class="tb-form-row no-border no-padding"> |
|||
<div class="fixed-title-width" translate>widgets.widget-font.font-style</div> |
|||
<mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic"> |
|||
<mat-select formControlName="style"> |
|||
<mat-option *ngFor="let style of fontStylesList" [value]="style"> |
|||
{{ fontStyleTranslationsMap.get(style) | translate }} |
|||
</mat-option> |
|||
</mat-select> |
|||
</mat-form-field> |
|||
</div> |
|||
<mat-divider></mat-divider> |
|||
<div class="tb-form-row no-border no-padding font-preview"> |
|||
<div class="fixed-title-width" translate>widgets.widget-font.preview</div> |
|||
<div class="preview-text" fxFlex [style]="previewStyle">{{ previewText }}</div> |
|||
</div> |
|||
<div class="tb-font-settings-panel-buttons"> |
|||
<button mat-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="cancel()"> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
<button mat-raised-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="applyFont()" |
|||
[disabled]="fontFormGroup.invalid || !fontFormGroup.dirty"> |
|||
{{ 'action.apply' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,51 @@ |
|||
/** |
|||
* 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. |
|||
*/ |
|||
.tb-font-settings-panel { |
|||
width: 100%; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
.tb-font-settings-title { |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
letter-spacing: 0.25px; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
.tb-form-row { |
|||
.fixed-title-width { |
|||
min-width: 120px; |
|||
} |
|||
&.font-preview { |
|||
align-items: flex-start; |
|||
.preview-text { |
|||
max-height: 300px; |
|||
max-width: 400px; |
|||
overflow: hidden; |
|||
white-space: nowrap; |
|||
text-overflow: ellipsis; |
|||
} |
|||
} |
|||
} |
|||
.tb-font-settings-panel-buttons { |
|||
height: 60px; |
|||
display: flex; |
|||
flex-direction: row; |
|||
gap: 16px; |
|||
justify-content: flex-end; |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
@ -0,0 +1,133 @@ |
|||
///
|
|||
/// 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, |
|||
ElementRef, |
|||
EventEmitter, |
|||
Input, |
|||
OnInit, |
|||
Output, |
|||
ViewChild, |
|||
ViewEncapsulation |
|||
} from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { |
|||
commonFonts, |
|||
ComponentStyle, |
|||
Font, |
|||
fontStyles, |
|||
fontStyleTranslations, |
|||
fontWeights, |
|||
fontWeightTranslations, |
|||
textStyle |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Observable } from 'rxjs'; |
|||
import { map, startWith, tap } from 'rxjs/operators'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-font-settings-panel', |
|||
templateUrl: './font-settings-panel.component.html', |
|||
providers: [], |
|||
styleUrls: ['./font-settings-panel.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class FontSettingsPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() |
|||
font: Font; |
|||
|
|||
@Input() |
|||
previewText = 'AaBbCcDd'; |
|||
|
|||
@Input() |
|||
popover: TbPopoverComponent<FontSettingsPanelComponent>; |
|||
|
|||
@Output() |
|||
fontApplied = new EventEmitter<Font>(); |
|||
|
|||
@ViewChild('familyInput', {static: true}) familyInput: ElementRef; |
|||
|
|||
fontWeightsList = fontWeights; |
|||
|
|||
fontWeightTranslationsMap = fontWeightTranslations; |
|||
|
|||
fontStylesList = fontStyles; |
|||
|
|||
fontStyleTranslationsMap = fontStyleTranslations; |
|||
|
|||
fontFormGroup: UntypedFormGroup; |
|||
|
|||
filteredFontFamilies: Observable<Array<string>>; |
|||
|
|||
familySearchText = ''; |
|||
|
|||
previewStyle: ComponentStyle = {}; |
|||
|
|||
constructor(private fb: UntypedFormBuilder, |
|||
protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.fontFormGroup = this.fb.group( |
|||
{ |
|||
size: [this.font?.size, [Validators.required, Validators.min(0)]], |
|||
sizeUnit: [this.font?.sizeUnit, [Validators.required]], |
|||
family: [this.font?.family, [Validators.required]], |
|||
weight: [this.font?.weight, [Validators.required]], |
|||
style: [this.font?.style, [Validators.required]] |
|||
} |
|||
); |
|||
if (this.font) { |
|||
this.previewStyle = textStyle(this.font, '1'); |
|||
} |
|||
this.fontFormGroup.valueChanges.subscribe((value: Font) => { |
|||
if (this.fontFormGroup.valid) { |
|||
this.previewStyle = textStyle(value, '1'); |
|||
setTimeout(() => {this.popover?.updatePosition();}, 0); |
|||
} |
|||
}); |
|||
this.filteredFontFamilies = this.fontFormGroup.get('family').valueChanges |
|||
.pipe( |
|||
startWith<string>(''), |
|||
tap((searchText) => { this.familySearchText = searchText || ''; }), |
|||
map(() => commonFonts.filter(f => f.toUpperCase().includes(this.familySearchText.toUpperCase()))) |
|||
); |
|||
} |
|||
|
|||
clearFamily() { |
|||
this.fontFormGroup.get('family').patchValue(null, {emitEvent: true}); |
|||
setTimeout(() => { |
|||
this.familyInput.nativeElement.blur(); |
|||
this.familyInput.nativeElement.focus(); |
|||
}, 0); |
|||
} |
|||
|
|||
cancel() { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
applyFont() { |
|||
const font = this.fontFormGroup.value; |
|||
this.fontApplied.emit(font); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<button type="button" |
|||
mat-stroked-button |
|||
class="tb-box-button" |
|||
[disabled]="disabled" |
|||
#matButton |
|||
(click)="openFontSettingsPopup($event, matButton)"> |
|||
<tb-icon matButtonIcon>text_format</tb-icon> |
|||
</button> |
|||
@ -0,0 +1,102 @@ |
|||
///
|
|||
/// 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, forwardRef, Input, OnInit, Renderer2, ViewContainerRef } from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
import { Font } from '@home/components/widget/config/widget-settings.models'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { FontSettingsPanelComponent } from '@home/components/widget/lib/settings/common/font-settings-panel.component'; |
|||
import { isDefinedAndNotNull } from '@core/utils'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-font-settings', |
|||
templateUrl: './font-settings.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => FontSettingsComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class FontSettingsComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
@Input() |
|||
previewText: string | (() => string); |
|||
|
|||
private modelValue: Font; |
|||
|
|||
private propagateChange = null; |
|||
|
|||
constructor(private popoverService: TbPopoverService, |
|||
private renderer: Renderer2, |
|||
private viewContainerRef: ViewContainerRef) {} |
|||
|
|||
ngOnInit(): void { |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
} |
|||
|
|||
writeValue(value: Font): void { |
|||
this.modelValue = value; |
|||
} |
|||
|
|||
openFontSettingsPopup($event: Event, matButton: MatButton) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const trigger = matButton._elementRef.nativeElement; |
|||
if (this.popoverService.hasPopover(trigger)) { |
|||
this.popoverService.hidePopover(trigger); |
|||
} else { |
|||
const ctx: any = { |
|||
font: this.modelValue |
|||
}; |
|||
if (isDefinedAndNotNull(this.previewText)) { |
|||
const previewText = typeof this.previewText === 'string' ? this.previewText : this.previewText(); |
|||
if (previewText) { |
|||
ctx.previewText = previewText; |
|||
} |
|||
} |
|||
const fontSettingsPanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, FontSettingsPanelComponent, 'left', true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
fontSettingsPanelPopover.tbComponentRef.instance.popover = fontSettingsPanelPopover; |
|||
fontSettingsPanelPopover.tbComponentRef.instance.fontApplied.subscribe((font) => { |
|||
fontSettingsPanelPopover.hide(); |
|||
this.modelValue = font; |
|||
this.propagateChange(this.modelValue); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div class="tb-image-cards-select tb-form-panel stroked no-padding"> |
|||
<mat-expansion-panel class="tb-settings" [expanded]="expanded" disabled> |
|||
<mat-expansion-panel-header class="fill-width" fxLayout="row wrap"> |
|||
<div fxFlex class="tb-form-row no-border" [class.expanded]="expanded"> |
|||
<div class="fixed-title-width">{{ label }}</div> |
|||
<mat-form-field class="tb-image-cards-value-field" fxFlex appearance="outline" subscriptSizing="dynamic" (click)="toggleSelectPanel($event)"> |
|||
<input readonly matInput [formControl]="valueFormControl" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<mat-icon matSuffix>{{ expanded ? 'expand_less' : 'expand_more' }}</mat-icon> |
|||
</mat-form-field> |
|||
</div> |
|||
</mat-expansion-panel-header> |
|||
<ng-template matExpansionPanelContent> |
|||
<mat-grid-list class="tb-image-cards-options" [cols]="cols$ | async" [rowHeight]="rowHeight" gutterSize="8"> |
|||
<mat-grid-tile *ngFor="let option of options" (click)="updateModel(option.value)"> |
|||
<div class="tb-image-cards-option" [class.selected]="modelValue === option.value"> |
|||
<div class="tb-image-cards-option-background"></div> |
|||
<div class="tb-image-cards-option-title">{{ option.name }}</div> |
|||
<div class="tb-image-cards-option-image-container"> |
|||
<img class="tb-image-cards-option-image" src="{{ option.image }}"/> |
|||
</div> |
|||
</div> |
|||
</mat-grid-tile> |
|||
</mat-grid-list> |
|||
</ng-template> |
|||
</mat-expansion-panel> |
|||
</div> |
|||
@ -0,0 +1,116 @@ |
|||
/** |
|||
* 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. |
|||
*/ |
|||
.tb-image-cards-select.tb-form-panel { |
|||
.tb-form-row { |
|||
transition: all .3s; |
|||
&.expanded { |
|||
padding: 11px 7px 11px 16px; |
|||
} |
|||
} |
|||
.tb-image-cards-value-field { |
|||
cursor: pointer; |
|||
user-select: none; |
|||
input { |
|||
cursor: pointer; |
|||
pointer-events: none; |
|||
} |
|||
} |
|||
.mat-expansion-panel { |
|||
&.tb-settings { |
|||
> .mat-expansion-panel-header { |
|||
height: auto; |
|||
.mat-content { |
|||
margin: 0; |
|||
} |
|||
.tb-form-row { |
|||
font-weight: normal; |
|||
font-size: 16px; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
.mat-expansion-indicator { |
|||
display: none; |
|||
} |
|||
} |
|||
> .mat-expansion-panel-content { |
|||
> .mat-expansion-panel-body { |
|||
padding: 0 16px 16px !important; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
.tb-image-cards-option { |
|||
width: 100%; |
|||
height: 100%; |
|||
cursor: pointer; |
|||
padding: 8px 12px 12px 12px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 8px; |
|||
align-items: start; |
|||
position: relative; |
|||
.tb-image-cards-option-background { |
|||
border-radius: 4px; |
|||
position: absolute; |
|||
top: 1px; |
|||
left: 1px; |
|||
right: 1px; |
|||
bottom: 1px; |
|||
background: rgba(0, 0, 0, 0.04); |
|||
} |
|||
&:before { |
|||
content: unset; |
|||
border-radius: 4px; |
|||
position: absolute; |
|||
top: 0; |
|||
left: 0; |
|||
right: 0; |
|||
bottom: 0; |
|||
} |
|||
.tb-image-cards-option-title { |
|||
z-index: 1; |
|||
font-size: 12px; |
|||
font-style: normal; |
|||
font-weight: 400; |
|||
line-height: 16px; |
|||
letter-spacing: 0.25px; |
|||
color: rgba(0, 0, 0, 0.54); |
|||
} |
|||
.tb-image-cards-option-image-container { |
|||
z-index: 1; |
|||
flex: 1; |
|||
width: 100%; |
|||
min-height: 0; |
|||
display: flex; |
|||
justify-content: center; |
|||
} |
|||
&.selected { |
|||
.tb-image-cards-option-background { |
|||
background: #305680; |
|||
opacity: 0.04; |
|||
} |
|||
&:before { |
|||
content: ""; |
|||
border: 1px solid #305680; |
|||
opacity: 0.32; |
|||
} |
|||
.tb-image-cards-option-title { |
|||
font-size: 13px; |
|||
font-weight: 500; |
|||
color: #305680; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue