26 changed files with 2035 additions and 84 deletions
@ -0,0 +1,84 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2025 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-shape-fill-image-settings-panel" [formGroup]="shapeFillImageSettingsFormGroup"> |
||||
|
<div class="tb-shape-fill-image-settings-title" translate>widgets.maps.data-layer.shape.fill-image</div> |
||||
|
<div class="flex flex-row"> |
||||
|
<tb-toggle-select formControlName="type" class="flex-1"> |
||||
|
<tb-toggle-option [value]="ShapeFillImageType.image"> |
||||
|
{{ 'widgets.maps.data-layer.shape.fill-image-type-image' | translate }} |
||||
|
</tb-toggle-option> |
||||
|
<tb-toggle-option [value]="ShapeFillImageType.function"> |
||||
|
{{ 'widgets.maps.data-layer.shape.fill-image-type-function' | translate }} |
||||
|
</tb-toggle-option> |
||||
|
</tb-toggle-select> |
||||
|
</div> |
||||
|
<div class="tb-shape-fill-image-settings-panel-body" [class.!hidden]="shapeFillImageSettingsFormGroup.get('type').value !== ShapeFillImageType.image"> |
||||
|
<div class="tb-form-panel no-padding no-border"> |
||||
|
<tb-gallery-image-input required formControlName="image"></tb-gallery-image-input> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widgets.maps.data-layer.shape.opacity</div> |
||||
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="opacity" type="number" min="0" max="1" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widgets.maps.data-layer.shape.angle</div> |
||||
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="angle" type="number" min="0" max="360" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
<div matSuffix>deg</div> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widgets.maps.data-layer.shape.scale</div> |
||||
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="scale" type="number" min="0" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-shape-fill-image-settings-panel-body" [class.!hidden]="shapeFillImageSettingsFormGroup.get('type').value !== ShapeFillImageType.function"> |
||||
|
<div class="tb-form-panel no-padding no-border"> |
||||
|
<tb-js-func formControlName="imageFunction" |
||||
|
withModules |
||||
|
[functionArgs]="['data', 'images', 'dsData']" |
||||
|
[globalVariables]="functionScopeVariables" |
||||
|
functionTitle="{{ 'widgets.maps.data-layer.shape.fill-image-function' | translate }}" |
||||
|
helpId="widget/lib/map/shape_fill_image_fn"> |
||||
|
</tb-js-func> |
||||
|
<tb-multiple-gallery-image-input label="{{ 'widgets.maps.data-layer.shape.fill-images' | translate }}" |
||||
|
formControlName="images"> |
||||
|
</tb-multiple-gallery-image-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-shape-fill-image-settings-panel-buttons"> |
||||
|
<span class="flex-1"></span> |
||||
|
<button mat-button |
||||
|
color="primary" |
||||
|
type="button" |
||||
|
(click)="cancel()"> |
||||
|
{{ 'action.cancel' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button |
||||
|
color="primary" |
||||
|
type="button" |
||||
|
(click)="applyShapeFillImageSettings()" |
||||
|
[disabled]="shapeFillImageSettingsFormGroup.invalid || !shapeFillImageSettingsFormGroup.dirty"> |
||||
|
{{ 'action.apply' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,54 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2025 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-shape-fill-image-settings-panel { |
||||
|
width: 700px; |
||||
|
max-width: 90vw; |
||||
|
min-height: 300px; |
||||
|
max-height: 90vh; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
gap: 16px; |
||||
|
@media #{$mat-xs} { |
||||
|
width: 90vw; |
||||
|
} |
||||
|
.tb-shape-fill-image-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 { |
||||
|
height: auto; |
||||
|
} |
||||
|
.tb-shape-fill-image-settings-panel-body { |
||||
|
flex: 1; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
min-height: 0; |
||||
|
overflow: auto; |
||||
|
} |
||||
|
.tb-shape-fill-image-settings-panel-buttons { |
||||
|
height: 40px; |
||||
|
display: flex; |
||||
|
flex-direction: row; |
||||
|
gap: 16px; |
||||
|
justify-content: flex-end; |
||||
|
align-items: flex-end; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2025 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, DestroyRef, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
||||
|
import { TbPopoverComponent } from '@shared/components/popover.component'; |
||||
|
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
||||
|
import { WidgetService } from '@core/http/widget.service'; |
||||
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
||||
|
import { ShapeFillImageSettings, ShapeFillImageType } from '@shared/models/widget/maps/map.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-shape-fill-image-settings-panel', |
||||
|
templateUrl: './shape-fill-image-settings-panel.component.html', |
||||
|
providers: [], |
||||
|
styleUrls: ['./shape-fill-image-settings-panel.component.scss'], |
||||
|
encapsulation: ViewEncapsulation.None |
||||
|
}) |
||||
|
export class ShapeFillImageSettingsPanelComponent implements OnInit { |
||||
|
|
||||
|
@Input() |
||||
|
shapeFillImageSettings: ShapeFillImageSettings; |
||||
|
|
||||
|
@Output() |
||||
|
shapeFillImageSettingsApplied = new EventEmitter<ShapeFillImageSettings>(); |
||||
|
|
||||
|
ShapeFillImageType = ShapeFillImageType; |
||||
|
|
||||
|
shapeFillImageSettingsFormGroup: UntypedFormGroup; |
||||
|
|
||||
|
functionScopeVariables = this.widgetService.getWidgetScopeVariables(); |
||||
|
|
||||
|
constructor(private fb: UntypedFormBuilder, |
||||
|
private popover: TbPopoverComponent, |
||||
|
private widgetService: WidgetService, |
||||
|
private destroyRef: DestroyRef) { |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.shapeFillImageSettingsFormGroup = this.fb.group( |
||||
|
{ |
||||
|
type: [this.shapeFillImageSettings?.type || ShapeFillImageType.image, []], |
||||
|
image: [this.shapeFillImageSettings?.image, [Validators.required]], |
||||
|
opacity: [this.shapeFillImageSettings?.opacity, [Validators.min(0), Validators.max(1)]], |
||||
|
angle: [this.shapeFillImageSettings?.angle, [Validators.min(0), Validators.max(360)]], |
||||
|
scale: [this.shapeFillImageSettings?.scale, [Validators.min(0)]], |
||||
|
imageFunction: [this.shapeFillImageSettings?.imageFunction, [Validators.required]], |
||||
|
images: [this.shapeFillImageSettings?.images, []] |
||||
|
} |
||||
|
); |
||||
|
this.shapeFillImageSettingsFormGroup.get('type').valueChanges.pipe( |
||||
|
takeUntilDestroyed(this.destroyRef) |
||||
|
).subscribe(() => { |
||||
|
this.updateValidators(); |
||||
|
setTimeout(() => {this.popover?.updatePosition();}, 0); |
||||
|
}); |
||||
|
this.updateValidators(); |
||||
|
} |
||||
|
|
||||
|
cancel() { |
||||
|
this.popover?.hide(); |
||||
|
} |
||||
|
|
||||
|
applyShapeFillImageSettings() { |
||||
|
const shapeFillImageSettings: ShapeFillImageSettings = this.shapeFillImageSettingsFormGroup.value; |
||||
|
this.shapeFillImageSettingsApplied.emit(shapeFillImageSettings); |
||||
|
this.popover?.hide(); |
||||
|
} |
||||
|
|
||||
|
private updateValidators() { |
||||
|
const type: ShapeFillImageType = this.shapeFillImageSettingsFormGroup.get('type').value; |
||||
|
if (type === ShapeFillImageType.image) { |
||||
|
this.shapeFillImageSettingsFormGroup.get('image').enable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('opacity').enable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('angle').enable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('scale').enable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('imageFunction').disable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('images').disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.shapeFillImageSettingsFormGroup.get('image').disable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('opacity').disable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('angle').disable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('scale').disable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('imageFunction').enable({emitEvent: false}); |
||||
|
this.shapeFillImageSettingsFormGroup.get('images').enable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2025 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)="openImageSettingsPopup($event, matButton)"> |
||||
|
<tb-icon matButtonIcon *ngIf="modelValue?.type === ShapeFillImageType.function; else imagePreview">mdi:function-variant</tb-icon> |
||||
|
</button> |
||||
|
<ng-template #imagePreview> |
||||
|
<img width="24px" height="24px" [style.transform]="modelValue?.angle ? ('rotate('+modelValue.angle+'deg)') : ''" [style.opacity]="modelValue?.opacity" |
||||
|
style="object-fit: contain;" [src]="modelValue?.image | image : {preview: true} | async" [class.disabled]="disabled"/> |
||||
|
</ng-template> |
||||
@ -0,0 +1,96 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2025 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, forwardRef, Input, Renderer2, ViewContainerRef } from '@angular/core'; |
||||
|
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
||||
|
import { MatButton } from '@angular/material/button'; |
||||
|
import { TbPopoverService } from '@shared/components/popover.service'; |
||||
|
import { ShapeFillImageSettings, ShapeFillImageType } from '@shared/models/widget/maps/map.models'; |
||||
|
import { |
||||
|
ShapeFillImageSettingsPanelComponent |
||||
|
} from '@home/components/widget/lib/settings/common/map/shape-fill-image-settings-panel.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-shape-fill-image-settings', |
||||
|
templateUrl: './shape-fill-image-settings.component.html', |
||||
|
styleUrls: [], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => ShapeFillImageSettingsComponent), |
||||
|
multi: true |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class ShapeFillImageSettingsComponent implements ControlValueAccessor { |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
ShapeFillImageType = ShapeFillImageType; |
||||
|
|
||||
|
modelValue: ShapeFillImageSettings; |
||||
|
|
||||
|
private propagateChange: (v: any) => void = () => { }; |
||||
|
|
||||
|
constructor(private popoverService: TbPopoverService, |
||||
|
private renderer: Renderer2, |
||||
|
private cd: ChangeDetectorRef, |
||||
|
private viewContainerRef: ViewContainerRef) {} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(_fn: any): void { |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
} |
||||
|
|
||||
|
writeValue(value: ShapeFillImageSettings): void { |
||||
|
if (value) { |
||||
|
this.modelValue = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
openImageSettingsPopup($event: Event, matButton: MatButton) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
const trigger = matButton._elementRef.nativeElement; |
||||
|
if (this.popoverService.hasPopover(trigger)) { |
||||
|
this.popoverService.hidePopover(trigger); |
||||
|
} else { |
||||
|
this.popoverService.displayPopover({ |
||||
|
trigger, |
||||
|
renderer: this.renderer, |
||||
|
componentType: ShapeFillImageSettingsPanelComponent, |
||||
|
hostView: this.viewContainerRef, |
||||
|
preferredPlacement: 'left', |
||||
|
context: { |
||||
|
shapeFillImageSettings: this.modelValue, |
||||
|
}, |
||||
|
isModal: true |
||||
|
}).tbComponentRef.instance.shapeFillImageSettingsApplied.subscribe((shapeFillImageSettings) => { |
||||
|
this.modelValue = shapeFillImageSettings; |
||||
|
this.propagateChange(this.modelValue); |
||||
|
this.cd.detectChanges(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2025 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-shape-fill-stripe-settings-panel" [formGroup]="shapeFillStripeSettingsFormGroup"> |
||||
|
<div class="tb-shape-fill-stripe-settings-title" translate>widgets.maps.data-layer.shape.stripe-pattern</div> |
||||
|
<div class="tb-shape-fill-stripe-settings-panel-body"> |
||||
|
<div class="tb-form-panel no-padding no-border"> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widgets.maps.data-layer.shape.first-stripe</div> |
||||
|
<div class="flex flex-row items-center gap-2"> |
||||
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
||||
|
<input matInput type="number" min="0" formControlName="weight" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
<span matSuffix>px</span> |
||||
|
</mat-form-field> |
||||
|
<tb-data-layer-color-settings |
||||
|
[context]="context" |
||||
|
[dsType]="dsType" |
||||
|
[dsEntityAliasId]="dsEntityAliasId" |
||||
|
[dsDeviceId]="dsDeviceId" |
||||
|
helpId="{{ dataLayerType === 'polygons' ? 'widget/lib/map/polygon_stroke_color_fn' : 'widget/lib/map/circle_stroke_color_fn' }}" formControlName="color"></tb-data-layer-color-settings> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widgets.maps.data-layer.shape.second-stripe</div> |
||||
|
<div class="flex flex-row items-center gap-2"> |
||||
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
||||
|
<input matInput type="number" min="0" formControlName="spaceWeight" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
<span matSuffix>px</span> |
||||
|
</mat-form-field> |
||||
|
<tb-data-layer-color-settings |
||||
|
[context]="context" |
||||
|
[dsType]="dsType" |
||||
|
[dsEntityAliasId]="dsEntityAliasId" |
||||
|
[dsDeviceId]="dsDeviceId" |
||||
|
helpId="{{ dataLayerType === 'polygons' ? 'widget/lib/map/polygon_stroke_color_fn' : 'widget/lib/map/circle_stroke_color_fn' }}" formControlName="spaceColor"></tb-data-layer-color-settings> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widgets.maps.data-layer.shape.angle</div> |
||||
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="angle" type="number" min="0" max="180" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
<div matSuffix>deg</div> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-shape-fill-stripe-settings-preview"> |
||||
|
<div class="tb-shape-fill-stripe-settings-preview-title" translate> |
||||
|
widgets.background.preview |
||||
|
</div> |
||||
|
<div class="tb-shape-fill-stripe-settings-preview-box mat-elevation-z4" [style]="stripePreviewStyle"> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-shape-fill-stripe-settings-panel-buttons"> |
||||
|
<span class="flex-1"></span> |
||||
|
<button mat-button |
||||
|
color="primary" |
||||
|
type="button" |
||||
|
(click)="cancel()"> |
||||
|
{{ 'action.cancel' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button |
||||
|
color="primary" |
||||
|
type="button" |
||||
|
(click)="applyShapeFillStripeSettings()" |
||||
|
[disabled]="shapeFillStripeSettingsFormGroup.invalid || !shapeFillStripeSettingsFormGroup.dirty"> |
||||
|
{{ 'action.apply' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,80 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2025 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-shape-fill-stripe-settings-panel { |
||||
|
width: 700px; |
||||
|
max-width: 90vw; |
||||
|
min-height: 300px; |
||||
|
max-height: 90vh; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
gap: 16px; |
||||
|
@media #{$mat-xs} { |
||||
|
width: 90vw; |
||||
|
} |
||||
|
.tb-shape-fill-stripe-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 { |
||||
|
height: auto; |
||||
|
} |
||||
|
.tb-shape-fill-stripe-settings-panel-body { |
||||
|
flex: 1; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
min-height: 0; |
||||
|
overflow: auto; |
||||
|
} |
||||
|
.tb-shape-fill-stripe-settings-preview { |
||||
|
flex: 1; |
||||
|
background: #fff; |
||||
|
border-radius: 4px; |
||||
|
border: 1px solid rgba(0, 0, 0, 0.12); |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
padding: 12px 16px 24px 16px; |
||||
|
align-items: center; |
||||
|
gap: 12px; |
||||
|
} |
||||
|
.tb-shape-fill-stripe-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-shape-fill-stripe-settings-preview-box { |
||||
|
position: relative; |
||||
|
width: 136px; |
||||
|
height: 118px; |
||||
|
border-radius: 2.666px; |
||||
|
} |
||||
|
|
||||
|
.tb-shape-fill-stripe-settings-panel-buttons { |
||||
|
height: 40px; |
||||
|
display: flex; |
||||
|
flex-direction: row; |
||||
|
gap: 16px; |
||||
|
justify-content: flex-end; |
||||
|
align-items: flex-end; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,106 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2025 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, DestroyRef, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
||||
|
import { TbPopoverComponent } from '@shared/components/popover.component'; |
||||
|
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
||||
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
||||
|
import { MapDataLayerType, ShapeFillStripeSettings } from '@shared/models/widget/maps/map.models'; |
||||
|
import { DomSanitizer } from '@angular/platform-browser'; |
||||
|
import { |
||||
|
generateStripePreviewUrl |
||||
|
} from '@home/components/widget/lib/settings/common/map/shape-fill-stripe-settings.component'; |
||||
|
import { ComponentStyle } from '@shared/models/widget-settings.models'; |
||||
|
import { MapSettingsContext } from '@home/components/widget/lib/settings/common/map/map-settings.component.models'; |
||||
|
import { DatasourceType } from '@shared/models/widget.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-shape-fill-stripe-settings-panel', |
||||
|
templateUrl: './shape-fill-stripe-settings-panel.component.html', |
||||
|
providers: [], |
||||
|
styleUrls: ['./shape-fill-stripe-settings-panel.component.scss'], |
||||
|
encapsulation: ViewEncapsulation.None |
||||
|
}) |
||||
|
export class ShapeFillStripeSettingsPanelComponent implements OnInit { |
||||
|
|
||||
|
@Input() |
||||
|
shapeFillStripeSettings: ShapeFillStripeSettings; |
||||
|
|
||||
|
@Input() |
||||
|
context: MapSettingsContext; |
||||
|
|
||||
|
@Input() |
||||
|
dsType: DatasourceType; |
||||
|
|
||||
|
@Input() |
||||
|
dsEntityAliasId: string; |
||||
|
|
||||
|
@Input() |
||||
|
dsDeviceId: string; |
||||
|
|
||||
|
@Input() |
||||
|
dataLayerType: MapDataLayerType; |
||||
|
|
||||
|
@Output() |
||||
|
shapeFillStripeSettingsApplied = new EventEmitter<ShapeFillStripeSettings>(); |
||||
|
|
||||
|
stripePreviewStyle: ComponentStyle; |
||||
|
|
||||
|
shapeFillStripeSettingsFormGroup: UntypedFormGroup; |
||||
|
|
||||
|
constructor(private fb: UntypedFormBuilder, |
||||
|
private sanitizer: DomSanitizer, |
||||
|
private popover: TbPopoverComponent, |
||||
|
private destroyRef: DestroyRef) { |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.shapeFillStripeSettingsFormGroup = this.fb.group( |
||||
|
{ |
||||
|
weight: [this.shapeFillStripeSettings?.weight, [Validators.min(0)]], |
||||
|
color: [this.shapeFillStripeSettings?.color, []], |
||||
|
spaceWeight: [this.shapeFillStripeSettings?.spaceWeight, [Validators.min(0)]], |
||||
|
spaceColor: [this.shapeFillStripeSettings?.spaceColor, []], |
||||
|
angle: [this.shapeFillStripeSettings?.angle, [Validators.min(0), Validators.max(180)]] |
||||
|
} |
||||
|
); |
||||
|
this.shapeFillStripeSettingsFormGroup.valueChanges.pipe( |
||||
|
takeUntilDestroyed(this.destroyRef) |
||||
|
).subscribe(() => { |
||||
|
this.updatePreview(); |
||||
|
}); |
||||
|
this.updatePreview(); |
||||
|
} |
||||
|
|
||||
|
cancel() { |
||||
|
this.popover?.hide(); |
||||
|
} |
||||
|
|
||||
|
applyShapeFillStripeSettings() { |
||||
|
const shapeFillStripeSettings: ShapeFillStripeSettings = this.shapeFillStripeSettingsFormGroup.value; |
||||
|
this.shapeFillStripeSettingsApplied.emit(shapeFillStripeSettings); |
||||
|
this.popover?.hide(); |
||||
|
} |
||||
|
|
||||
|
private updatePreview() { |
||||
|
const shapeFillStripeSettings: ShapeFillStripeSettings = this.shapeFillStripeSettingsFormGroup.value; |
||||
|
const previewUrl = generateStripePreviewUrl(shapeFillStripeSettings); |
||||
|
this.stripePreviewStyle = { |
||||
|
background: this.sanitizer.bypassSecurityTrustStyle(`url(${previewUrl}) no-repeat 50% 50% / cover`) |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2025 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)="openStripeSettingsPopup($event, matButton)"> |
||||
|
<img matButtonIcon width="24px" height="24px" |
||||
|
style="object-fit: contain; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.12);" |
||||
|
[src]="stripePreviewUrl" [class.disabled]="disabled"/> |
||||
|
</button> |
||||
@ -0,0 +1,148 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2025 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, forwardRef, Input, Renderer2, ViewContainerRef } from '@angular/core'; |
||||
|
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
||||
|
import { MatButton } from '@angular/material/button'; |
||||
|
import { TbPopoverService } from '@shared/components/popover.service'; |
||||
|
import { MapDataLayerType, ShapeFillStripeSettings } from '@shared/models/widget/maps/map.models'; |
||||
|
import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; |
||||
|
import { isDefinedAndNotNull, stringToBase64 } from '@core/utils'; |
||||
|
import { MapSettingsContext } from '@home/components/widget/lib/settings/common/map/map-settings.component.models'; |
||||
|
import { DatasourceType } from '@shared/models/widget.models'; |
||||
|
import { |
||||
|
ShapeFillStripeSettingsPanelComponent |
||||
|
} from '@home/components/widget/lib/settings/common/map/shape-fill-stripe-settings-panel.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-shape-fill-stripe-settings', |
||||
|
templateUrl: './shape-fill-stripe-settings.component.html', |
||||
|
styleUrls: [], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => ShapeFillStripeSettingsComponent), |
||||
|
multi: true |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class ShapeFillStripeSettingsComponent implements ControlValueAccessor { |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
@Input() |
||||
|
context: MapSettingsContext; |
||||
|
|
||||
|
@Input() |
||||
|
dsType: DatasourceType; |
||||
|
|
||||
|
@Input() |
||||
|
dsEntityAliasId: string; |
||||
|
|
||||
|
@Input() |
||||
|
dsDeviceId: string; |
||||
|
|
||||
|
@Input() |
||||
|
dataLayerType: MapDataLayerType; |
||||
|
|
||||
|
modelValue: ShapeFillStripeSettings; |
||||
|
|
||||
|
stripePreviewUrl: SafeUrl; |
||||
|
|
||||
|
private propagateChange: (v: any) => void = () => { }; |
||||
|
|
||||
|
constructor(private popoverService: TbPopoverService, |
||||
|
private sanitizer: DomSanitizer, |
||||
|
private renderer: Renderer2, |
||||
|
private cd: ChangeDetectorRef, |
||||
|
private viewContainerRef: ViewContainerRef) {} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(_fn: any): void { |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
} |
||||
|
|
||||
|
writeValue(value: ShapeFillStripeSettings): void { |
||||
|
if (value) { |
||||
|
this.modelValue = value; |
||||
|
} |
||||
|
this.updatePreview(); |
||||
|
} |
||||
|
|
||||
|
openStripeSettingsPopup($event: Event, matButton: MatButton) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
const trigger = matButton._elementRef.nativeElement; |
||||
|
if (this.popoverService.hasPopover(trigger)) { |
||||
|
this.popoverService.hidePopover(trigger); |
||||
|
} else { |
||||
|
this.popoverService.displayPopover({ |
||||
|
trigger, |
||||
|
renderer: this.renderer, |
||||
|
componentType: ShapeFillStripeSettingsPanelComponent, |
||||
|
hostView: this.viewContainerRef, |
||||
|
preferredPlacement: 'left', |
||||
|
context: { |
||||
|
shapeFillStripeSettings: this.modelValue, |
||||
|
context: this.context, |
||||
|
dsType: this.dsType, |
||||
|
dsEntityAliasId: this.dsEntityAliasId, |
||||
|
dsDeviceId: this.dsDeviceId, |
||||
|
dataLayerType: this.dataLayerType |
||||
|
}, |
||||
|
isModal: true |
||||
|
}).tbComponentRef.instance.shapeFillStripeSettingsApplied.subscribe((shapeFillStripeSettings) => { |
||||
|
this.modelValue = shapeFillStripeSettings; |
||||
|
this.updatePreview(); |
||||
|
this.propagateChange(this.modelValue); |
||||
|
this.cd.detectChanges(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private updatePreview() { |
||||
|
this.stripePreviewUrl = this.sanitizer.bypassSecurityTrustUrl(generateStripePreviewUrl(this.modelValue)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export const generateStripePreviewUrl = (settings: ShapeFillStripeSettings): string => { |
||||
|
const weight = isDefinedAndNotNull(settings?.weight) ? settings.weight : 3; |
||||
|
const spaceWeight = isDefinedAndNotNull(settings?.spaceWeight) ? settings.spaceWeight : 9; |
||||
|
const angle = isDefinedAndNotNull(settings?.angle) ? settings.angle : 45; |
||||
|
const height = weight + spaceWeight; |
||||
|
const color = settings?.color?.color || '#8f8f8f'; |
||||
|
const spaceColor = settings?.spaceColor?.color || 'rgba(143,143,143,0)'; |
||||
|
const svgStr = `<svg x="0" y="0" width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
|
<rect x="0" y="0" width="48" height="48" fill="url(#stripePattern)" fill-opacity="1"></rect> |
||||
|
<defs> |
||||
|
<pattern id="stripePattern" x="0" y="0" width="8" height="${height}" patternUnits="userSpaceOnUse" |
||||
|
patternContentUnits="userSpaceOnUse" patternTransform="rotate(${angle})"> |
||||
|
<path d="M0 ${weight/2} H 8" stroke="${color}" stroke-width="${weight}" stroke-opacity="1"></path> |
||||
|
<path d="M0 ${weight + spaceWeight/2} H 8" stroke="${spaceColor}" stroke-width="${spaceWeight}" stroke-opacity="1"></path> |
||||
|
</pattern> |
||||
|
</defs> |
||||
|
</svg>`;
|
||||
|
const encodedSvg = stringToBase64(svgStr); |
||||
|
return `data:image/svg+xml;base64,${encodedSvg}`; |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
#### Shape fill image function |
||||
|
|
||||
|
<div class="divider"></div> |
||||
|
<br/> |
||||
|
|
||||
|
*function (data, images, dsData): {url: string}* |
||||
|
|
||||
|
A JavaScript function used to compute shape fill image. |
||||
|
|
||||
|
**Parameters:** |
||||
|
|
||||
|
<ul> |
||||
|
{% include widget/lib/map/shape_fill_image_fn_args %} |
||||
|
</ul> |
||||
|
|
||||
|
**Returns:** |
||||
|
|
||||
|
Should return shape fill image data having the following structure: |
||||
|
|
||||
|
```typescript |
||||
|
{ |
||||
|
url: string; |
||||
|
opacity?: number; |
||||
|
angle?: number; |
||||
|
scale?: number; |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
- *url* - fill image url; |
||||
|
- *opacity* - optional image opacity, number value from 0 to 1; |
||||
|
- *angle* - optional image rotation angle, number value from 0 to 360; |
||||
|
- *scale* - optional image scale, number value (1 - original size, smaller value - scale down, bigger value - scale up); |
||||
|
|
||||
|
In case no data is returned, default fill image will be used. |
||||
|
|
||||
|
<div class="divider"></div> |
||||
|
|
||||
|
##### Examples |
||||
|
|
||||
|
<ul> |
||||
|
<li> |
||||
|
TODO: |
||||
|
</li> |
||||
|
</ul> |
||||
|
|
||||
|
```javascript |
||||
|
TODO: |
||||
|
{:copy-code} |
||||
|
``` |
||||
|
|
||||
|
<br> |
||||
|
<br> |
||||
@ -0,0 +1,9 @@ |
|||||
|
<li><b>data:</b> <code><a href="https://github.com/thingsboard/thingsboard/blob/b881f1c2985399f9665e033e2479549e97da1f36/ui-ngx/src/app/shared/models/widget.models.ts#L513" target="_blank">FormattedData</a></code> object associated with data layer (markers/polygons/circles) or data point of the route (trips data layer).<br/> |
||||
|
Represents basic entity properties (ex. <code>entityId</code>, <code>entityName</code>)<br/>and provides access to other entity attributes/timeseries declared in datasource of the data layer configuration. |
||||
|
</li> |
||||
|
<li><b>images:</b> <code>string[]</code> - array of image urls configured in the <b>Shape fill images</b> section. |
||||
|
</li> |
||||
|
<li><b>dsData:</b> <code><a href="https://github.com/thingsboard/thingsboard/blob/b881f1c2985399f9665e033e2479549e97da1f36/ui-ngx/src/app/shared/models/widget.models.ts#L513" target="_blank">FormattedData[]</a></code> - All available data associated with data layers including additional datasources as array of <a href="https://github.com/thingsboard/thingsboard/blob/b881f1c2985399f9665e033e2479549e97da1f36/ui-ngx/src/app/shared/models/widget.models.ts#L513" target="_blank">FormattedData</a> objects<br/> |
||||
|
resolved from configured datasources. Each object represents basic entity properties (ex. <code>entityId</code>, <code>entityName</code>)<br/> |
||||
|
and provides access to other entity attributes/timeseries declared in datasources of data layers configuration including additional datasources of the map configuration. |
||||
|
</li> |
||||
Loading…
Reference in new issue