Browse Source

Merge pull request #8527 from thingsboard/feature/notification-rules-disabling

Ability to disable notification rules
pull/8587/head
Andrew Shvayka 3 years ago
committed by GitHub
parent
commit
76a017e429
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      application/src/main/data/upgrade/3.5.0/schema_update.sql
  2. 12
      application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java
  3. 13
      application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java
  4. 2
      application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java
  5. 4
      application/src/main/java/org/thingsboard/server/service/notification/rule/cache/DefaultNotificationRulesCache.java
  6. 2
      application/src/main/java/org/thingsboard/server/service/notification/rule/cache/NotificationRulesCache.java
  7. 1
      application/src/test/java/org/thingsboard/server/service/notification/AbstractNotificationApiTest.java
  8. 35
      application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java
  9. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java
  10. 2
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java
  11. 1
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  12. 6
      dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRuleEntity.java
  13. 4
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java
  14. 3
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java
  15. 2
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java
  16. 10
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java
  17. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java
  18. 1
      dao/src/main/resources/sql/schema-entities.sql
  19. 6
      ui-ngx/src/app/modules/home/components/entity/entities-table.component.html
  20. 1
      ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts
  21. 3
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html
  22. 1
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts
  23. 26
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-table-config.resolver.ts
  24. 1
      ui-ngx/src/app/shared/models/notification.models.ts
  25. 2
      ui-ngx/src/assets/locale/locale.constant-en_US.json

17
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;

12
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

13
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);
}

2
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<NotificationRule> rules = notificationRulesCache.get(tenantId, triggerType);
List<NotificationRule> rules = notificationRulesCache.getEnabled(tenantId, triggerType);
for (NotificationRule rule : rules) {
notificationExecutor.submit(() -> {
try {

4
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<NotificationRule> get(TenantId tenantId, NotificationRuleTriggerType triggerType) {
public List<NotificationRule> 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<NotificationRule> rules = notificationRuleService.findNotificationRulesByTenantIdAndTriggerType(tenantId, triggerType);
List<NotificationRule> 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();
});

2
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<NotificationRule> get(TenantId tenantId, NotificationRuleTriggerType triggerType);
List<NotificationRule> getEnabled(TenantId tenantId, NotificationRuleTriggerType triggerType);
}

1
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);

35
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> R checkNotificationAfter(Callable<R> action, BiConsumer<Notification, R> check) throws Exception {
if (getWsClient().getLastDataUpdate() == null) {
getWsClient().subscribeForUnreadNotifications(10).waitForReply(true);

2
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java

@ -37,7 +37,7 @@ public interface NotificationRuleService {
PageData<NotificationRule> findNotificationRulesByTenantId(TenantId tenantId, PageLink pageLink);
List<NotificationRule> findNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType);
List<NotificationRule> findEnabledNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType);
void deleteNotificationRuleById(TenantId tenantId, NotificationRuleId id);

2
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java

@ -46,6 +46,7 @@ public class NotificationRule extends BaseData<NotificationRuleId> 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<NotificationRuleId> 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;

1
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -612,6 +612,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";

6
dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRuleEntity.java

@ -50,6 +50,9 @@ public class NotificationRuleEntity extends BaseSqlEntity<NotificationRule> {
@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<NotificationRule> {
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<NotificationRule> {
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> {
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));

4
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java

@ -79,8 +79,8 @@ public class DefaultNotificationRuleService extends AbstractEntityService implem
}
@Override
public List<NotificationRule> findNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType) {
return notificationRuleDao.findByTenantIdAndTriggerType(tenantId, triggerType);
public List<NotificationRule> findEnabledNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType) {
return notificationRuleDao.findByTenantIdAndTriggerTypeAndEnabled(tenantId, triggerType, true);
}
@Override

3
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;
}

2
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleDao.java

@ -35,7 +35,7 @@ public interface NotificationRuleDao extends Dao<NotificationRule> {
boolean existsByTenantIdAndTargetId(TenantId tenantId, NotificationTargetId targetId);
List<NotificationRule> findByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType);
List<NotificationRule> findByTenantIdAndTriggerTypeAndEnabled(TenantId tenantId, NotificationRuleTriggerType triggerType, boolean enabled);
NotificationRuleInfo findInfoById(TenantId tenantId, NotificationRuleId id);

10
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRuleDao.java

@ -55,9 +55,9 @@ public class JpaNotificationRuleDao extends JpaAbstractDao<NotificationRuleEntit
@Override
public PageData<NotificationRuleInfo> 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<NotificationRuleEntit
}
@Override
public List<NotificationRule> findByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType) {
return DaoUtil.convertDataList(notificationRuleRepository.findAllByTenantIdAndTriggerType(tenantId.getId(), triggerType));
public List<NotificationRule> findByTenantIdAndTriggerTypeAndEnabled(TenantId tenantId, NotificationRuleTriggerType triggerType, boolean enabled) {
return DaoUtil.convertDataList(notificationRuleRepository.findAllByTenantIdAndTriggerTypeAndEnabled(tenantId.getId(), triggerType, enabled));
}
@Override

2
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRuleRepository.java

@ -46,7 +46,7 @@ public interface NotificationRuleRepository extends JpaRepository<NotificationRu
boolean existsByTenantIdAndRecipientsConfigContaining(@Param("tenantId") UUID tenantId,
@Param("searchString") String searchString);
List<NotificationRuleEntity> findAllByTenantIdAndTriggerType(UUID tenantId, NotificationRuleTriggerType triggerType);
List<NotificationRuleEntity> findAllByTenantIdAndTriggerTypeAndEnabled(UUID tenantId, NotificationRuleTriggerType triggerType, boolean enabled);
@Query(RULE_INFO_QUERY + " WHERE r.id = :id")
NotificationRuleInfoEntity findInfoById(@Param("id") UUID id);

1
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,

6
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)">
<mat-icon [svgIcon]="actionDescriptor.mdiIcon" [ngStyle]="actionDescriptor.style">
<mat-icon svgIcon="{{ actionDescriptor.mdiIconFunction ? actionDescriptor.mdiIconFunction(entity) : actionDescriptor.mdiIcon }}"
[ngStyle]="actionDescriptor.style">
{{actionDescriptor.icon}}</mat-icon>
</button>
</div>
@ -239,7 +240,8 @@
[disabled]="isLoading$ | async"
[fxShow]="actionDescriptor.isEnabled(entity)"
(click)="actionDescriptor.onAction($event, entity)">
<mat-icon [svgIcon]="actionDescriptor.mdiIcon" [ngStyle]="actionDescriptor.style">
<mat-icon svgIcon="{{ actionDescriptor.mdiIconFunction ? actionDescriptor.mdiIconFunction(entity) : actionDescriptor.mdiIcon }}"
[ngStyle]="actionDescriptor.style">
{{actionDescriptor.icon}}</mat-icon>
<span>{{ actionDescriptor.nameFunction ? actionDescriptor.nameFunction(entity) : actionDescriptor.name }}</span>
</button>

