Browse Source

Merge pull request #16372 from thingsboard/rc

Merge rc into master
pull/16395/head
Vladyslav Prykhodko 2 months ago
committed by GitHub
parent
commit
99ceea9b5b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      application/src/main/java/org/thingsboard/server/actors/tenant/TenantActor.java
  2. 4
      application/src/main/java/org/thingsboard/server/service/cf/ctx/state/alarm/AlarmRuleState.java
  3. 18
      tools/src/main/python/license-headers/curations.json
  4. 21
      ui-ngx/src/app/core/services/calculated-field-form.service.ts
  5. 54
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts
  6. 41
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts
  7. 8
      ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.ts
  8. 8
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts
  9. 41
      ui-ngx/src/app/modules/home/components/dashboard-page/states/default-state-controller.component.ts
  10. 44
      ui-ngx/src/app/modules/home/components/dashboard-page/states/entity-state-controller.component.ts
  11. 14
      ui-ngx/src/app/modules/home/components/dashboard-page/states/state-controller.component.ts
  12. 35
      ui-ngx/src/app/modules/home/components/widget/lib/analogue-gauge.models.ts
  13. 16
      ui-ngx/src/app/modules/home/components/widget/lib/canvas-digital-gauge.ts
  14. 46
      ui-ngx/src/app/modules/home/components/widget/lib/digital-gauge.ts
  15. 6
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/action-settings-panel.component.scss
  16. 1
      ui-ngx/src/app/modules/home/home.component.scss
  17. 2
      ui-ngx/src/app/modules/home/pages/admin/license-management.component.html
  18. 1
      ui-ngx/src/app/modules/home/pages/admin/license-management.component.scss
  19. 10
      ui-ngx/src/app/modules/home/pages/admin/license-management.component.ts
  20. 17
      ui-ngx/src/app/shared/models/alarm-rule.models.ts
  21. 2150
      ui-ngx/src/assets/locale/locale.constant-it_IT.json
  22. 2926
      ui-ngx/src/assets/locale/locale.constant-pt_BR.json

4
application/src/main/java/org/thingsboard/server/actors/tenant/TenantActor.java

