38 changed files with 1020 additions and 104 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,89 @@ |
|||
<!-- |
|||
|
|||
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]="valueCardWidgetSettingsForm"> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.value-card.value-card-style</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 space-between"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showLabel"> |
|||
{{ 'widgets.value-card.label' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-font-settings formControlName="labelFont" |
|||
[previewText]="label"> |
|||
</tb-font-settings> |
|||
<tb-color-settings formControlName="labelColor"> |
|||
</tb-color-settings> |
|||
</div> |
|||
</div> |
|||
<div [fxShow]="iconEnabled" 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]="valueCardWidgetSettingsForm.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 space-between"> |
|||
<div translate>widgets.value-card.value</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-font-settings formControlName="valueFont" |
|||
[previewText]="valuePreviewFn"> |
|||
</tb-font-settings> |
|||
<tb-color-settings formControlName="valueColor"> |
|||
</tb-color-settings> |
|||
</div> |
|||
</div> |
|||
<div [fxShow]="dateEnabled" 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> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widgets.background.background' | translate }}</div> |
|||
<tb-background-settings formControlName="background"> |
|||
</tb-background-settings> |
|||
</div> |
|||
</div> |
|||
</ng-container> |
|||
@ -0,0 +1,200 @@ |
|||
///
|
|||
/// 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, Injector } from '@angular/core'; |
|||
import { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { |
|||
valueCardDefaultSettings, |
|||
ValueCardLayout, valueCardLayoutImages, |
|||
valueCardLayouts, valueCardLayoutTranslations |
|||
} from '@home/components/widget/lib/cards/value-card-widget.models'; |
|||
import { formatValue, isDefinedAndNotNull } from '@core/utils'; |
|||
import { WidgetConfigComponentData } from '@home/models/widget-component.models'; |
|||
import { |
|||
DateFormatProcessor, |
|||
DateFormatSettings, |
|||
getLabel |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-value-card-widget-settings', |
|||
templateUrl: './value-card-widget-settings.component.html', |
|||
styleUrls: [] |
|||
}) |
|||
export class ValueCardWidgetSettingsComponent extends WidgetSettingsComponent { |
|||
|
|||
valueCardLayouts: ValueCardLayout[] = []; |
|||
|
|||
valueCardLayoutTranslationMap = valueCardLayoutTranslations; |
|||
valueCardLayoutImageMap = valueCardLayoutImages; |
|||
|
|||
horizontal = false; |
|||
|
|||
valueCardWidgetSettingsForm: UntypedFormGroup; |
|||
|
|||
valuePreviewFn = this._valuePreviewFn.bind(this); |
|||
|
|||
datePreviewFn = this._datePreviewFn.bind(this); |
|||
|
|||
|
|||
get label(): string { |
|||
return getLabel(this.widgetConfig.config.datasources); |
|||
} |
|||
|
|||
get dateEnabled(): boolean { |
|||
const layout: ValueCardLayout = this.valueCardWidgetSettingsForm.get('layout').value; |
|||
return ![ValueCardLayout.vertical, ValueCardLayout.simplified].includes(layout); |
|||
} |
|||
|
|||
get iconEnabled(): boolean { |
|||
const layout: ValueCardLayout = this.valueCardWidgetSettingsForm.get('layout').value; |
|||
return layout !== ValueCardLayout.simplified; |
|||
} |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private $injector: Injector, |
|||
private fb: UntypedFormBuilder) { |
|||
super(store); |
|||
} |
|||
|
|||
protected settingsForm(): UntypedFormGroup { |
|||
return this.valueCardWidgetSettingsForm; |
|||
} |
|||
|
|||
protected onWidgetConfigSet(widgetConfig: WidgetConfigComponentData) { |
|||
const params = widgetConfig.typeParameters as any; |
|||
this.horizontal = isDefinedAndNotNull(params.horizontal) ? params.horizontal : false; |
|||
this.valueCardLayouts = valueCardLayouts(this.horizontal); |
|||
} |
|||
|
|||
protected defaultSettings(): WidgetSettings { |
|||
return valueCardDefaultSettings(this.horizontal); |
|||
} |
|||
|
|||
protected onSettingsSet(settings: WidgetSettings) { |
|||
this.valueCardWidgetSettingsForm = this.fb.group({ |
|||
layout: [settings.layout, []], |
|||
|
|||
showLabel: [settings.showLabel, []], |
|||
labelFont: [settings.labelFont, []], |
|||
labelColor: [settings.labelColor, []], |
|||
|
|||
showIcon: [settings.showIcon, []], |
|||
iconSize: [settings.iconSize, [Validators.min(0)]], |
|||
iconSizeUnit: [settings.iconSizeUnit, []], |
|||
icon: [settings.icon, []], |
|||
iconColor: [settings.iconColor, []], |
|||
|
|||
valueFont: [settings.valueFont, []], |
|||
valueColor: [settings.valueColor, []], |
|||
|
|||
showDate: [settings.showDate, []], |
|||
dateFormat: [settings.dateFormat, []], |
|||
dateFont: [settings.dateFont, []], |
|||
dateColor: [settings.dateColor, []], |
|||
|
|||
background: [settings.background, []] |
|||
}); |
|||
} |
|||
|
|||
protected validatorTriggers(): string[] { |
|||
return ['layout', 'showLabel', 'showIcon', 'showDate']; |
|||
} |
|||
|
|||
protected updateValidators(emitEvent: boolean) { |
|||
const layout: ValueCardLayout = this.valueCardWidgetSettingsForm.get('layout').value; |
|||
const showLabel: boolean = this.valueCardWidgetSettingsForm.get('showLabel').value; |
|||
const showIcon: boolean = this.valueCardWidgetSettingsForm.get('showIcon').value; |
|||
const showDate: boolean = this.valueCardWidgetSettingsForm.get('showDate').value; |
|||
|
|||
const dateEnabled = ![ValueCardLayout.vertical, ValueCardLayout.simplified].includes(layout); |
|||
const iconEnabled = layout !== ValueCardLayout.simplified; |
|||
|
|||
if (showLabel) { |
|||
this.valueCardWidgetSettingsForm.get('labelFont').enable(); |
|||
this.valueCardWidgetSettingsForm.get('labelColor').enable(); |
|||
} else { |
|||
this.valueCardWidgetSettingsForm.get('labelFont').disable(); |
|||
this.valueCardWidgetSettingsForm.get('labelColor').disable(); |
|||
} |
|||
|
|||
if (iconEnabled) { |
|||
this.valueCardWidgetSettingsForm.get('showIcon').enable({emitEvent: false}); |
|||
if (showIcon) { |
|||
this.valueCardWidgetSettingsForm.get('iconSize').enable(); |
|||
this.valueCardWidgetSettingsForm.get('iconSizeUnit').enable(); |
|||
this.valueCardWidgetSettingsForm.get('icon').enable(); |
|||
this.valueCardWidgetSettingsForm.get('iconColor').enable(); |
|||
} else { |
|||
this.valueCardWidgetSettingsForm.get('iconSize').disable(); |
|||
this.valueCardWidgetSettingsForm.get('iconSizeUnit').disable(); |
|||
this.valueCardWidgetSettingsForm.get('icon').disable(); |
|||
this.valueCardWidgetSettingsForm.get('iconColor').disable(); |
|||
} |
|||
} else { |
|||
this.valueCardWidgetSettingsForm.get('showIcon').disable({emitEvent: false}); |
|||
this.valueCardWidgetSettingsForm.get('iconSize').disable(); |
|||
this.valueCardWidgetSettingsForm.get('iconSizeUnit').disable(); |
|||
this.valueCardWidgetSettingsForm.get('icon').disable(); |
|||
this.valueCardWidgetSettingsForm.get('iconColor').disable(); |
|||
} |
|||
|
|||
if (dateEnabled) { |
|||
this.valueCardWidgetSettingsForm.get('showDate').enable({emitEvent: false}); |
|||
if (showDate) { |
|||
this.valueCardWidgetSettingsForm.get('dateFormat').enable(); |
|||
this.valueCardWidgetSettingsForm.get('dateFont').enable(); |
|||
this.valueCardWidgetSettingsForm.get('dateColor').enable(); |
|||
} else { |
|||
this.valueCardWidgetSettingsForm.get('dateFormat').disable(); |
|||
this.valueCardWidgetSettingsForm.get('dateFont').disable(); |
|||
this.valueCardWidgetSettingsForm.get('dateColor').disable(); |
|||
} |
|||
} else { |
|||
this.valueCardWidgetSettingsForm.get('showDate').disable({emitEvent: false}); |
|||
this.valueCardWidgetSettingsForm.get('dateFormat').disable(); |
|||
this.valueCardWidgetSettingsForm.get('dateFont').disable(); |
|||
this.valueCardWidgetSettingsForm.get('dateColor').disable(); |
|||
} |
|||
this.valueCardWidgetSettingsForm.get('showIcon').updateValueAndValidity({emitEvent: false}); |
|||
this.valueCardWidgetSettingsForm.get('showDate').updateValueAndValidity({emitEvent: false}); |
|||
this.valueCardWidgetSettingsForm.get('labelFont').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('labelColor').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('iconSize').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('iconSizeUnit').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('icon').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('iconColor').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('dateFormat').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('dateFont').updateValueAndValidity({emitEvent}); |
|||
this.valueCardWidgetSettingsForm.get('dateColor').updateValueAndValidity({emitEvent}); |
|||
} |
|||
|
|||
private _valuePreviewFn(): string { |
|||
const units: string = this.widgetConfig.config.units; |
|||
const decimals: number = this.widgetConfig.config.decimals; |
|||
return formatValue(22, decimals, units, true); |
|||
} |
|||
|
|||
private _datePreviewFn(): string { |
|||
const dateFormat: DateFormatSettings = this.valueCardWidgetSettingsForm.get('dateFormat').value; |
|||
const processor = DateFormatProcessor.fromSettings(this.$injector, dateFormat); |
|||
processor.update(Date.now()); |
|||
return processor.formatted; |
|||
} |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
<!-- |
|||
|
|||
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-background-settings-panel" [formGroup]="backgroundSettingsFormGroup"> |
|||
<div class="tb-background-settings-title" translate>widgets.background.background-settings</div> |
|||
<div class="tb-form-panel"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px"> |
|||
<div class="tb-form-panel-title" translate>widgets.background.background</div> |
|||
<tb-toggle-select formControlName="type" fxFlex> |
|||
<tb-toggle-option *ngFor="let type of backgroundTypes" |
|||
[value]="type"> |
|||
{{ backgroundTypeTranslationsMap.get(type) | translate }} |
|||
</tb-toggle-option> |
|||
</tb-toggle-select> |
|||
</div> |
|||
<tb-image-input [fxShow]="backgroundSettingsFormGroup.get('type').value === backgroundType.image" formControlName="imageBase64"></tb-image-input> |
|||
<div [fxShow]="backgroundSettingsFormGroup.get('type').value === backgroundType.imageUrl" class="tb-form-row space-between"> |
|||
<div translate>widgets.background.image-url</div> |
|||
<mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="imageUrl" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
</div> |
|||
<div [fxShow]="backgroundSettingsFormGroup.get('type').value === backgroundType.color" class="tb-form-row space-between"> |
|||
<div translate>widgets.color.color</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="color"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel" formGroupName="overlay"> |
|||
<div class="tb-form-panel-title" translate>widgets.background.overlay</div> |
|||
<mat-slide-toggle class="mat-slide" formControlName="enabled"> |
|||
{{ 'widgets.background.enable-overlay' | translate }} |
|||
</mat-slide-toggle> |
|||
<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-form-row space-between"> |
|||
<div translate>widgets.background.blur</div> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="blur" type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<div matSuffix>px</div> |
|||
</mat-form-field> |
|||
</div> |
|||
</div> |
|||
<div class="tb-background-settings-preview"> |
|||
<div class="tb-background-settings-preview-title" translate> |
|||
widgets.background.preview |
|||
</div> |
|||
<div class="tb-background-settings-preview-box mat-elevation-z4" [style]="backgroundStyle"> |
|||
<div class="tb-background-settings-preview-overlay" [style]="overlayStyle"> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-background-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]="backgroundSettingsFormGroup.invalid || !backgroundSettingsFormGroup.dirty"> |
|||
{{ 'action.apply' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,73 @@ |
|||
/** |
|||
* 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-background-settings-panel { |
|||
width: 620px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
@media #{$mat-lt-md} { |
|||
width: 90vw; |
|||
} |
|||
.tb-background-settings-title { |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
letter-spacing: 0.25px; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
.tb-background-settings-preview { |
|||
flex: 1; |
|||
background: rgba(0, 0, 0, 0.04); |
|||
display: flex; |
|||
flex-direction: column; |
|||
padding: 12px 16px 24px 16px; |
|||
align-items: center; |
|||
gap: 12px; |
|||
} |
|||
.tb-background-settings-preview-title { |
|||
align-self: stretch; |
|||
font-size: 16px; |
|||
font-style: normal; |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
color: rgba(0, 0, 0, 0.38); |
|||
} |
|||
.tb-background-settings-preview-box { |
|||
position: relative; |
|||
width: 136px; |
|||
height: 118px; |
|||
border-radius: 2.666px; |
|||
} |
|||
.tb-background-settings-preview-overlay { |
|||
position: absolute; |
|||
border-radius: 2.666px; |
|||
top: 7.998px; |
|||
bottom: 7.998px; |
|||
left: 7.998px; |
|||
right: 7.998px; |
|||
} |
|||
.tb-background-settings-panel-buttons { |
|||
height: 40px; |
|||
display: flex; |
|||
flex-direction: row; |
|||
gap: 16px; |
|||
justify-content: flex-end; |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
///
|
|||
/// 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 { |
|||
backgroundStyle, |
|||
overlayStyle, |
|||
BackgroundSettings, |
|||
BackgroundType, |
|||
backgroundTypeTranslations, ComponentStyle |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-background-settings-panel', |
|||
templateUrl: './background-settings-panel.component.html', |
|||
providers: [], |
|||
styleUrls: ['./background-settings-panel.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class BackgroundSettingsPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() |
|||
backgroundSettings: BackgroundSettings; |
|||
|
|||
@Input() |
|||
popover: TbPopoverComponent<BackgroundSettingsPanelComponent>; |
|||
|
|||
@Output() |
|||
backgroundSettingsApplied = new EventEmitter<BackgroundSettings>(); |
|||
|
|||
backgroundType = BackgroundType; |
|||
|
|||
backgroundTypes = Object.keys(BackgroundType) as BackgroundType[]; |
|||
|
|||
backgroundTypeTranslationsMap = backgroundTypeTranslations; |
|||
|
|||
backgroundSettingsFormGroup: UntypedFormGroup; |
|||
|
|||
backgroundStyle: ComponentStyle = {}; |
|||
overlayStyle: ComponentStyle = {}; |
|||
|
|||
constructor(private fb: UntypedFormBuilder, |
|||
protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.backgroundSettingsFormGroup = this.fb.group( |
|||
{ |
|||
type: [this.backgroundSettings?.type, []], |
|||
imageBase64: [this.backgroundSettings?.imageBase64, []], |
|||
imageUrl: [this.backgroundSettings?.imageUrl, []], |
|||
color: [this.backgroundSettings?.color, []], |
|||
overlay: this.fb.group({ |
|||
enabled: [this.backgroundSettings?.overlay?.enabled, []], |
|||
color: [this.backgroundSettings?.overlay?.color, []], |
|||
blur: [this.backgroundSettings?.overlay?.blur, []] |
|||
}) |
|||
} |
|||
); |
|||
this.backgroundSettingsFormGroup.get('type').valueChanges.subscribe(() => { |
|||
setTimeout(() => {this.popover?.updatePosition();}, 0); |
|||
}); |
|||
this.backgroundSettingsFormGroup.get('overlay').get('enabled').valueChanges.subscribe(() => { |
|||
this.updateValidators(); |
|||
}); |
|||
this.backgroundSettingsFormGroup.valueChanges.subscribe(() => { |
|||
this.updateBackgroundStyle(); |
|||
}); |
|||
this.updateValidators(); |
|||
this.updateBackgroundStyle(); |
|||
} |
|||
|
|||
cancel() { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
applyColorSettings() { |
|||
const backgroundSettings = this.backgroundSettingsFormGroup.value; |
|||
this.backgroundSettingsApplied.emit(backgroundSettings); |
|||
} |
|||
|
|||
private updateValidators() { |
|||
const overlayEnabled: boolean = this.backgroundSettingsFormGroup.get('overlay').get('enabled').value; |
|||
if (overlayEnabled) { |
|||
this.backgroundSettingsFormGroup.get('overlay').get('color').enable(); |
|||
this.backgroundSettingsFormGroup.get('overlay').get('blur').enable(); |
|||
} else { |
|||
this.backgroundSettingsFormGroup.get('overlay').get('color').disable(); |
|||
this.backgroundSettingsFormGroup.get('overlay').get('blur').disable(); |
|||
} |
|||
this.backgroundSettingsFormGroup.get('overlay').get('color').updateValueAndValidity({emitEvent: false}); |
|||
this.backgroundSettingsFormGroup.get('overlay').get('blur').updateValueAndValidity({emitEvent: false}); |
|||
} |
|||
|
|||
private updateBackgroundStyle() { |
|||
const background: BackgroundSettings = this.backgroundSettingsFormGroup.value; |
|||
this.backgroundStyle = backgroundStyle(background); |
|||
this.overlayStyle = overlayStyle(background.overlay); |
|||
} |
|||
|
|||
} |
|||
@ -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 tb-background-settings" |
|||
[disabled]="disabled" |
|||
#matButton |
|||
(click)="openBackgroundSettingsPopup($event, matButton)"> |
|||
<div class="tb-color-preview box" [ngClass]="{'disabled': disabled}"> |
|||
<div class="tb-color-result" [style]="backgroundStyle"> |
|||
<div class="tb-color-overlay" [style]="overlayStyle"> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</button> |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* 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.mat-mdc-button-base.tb-box-button.tb-background-settings { |
|||
padding: 0; |
|||
.mat-mdc-button-persistent-ripple { |
|||
z-index: 2; |
|||
} |
|||
.tb-color-preview { |
|||
width: 38px; |
|||
min-width: 38px; |
|||
height: 38px; |
|||
&.box { |
|||
.tb-color-result { |
|||
&:after { |
|||
border: none; |
|||
} |
|||
} |
|||
.tb-color-overlay { |
|||
position: absolute; |
|||
border-radius: 3px; |
|||
top: 4px; |
|||
bottom: 4px; |
|||
left: 4px; |
|||
right: 4px; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
///
|
|||
/// 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, ViewEncapsulation } from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
import { |
|||
BackgroundSettings, |
|||
backgroundStyle, |
|||
BackgroundType, |
|||
ComponentStyle, |
|||
overlayStyle |
|||
} from '@home/components/widget/config/widget-settings.models'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { |
|||
BackgroundSettingsPanelComponent |
|||
} from '@home/components/widget/lib/settings/common/background-settings-panel.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-background-settings', |
|||
templateUrl: './background-settings.component.html', |
|||
styleUrls: ['./background-settings.component.scss'], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => BackgroundSettingsComponent), |
|||
multi: true |
|||
} |
|||
], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class BackgroundSettingsComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
backgroundType = BackgroundType; |
|||
|
|||
modelValue: BackgroundSettings; |
|||
|
|||
backgroundStyle: ComponentStyle = {}; |
|||
|
|||
overlayStyle: 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.updateBackgroundStyle(); |
|||
} |
|||
|
|||
writeValue(value: BackgroundSettings): void { |
|||
this.modelValue = value; |
|||
this.updateBackgroundStyle(); |
|||
} |
|||
|
|||
openBackgroundSettingsPopup($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 = { |
|||
backgroundSettings: this.modelValue |
|||
}; |
|||
const backgroundSettingsPanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, BackgroundSettingsPanelComponent, 'left', true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
backgroundSettingsPanelPopover.tbComponentRef.instance.popover = backgroundSettingsPanelPopover; |
|||
backgroundSettingsPanelPopover.tbComponentRef.instance.backgroundSettingsApplied.subscribe((backgroundSettings) => { |
|||
backgroundSettingsPanelPopover.hide(); |
|||
this.modelValue = backgroundSettings; |
|||
this.updateBackgroundStyle(); |
|||
this.propagateChange(this.modelValue); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
private updateBackgroundStyle() { |
|||
if (!this.disabled) { |
|||
this.backgroundStyle = backgroundStyle(this.modelValue); |
|||
this.overlayStyle = overlayStyle(this.modelValue.overlay); |
|||
} else { |
|||
this.backgroundStyle = {}; |
|||
this.overlayStyle = {}; |
|||
} |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue