19 changed files with 916 additions and 24 deletions
@ -0,0 +1,69 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2024 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-data-layer-color-settings-panel" [formGroup]="colorSettingsFormGroup"> |
||||
|
<div class="tb-data-layer-color-settings-title" translate>widgets.maps.data-layer.color-settings</div> |
||||
|
<div class="flex flex-row"> |
||||
|
<tb-toggle-select formControlName="type" class="flex-1"> |
||||
|
<tb-toggle-option [value]="DataLayerColorType.constant"> |
||||
|
{{ 'widgets.maps.data-layer.color-type-constant' | translate }} |
||||
|
</tb-toggle-option> |
||||
|
<tb-toggle-option [value]="DataLayerColorType.function"> |
||||
|
{{ 'widgets.maps.data-layer.color-type-function' | translate }} |
||||
|
</tb-toggle-option> |
||||
|
</tb-toggle-select> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widgets.maps.data-layer.color</div> |
||||
|
<tb-color-input asBoxInput |
||||
|
formControlName="color"> |
||||
|
</tb-color-input> |
||||
|
</div> |
||||
|
<div class="tb-data-layer-color-settings-panel-body" [class.!hidden]="colorSettingsFormGroup.get('type').value !== DataLayerColorType.constant"> |
||||
|
</div> |
||||
|
<div class="tb-data-layer-color-settings-panel-body" [class.!hidden]="colorSettingsFormGroup.get('type').value !== DataLayerColorType.function"> |
||||
|
<ng-container *ngTemplateOutlet="function"></ng-container> |
||||
|
</div> |
||||
|
<div class="tb-data-layer-color-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)="applyColorSettings()" |
||||
|
[disabled]="colorSettingsFormGroup.invalid || !colorSettingsFormGroup.dirty"> |
||||
|
{{ 'action.apply' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<ng-template #function> |
||||
|
<div class="tb-form-panel no-padding no-border" [formGroup]="colorSettingsFormGroup"> |
||||
|
<tb-js-func formControlName="colorFunction" |
||||
|
withModules |
||||
|
[functionArgs]="['data', 'dsData']" |
||||
|
[globalVariables]="functionScopeVariables" |
||||
|
functionTitle="{{ 'widgets.maps.data-layer.color-function' | translate }}" |
||||
|
helpId="widget/lib/map/color_fn"> |
||||
|
</tb-js-func> |
||||
|
</div> |
||||
|
</ng-template> |
||||
@ -0,0 +1,53 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 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-data-layer-color-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-data-layer-color-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-data-layer-color-settings-panel-body { |
||||
|
flex: 1; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
min-height: 0; |
||||
|
} |
||||
|
.tb-data-layer-color-settings-panel-buttons { |
||||
|
height: 40px; |
||||
|
display: flex; |
||||
|
flex-direction: row; |
||||
|
gap: 16px; |
||||
|
justify-content: flex-end; |
||||
|
align-items: flex-end; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2024 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 { PageComponent } from '@shared/components/page.component'; |
||||
|
import { TbPopoverComponent } from '@shared/components/popover.component'; |
||||
|
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { WidgetService } from '@core/http/widget.service'; |
||||
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
||||
|
import { DataLayerColorSettings, DataLayerColorType } from '@home/components/widget/lib/maps/map.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-data-layer-color-settings-panel', |
||||
|
templateUrl: './data-layer-color-settings-panel.component.html', |
||||
|
providers: [], |
||||
|
styleUrls: ['./data-layer-color-settings-panel.component.scss'], |
||||
|
encapsulation: ViewEncapsulation.None |
||||
|
}) |
||||
|
export class DataLayerColorSettingsPanelComponent extends PageComponent implements OnInit { |
||||
|
|
||||
|
@Input() |
||||
|
colorSettings: DataLayerColorSettings; |
||||
|
|
||||
|
@Input() |
||||
|
popover: TbPopoverComponent<DataLayerColorSettingsPanelComponent>; |
||||
|
|
||||
|
@Output() |
||||
|
colorSettingsApplied = new EventEmitter<DataLayerColorSettings>(); |
||||
|
|
||||
|
DataLayerColorType = DataLayerColorType; |
||||
|
|
||||
|
colorSettingsFormGroup: UntypedFormGroup; |
||||
|
|
||||
|
functionScopeVariables = this.widgetService.getWidgetScopeVariables(); |
||||
|
|
||||
|
constructor(private fb: UntypedFormBuilder, |
||||
|
private widgetService: WidgetService, |
||||
|
protected store: Store<AppState>, |
||||
|
private destroyRef: DestroyRef) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.colorSettingsFormGroup = this.fb.group( |
||||
|
{ |
||||
|
type: [this.colorSettings?.type || DataLayerColorType.constant, []], |
||||
|
color: [this.colorSettings?.color, []], |
||||
|
colorFunction: [this.colorSettings?.colorFunction, []] |
||||
|
} |
||||
|
); |
||||
|
this.colorSettingsFormGroup.get('type').valueChanges.pipe( |
||||
|
takeUntilDestroyed(this.destroyRef) |
||||
|
).subscribe(() => { |
||||
|
setTimeout(() => {this.popover?.updatePosition();}, 0); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
cancel() { |
||||
|
this.popover?.hide(); |
||||
|
} |
||||
|
|
||||
|
applyColorSettings() { |
||||
|
const colorSettings: DataLayerColorSettings = this.colorSettingsFormGroup.value; |
||||
|
this.colorSettingsApplied.emit(colorSettings); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2024 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 === DataLayerColorType.function; else colorPreview">mdi:function-variant</tb-icon> |
||||
|
</button> |
||||
|
<ng-template #colorPreview> |
||||
|
<div class="tb-color-preview box" [class.disabled]="disabled"> |
||||
|
<div class="tb-color-result" [style]="colorStyle"></div> |
||||
|
</div> |
||||
|
</ng-template> |
||||
@ -0,0 +1,113 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2024 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, Renderer2, ViewContainerRef } from '@angular/core'; |
||||
|
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
||||
|
import { ComponentStyle } from '@shared/models/widget-settings.models'; |
||||
|
import { MatButton } from '@angular/material/button'; |
||||
|
import { TbPopoverService } from '@shared/components/popover.service'; |
||||
|
import { DataLayerColorSettings, DataLayerColorType } from '@home/components/widget/lib/maps/map.models'; |
||||
|
import { |
||||
|
DataLayerColorSettingsPanelComponent |
||||
|
} from '@home/components/widget/lib/settings/common/map/data-layer-color-settings-panel.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-data-layer-color-settings', |
||||
|
templateUrl: './data-layer-color-settings.component.html', |
||||
|
styleUrls: [], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => DataLayerColorSettingsComponent), |
||||
|
multi: true |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class DataLayerColorSettingsComponent implements ControlValueAccessor { |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
DataLayerColorType = DataLayerColorType; |
||||
|
|
||||
|
modelValue: DataLayerColorSettings; |
||||
|
|
||||
|
colorStyle: ComponentStyle = {}; |
||||
|
|
||||
|
private propagateChange: (v: any) => void = () => { }; |
||||
|
|
||||
|
constructor(private popoverService: TbPopoverService, |
||||
|
private renderer: Renderer2, |
||||
|
private viewContainerRef: ViewContainerRef) {} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(fn: any): void { |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
this.updateColorStyle(); |
||||
|
} |
||||
|
|
||||
|
writeValue(value: DataLayerColorSettings): void { |
||||
|
if (value) { |
||||
|
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, DataLayerColorSettingsPanelComponent, '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 && this.modelValue) { |
||||
|
if (this.modelValue.type === DataLayerColorType.constant) { |
||||
|
this.colorStyle = {backgroundColor: this.modelValue.color}; |
||||
|
} else { |
||||
|
this.colorStyle = {}; |
||||
|
} |
||||
|
} else { |
||||
|
this.colorStyle = {}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2024 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-marker-image-settings-panel" [formGroup]="markerImageSettingsFormGroup"> |
||||
|
<div class="tb-marker-image-settings-title" translate>widgets.maps.data-layer.marker.marker-image</div> |
||||
|
<div class="flex flex-row"> |
||||
|
<tb-toggle-select formControlName="type" class="flex-1"> |
||||
|
<tb-toggle-option [value]="MarkerImageType.image"> |
||||
|
{{ 'widgets.maps.data-layer.marker.marker-image-type-image' | translate }} |
||||
|
</tb-toggle-option> |
||||
|
<tb-toggle-option [value]="MarkerImageType.function"> |
||||
|
{{ 'widgets.maps.data-layer.marker.marker-image-type-function' | translate }} |
||||
|
</tb-toggle-option> |
||||
|
</tb-toggle-select> |
||||
|
</div> |
||||
|
<div class="tb-marker-image-settings-panel-body" [class.!hidden]="markerImageSettingsFormGroup.get('type').value !== MarkerImageType.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>{{ 'widgets.maps.data-layer.marker.custom-marker-image-size' | translate }}</div> |
||||
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="imageSize" type="number" min="1" step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
<div matSuffix>px</div> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-marker-image-settings-panel-body" [class.!hidden]="markerImageSettingsFormGroup.get('type').value !== MarkerImageType.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.marker.marker-image-function' | translate }}" |
||||
|
helpId="widget/lib/map/marker_image_fn"> |
||||
|
</tb-js-func> |
||||
|
<tb-multiple-gallery-image-input label="{{ 'widgets.maps.data-layer.marker.marker-images' | translate }}" |
||||
|
formControlName="images"> |
||||
|
</tb-multiple-gallery-image-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-marker-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)="applyMarkerImageSettings()" |
||||
|
[disabled]="markerImageSettingsFormGroup.invalid || !markerImageSettingsFormGroup.dirty"> |
||||
|
{{ 'action.apply' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,53 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 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-marker-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-marker-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-marker-image-settings-panel-body { |
||||
|
flex: 1; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
min-height: 0; |
||||
|
} |
||||
|
.tb-marker-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-2024 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 { PageComponent } from '@shared/components/page.component'; |
||||
|
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 { WidgetService } from '@core/http/widget.service'; |
||||
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
||||
|
import { MarkerImageSettings, MarkerImageType } from '@home/components/widget/lib/maps/map.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-marker-image-settings-panel', |
||||
|
templateUrl: './marker-image-settings-panel.component.html', |
||||
|
providers: [], |
||||
|
styleUrls: ['./marker-image-settings-panel.component.scss'], |
||||
|
encapsulation: ViewEncapsulation.None |
||||
|
}) |
||||
|
export class MarkerImageSettingsPanelComponent extends PageComponent implements OnInit { |
||||
|
|
||||
|
@Input() |
||||
|
markerImageSettings: MarkerImageSettings; |
||||
|
|
||||
|
@Input() |
||||
|
popover: TbPopoverComponent<MarkerImageSettingsPanelComponent>; |
||||
|
|
||||
|
@Output() |
||||
|
markerImageSettingsApplied = new EventEmitter<MarkerImageSettings>(); |
||||
|
|
||||
|
MarkerImageType = MarkerImageType; |
||||
|
|
||||
|
markerImageSettingsFormGroup: UntypedFormGroup; |
||||
|
|
||||
|
functionScopeVariables = this.widgetService.getWidgetScopeVariables(); |
||||
|
|
||||
|
constructor(private fb: UntypedFormBuilder, |
||||
|
private widgetService: WidgetService, |
||||
|
protected store: Store<AppState>, |
||||
|
private destroyRef: DestroyRef) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.markerImageSettingsFormGroup = this.fb.group( |
||||
|
{ |
||||
|
type: [this.markerImageSettings?.type || MarkerImageType.image, []], |
||||
|
image: [this.markerImageSettings?.image, [Validators.required]], |
||||
|
imageSize: [this.markerImageSettings?.imageSize, [Validators.min(1)]], |
||||
|
imageFunction: [this.markerImageSettings?.imageFunction, [Validators.required]], |
||||
|
images: [this.markerImageSettings?.images, []] |
||||
|
} |
||||
|
); |
||||
|
this.markerImageSettingsFormGroup.get('type').valueChanges.pipe( |
||||
|
takeUntilDestroyed(this.destroyRef) |
||||
|
).subscribe(() => { |
||||
|
this.updateValidators(); |
||||
|
setTimeout(() => {this.popover?.updatePosition();}, 0); |
||||
|
}); |
||||
|
this.updateValidators(); |
||||
|
} |
||||
|
|
||||
|
cancel() { |
||||
|
this.popover?.hide(); |
||||
|
} |
||||
|
|
||||
|
applyMarkerImageSettings() { |
||||
|
const markerImageSettings: MarkerImageSettings = this.markerImageSettingsFormGroup.value; |
||||
|
this.markerImageSettingsApplied.emit(markerImageSettings); |
||||
|
} |
||||
|
|
||||
|
private updateValidators() { |
||||
|
const type: MarkerImageType = this.markerImageSettingsFormGroup.get('type').value; |
||||
|
if (type === MarkerImageType.image) { |
||||
|
this.markerImageSettingsFormGroup.get('image').enable({emitEvent: false}); |
||||
|
this.markerImageSettingsFormGroup.get('imageSize').enable({emitEvent: false}); |
||||
|
this.markerImageSettingsFormGroup.get('imageFunction').disable({emitEvent: false}); |
||||
|
this.markerImageSettingsFormGroup.get('images').disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.markerImageSettingsFormGroup.get('image').disable({emitEvent: false}); |
||||
|
this.markerImageSettingsFormGroup.get('imageSize').disable({emitEvent: false}); |
||||
|
this.markerImageSettingsFormGroup.get('imageFunction').enable({emitEvent: false}); |
||||
|
this.markerImageSettingsFormGroup.get('images').enable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2024 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 === MarkerImageType.function; else imagePreview">mdi:function-variant</tb-icon> |
||||
|
</button> |
||||
|
<ng-template #imagePreview> |
||||
|
<img width="24px" height="24px" style="object-fit: contain;" [src]="modelValue?.image | image : {preview: true} | async" [class.disabled]="disabled"/> |
||||
|
</ng-template> |
||||
@ -0,0 +1,96 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2024 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 { MarkerImageSettings, MarkerImageType } from '@home/components/widget/lib/maps/map.models'; |
||||
|
import { |
||||
|
MarkerImageSettingsPanelComponent |
||||
|
} from '@home/components/widget/lib/settings/common/map/marker-image-settings-panel.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-marker-image-settings', |
||||
|
templateUrl: './marker-image-settings.component.html', |
||||
|
styleUrls: [], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => MarkerImageSettingsComponent), |
||||
|
multi: true |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class MarkerImageSettingsComponent implements ControlValueAccessor { |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
MarkerImageType = MarkerImageType; |
||||
|
|
||||
|
modelValue: MarkerImageSettings; |
||||
|
|
||||
|
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: MarkerImageSettings): 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 { |
||||
|
const ctx: any = { |
||||
|
markerImageSettings: this.modelValue, |
||||
|
}; |
||||
|
const markerImageSettingsPanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
||||
|
this.viewContainerRef, MarkerImageSettingsPanelComponent, 'left', true, null, |
||||
|
ctx, |
||||
|
{}, |
||||
|
{}, {}, true); |
||||
|
markerImageSettingsPanelPopover.tbComponentRef.instance.popover = markerImageSettingsPanelPopover; |
||||
|
markerImageSettingsPanelPopover.tbComponentRef.instance.markerImageSettingsApplied.subscribe((markerImageSettings) => { |
||||
|
markerImageSettingsPanelPopover.hide(); |
||||
|
this.modelValue = markerImageSettings; |
||||
|
this.propagateChange(this.modelValue); |
||||
|
this.cd.detectChanges(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue