diff --git a/ui-ngx/src/app/core/http/dashboard.service.ts b/ui-ngx/src/app/core/http/dashboard.service.ts index 7af0639d66..c039fed4da 100644 --- a/ui-ngx/src/app/core/http/dashboard.service.ts +++ b/ui-ngx/src/app/core/http/dashboard.service.ts @@ -163,7 +163,8 @@ export class DashboardService { defaultHttpOptionsFromConfig(config)) } - public assignDashboardToEdge(edgeId: string, dashboardId: string, config?: RequestConfig): Observable { + public assignDashboardToEdge(edgeId: string, dashboardId: string, + config?: RequestConfig): Observable { return this.http.post(`/api/edge/${edgeId}/dashboard/${dashboardId}`, null, defaultHttpOptionsFromConfig(config)); } diff --git a/ui-ngx/src/app/core/http/rule-chain.service.ts b/ui-ngx/src/app/core/http/rule-chain.service.ts index 888a04209f..f2be8bf075 100644 --- a/ui-ngx/src/app/core/http/rule-chain.service.ts +++ b/ui-ngx/src/app/core/http/rule-chain.service.ts @@ -318,8 +318,8 @@ export class RuleChainService { return this.http.delete(`/api/ruleChain/${ruleChainId}/defaultEdge`, defaultHttpOptionsFromConfig(config)); } - public getDefaultEdgeRuleChains(pageLink: PageLink, config?: RequestConfig): Observable> { - return this.http.get>(`/api/ruleChain/defaultEdgeRuleChains${pageLink.toQuery()}`, + public getDefaultEdgeRuleChains(config?: RequestConfig): Observable> { + return this.http.get>(`/api/ruleChain/defaultEdgeRuleChains`, defaultHttpOptionsFromConfig(config)); } diff --git a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html index ca1722dc24..ad45c32de0 100644 --- a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html +++ b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html @@ -34,8 +34,7 @@ + [entityType]="entityType"> @@ -50,7 +49,7 @@ style="margin-right: 20px;" type="button" [disabled]="(isLoading$ | async)" - (click)="cancel()" cdkFocusInitial> + (click)="cancel()"> {{ 'action.cancel' | translate }} diff --git a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts index 379e26dc99..0c4d68d435 100644 --- a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts @@ -74,7 +74,6 @@ import { export class DashboardsTableConfigResolver implements Resolve> { private readonly config: EntityTableConfig = new EntityTableConfig(); - private edgeId: string; constructor(private store: Store, private dashboardService: DashboardService, @@ -111,9 +110,9 @@ export class DashboardsTableConfigResolver implements Resolve { if (authUser.authority === Authority.CUSTOMER_USER) { @@ -133,7 +132,7 @@ export class DashboardsTableConfigResolver implements Resolve + this.edgeService.getEdge(this.config.componentsData.edgeId).pipe(map(edge => this.config.tableTitle = edge.name + ': ' + this.translate.instant('dashboard.dashboards'))).subscribe(); } else { this.config.tableTitle = this.translate.instant('dashboard.dashboards'); @@ -178,7 +177,7 @@ export class DashboardsTableConfigResolver implements Resolve this.dashboardService.deleteDashboard(id.id); } else if (dashboardScope === 'edge') { this.config.entitiesFetchFunction = pageLink => - this.dashboardService.getEdgeDashboards(this.edgeId, pageLink, this.config.componentsData.dashboardsType); + this.dashboardService.getEdgeDashboards(this.config.componentsData.edgeId, pageLink, this.config.componentsData.dashboardsType); } else { this.config.entitiesFetchFunction = pageLink => this.dashboardService.getCustomerDashboards(this.config.componentsData.customerId, pageLink); @@ -556,7 +555,7 @@ export class DashboardsTableConfigResolver implements Resolve { if (res) { - this.dashboardService.unassignDashboardFromEdge(this.edgeId, dashboard.id.id).subscribe( + this.dashboardService.unassignDashboardFromEdge(this.config.componentsData.edgeId, dashboard.id.id).subscribe( () => { this.config.table.updateData(); } @@ -604,7 +603,7 @@ export class DashboardsTableConfigResolver implements Resolve[] = []; dashboards.forEach( (dashboard) => { - tasks.push(this.dashboardService.unassignDashboardFromEdge(this.edgeId, dashboard.id.id)); + tasks.push(this.dashboardService.unassignDashboardFromEdge(this.config.componentsData.edgeId, dashboard.id.id)); } ); forkJoin(tasks).subscribe( diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts index e4f32ae9d6..ce0eec72d7 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts @@ -29,7 +29,7 @@ import { TranslateService } from '@ngx-translate/core'; import { DatePipe } from '@angular/common'; import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models'; import { EntityAction } from '@home/models/entity/entity-component.models'; -import { RuleChain, ruleChainType } from '@shared/models/rule-chain.models'; +import {RuleChain, RuleChainType, ruleChainType} from '@shared/models/rule-chain.models'; import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component'; import { DialogService } from '@core/services/dialog.service'; @@ -44,7 +44,8 @@ import { AddEntitiesToEdgeDialogData } from "@home/dialogs/add-entities-to-edge-dialog.component"; import { MatDialog } from "@angular/material/dialog"; -import {isUndefined} from "@core/utils"; +import { isDefined, isUndefined } from "@core/utils"; +import { PageLink } from "@shared/models/page/page-link"; @Injectable() export class RuleChainsTableConfigResolver implements Resolve> { @@ -178,10 +179,10 @@ export class RuleChainsTableConfigResolver implements Resolve this.ruleChainService.getRuleChains(pageLink, ruleChainType.core); + this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink, ruleChainType.core, ruleChainScope); } else if (ruleChainScope === 'edges') { this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); - this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge); + this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink, ruleChainType.edge, ruleChainScope); } else if (ruleChainScope === 'edge') { if (this.edgeId) { this.edgeService.getEdge(this.edgeId) @@ -235,10 +236,16 @@ export class RuleChainsTableConfigResolver implements Resolve true, - onAction: ($event, entity) => this.setDefaultRootEdgeRuleChain($event, entity) + onAction: ($event, entity) => this.setDefaultEdgeRuleChain($event, entity) + }, + { + name: this.translate.instant('rulechain.remove-default-edge'), + icon: 'bookmark', + isEnabled: () => true, + onAction: ($event, entity) => this.removeDefaultEdgeRuleChain($event, entity) } ) } @@ -368,7 +375,8 @@ export class RuleChainsTableConfigResolver implements Resolve { + if (res) { + this.ruleChainService.addDefaultEdgeRuleChain(ruleChain.id.id).subscribe( + () => { + this.config.table.updateData(); + } + ) + } + } + ); + } + + removeDefaultEdgeRuleChain($event: Event, ruleChain: RuleChain) { + if ($event) { + $event.stopPropagation(); + } + this.dialogService.confirm( + this.translate.instant('rulechain.remove-default-edge-title', {ruleChainName: ruleChain.name}), + this.translate.instant('rulechain.remove-default-edge-text'), + this.translate.instant('action.no'), + this.translate.instant('action.yes'), + true + ).subscribe((res) => { + if (res) { + this.ruleChainService.removeDefaultEdgeRuleChain(ruleChain.id.id).subscribe( + () => { + this.config.table.updateData(); + } + ) + } + } + ); + } + + isRootRuleChain(ruleChain: RuleChain) { + return (isDefined(ruleChain)) && !ruleChain.root && ruleChain.isDefault; + } + + isNonRootRuleChain(ruleChain: RuleChain) { + return (isDefined(ruleChain)) && !ruleChain.root && !ruleChain.isDefault; + } + + fetchRuleChains(pageLink: PageLink, type: string, ruleChainScope: string) { + if (ruleChainScope === 'tenant') { + return this.ruleChainService.getRuleChains(pageLink, type); + } + else if (ruleChainScope === 'edges') { + this.ruleChainService.getRuleChains(pageLink, type) + } + } + } diff --git a/ui-ngx/src/app/shared/models/rule-chain.models.ts b/ui-ngx/src/app/shared/models/rule-chain.models.ts index 5d2b8d664d..dac7b772d2 100644 --- a/ui-ngx/src/app/shared/models/rule-chain.models.ts +++ b/ui-ngx/src/app/shared/models/rule-chain.models.ts @@ -30,6 +30,7 @@ export interface RuleChain extends BaseData { type: string; configuration?: any; additionalInfo?: any; + isDefault?: boolean; } export interface RuleChainMetaData { 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 683fd12ad1..df531546c6 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1555,7 +1555,13 @@ "debug-mode": "Debug mode", "search": "Search rule chains", "selected-rulechains": "{ count, plural, 1 {1 rule chain} other {# rule chains} } selected", - "open-rulechain": "Open rule chain" + "open-rulechain": "Open rule chain", + "set-default-edge": "Make edge rule chain default", + "set-default-edge-title": "Are you sure you want to make the edge rule chain '{{ruleChainName}}' default?", + "set-default-edge-text": "After the confirmation the edge rule chain will be added to default list and assigned to newly created edge(s).", + "remove-default-edge": "Remove edge rule chain from defaults", + "remove-default-edge-title": "Are you sure you want to remove the edge rule chain '{{ruleChainName}}' from default list?", + "remove-default-edge-text": "After the confirmation the edge rule chain will not be assigned for a newly created edges." }, "rulenode": { "details": "Details",