Edge Dashboard and RuleChain partially fixed. Not working: get edge dashboards; default edges; assing edge rule chains to edge

This commit is contained in:
deaflynx 2020-06-24 11:16:46 +03:00
parent bc28406594
commit 95babbe246
7 changed files with 98 additions and 23 deletions

View File

@ -163,7 +163,8 @@ export class DashboardService {
defaultHttpOptionsFromConfig(config)) defaultHttpOptionsFromConfig(config))
} }
public assignDashboardToEdge(edgeId: string, dashboardId: string, config?: RequestConfig): Observable<Dashboard> { public assignDashboardToEdge(edgeId: string, dashboardId: string,
config?: RequestConfig): Observable<Dashboard> {
return this.http.post<Dashboard>(`/api/edge/${edgeId}/dashboard/${dashboardId}`, return this.http.post<Dashboard>(`/api/edge/${edgeId}/dashboard/${dashboardId}`,
null, defaultHttpOptionsFromConfig(config)); null, defaultHttpOptionsFromConfig(config));
} }

View File

@ -318,8 +318,8 @@ export class RuleChainService {
return this.http.delete<RuleChain>(`/api/ruleChain/${ruleChainId}/defaultEdge`, defaultHttpOptionsFromConfig(config)); return this.http.delete<RuleChain>(`/api/ruleChain/${ruleChainId}/defaultEdge`, defaultHttpOptionsFromConfig(config));
} }
public getDefaultEdgeRuleChains(pageLink: PageLink, config?: RequestConfig): Observable<PageData<RuleChain>> { public getDefaultEdgeRuleChains(config?: RequestConfig): Observable<PageData<RuleChain>> {
return this.http.get<PageData<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains${pageLink.toQuery()}`, return this.http.get<PageData<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains`,
defaultHttpOptionsFromConfig(config)); defaultHttpOptionsFromConfig(config));
} }

View File

@ -34,8 +34,7 @@
<tb-entity-list <tb-entity-list
formControlName="entityIds" formControlName="entityIds"
required required
[entityType]="entityType" [entityType]="entityType">
>
</tb-entity-list> </tb-entity-list>
</fieldset> </fieldset>
</div> </div>
@ -50,7 +49,7 @@
style="margin-right: 20px;" style="margin-right: 20px;"
type="button" type="button"
[disabled]="(isLoading$ | async)" [disabled]="(isLoading$ | async)"
(click)="cancel()" cdkFocusInitial> (click)="cancel()">
{{ 'action.cancel' | translate }} {{ 'action.cancel' | translate }}
</button> </button>
</div> </div>

View File

