From 5cec1b8af222172c668781e04a8fa30310a04e57 Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Thu, 11 May 2023 14:57:40 +0300 Subject: [PATCH 1/3] Ability to disable notification rule --- .../main/data/upgrade/3.5.0/schema_update.sql | 17 +++++++++ .../DefaultNotificationRuleProcessor.java | 2 +- .../cache/DefaultNotificationRulesCache.java | 4 +-- .../rule/cache/NotificationRulesCache.java | 2 +- .../AbstractNotificationApiTest.java | 1 + .../notification/NotificationRuleApiTest.java | 35 +++++++++++++++++++ .../notification/NotificationRuleService.java | 2 +- .../notification/rule/NotificationRule.java | 2 ++ .../server/dao/model/ModelConstants.java | 1 + .../dao/model/sql/NotificationRuleEntity.java | 6 ++++ .../DefaultNotificationRuleService.java | 4 +-- .../notification/DefaultNotifications.java | 3 ++ .../dao/notification/NotificationRuleDao.java | 2 +- .../notification/JpaNotificationRuleDao.java | 10 +++--- .../NotificationRuleRepository.java | 2 +- .../main/resources/sql/schema-entities.sql | 1 + .../rule-notification-dialog.component.html | 5 +++ .../rule-notification-dialog.component.ts | 1 + .../app/shared/models/notification.models.ts | 1 + .../assets/locale/locale.constant-en_US.json | 1 + 20 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 application/src/main/data/upgrade/3.5.0/schema_update.sql diff --git a/application/src/main/data/upgrade/3.5.0/schema_update.sql b/application/src/main/data/upgrade/3.5.0/schema_update.sql new file mode 100644 index 0000000000..09ce186811 --- /dev/null +++ b/application/src/main/data/upgrade/3.5.0/schema_update.sql @@ -0,0 +1,17 @@ +-- +-- Copyright © 2016-2023 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. +-- + +ALTER TABLE notification_rule ADD COLUMN IF NOT EXISTS enabled BOOLEAN NOT NULL DEFAULT true; diff --git a/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java b/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java index 8bfdc0e243..3e7f67e09b 100644 --- a/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java @@ -97,7 +97,7 @@ public class DefaultNotificationRuleProcessor implements NotificationRuleProcess TenantId tenantId = triggerType.isTenantLevel() ? trigger.getTenantId() : TenantId.SYS_TENANT_ID; try { - List rules = notificationRulesCache.get(tenantId, triggerType); + List rules = notificationRulesCache.getEnabled(tenantId, triggerType); for (NotificationRule rule : rules) { notificationExecutor.submit(() -> { try { diff --git a/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/DefaultNotificationRulesCache.java b/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/DefaultNotificationRulesCache.java index b0cd1bd557..a02b7bf1e4 100644 --- a/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/DefaultNotificationRulesCache.java +++ b/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/DefaultNotificationRulesCache.java @@ -82,12 +82,12 @@ public class DefaultNotificationRulesCache implements NotificationRulesCache { } @Override - public List get(TenantId tenantId, NotificationRuleTriggerType triggerType) { + public List getEnabled(TenantId tenantId, NotificationRuleTriggerType triggerType) { lock.readLock().lock(); try { log.trace("Retrieving notification rules of type {} for tenant {} from cache", triggerType, tenantId); return cache.get(key(tenantId, triggerType), k -> { - List rules = notificationRuleService.findNotificationRulesByTenantIdAndTriggerType(tenantId, triggerType); + List rules = notificationRuleService.findEnabledNotificationRulesByTenantIdAndTriggerType(tenantId, triggerType); log.trace("Fetched notification rules of type {} for tenant {} (count: {})", triggerType, tenantId, rules.size()); return !rules.isEmpty() ? rules : Collections.emptyList(); }); diff --git a/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/NotificationRulesCache.java b/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/NotificationRulesCache.java index 43ea3c4cc3..2a1054b352 100644 --- a/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/NotificationRulesCache.java +++ b/application/src/main/java/org/thingsboard/server/service/notification/rule/cache/NotificationRulesCache.java @@ -23,6 +23,6 @@ import java.util.List; public interface NotificationRulesCache { - List get(TenantId tenantId, NotificationRuleTriggerType triggerType); + List getEnabled(TenantId tenantId, NotificationRuleTriggerType triggerType); } diff --git a/application/src/test/java/org/thingsboard/server/service/notification/AbstractNotificationApiTest.java b/application/src/test/java/org/thingsboard/server/service/notification/AbstractNotificationApiTest.java index a22143ab1c..ac3857dbdf 100644 --- a/application/src/test/java/org/thingsboard/server/service/notification/AbstractNotificationApiTest.java +++ b/application/src/test/java/org/thingsboard/server/service/notification/AbstractNotificationApiTest.java @@ -205,6 +205,7 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest NotificationRule rule = new NotificationRule(); rule.setName(triggerConfig.getTriggerType() + " " + Arrays.toString(targets)); + rule.setEnabled(true); rule.setTemplateId(template.getId()); rule.setTriggerType(triggerConfig.getTriggerType()); rule.setTriggerConfig(triggerConfig); diff --git a/application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java b/application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java index b03a914d1f..85cc0a2478 100644 --- a/application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java +++ b/application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java @@ -154,6 +154,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest { NotificationRule notificationRule = new NotificationRule(); notificationRule.setName("Web notification on any alarm"); + notificationRule.setEnabled(true); notificationRule.setTemplateId(notificationTemplate.getId()); notificationRule.setTriggerType(NotificationRuleTriggerType.ALARM); @@ -239,6 +240,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest { NotificationRule notificationRule = new NotificationRule(); notificationRule.setName("Web notification on any alarm"); + notificationRule.setEnabled(true); notificationRule.setTemplateId(notificationTemplate.getId()); notificationRule.setTriggerType(NotificationRuleTriggerType.ALARM); @@ -375,6 +377,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest { NotificationRule rule = new NotificationRule(); rule.setName("Test"); + rule.setEnabled(true); rule.setTemplateId(template.getId()); rule.setTriggerType(NotificationRuleTriggerType.ENTITY_ACTION); @@ -402,6 +405,7 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest { NotificationRule rule = new NotificationRule(); rule.setName("Device created"); + rule.setEnabled(true); rule.setTriggerType(NotificationRuleTriggerType.ENTITY_ACTION); NotificationTemplate template = createNotificationTemplate(NotificationType.ENTITY_ACTION, "Device created", "Device created", NotificationDeliveryMethod.WEB); @@ -467,6 +471,37 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest { }); } + @Test + public void testNotificationRuleDisabling() throws Exception { + EntityActionNotificationRuleTriggerConfig triggerConfig = new EntityActionNotificationRuleTriggerConfig(); + triggerConfig.setEntityTypes(Set.of(EntityType.DEVICE)); + triggerConfig.setCreated(true); + NotificationRule rule = createNotificationRule(triggerConfig, "Created", "Created", createNotificationTarget(tenantAdminUserId).getId()); + + assertThat(getMyNotifications(false, 100)).size().isZero(); + createDevice("Device 1", "default", "111"); + await().atMost(15, TimeUnit.SECONDS) + .untilAsserted(() -> { + assertThat(getMyNotifications(false, 100)).size().isEqualTo(1); + }); + + rule.setEnabled(false); + saveNotificationRule(rule); + + createDevice("Device 2", "default", "222"); + TimeUnit.SECONDS.sleep(5); + assertThat(getMyNotifications(false, 100)).as("No new notifications arrived").size().isEqualTo(1); + + rule.setEnabled(true); + saveNotificationRule(rule); + + createDevice("Device 3", "default", "333"); + await().atMost(15, TimeUnit.SECONDS) + .untilAsserted(() -> { + assertThat(getMyNotifications(false, 100)).size().isEqualTo(2); + }); + } + private R checkNotificationAfter(Callable action, BiConsumer check) throws Exception { if (getWsClient().getLastDataUpdate() == null) { getWsClient().subscribeForUnreadNotifications(10).waitForReply(true); diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java index 29bdf09a56..bd23f1c48d 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java @@ -37,7 +37,7 @@ public interface NotificationRuleService { PageData findNotificationRulesByTenantId(TenantId tenantId, PageLink pageLink); - List findNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType); + List findEnabledNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType); void deleteNotificationRuleById(TenantId tenantId, NotificationRuleId id); diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java index 450fbdb23f..607ca7f639 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java @@ -46,6 +46,7 @@ public class NotificationRule extends BaseData implements Ha @NoXss @Length(max = 255, message = "cannot be longer than 255 chars") private String name; + private boolean enabled; @NotNull private NotificationTemplateId templateId; @@ -64,6 +65,7 @@ public class NotificationRule extends BaseData implements Ha super(other); this.tenantId = other.tenantId; this.name = other.name; + this.enabled = other.enabled; this.templateId = other.templateId; this.triggerType = other.triggerType; this.triggerConfig = other.triggerConfig; diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java index 122716181c..9109312ec8 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java @@ -714,6 +714,7 @@ public class ModelConstants { public static final String NOTIFICATION_REQUEST_STATS_PROPERTY = "stats"; public static final String NOTIFICATION_RULE_TABLE_NAME = "notification_rule"; + public static final String NOTIFICATION_RULE_ENABLED_PROPERTY = "enabled"; public static final String NOTIFICATION_RULE_TEMPLATE_ID_PROPERTY = "template_id"; public static final String NOTIFICATION_RULE_TRIGGER_TYPE_PROPERTY = "trigger_type"; public static final String NOTIFICATION_RULE_TRIGGER_CONFIG_PROPERTY = "trigger_config"; diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRuleEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRuleEntity.java index 0e8264d4f7..c3bc8cce0a 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRuleEntity.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRuleEntity.java @@ -50,6 +50,9 @@ public class NotificationRuleEntity extends BaseSqlEntity { @Column(name = ModelConstants.NAME_PROPERTY, nullable = false) private String name; + @Column(name = ModelConstants.NOTIFICATION_RULE_ENABLED_PROPERTY, nullable = false) + private boolean enabled; + @Column(name = ModelConstants.NOTIFICATION_RULE_TEMPLATE_ID_PROPERTY, nullable = false) private UUID templateId; @@ -76,6 +79,7 @@ public class NotificationRuleEntity extends BaseSqlEntity { setCreatedTime(notificationRule.getCreatedTime()); setTenantId(getTenantUuid(notificationRule.getTenantId())); setName(notificationRule.getName()); + setEnabled(notificationRule.isEnabled()); setTemplateId(getUuid(notificationRule.getTemplateId())); setTriggerType(notificationRule.getTriggerType()); setTriggerConfig(toJson(notificationRule.getTriggerConfig())); @@ -88,6 +92,7 @@ public class NotificationRuleEntity extends BaseSqlEntity { this.createdTime = other.createdTime; this.tenantId = other.tenantId; this.name = other.name; + this.enabled = other.enabled; this.templateId = other.templateId; this.triggerType = other.triggerType; this.triggerConfig = other.triggerConfig; @@ -102,6 +107,7 @@ public class NotificationRuleEntity extends BaseSqlEntity { notificationRule.setCreatedTime(createdTime); notificationRule.setTenantId(getTenantId(tenantId)); notificationRule.setName(name); + notificationRule.setEnabled(enabled); notificationRule.setTemplateId(getEntityId(templateId, NotificationTemplateId::new)); notificationRule.setTriggerType(triggerType); notificationRule.setTriggerConfig(fromJson(triggerConfig, NotificationRuleTriggerConfig.class)); diff --git a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java index 3b2d8e0984..bafa145476 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java @@ -79,8 +79,8 @@ public class DefaultNotificationRuleService extends AbstractEntityService implem } @Override - public List findNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType) { - return notificationRuleDao.findByTenantIdAndTriggerType(tenantId, triggerType); + public List findEnabledNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType) { + return notificationRuleDao.findByTenantIdAndTriggerTypeAndEnabled(tenantId, triggerType, true); } @Override diff --git a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java index 00d57d1121..01f9f68ae4 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java +++ b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java @@ -206,6 +206,7 @@ public class DefaultNotifications { .button("Go to device").link("/devices/${deviceId}") .rule(DefaultRule.builder() .name("Device activity status change") + .enabled(false) .triggerConfig(DeviceActivityNotificationRuleTriggerConfig.builder() .devices(null) .deviceProfiles(null) @@ -342,6 +343,7 @@ public class DefaultNotifications { DefaultRule defaultRule = this.rule; NotificationRule rule = new NotificationRule(); rule.setName(defaultRule.getName()); + rule.setEnabled(defaultRule.getEnabled() == null || defaultRule.getEnabled()); rule.setTemplateId(templateId); rule.setTriggerType(defaultRule.getTriggerConfig().getTriggerType()); rule.setTriggerConfig(defaultRule.getTriggerConfig()); @@ -368,6 +370,7 @@ public class DefaultNotifications { @Builder(toBuilder = true) public static class DefaultRule { private final String name; + private final Boolean enabled; private final NotificationRuleTriggerConfig triggerConfig; private final String description; } diff --git a/dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java b/dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java index a2cd2caeab..a2d62d9a72 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java @@ -35,7 +35,7 @@ public interface NotificationRuleDao extends Dao { boolean existsByTenantIdAndTargetId(TenantId tenantId, NotificationTargetId targetId); - List findByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType); + List findByTenantIdAndTriggerTypeAndEnabled(TenantId tenantId, NotificationRuleTriggerType triggerType, boolean enabled); NotificationRuleInfo findInfoById(TenantId tenantId, NotificationRuleId id); diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java index 46910f119f..af526b8d64 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java @@ -55,9 +55,9 @@ public class JpaNotificationRuleDao extends JpaAbstractDao findInfosByTenantIdAndPageLink(TenantId tenantId, PageLink pageLink) { return DaoUtil.pageToPageData(notificationRuleRepository.findInfosByTenantIdAndSearchText(tenantId.getId(), - Strings.nullToEmpty(pageLink.getTextSearch()), DaoUtil.toPageable(pageLink, Map.of( - "templateName", "t.name" - )))) + Strings.nullToEmpty(pageLink.getTextSearch()), DaoUtil.toPageable(pageLink, Map.of( + "templateName", "t.name" + )))) .mapData(NotificationRuleInfoEntity::toData); } @@ -67,8 +67,8 @@ public class JpaNotificationRuleDao extends JpaAbstractDao findByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType) { - return DaoUtil.convertDataList(notificationRuleRepository.findAllByTenantIdAndTriggerType(tenantId.getId(), triggerType)); + public List findByTenantIdAndTriggerTypeAndEnabled(TenantId tenantId, NotificationRuleTriggerType triggerType, boolean enabled) { + return DaoUtil.convertDataList(notificationRuleRepository.findAllByTenantIdAndTriggerTypeAndEnabled(tenantId.getId(), triggerType, enabled)); } @Override diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java index 32c6d5388e..2f2ffc4a43 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java @@ -46,7 +46,7 @@ public interface NotificationRuleRepository extends JpaRepository findAllByTenantIdAndTriggerType(UUID tenantId, NotificationRuleTriggerType triggerType); + List findAllByTenantIdAndTriggerTypeAndEnabled(UUID tenantId, NotificationRuleTriggerType triggerType, boolean enabled); @Query(RULE_INFO_QUERY + " WHERE r.id = :id") NotificationRuleInfoEntity findInfoById(@Param("id") UUID id); diff --git a/dao/src/main/resources/sql/schema-entities.sql b/dao/src/main/resources/sql/schema-entities.sql index 9e219ed933..ed1a124764 100644 --- a/dao/src/main/resources/sql/schema-entities.sql +++ b/dao/src/main/resources/sql/schema-entities.sql @@ -815,6 +815,7 @@ CREATE TABLE IF NOT EXISTS notification_rule ( created_time BIGINT NOT NULL, tenant_id UUID NOT NULL, name VARCHAR(255) NOT NULL, + enabled BOOLEAN NOT NULL DEFAULT true, template_id UUID NOT NULL CONSTRAINT fk_notification_rule_template_id REFERENCES notification_template(id), trigger_type VARCHAR(50) NOT NULL, trigger_config VARCHAR(1000) NOT NULL, diff --git a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html index 5690052001..dd7c6c906c 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html @@ -55,6 +55,11 @@ {{ 'notification.trigger.trigger-required' | translate }} +
+ + {{ 'notification.rule-enable' | translate }} + +
, 'label'>{ tenantId: TenantId; + enabled: boolean; templateId: NotificationTemplateId; triggerType: TriggerType; triggerConfig: NotificationRuleTriggerConfig; diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index bcaa4a183f..11835f7e20 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2954,6 +2954,7 @@ "rule-engine-filter": "Rule engine filter", "rule-name": "Rule name", "rule-name-required": "Name is required", + "rule-enable": "Enable notification rule", "rule-node-filter": "Rule node filter", "rules": "Rules", "notification-rules": "Notifications / Rules", From 30ac9942f0dcffc3eb369b4a4dcebd8b1e14aae4 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 19 May 2023 13:43:33 +0300 Subject: [PATCH 2/3] UI: Add enabled notification rule property --- .../entity/entities-table.component.html | 6 +++-- .../entity/entities-table-config.models.ts | 1 + .../rule-notification-dialog.component.html | 8 +++--- .../rule/rule-table-config.resolver.ts | 26 +++++++++++++++++++ .../assets/locale/locale.constant-en_US.json | 1 + 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html b/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html index f07010854c..65f4bed2ae 100644 --- a/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html +++ b/ui-ngx/src/app/modules/home/components/entity/entities-table.component.html @@ -224,7 +224,8 @@ matTooltip="{{ actionDescriptor.nameFunction ? actionDescriptor.nameFunction(entity) : actionDescriptor.name }}" matTooltipPosition="above" (click)="actionDescriptor.onAction($event, entity)"> - + {{actionDescriptor.icon}} @@ -239,7 +240,8 @@ [disabled]="isLoading$ | async" [fxShow]="actionDescriptor.isEnabled(entity)" (click)="actionDescriptor.onAction($event, entity)"> - + {{actionDescriptor.icon}} {{ actionDescriptor.nameFunction ? actionDescriptor.nameFunction(entity) : actionDescriptor.name }} diff --git a/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts b/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts index e7caba0e3c..e9fb01c54a 100644 --- a/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts +++ b/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts @@ -58,6 +58,7 @@ export interface CellActionDescriptor> { nameFunction?: (entity: T) => string; icon?: string; mdiIcon?: string; + mdiIconFunction?: (entity: T) => string; style?: any; isEnabled: (entity: T) => boolean; onAction: ($event: MouseEvent, entity: T) => any; diff --git a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html index dd7c6c906c..fc48392e8c 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html @@ -44,6 +44,9 @@ {{ 'notification.rule-name-required' | translate }} + + {{ 'notification.rule-enable' | translate }} + notification.trigger.trigger @@ -55,11 +58,6 @@ {{ 'notification.trigger.trigger-required' | translate }} -
- - {{ 'notification.rule-enable' | translate }} - -
> { return [{ + name: '', + nameFunction: (entity) => + this.translate.instant(entity.enabled ? 'notification.rule-disable' : 'notification.rule-enable'), + mdiIcon: 'mdi:toggle-switch', + isEnabled: () => true, + mdiIconFunction: (entity) => entity.enabled ? 'mdi:toggle-switch' : 'mdi:toggle-switch-off-outline', + onAction: ($event, entity) => this.toggleEnableMode($event, entity) + }, + { name: this.translate.instant('notification.copy-rule'), icon: 'content_copy', isEnabled: () => true, @@ -128,4 +137,21 @@ export class RuleTableConfigResolver implements Resolve { + rule.enabled = notificationRule.enabled; + this.config.getTable().detectChanges(); + }); + } } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 11835f7e20..67732324b5 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2954,6 +2954,7 @@ "rule-engine-filter": "Rule engine filter", "rule-name": "Rule name", "rule-name-required": "Name is required", + "rule-disable": "Disable notification rule", "rule-enable": "Enable notification rule", "rule-node-filter": "Rule node filter", "rules": "Rules", From b163fb8e2dde1585ec8de25813c3a1879ecfea5c Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Fri, 19 May 2023 13:58:55 +0300 Subject: [PATCH 3/3] Upgrade from 3.5.0 --- .../server/install/ThingsboardInstallService.java | 12 ++++++++---- .../service/install/SqlDatabaseUpgradeService.java | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java index ea13de3779..fc72c354ed 100644 --- a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java +++ b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java @@ -249,15 +249,19 @@ public class ThingsboardInstallService { case "3.4.4": log.info("Upgrading ThingsBoard from version 3.4.4 to 3.5.0 ..."); databaseEntitiesUpgradeService.upgradeDatabase("3.4.4"); - entityDatabaseSchemaService.createOrUpdateViewsAndFunctions(); - entityDatabaseSchemaService.createOrUpdateDeviceInfoView(persistToTelemetry); - log.info("Updating system data..."); - systemDataLoaderService.updateSystemWidgets(); if (!getEnv("SKIP_DEFAULT_NOTIFICATION_CONFIGS_CREATION", false)) { systemDataLoaderService.createDefaultNotificationConfigs(); } else { log.info("Skipping default notification configs creation"); } + case "3.5.0": + log.info("Upgrading ThingsBoard from version 3.5.0 to 3.5.1 ..."); + databaseEntitiesUpgradeService.upgradeDatabase("3.5.0"); + + entityDatabaseSchemaService.createOrUpdateViewsAndFunctions(); + entityDatabaseSchemaService.createOrUpdateDeviceInfoView(persistToTelemetry); + log.info("Updating system data..."); + systemDataLoaderService.updateSystemWidgets(); installScripts.loadSystemLwm2mResources(); break; //TODO update CacheCleanupService on the next version upgrade diff --git a/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java b/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java index 504b058879..f79e0dca08 100644 --- a/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java +++ b/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java @@ -713,6 +713,19 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService log.error("Failed updating schema!!!", e); } break; + case "3.5.0": + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { + log.info("Updating schema ..."); + if (isOldSchema(conn, 3005000)) { + schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "3.5.0", SCHEMA_UPDATE_SQL); + loadSql(schemaUpdateFile, conn); + conn.createStatement().execute("UPDATE tb_schema_settings SET schema_version = 3005001;"); + } + log.info("Schema updated."); + } catch (Exception e) { + log.error("Failed updating schema!!!", e); + } + break; default: throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); }