Browse Source

Fixed infinite loop in LED indicator, Round switch and Switch widgets font fitting (#16529)

* Fixed infinite loop in LED indicator, Round switch and Switch widgets font fitting

* Fixed license headers
pull/16540/head
Maksym Tsymbarov 1 month ago
committed by GitHub
parent
commit
c5c80e0dc2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      ui-ngx/src/app/modules/home/components/widget/lib/rpc/knob.component.ts
  2. 5
      ui-ngx/src/app/modules/home/components/widget/lib/rpc/led-indicator.component.ts
  3. 5
      ui-ngx/src/app/modules/home/components/widget/lib/rpc/round-switch.component.ts
  4. 6
      ui-ngx/src/app/modules/home/components/widget/lib/rpc/switch.component.ts

8
ui-ngx/src/app/modules/home/components/widget/lib/rpc/knob.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { ChangeDetectorRef, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { WidgetContext } from '@home/models/widget-component.models';
import { deepClone, isDefined } from '@core/utils';
@ -318,11 +319,8 @@ export class KnobComponent extends BasicActionWidgetComponent implements OnInit,
private setFontSize(element: JQuery<HTMLElement>, text: string, fontSize: number, maxWidth: number) {
let textWidth = this.measureTextWidth(text, fontSize);
while (textWidth > maxWidth) {
while (textWidth > maxWidth && fontSize > 1) {
fontSize--;
if (fontSize < 0) {
break;
}
textWidth = this.measureTextWidth(text, fontSize);
}
element.css({fontSize: fontSize + 'px', lineHeight: fontSize + 'px'});

5
ui-ngx/src/app/modules/home/components/widget/lib/rpc/led-indicator.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { PageComponent } from '@shared/components/page.component';
import { WidgetContext } from '@home/models/widget-component.models';
@ -212,7 +213,7 @@ export class LedIndicatorComponent extends PageComponent implements OnInit, OnDe
private setFontSize(element: JQuery<HTMLElement>, text: string, fontSize: number, maxWidth: number) {
let textWidth = this.measureTextWidth(text, fontSize);
while (textWidth > maxWidth) {
while (textWidth > maxWidth && fontSize > 1) {
fontSize--;
textWidth = this.measureTextWidth(text, fontSize);
}

5
ui-ngx/src/app/modules/home/components/widget/lib/rpc/round-switch.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { PageComponent } from '@shared/components/page.component';
import { WidgetContext } from '@home/models/widget-component.models';
@ -208,7 +209,7 @@ export class RoundSwitchComponent extends PageComponent implements OnInit, OnDes
private setFontSize(element: JQuery<HTMLElement>, text: string, fontSize: number, maxWidth: number) {
let textWidth = this.measureTextWidth(text, fontSize);
while (textWidth > maxWidth) {
while (textWidth > maxWidth && fontSize > 1) {
fontSize--;
textWidth = this.measureTextWidth(text, fontSize);
}

6
ui-ngx/src/app/modules/home/components/widget/lib/rpc/switch.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { AfterViewInit, Component, ElementRef, Input, OnDestroy, ViewChild } from '@angular/core';
import { PageComponent } from '@shared/components/page.component';
import { WidgetContext } from '@home/models/widget-component.models';
@ -10,7 +11,6 @@ import { isDefined } from '@core/utils';
import { IWidgetSubscription, SubscriptionInfo, WidgetSubscriptionOptions } from '@core/api/widget-api.models';
import { DatasourceType, widgetType } from '@shared/models/widget.models';
import { EntityType } from '@shared/models/entity-type.models';
import { MatSlideToggle } from '@angular/material/slide-toggle';
import { ThemePalette } from '@angular/material/core';
const switchAspectRation = 2.7893;
@ -241,7 +241,7 @@ export class SwitchComponent extends PageComponent implements AfterViewInit, OnD
private setFontSize(element: JQuery<HTMLElement>, text: string, fontSize: number, maxWidth: number) {
let textWidth = this.measureTextWidth(text, fontSize);
while (textWidth > maxWidth) {
while (textWidth > maxWidth && fontSize > 1) {
fontSize--;
textWidth = this.measureTextWidth(text, fontSize);
}

Loading…
Cancel
Save