@ -74,7 +74,6 @@ import {
export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<DashboardInfo | Dashboard>> { export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<DashboardInfo | Dashboard>> {
private readonly config: EntityTableConfig<DashboardInfo | Dashboard> = new EntityTableConfig<DashboardInfo | Dashboard>(); private readonly config: EntityTableConfig<DashboardInfo | Dashboard> = new EntityTableConfig<DashboardInfo | Dashboard>();
private edgeId: string;
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
private dashboardService: DashboardService, private dashboardService: DashboardService,
@ -111,9 +110,9 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
const routeParams = route.params; const routeParams = route.params;
this.config.componentsData = { this.config.componentsData = {
dashboardScope: route.data.dashboardsType, dashboardScope: route.data.dashboardsType,
customerId: routeParams.customerId customerId: routeParams.customerId,
edgeId: routeParams.edgeId
}; };
this.edgeId = routeParams.edgeId;
return this.store.pipe(select(selectAuthUser), take(1)).pipe( return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => { tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) { if (authUser.authority === Authority.CUSTOMER_USER) {
@ -133,7 +132,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('dashboard.dashboards'); this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('dashboard.dashboards');
} }
} else if (this.config.componentsData.dashboardScope === 'edge') { } else if (this.config.componentsData.dashboardScope === 'edge') {
this.edgeService.getEdge(this.edgeId).pipe(map(edge => this.edgeService.getEdge(this.config.componentsData.edgeId).pipe(map(edge =>
this.config.tableTitle = edge.name + ': ' + this.translate.instant('dashboard.dashboards'))).subscribe(); this.config.tableTitle = edge.name + ': ' + this.translate.instant('dashboard.dashboards'))).subscribe();
} else { } else {
this.config.tableTitle = this.translate.instant('dashboard.dashboards'); this.config.tableTitle = this.translate.instant('dashboard.dashboards');
@ -178,7 +177,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.deleteEntity = id => this.dashboardService.deleteDashboard(id.id); this.config.deleteEntity = id => this.dashboardService.deleteDashboard(id.id);
} else if (dashboardScope === 'edge') { } else if (dashboardScope === 'edge') {
this.config.entitiesFetchFunction = pageLink => 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 { } else {
this.config.entitiesFetchFunction = pageLink => this.config.entitiesFetchFunction = pageLink =>
this.dashboardService.getCustomerDashboards(this.config.componentsData.customerId, pageLink); this.dashboardService.getCustomerDashboards(this.config.componentsData.customerId, pageLink);
@ -556,7 +555,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
edgeId: this.edgeId, edgeId: this.config.componentsData.edgeId,
entityType: EntityType.DASHBOARD entityType: EntityType.DASHBOARD
} }
}).afterClosed() }).afterClosed()
@ -579,7 +578,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
true true
).subscribe((res) => { ).subscribe((res) => {
if (res) { 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(); this.config.table.updateData();
} }
@ -604,7 +603,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
const tasks: Observable<any>[] = []; const tasks: Observable<any>[] = [];
dashboards.forEach( dashboards.forEach(
(dashboard) => { (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( forkJoin(tasks).subscribe(

View File

@ -29,7 +29,7 @@ import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '@angular/common'; import { DatePipe } from '@angular/common';
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models'; import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
import { EntityAction } from '@home/models/entity/entity-component.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 { RuleChainService } from '@core/http/rule-chain.service';
import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component'; import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
@ -44,7 +44,8 @@ import {
AddEntitiesToEdgeDialogData AddEntitiesToEdgeDialogData
} from "@home/dialogs/add-entities-to-edge-dialog.component"; } from "@home/dialogs/add-entities-to-edge-dialog.component";
import { MatDialog } from "@angular/material/dialog"; 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() @Injectable()
export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> { export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> {
@ -178,10 +179,10 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
configureEntityFunctions(ruleChainScope: string): void { configureEntityFunctions(ruleChainScope: string): void {
if (ruleChainScope === 'tenant') { if (ruleChainScope === 'tenant') {
this.config.tableTitle = this.translate.instant('rulechain.core-rulechains'); this.config.tableTitle = this.translate.instant('rulechain.core-rulechains');
this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.core); this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink, ruleChainType.core, ruleChainScope);
} else if (ruleChainScope === 'edges') { } else if (ruleChainScope === 'edges') {
this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); 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') { } else if (ruleChainScope === 'edge') {
if (this.edgeId) { if (this.edgeId) {
this.edgeService.getEdge(this.edgeId) this.edgeService.getEdge(this.edgeId)
@ -235,10 +236,16 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
if (ruleChainScope === 'edges') { if (ruleChainScope === 'edges') {
actions.push( actions.push(
{ {
name: this.translate.instant('rulechain.make-default!!!'), name: this.translate.instant('rulechain.set-default-edge'),
icon: 'flag', icon: 'bookmark_outline',
isEnabled: () => true, isEnabled: () => 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<EntityTableConfig<
if (res) { if (res) {
this.config.table.updateData(); this.config.table.updateData();
} }
}); }
)
} }
unassignFromEdge($event: Event, ruleChain: RuleChain) { unassignFromEdge($event: Event, ruleChain: RuleChain) {
@ -421,4 +429,65 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
); );
} }
setDefaultEdgeRuleChain($event: Event, ruleChain: RuleChain) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('rulechain.set-default-edge-title', {ruleChainName: ruleChain.name}),
this.translate.instant('rulechain.set-default-edge-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
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)
}
}
} }

View File

@ -30,6 +30,7 @@ export interface RuleChain extends BaseData<RuleChainId> {
type: string; type: string;
configuration?: any; configuration?: any;
additionalInfo?: any; additionalInfo?: any;
isDefault?: boolean;
} }
export interface RuleChainMetaData { export interface RuleChainMetaData {

View File

@ -1555,7 +1555,13 @@
"debug-mode": "Debug mode", "debug-mode": "Debug mode",
"search": "Search rule chains", "search": "Search rule chains",
"selected-rulechains": "{ count, plural, 1 {1 rule chain} other {# rule chains} } selected", "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": { "rulenode": {
"details": "Details", "details": "Details",