@ -199,8 +199,8 @@ public class TenantActor extends RuleChainManagerActor {
private void forwardToCfActor(TenantAwareMsg msg, boolean priority) {
if (cfActor == null) {
if (msg instanceof CalculatedFieldStateRestoreMsg) {
log.warn("[{}] CF Actor is not initialized. ToCalculatedFieldSystemMsg: [{}]", tenantId, msg);
if (msg instanceof CalculatedFieldStateRestoreMsg restoreMsg) {
log.warn("[{}] CF Actor is not initialized. Skipping CF state restore: [{}]", tenantId, restoreMsg.getId());
} else {
log.debug("[{}] CF Actor is not initialized. ToCalculatedFieldSystemMsg: [{}]", tenantId, msg);
}

4
application/src/main/java/org/thingsboard/server/service/cf/ctx/state/alarm/AlarmRuleState.java

@ -4,6 +4,8 @@ package org.thingsboard.server.service.cf.ctx.state.alarm;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.common.util.KvUtil;
@ -38,6 +40,8 @@ public class AlarmRuleState {
private final AlarmSeverity severity;
private AlarmRule alarmRule;
@ToString.Exclude
@EqualsAndHashCode.Exclude
private AlarmCalculatedFieldState state;
private AlarmCondition condition;

18
tools/src/main/python/license-headers/curations.json

@ -475,18 +475,6 @@
"reason": "PE-specific data/configuration type IntegrationLifecycleEventTrigger.java. Reviewed fields, type discriminators and serialization hooks describe PE entities or PE behavior; matching CE types supply only the common DTO/interface pattern. Resolved as PE-authored consistently with the maintainer decision for PE entity wrappers. Reviewed candidate common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/RuleEngineComponentLifecycleEventTrigger.java at 0d3b41e002f958887a317ca8366fdc4efa549058 (blob e4c967c19792ecf5fa6409973459efe5ce73cb8d).",
"contentHash": "sha256:c5da9a11ed196635c09972733cf511bee2bd111242c0d084d115d37e2e7524c5"
},
{
"path": "common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/platform/UserGroupListFilter.java",
"header": "busl",
"reason": "PE user group notification target filter UserGroupListFilter.java; the path has never existed in CE history. Similarity to the CE candidate is the shared filter shape, not a relocation of the CE implementation. Reviewed candidate common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/platform/UserListFilter.java at aeaf9d1e299 (blob 07cd0280ba84ab71b6823242e18c7c7285296b84).",
"contentHash": "sha256:64563fbc6ee416025b555c14cf3c517c5027bfc112a883078cc717ed471c5b52"
},
{
"path": "common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/platform/UserRoleFilter.java",
"header": "busl",
"reason": "PE role-based notification target filter UserRoleFilter.java; the path has never existed in CE history. Similarity to the CE candidate is the shared filter shape, not a relocation of the CE implementation. Reviewed candidate common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/platform/UserListFilter.java at aeaf9d1e299 (blob 07cd0280ba84ab71b6823242e18c7c7285296b84).",
"contentHash": "sha256:007e94e798f25a9d0ccd1716b8a68eada4fe3ced71e531bd0538c2c56e24ecb7"
},
{
"path": "common/data/src/main/java/org/thingsboard/server/common/data/permission/Operation.java",
"header": "ce-modified",
@ -505,12 +493,6 @@
"reason": "PE-specific data/configuration type EntityGroupNameFilter.java. Reviewed fields, type discriminators and serialization hooks describe PE entities or PE behavior; matching CE types supply only the common DTO/interface pattern. Resolved as PE-authored consistently with the maintainer decision for PE entity wrappers. Reviewed candidate common/data/src/main/java/org/thingsboard/server/common/data/query/EntityNameFilter.java at 0d3b41e002f958887a317ca8366fdc4efa549058 (blob a3889bc7c07de44917eac165a9c4e8578bbbcd62).",
"contentHash": "sha256:46cc0073210fb81fb1a71f44604042da6056f78f62468cf45bdc78cdaf8cdd09"
},
{
"path": "common/data/src/main/java/org/thingsboard/server/common/data/query/StateEntityFilter.java",
"header": "busl",
"reason": "PE entity filter StateEntityFilter.java; the path has never existed in CE history. Similarity to the CE candidate is the shared filter shape, not a relocation of the CE implementation. Reviewed candidate common/data/src/main/java/org/thingsboard/server/common/data/query/SingleEntityFilter.java at aeaf9d1e299 (blob dacd7de6eae6cd80cfd63047dad8951d76aeb455).",
"contentHash": "sha256:46835b82b0320007209a5d53528f9fdb534af41c2fcb5a528754c316c530394a"
},
{
"path": "common/data/src/main/java/org/thingsboard/server/common/data/query/StateEntityOwnerFilter.java",
"header": "busl",

21
ui-ngx/src/app/core/services/calculated-field-form.service.ts

@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { DestroyRef, inject, Injectable } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { AbstractControl, FormBuilder, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
import { pairwise, switchMap } from 'rxjs/operators';
import { Observable } from 'rxjs';
import {
@ -15,6 +15,7 @@ import {
import { isDefined } from '@core/utils';
import { CalculatedFieldsService } from '@core/http/calculated-fields.service';
import { CalculatedFieldsTableEntity } from '@home/components/calculated-fields/calculated-fields-table-config';
import { AlarmRule, areAlarmRuleArgumentsValid } from '@shared/models/alarm-rule.models';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { getTimezoneInfo } from '@shared/models/time/time.models';
@ -49,10 +50,26 @@ export class CalculatedFieldFormService {
propagateRelationTypes: [null],
createRules: [null, Validators.required],
clearRule: [null],
}),
}, {validators: this.alarmRulesArgumentsValidator()}),
});
}
private alarmRulesArgumentsValidator(): ValidatorFn {
return (configuration: AbstractControl): ValidationErrors | null => {
const args = configuration.get('arguments').value;
const createRulesControl = configuration.get('createRules');
const clearRuleControl = configuration.get('clearRule');
const rules: AlarmRule[] = [];
if (createRulesControl.enabled) {
rules.push(...Object.values<AlarmRule>(createRulesControl.value ?? {}));
}
if (clearRuleControl.enabled) {
rules.push(clearRuleControl.value);
}
return rules.every(rule => areAlarmRuleArgumentsValid(rule, args)) ? null : {alarmRuleArguments: {valid: false}};
};
}
setupTypeChange(form: FormGroup, destroyRef: DestroyRef, isEditActive?: () => boolean): void {
form.get('type').valueChanges.pipe(
pairwise(),

54
ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts

@ -29,7 +29,8 @@ import {
AlarmRuleExpressionType,
AlarmRuleSchedule,
AlarmRuleScheduleType,
checkPredicates
areAlarmRuleConditionFilterArgumentsValid,
isAlarmRuleConditionScheduleArgumentValid
} from "@shared/models/alarm-rule.models";
import { CalculatedFieldArgument } from "@shared/models/calculated-field.models";
import {
@ -93,7 +94,6 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
private modelValue: AlarmRuleCondition;
private propagateChange = (v: any) => { };
private onValidatorChange = () => { };
constructor(private dialog: MatDialog,
private fb: FormBuilder,
@ -108,10 +108,6 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
registerOnTouched(fn: any): void {
}
registerOnValidatorChange(fn: () => void): void {
this.onValidatorChange = fn;
}
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
if (this.disabled) {
@ -129,46 +125,18 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
ngOnChanges(changes: SimpleChanges) {
if (changes.arguments && !changes.arguments.firstChange) {
if (this.recalculateArgumentValidity()) {
this.onValidatorChange();
}
this.recalculateArgumentValidity();
}
}
private recalculateArgumentValidity(): boolean {
const prevFiltersValid = this.filtersArgumentsValid;
const prevSchedulerValid = this.schedulerArgumentsValid;
private recalculateArgumentValidity(): void {
if (!this.modelValue || !this.arguments) {
this.filtersArgumentsValid = true;
this.schedulerArgumentsValid = true;
} else {
this.filtersArgumentsValid = this.areFilterAndPredicateArgumentsValid(this.modelValue, this.arguments);
this.schedulerArgumentsValid = this.isScheduleArgumentValid(this.modelValue, Object.keys(this.arguments));
this.filtersArgumentsValid = areAlarmRuleConditionFilterArgumentsValid(this.modelValue, this.arguments);
this.schedulerArgumentsValid = isAlarmRuleConditionScheduleArgumentValid(this.modelValue, this.arguments);
}
return prevFiltersValid !== this.filtersArgumentsValid || prevSchedulerValid !== this.schedulerArgumentsValid;
}
private isScheduleArgumentValid(obj: any, validArguments: string[]): boolean {
const arg = obj?.schedule?.dynamicValueArgument;
return !arg || validArguments.includes(arg);
}
private areFilterAndPredicateArgumentsValid(obj: any, args: Record<string, CalculatedFieldArgument>): boolean {
const validSet = new Set(Object.keys(args));
const filters = obj?.expression?.filters || obj?.filters || [];
for (const filter of filters) {
if (filter.argument && !validSet.has(filter.argument)) {
return false;
}
}
for (const filter of filters) {
if (Array.isArray(filter.predicates)) {
if (!checkPredicates(filter.predicates, validSet)) {
return false;
}
}
}
return true;
}
public conditionSet(): boolean {
@ -176,9 +144,7 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
}
public validate(control: AbstractControl): ValidationErrors | null {
const hasCondition = this.conditionSet();
const argsValid = this.filtersArgumentsValid && this.schedulerArgumentsValid;
return (hasCondition && argsValid) ? null : { alarmRuleCondition: { valid: false } };
return this.conditionSet() ? null : { alarmRuleCondition: { valid: false } };
}
public openFilterDialog($event: Event) {
@ -266,7 +232,6 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
this.updateConditionInfo();
this.recalculateArgumentValidity();
this.propagateChange(this.modelValue);
this.onValidatorChange();
this.cd.detectChanges();
}
@ -285,10 +250,7 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
}
}).afterClosed().subscribe((result) => {
if (result) {
if (!this.modelValue) {
this.modelValue = {} as AlarmRuleCondition;
}
this.modelValue.schedule = result;
this.modelValue = {...this.modelValue, schedule: result} as AlarmRuleCondition;
this.updateModel();
}
});

41
ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts

@ -65,12 +65,11 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
alarmRuleFormGroup = this.fb.group({
condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required),
alarmDetails: [null],
dashboardId: [null]
alarmDetails: this.fb.control<string | null>(null),
dashboardId: this.fb.control<string | null>(null)
});
private propagateChange = (v: any) => { };
private onValidatorChange = () => { };
constructor(private dialog: MatDialog,
private fb: FormBuilder,
@ -84,20 +83,11 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
registerOnTouched(fn: any): void {
}
registerOnValidatorChange(fn: () => void): void {
this.onValidatorChange = fn;
}
ngOnInit() {
this.alarmRuleFormGroup.valueChanges.pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe(() => {
this.updateModel();
});
this.alarmRuleFormGroup.statusChanges.pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe(() => {
this.onValidatorChange();
).subscribe((value) => {
this.updateModel(value);
});
}
@ -111,12 +101,14 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
}
writeValue(value: AlarmRule): void {
this.modelValue = value;
const model = this.modelValue ? {
...this.modelValue,
dashboardId: this.modelValue.dashboardId?.id
} : null;
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false});
this.alarmRuleFormGroup.reset(undefined, {emitEvent: false});
if (value) {
this.alarmRuleFormGroup.patchValue({
...value,
dashboardId: value.dashboardId?.id
}, {emitEvent: false});
}
this.modelValue = value ? this.toModel(this.alarmRuleFormGroup.value) : null;
}
public openEditDetailsDialog($event: Event) {
@ -146,9 +138,12 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
};
}
private updateModel() {
const value = this.alarmRuleFormGroup.value;
this.modelValue = {...value, dashboardId: value.dashboardId ? new DashboardId(value.dashboardId) : null} as AlarmRule;
private updateModel(value: typeof this.alarmRuleFormGroup.value): void {
this.modelValue = this.toModel(value);
this.propagateChange(this.modelValue);
}
private toModel(value: typeof this.alarmRuleFormGroup.value): AlarmRule {
return {...value, dashboardId: value.dashboardId ? new DashboardId(value.dashboardId) : null} as AlarmRule;
}
}

8
ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.ts

@ -63,16 +63,12 @@ export class CreateCfAlarmRulesComponent implements ControlValueAccessor, Valida
private usedSeverities: AlarmSeverity[] = [];
private propagateChange = (v: any) => { };
private onValidatorChange = () => { };
constructor(private fb: FormBuilder,
private destroyRef: DestroyRef) {
this.createAlarmRulesFormGroup.valueChanges.pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe(() => this.updateModel());
this.createAlarmRulesFormGroup.statusChanges.pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe(() => this.onValidatorChange());
}
registerOnChange(fn: any): void {
@ -82,10 +78,6 @@ export class CreateCfAlarmRulesComponent implements ControlValueAccessor, Valida
registerOnTouched(fn: any): void {
}
registerOnValidatorChange(fn: () => void): void {
this.onValidatorChange = fn;
}
createAlarmRulesFormArray(): UntypedFormArray {
return this.createAlarmRulesFormGroup.get('createAlarmRules') as UntypedFormArray;
}

8
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

@ -104,6 +104,7 @@ import {
} from '@home/components/dashboard-page/states/manage-dashboard-states-dialog.component';
import { ImportExportService } from '@shared/import-export/import-export.service';
import { AuthState } from '@app/core/auth/auth.models';
import { IStateControllerComponent } from '@home/components/dashboard-page/states/state-controller.models';
import { DashboardReportService } from '@core/http/dashboard-report.service';
import { EntityGroupInfo, resolveGroupParams } from '@shared/models/entity-group.models';
import { UserPermissionsService } from '@core/http/user-permissions.service';
@ -1198,11 +1199,10 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
private updateStates(states: {[id: string]: DashboardState }) {
this.dashboard.configuration.states = states;
this.dashboardUtils.removeUnusedWidgets(this.dashboard);
let targetState = this.dashboardCtx.state;
if (!this.dashboard.configuration.states[targetState]) {
targetState = this.dashboardUtils.getRootStateId(this.dashboardConfiguration.states);
if (states[this.dashboardCtx.state]) {
this.openDashboardState(this.dashboardCtx.state);
}
this.openDashboardState(targetState);
(this.dashboardCtx.stateController as IStateControllerComponent).states = states;
}
public importWidget($event: Event) {

41
ui-ngx/src/app/modules/home/components/dashboard-page/states/default-state-controller.component.ts

@ -36,9 +36,9 @@ export class DefaultStateControllerComponent extends StateControllerComponent im
protected utils: UtilsService,
private entityService: EntityService,
private mobileService: MobileService,
private dashboardUtils: DashboardUtilsService,
dashboardUtils: DashboardUtilsService,
private breadcrumbService: BreadcrumbService) {
super(router, route, utils, window, ngZone, statesControllerService);
super(router, route, utils, window, ngZone, statesControllerService, dashboardUtils);
}
ngOnInit(): void {
@ -51,7 +51,7 @@ export class DefaultStateControllerComponent extends StateControllerComponent im
public init() {
if (this.preservedState) {
this.stateObject = this.preservedState;
this.stateObject = this.normalizeStateObject(this.preservedState);
setTimeout(() => {
this.gotoState(this.stateObject[0].id, true);
}, 1);
@ -71,6 +71,13 @@ export class DefaultStateControllerComponent extends StateControllerComponent im
}
protected onStatesChanged() {
const prevStateId = this.getStateId();
this.stateObject = this.normalizeStateObject(this.stateObject);
const newStateId = this.getStateId();
if (newStateId !== prevStateId) {
this.gotoState(newStateId, false);
this.updateStateParam(objToBase64(this.stateObject), true);
}
}
protected onStateChanged() {
@ -204,33 +211,13 @@ export class DefaultStateControllerComponent extends StateControllerComponent im
try {
result = base64toObj(stateBase64);
} catch (e) {
result = [ { id: null, params: {} } ];
result = [];
}
}
if (!result) {
result = [];
}
if (!result.length) {
result[0] = { id: null, params: {} };
} else if (result.length > 1) {
const newResult = [];
newResult.push(result[result.length - 1]);
result = newResult;
}
const rootStateId = this.dashboardUtils.getRootStateId(this.states);
if (!result[0].id) {
result[0].id = rootStateId;
}
if (!this.states[result[0].id]) {
result[0].id = rootStateId;
}
let i = result.length;
while (i--) {
if (!result[i].id || !this.states[result[i].id]) {
result.splice(i, 1);
}
if (result && result.length > 1) {
result = [ result[result.length - 1] ];
}
return result;
return this.normalizeStateObject(result);
}
private gotoState(stateId: string, update: boolean, openRightLayout?: boolean) {

44
ui-ngx/src/app/modules/home/components/dashboard-page/states/entity-state-controller.component.ts

@ -41,9 +41,9 @@ export class EntityStateControllerComponent extends StateControllerComponent imp
protected utils: UtilsService,
private entityService: EntityService,
private mobileService: MobileService,
private dashboardUtils: DashboardUtilsService,
dashboardUtils: DashboardUtilsService,
private breadcrumbService: BreadcrumbService) {
super(router, route, utils, window, ngZone, statesControllerService);
super(router, route, utils, window, ngZone, statesControllerService, dashboardUtils);
}
ngOnInit(): void {
@ -56,7 +56,7 @@ export class EntityStateControllerComponent extends StateControllerComponent imp
public init() {
if (this.preservedState) {
this.stateObject = this.preservedState;
this.stateObject = this.normalizeStateObject(this.preservedState);
this.selectedStateIndex = this.stateObject.length - 1;
setTimeout(() => {
this.gotoState(this.stateObject[this.stateObject.length - 1].id, true);
@ -78,6 +78,13 @@ export class EntityStateControllerComponent extends StateControllerComponent imp
}
protected onStatesChanged() {
const prevStateId = this.getStateId();
this.stateObject = this.normalizeStateObject(this.stateObject);
this.selectedStateIndex = this.stateObject.length - 1;
const newStateId = this.getStateId();
if (newStateId !== prevStateId) {
this.gotoState(newStateId, true, undefined, true);
}
}
protected onStateChanged() {
@ -248,32 +255,13 @@ export class EntityStateControllerComponent extends StateControllerComponent imp
try {
result = base64toObj(stateBase64);
} catch (e) {
result = [ { id: null, params: {} } ];
}
}
if (!result) {
result = [];
}
if (!result.length) {
result[0] = { id: null, params: {} };
}
const rootStateId = this.dashboardUtils.getRootStateId(this.states);
if (!result[0].id) {
result[0].id = rootStateId;
}
if (!this.states[result[0].id]) {
result[0].id = rootStateId;
}
let i = result.length;
while (i--) {
if (!result[i].id || !this.states[result[i].id]) {
result.splice(i, 1);
result = [];
}
}
return result;
return this.normalizeStateObject(result);
}
private gotoState(stateId: string, update: boolean, openRightLayout?: boolean) {
private gotoState(stateId: string, update: boolean, openRightLayout?: boolean, replaceCurrentHistoryUrl?: boolean) {
const isStateIdChanged = this.dashboardCtrl.dashboardCtx.state !== stateId;
this.dashboardCtrl.openDashboardState(stateId, openRightLayout);
if (isStateIdChanged) {
@ -283,11 +271,11 @@ export class EntityStateControllerComponent extends StateControllerComponent imp
this.mobileService.handleDashboardStateName(this.getStateName(this.stateObject.length - 1));
}
if (update) {
this.updateLocation(isStateIdChanged);
this.updateLocation(replaceCurrentHistoryUrl ?? !isStateIdChanged);
}
}
private updateLocation(isStateIdChanged: boolean) {
private updateLocation(replaceCurrentHistoryUrl: boolean) {
if (this.stateObject[this.stateObject.length - 1].id) {
let newState;
if (this.isDefaultState()) {
@ -295,7 +283,7 @@ export class EntityStateControllerComponent extends StateControllerComponent imp
} else {
newState = objToBase64(this.stateObject);
}
this.updateStateParam(newState, !isStateIdChanged);
this.updateStateParam(newState, replaceCurrentHistoryUrl);
}
}

14
ui-ngx/src/app/modules/home/components/dashboard-page/states/state-controller.component.ts

@ -4,12 +4,13 @@
import { IStateControllerComponent, StateControllerState } from '@home/components/dashboard-page/states/state-controller.models';
import { IDashboardController } from '../dashboard-page.models';
import { DashboardState } from '@app/shared/models/dashboard.models';
import { BehaviorSubject, Observable, Subject, Subscription } from 'rxjs';
import { Observable, Subject, Subscription } from 'rxjs';
import { NgZone, OnDestroy, OnInit, Directive } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { StatesControllerService } from '@home/components/dashboard-page/states/states-controller.service';
import { EntityId } from '@app/shared/models/id/entity-id';
import { StateObject, StateParams } from '@app/core/api/widget-api.models';
import { DashboardUtilsService } from '@core/services/dashboard-utils.service';
import { WindowMessage } from '@shared/models/window-message.model';
import { UtilsService } from '@core/services/utils.service';
@ -91,7 +92,8 @@ export abstract class StateControllerComponent implements IStateControllerCompon
protected utils: UtilsService,
protected window: Window,
protected ngZone: NgZone,
protected statesControllerService: StatesControllerService) {
protected statesControllerService: StatesControllerService,
protected dashboardUtils: DashboardUtilsService) {
}
ngOnInit(): void {
@ -123,6 +125,14 @@ export abstract class StateControllerComponent implements IStateControllerCompon
this.stateChangedSubject.complete();
}
protected normalizeStateObject(stateObject: StateControllerState): StateControllerState {
const result = (stateObject || []).filter((stateObj) => stateObj.id && this.states[stateObj.id]);
if (!result.length) {
result.push({ id: this.dashboardUtils.getRootStateId(this.states), params: {} });
}
return result;
}
protected updateStateParam(newState: string, replaceCurrentHistoryUrl = false) {
this.currentState = newState;
if (this.syncStateWithQueryParam) {

35
ui-ngx/src/app/modules/home/components/widget/lib/analogue-gauge.models.ts

@ -4,13 +4,14 @@
import * as CanvasGauges from 'canvas-gauges';
import { FontSettings, getFontFamily } from '@home/components/widget/lib/settings.models';
import { WidgetContext } from '@home/models/widget-component.models';
import { isDefined, isDefinedAndNotNull } from '@core/utils';
import { isDefined, isDefinedAndNotNull, isNumeric } from '@core/utils';
import tinycolor from 'tinycolor2';
import { TbUnit } from '@shared/models/unit.models';
import { ValueFormatProcessor } from '@shared/models/widget-settings.models';
import { UnitService } from '@core/services/unit.service';
import { DataKey } from '@shared/models/widget.models';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
import { NOT_SUPPORTED } from '@shared/models/telemetry/telemetry.models';
import Highlight = CanvasGauges.Highlight;
import BaseGauge = CanvasGauges.BaseGauge;
import GenericOptions = CanvasGauges.GenericOptions;
@ -61,6 +62,9 @@ interface BaseGaugeModel extends BaseGauge {
_value?: number;
}
export const getGaugeValueText = (value: any): string =>
!isDefinedAndNotNull(value) || value === '' ? 'N/A' : !isNumeric(value) ? NOT_SUPPORTED : '';
export abstract class TbBaseGauge<S, O extends GenericOptions> {
private gauge: BaseGaugeModel;
@ -80,20 +84,23 @@ export abstract class TbBaseGauge<S, O extends GenericOptions> {
update() {
if (this.ctx.data.length > 0) {
const cellData = this.ctx.data[0];
if (cellData.data.length > 0) {
const tvPair = cellData.data[cellData.data.length - 1];
let value = parseFloat(tvPair[1]);
if (this.formatValue) {
value = parseFloat(this.formatValue.format(value));
}
if (value !== this.gauge.value) {
if (!this.gauge.options.animation) {
this.gauge._value = value;
} else {
delete this.gauge._value;
}
this.gauge.value = value;
const origValue = cellData.data.length > 0 ? cellData.data[cellData.data.length - 1][1] : null;
let value = parseFloat(origValue);
if (this.formatValue) {
value = parseFloat(this.formatValue.format(value));
}
const valueText = getGaugeValueText(origValue);
if (this.gauge.options.valueText !== valueText) {
this.gauge.update({valueText} as GenericOptions);
}
const gaugeValue = valueText ? this.gauge.options.minValue : value;
if (!isNaN(gaugeValue) && gaugeValue !== this.gauge.value) {
if (!this.gauge.options.animation) {
this.gauge._value = gaugeValue;
} else {
delete this.gauge._value;
}
this.gauge.value = gaugeValue;
}
}
}

16
ui-ngx/src/app/modules/home/components/widget/lib/canvas-digital-gauge.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 * as CanvasGauges from 'canvas-gauges';
import { FontStyle, FontWeight } from '@home/components/widget/lib/settings.models';
import tinycolor from 'tinycolor2';
@ -750,19 +751,26 @@ function drawDigitalValue(context: DigitalGaugeCanvasRenderingContext2D, options
return;
}
const {valueY, baseX, width, fontSizeFactor, fontValueBaseline} =
const {valueY, baseX, width, Ri, fontSizeFactor, fontValueBaseline} =
context.barDimensions;
const textX = Math.round(baseX + width / 2);
const textY = valueY;
let text = options.valueText || padValue(options.valueFormat.format(value), options.valueDec);
text += options.symbol;
const text = options.valueText ? options.valueText : padValue(options.valueFormat.format(value), options.valueDec) + options.symbol;
context.save();
context.textAlign = 'center';
context.textBaseline = fontValueBaseline;
context.font = Drawings.font(options, 'Value', fontSizeFactor);
if (options.valueText) {
const isRound = options.gaugeType === 'donut' || options.gaugeType === 'arc';
const maxTextWidth = (isRound ? Ri * 2 : width) * 0.9;
const textWidth = context.measureText(text).width;
if (textWidth > maxTextWidth) {
context.font = Drawings.font(options, 'Value', fontSizeFactor * maxTextWidth / textWidth);
}
}
context.lineWidth = 0;
drawText(context, options, 'Value', text, textX, textY);
context.restore();

46
ui-ngx/src/app/modules/home/components/widget/lib/digital-gauge.ts

@ -23,6 +23,7 @@ import { UnitService } from '@core/services/unit.service';
import { isNotEmptyTbUnits } from '@shared/models/unit.models';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
import GenericOptions = CanvasGauges.GenericOptions;
import { getGaugeValueText } from '@home/components/widget/lib/analogue-gauge.models';
// @dynamic
export class TbCanvasDigitalGauge {
@ -247,27 +248,32 @@ export class TbCanvasDigitalGauge {
update() {
if (this.ctx.data.length > 0) {
const cellData = this.ctx.data[0];
if (cellData.data.length > 0) {
const tvPair = cellData.data[cellData.data.length -
1];
let timestamp: number;
if (this.localSettings.showTimestamp) {
timestamp = tvPair[0];
const filter = this.ctx.$injector.get(DatePipe);
(this.gauge.options as CanvasDigitalGaugeOptions).labelTimestamp =
filter.transform(timestamp, this.localSettings.timestampFormat);
}
const value = parseFloat(tvPair[1]);
if (value !== this.gauge.value) {
if (!this.gauge.options.animation) {
this.gauge._value = value;
} else {
delete this.gauge._value;
}
this.gauge.value = value;
} else if (this.localSettings.showTimestamp && this.gauge.timestamp !== timestamp) {
this.gauge.timestamp = timestamp;
const tvPair = cellData.data.length > 0 ? cellData.data[cellData.data.length - 1] : null;
let timestamp: number;
if (this.localSettings.showTimestamp && tvPair) {
timestamp = tvPair[0];
const filter = this.ctx.$injector.get(DatePipe);
(this.gauge.options as CanvasDigitalGaugeOptions).labelTimestamp =
filter.transform(timestamp, this.localSettings.timestampFormat);
}
const origValue = tvPair ? tvPair[1] : null;
const value = parseFloat(origValue);
const options = this.gauge.options as CanvasDigitalGaugeOptions;
const valueText = getGaugeValueText(origValue);
if (options.valueText !== valueText) {
options.valueText = valueText;
this.gauge.update({} as CanvasDigitalGaugeOptions);
}
const gaugeValue = valueText ? options.minValue : value;
if (!isNaN(gaugeValue) && gaugeValue !== this.gauge.value) {
if (!this.gauge.options.animation) {
this.gauge._value = gaugeValue;
} else {
delete this.gauge._value;
}
this.gauge.value = gaugeValue;
} else if (this.localSettings.showTimestamp && tvPair && this.gauge.timestamp !== timestamp) {
this.gauge.timestamp = timestamp;
}
}
}

6
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/action-settings-panel.component.scss

@ -1,9 +1,11 @@
// 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 '../../../../../../../../../scss/constants';
.tb-action-settings-panel {
width: 530px;
max-height: 90vh;
display: flex;
flex-direction: column;
gap: 16px;
@ -15,6 +17,8 @@
flex-direction: column;
gap: 16px;
overflow: auto;
flex: 1;
min-height: 0;
}
.tb-action-settings-title {
font-size: 16px;

1
ui-ngx/src/app/modules/home/home.component.scss

@ -168,6 +168,7 @@
position: relative;
overflow: clip;
flex: 1;
min-height: 0;
display: flex;
}

2
ui-ngx/src/app/modules/home/pages/admin/license-management.component.html

@ -28,7 +28,7 @@
<div class="item-row" [class]="itemLimitClass(itemType, count, max)">
<span class="item-name">{{ usageItemTypeTranslationMap.get(itemType) | translate }}</span>
<span class="item-meter">
<i [style.width.%]="max > 0 ? (count / max) * 100 : 0"></i>
<i [style.width.%]="itemMeterWidth(count, max)"></i>
</span>
<span class="item-value">
@if (max !== 0) {

1
ui-ngx/src/app/modules/home/pages/admin/license-management.component.scss

@ -296,6 +296,7 @@
height: 8px;
border-radius: 6px;
background: rgba(0, 105, 92, 0.10);
overflow: hidden;
i {
display: block;
height: 100%;

10
ui-ngx/src/app/modules/home/pages/admin/license-management.component.ts

@ -194,7 +194,17 @@ export class LicenseManagementComponent extends PageComponent implements OnInit,
return false;
}
itemMeterWidth(count: number, max: number): number {
if (count > 0 && max > 0) {
return Math.min(count / max, 1) * 100;
}
return 0;
}
itemLimitClass(itemType: UsageItemType, count: number, max: number): string {
if (max > 0 && count > max) {
return 'item-critical';
}
if ([UsageItemType.DEVICES, UsageItemType.ASSETS, UsageItemType.AI_CREDITS].includes(itemType)) {
if (this.itemLimitCritical(count, max)) {
return 'item-critical';

17
ui-ngx/src/app/shared/models/alarm-rule.models.ts

@ -330,6 +330,23 @@ export function areFiltersAndPredicateArgumentsValid(obj: any, args: Record<stri
return true;
}
export function areAlarmRuleConditionFilterArgumentsValid(condition: AlarmRuleCondition,
args: Record<string, CalculatedFieldArgument>): boolean {
return areFiltersAndPredicateArgumentsValid(condition?.expression?.filters, args);
}
export function isAlarmRuleConditionScheduleArgumentValid(condition: AlarmRuleCondition,
args: Record<string, CalculatedFieldArgument>): boolean {
const arg = condition?.schedule?.dynamicValueArgument;
return !arg || Object.keys(args).includes(arg);
}
export function areAlarmRuleArgumentsValid(alarmRule: AlarmRule, args: Record<string, CalculatedFieldArgument>): boolean {
const condition = alarmRule?.condition;
return !condition || !args ||
(areAlarmRuleConditionFilterArgumentsValid(condition, args) && isAlarmRuleConditionScheduleArgumentValid(condition, args));
}
export function isPredicateArgumentsValid(predicates: any, args: Record<string, CalculatedFieldArgument>): boolean {
const validSet = new Set(Object.keys(args));
if (Array.isArray(predicates)) {

2150
ui-ngx/src/assets/locale/locale.constant-it_IT.json

File diff suppressed because it is too large

2926
ui-ngx/src/assets/locale/locale.constant-pt_BR.json

File diff suppressed because it is too large
Loading…
Cancel
Save