1
ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts

@ -58,6 +58,7 @@ export interface CellActionDescriptor<T extends BaseData<HasId>> {
nameFunction?: (entity: T) => string;
icon?: string;
mdiIcon?: string;
mdiIconFunction?: (entity: T) => string;
style?: any;
isEnabled: (entity: T) => boolean;
onAction: ($event: MouseEvent, entity: T) => any;

3
ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html

@ -44,6 +44,9 @@
{{ 'notification.rule-name-required' | translate }}
</mat-error>
</mat-form-field>
<mat-slide-toggle formControlName="enabled" style="margin-bottom: 22px;">
{{ 'notification.rule-enable' | translate }}
</mat-slide-toggle>
<mat-form-field class="mat-block">
<mat-label translate>notification.trigger.trigger</mat-label>
<mat-select formControlName="triggerType" required>

1
ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts

@ -176,6 +176,7 @@ export class RuleNotificationDialogComponent extends
this.ruleNotificationForm = this.fb.group({
name: [null, Validators.required],
enabled: [true, Validators.required],
templateId: [null, Validators.required],
triggerType: [this.isSysAdmin() ? TriggerType.ENTITIES_LIMIT : TriggerType.ALARM, Validators.required],
recipientsConfig: this.fb.group({

26
ui-ngx/src/app/modules/home/pages/notification/rule/rule-table-config.resolver.ts

@ -92,6 +92,15 @@ export class RuleTableConfigResolver implements Resolve<EntityTableConfig<Notifi
private configureCellActions(): Array<CellActionDescriptor<NotificationRule>> {
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<EntityTableConfig<Notifi
}
return false;
}
private toggleEnableMode($event: Event, rule: NotificationRule): void {
if ($event) {
$event.stopPropagation();
}
const modifyRule: NotificationRule = {
...rule,
enabled: !rule.enabled
};
this.notificationService.saveNotificationRule(modifyRule, {ignoreLoading: true})
.subscribe((notificationRule) => {
rule.enabled = notificationRule.enabled;
this.config.getTable().detectChanges();
});
}
}

1
ui-ngx/src/app/shared/models/notification.models.ts

@ -109,6 +109,7 @@ export interface SlackConversation {
export interface NotificationRule extends Omit<BaseData<NotificationRuleId>, 'label'>{
tenantId: TenantId;
enabled: boolean;
templateId: NotificationTemplateId;
triggerType: TriggerType;
triggerConfig: NotificationRuleTriggerConfig;

2
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -2959,6 +2959,8 @@
"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",
"notification-rules": "Notifications / Rules",

Loading…
Cancel
Save