Merge branch 'master' of github.com:thingsboard/thingsboard

This commit is contained in:
Andrii Shvaika 2022-02-07 12:14:05 +02:00
commit 99afad3f6f
62 changed files with 233 additions and 108 deletions

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>application</artifactId>

File diff suppressed because one or more lines are too long

View File

@ -214,6 +214,8 @@ public class ThingsboardInstallService {
log.info("Upgrading ThingsBoard from version 3.3.2 to 3.3.3 ...");
databaseEntitiesUpgradeService.upgradeDatabase("3.3.2");
dataUpdateService.updateData("3.3.2");
case "3.3.3":
log.info("Upgrading ThingsBoard from version 3.3.3 to 3.3.4 ...");
log.info("Updating system data...");
systemDataLoaderService.updateSystemWidgets();
break;

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>common</artifactId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.common</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.common.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.common</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.common.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.common</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.common.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.common</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.common.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>org.thingsboard.common</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.common</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.common.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>common</artifactId>
</parent>
<groupId>org.thingsboard.common</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>dao</artifactId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>msa</artifactId>
</parent>
<groupId>org.thingsboard.msa</groupId>

View File

@ -1,7 +1,7 @@
{
"name": "thingsboard-js-executor",
"private": true,
"version": "3.3.3",
"version": "3.3.4",
"description": "ThingsBoard JavaScript Executor Microservice",
"main": "server.js",
"bin": "server.js",

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>msa</artifactId>
</parent>
<groupId>org.thingsboard.msa</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>msa</artifactId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>msa</artifactId>
</parent>
<groupId>org.thingsboard.msa</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>msa</artifactId>
</parent>
<groupId>org.thingsboard.msa</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.msa</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.msa.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.msa</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.msa.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.msa</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.msa.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard.msa</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.msa.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>msa</artifactId>
</parent>
<groupId>org.thingsboard.msa</groupId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>org.thingsboard.msa</groupId>
<artifactId>transport</artifactId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
</parent>
<groupId>org.thingsboard.msa.transport</groupId>

View File

@ -1,7 +1,7 @@
{
"name": "thingsboard-web-ui",
"private": true,
"version": "3.3.3",
"version": "3.3.4",
"description": "ThingsBoard Web UI Microservice",
"main": "server.js",
"bin": "server.js",

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>msa</artifactId>
</parent>
<groupId>org.thingsboard.msa</groupId>

View File

@ -19,11 +19,11 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>netty-mqtt</artifactId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Netty MQTT Client</name>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.thingsboard</groupId>
<artifactId>thingsboard</artifactId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Thingsboard</name>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>rest-client</artifactId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>rule-engine</artifactId>

View File

@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>rule-engine</artifactId>
</parent>
<groupId>org.thingsboard.rule-engine</groupId>

View File

@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>rule-engine</artifactId>
</parent>
<groupId>org.thingsboard.rule-engine</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>tools</artifactId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>
<groupId>org.thingsboard.transport</groupId>

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>transport</artifactId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>transport</artifactId>
</parent>

View File

@ -1,6 +1,6 @@
{
"name": "thingsboard",
"version": "3.3.3",
"version": "3.3.4",
"scripts": {
"ng": "ng",
"start": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve --configuration development --host 0.0.0.0 --open",

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.3.3-SNAPSHOT</version>
<version>3.3.4-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<groupId>org.thingsboard</groupId>

View File

@ -213,7 +213,7 @@ export class ResourcesService {
case 'js':
el = this.document.createElement('script');
el.type = 'text/javascript';
el.async = true;
el.async = false;
el.src = url;
break;
case 'css':

View File

@ -400,6 +400,40 @@ export default abstract class LeafletMap {
this.updatePending = false;
this.updateData(this.drawRoutes, this.showPolygon);
}
this.createdControlButtonTooltip();
}
private createdControlButtonTooltip() {
import('tooltipster').then(() => {
$(this.ctx.$container)
.find('a[role="button"]:not(.leaflet-pm-action)')
.each((index, element) => {
let title;
if (element.children.length) {
title = (element.children[0] as HTMLElement).title;
$(element).children().removeAttr('title');
} else {
title = element.title;
$(element).removeAttr('title');
}
$(element).tooltipster(
{
content: title,
theme: 'tooltipster-shadow',
delay: 10,
triggerClose: {
click: true,
tap: true,
scroll: true,
mouseleave: true
},
side: 'right',
distance: 2,
trackOrigin: true
}
);
});
});
}
createLatLng(lat: number, lng: number): L.LatLng {
@ -545,7 +579,10 @@ export default abstract class LeafletMap {
break;
}
}
// @ts-ignore
if (this.map.pm.Toolbar.getButtons().tbMarker.disable !== foundEntityWithoutLocation) {
this.map.pm.Toolbar.setButtonDisabled('tbMarker', !foundEntityWithoutLocation);
}
this.datasources = formattedData;
}
@ -561,8 +598,11 @@ export default abstract class LeafletMap {
break;
}
}
// @ts-ignore
if (this.map.pm.Toolbar.getButtons().tbPolygon.disable !== foundEntityWithoutPolygon) {
this.map.pm.Toolbar.setButtonDisabled('tbPolygon', !foundEntityWithoutPolygon);
this.map.pm.Toolbar.setButtonDisabled('tbRectangle', !foundEntityWithoutPolygon);
}
this.datasources = formattedData;
}
if (!this.options.hideRemoveControlButton && !this.options.hideAllControlButton) {
@ -574,26 +614,18 @@ export default abstract class LeafletMap {
}
if (!this.options.hideEditControlButton && !this.options.hideAllControlButton) {
const disabledButton = !foundEntityWithLocation && !foundEntityWithPolygon;
if (disabledButton) {
// @ts-ignore
this.map.pm.Toolbar.toggleButton('dragMode', false);
}
if (this.editPolygons && !foundEntityWithPolygon) {
// @ts-ignore
this.map.pm.Toolbar.toggleButton('editMode', false);
// @ts-ignore
this.map.pm.Toolbar.toggleButton('cutPolygon', false);
// @ts-ignore
this.map.pm.Toolbar.toggleButton('rotateMode', false);
}
if (this.map.pm.Toolbar.getButtons().dragMode.disable !== disabledButton) {
this.map.pm.Toolbar.setButtonDisabled('dragMode', disabledButton);
if (this.editPolygons) {
// @ts-ignore
if (this.editPolygons && this.map.pm.Toolbar.getButtons().editMode.disable !== foundEntityWithPolygon) {
this.map.pm.Toolbar.setButtonDisabled('editMode', !foundEntityWithPolygon);
this.map.pm.Toolbar.setButtonDisabled('cutPolygon', !foundEntityWithPolygon);
this.map.pm.Toolbar.setButtonDisabled('rotateMode', !foundEntityWithPolygon);
}
}
}
}
} else {
this.updatePending = true;
}

View File

@ -309,6 +309,12 @@ export class MapWidgetController implements MapWidgetInterface {
if (this.map) {
this.map.remove();
}
if ($.tooltipster) {
const instances = $.tooltipster.instances();
instances.forEach((instance) => {
instance.destroy();
});
}
}
}

View File

@ -41,7 +41,3 @@
.leaflet-container {
background-color: white;
}
.leaflet-buttons-control-button.pm-disabled {
pointer-events: none;
}

View File

@ -30,6 +30,9 @@ import { isDefined, isDefinedAndNotNull } from '@core/utils';
import LeafletMap from './leaflet-map';
export class Marker {
private editing = false;
leafletMarker: L.Marker;
labelOffset: L.LatLngTuple;
tooltipOffset: L.LatLngTuple;
@ -77,11 +80,13 @@ export class Marker {
this.leafletMarker.on('pm:dragstart', (e) => {
(this.leafletMarker.dragging as any)._draggable = { _moved: true };
(this.leafletMarker.dragging as any)._enabled = true;
this.editing = true;
});
this.leafletMarker.on('pm:dragend', (e) => {
onDragendListener(e, this.data);
delete (this.leafletMarker.dragging as any)._draggable;
delete (this.leafletMarker.dragging as any)._enabled;
this.editing = false;
});
}
}
@ -105,7 +110,7 @@ export class Marker {
}
updateMarkerPosition(position: L.LatLng) {
if (!this.leafletMarker.getLatLng().equals(position)) {
if (!this.leafletMarker.getLatLng().equals(position) && !this.editing) {
this.location = position;
this.leafletMarker.setLatLng(position);
}

View File

@ -27,6 +27,8 @@ import { FormattedData, PolygonSettings, UnitedMapSettings } from './map-models'
export class Polygon {
private editing = false;
leafletPoly: L.Polygon;
tooltip: L.Popup;
data: FormattedData;
@ -62,6 +64,8 @@ export class Polygon {
private createEventListeners() {
if (this.settings.editablePolygon && this.onDragendListener) {
this.leafletPoly.on('pm:markerdragstart', () => this.editing = true);
this.leafletPoly.on('pm:markerdragend', () => this.editing = false);
this.leafletPoly.on('pm:edit', (e) => this.onDragendListener(e, this.data));
}
@ -100,6 +104,9 @@ export class Polygon {
}
updatePolygon(data: FormattedData, dataSources: FormattedData[], settings: PolygonSettings) {
if (this.editing) {
return;
}
this.data = data;
this.dataSources = dataSources;
const polyData = data[this.settings.polygonKeyName];

View File

@ -15,7 +15,7 @@
limitations under the License.
-->
<div class="tb-switch" fxLayout="column" [ngStyle]="{'pointerEvents': ctx.isEdit ? 'none' : 'all'}">
<div class="tb-switch" fxLayout="column" [ngStyle]="{'pointerEvents': ctx.isEdit ? 'none' : 'all'}" *ngIf="switchType === 'switch'; else slideToggle">
<div #switchErrorContainer class="error-container" [ngStyle]="{'background': error?.length ? 'rgba(255,255,255,0.25)' : 'none'}"
fxLayout="row" fxLayoutAlign="center center">
<span #switchError class="switch-error">{{ error }}</span>
@ -37,3 +37,14 @@
</div>
<div #textMeasure id="text-measure"></div>
</div>
<ng-template #slideToggle>
<div class="tb-absolute-fill" fxLayout="column" [ngStyle]="{'pointerEvents': ctx.isEdit ? 'none' : 'all'}" fxLayoutAlign="center center">
<div>
<mat-slide-toggle [disabled]="executingUpdateValue" [labelPosition]="labelPosition" [color]="sliderColor" [(ngModel)]="value" (change)="onValue()">{{title}}</mat-slide-toggle>
<mat-progress-bar style="height: 2px;" [color]="sliderColor" mode="indeterminate" *ngIf="executingUpdateValue"></mat-progress-bar>
<div style="height: 2px;" *ngIf="!executingUpdateValue"></div>
<tb-error style="margin-top: -6px; display: block; pointer-events: none;"
[error]="error"></tb-error>
</div>
</div>
</ng-template>

View File

@ -14,7 +14,7 @@
/// limitations under the License.
///
import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { AfterViewInit, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { PageComponent } from '@shared/components/page.component';
import { WidgetContext } from '@home/models/widget-component.models';
import { UtilsService } from '@core/services/utils.service';
@ -26,11 +26,14 @@ import { DatasourceType, widgetType } from '@shared/models/widget.models';
import { EntityType } from '@shared/models/entity-type.models';
import { MatSlideToggle } from '@angular/material/slide-toggle';
import { ResizeObserver } from '@juggle/resize-observer';
import { ThemePalette } from '@angular/material/core/common-behaviors/color';
const switchAspectRation = 2.7893;
type RetrieveValueMethod = 'rpc' | 'attribute' | 'timeseries';
type SwitchType = 'switch' | 'slide-toggle';
interface SwitchSettings {
initialValue: boolean;
title: string;
@ -44,6 +47,8 @@ interface SwitchSettings {
requestTimeout: number;
requestPersistent: boolean;
persistentPollingInterval: number;
labelPosition: 'before' | 'after';
sliderColor: ThemePalette;
}
@Component({
@ -51,28 +56,33 @@ interface SwitchSettings {
templateUrl: './switch.component.html',
styleUrls: ['./switch.component.scss']
})
export class SwitchComponent extends PageComponent implements OnInit, OnDestroy {
export class SwitchComponent extends PageComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('switch', {static: true}) switchElementRef: ElementRef<HTMLElement>;
@ViewChild('switchContainer', {static: true}) switchContainerRef: ElementRef<HTMLElement>;
@ViewChild('matSlideToggle', {static: true}) matSlideToggleRef: MatSlideToggle;
@ViewChild('onoffContainer', {static: true}) onoffContainerRef: ElementRef<HTMLElement>;
@ViewChild('onLabel', {static: true}) onLabelRef: ElementRef<HTMLElement>;
@ViewChild('offLabel', {static: true}) offLabelRef: ElementRef<HTMLElement>;
@ViewChild('switchTitleContainer', {static: true}) switchTitleContainerRef: ElementRef<HTMLElement>;
@ViewChild('switchTitle', {static: true}) switchTitleRef: ElementRef<HTMLElement>;
@ViewChild('textMeasure', {static: true}) textMeasureRef: ElementRef<HTMLElement>;
@ViewChild('switchErrorContainer', {static: true}) switchErrorContainerRef: ElementRef<HTMLElement>;
@ViewChild('switchError', {static: true}) switchErrorRef: ElementRef<HTMLElement>;
@ViewChild('switch', {static: false}) switchElementRef: ElementRef<HTMLElement>;
@ViewChild('switchContainer', {static: false}) switchContainerRef: ElementRef<HTMLElement>;
@ViewChild('matSlideToggle', {static: false}) matSlideToggleRef: MatSlideToggle;
@ViewChild('onoffContainer', {static: false}) onoffContainerRef: ElementRef<HTMLElement>;
@ViewChild('onLabel', {static: false}) onLabelRef: ElementRef<HTMLElement>;
@ViewChild('offLabel', {static: false}) offLabelRef: ElementRef<HTMLElement>;
@ViewChild('switchTitleContainer', {static: false}) switchTitleContainerRef: ElementRef<HTMLElement>;
@ViewChild('switchTitle', {static: false}) switchTitleRef: ElementRef<HTMLElement>;
@ViewChild('textMeasure', {static: false}) textMeasureRef: ElementRef<HTMLElement>;
@ViewChild('switchErrorContainer', {static: false}) switchErrorContainerRef: ElementRef<HTMLElement>;
@ViewChild('switchError', {static: false}) switchErrorRef: ElementRef<HTMLElement>;
@Input()
ctx: WidgetContext;
@Input()
switchType: SwitchType = 'switch';
showTitle = false;
value = false;
error = '';
title = '';
showOnOffLabels = false;
labelPosition: 'before' | 'after' = 'after';
sliderColor: ThemePalette = 'accent';
private isSimulated: boolean;
private requestTimeout: number;
@ -87,7 +97,7 @@ export class SwitchComponent extends PageComponent implements OnInit, OnDestroy
private valueSubscription: IWidgetSubscription;
private executingUpdateValue: boolean;
public executingUpdateValue: boolean;
private scheduledValue: boolean;
private rpcValue: boolean;
@ -111,6 +121,10 @@ export class SwitchComponent extends PageComponent implements OnInit, OnDestroy
}
ngOnInit(): void {
}
ngAfterViewInit() {
if (this.switchType === 'switch') {
this.switchElement = $(this.switchElementRef.nativeElement);
this.switchContainer = $(this.switchContainerRef.nativeElement);
this.matSlideToggle = $(this.matSlideToggleRef._elementRef.nativeElement);
@ -127,6 +141,7 @@ export class SwitchComponent extends PageComponent implements OnInit, OnDestroy
this.resize();
});
this.switchResize$.observe(this.switchContainerRef.nativeElement);
}
this.init();
}
@ -145,6 +160,8 @@ export class SwitchComponent extends PageComponent implements OnInit, OnDestroy
this.title = isDefined(settings.title) ? settings.title : '';
this.showTitle = !!(this.title && this.title.length);
this.showOnOffLabels = isDefined(settings.showOnOffLabels) ? settings.showOnOffLabels : true;
this.labelPosition = isDefined(settings.labelPosition) ? settings.labelPosition : 'after';
this.sliderColor = isDefined(settings.sliderColor) ? settings.sliderColor : 'accent';
const initialValue = isDefined(settings.initialValue) ? settings.initialValue : false;
this.setValue(initialValue);
@ -256,7 +273,9 @@ export class SwitchComponent extends PageComponent implements OnInit, OnDestroy
private onError(error: string) {
this.error = error;
if (this.switchType === 'switch') {
this.setFontSize(this.switchError, this.error, this.switchErrorContainer.height(), this.switchErrorContainer.width());
}
this.ctx.detectChanges();
}
@ -278,6 +297,10 @@ export class SwitchComponent extends PageComponent implements OnInit, OnDestroy
},
() => {
const errorText = this.ctx.defaultSubscription.rpcErrorText;
if (this.switchType === 'slide-toggle') {
this.ctx.defaultSubscription.rpcErrorText = null;
this.ctx.hideToast(this.ctx.toastTargetId);
}
this.onError(errorText);
}
);
@ -304,6 +327,10 @@ export class SwitchComponent extends PageComponent implements OnInit, OnDestroy
() => {
this.executingUpdateValue = false;
const errorText = this.ctx.defaultSubscription.rpcErrorText;
if (this.switchType === 'slide-toggle') {
this.ctx.defaultSubscription.rpcErrorText = null;
this.ctx.hideToast(this.ctx.toastTargetId);
}
this.onError(errorText);
}
);

View File

@ -922,7 +922,7 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont
} else if (this.modelValue) {
const config = this.modelValue.config;
if (this.widgetType === widgetType.rpc && this.modelValue.isDataEnabled) {
if (!config.targetDeviceAliasIds || !config.targetDeviceAliasIds.length) {
if (!this.widgetEditMode && (!config.targetDeviceAliasIds || !config.targetDeviceAliasIds.length)) {
return {
targetDeviceAliasIds: {
valid: false