@ -52,7 +52,6 @@ import { Edge } from "@shared/models/edge.models";
export class RuleChainsTableConfigResolver implements Resolve < EntityTableConfig < RuleChain > > {
export class RuleChainsTableConfigResolver implements Resolve < EntityTableConfig < RuleChain > > {
private readonly config : EntityTableConfig < RuleChain > = new EntityTableConfig < RuleChain > ( ) ;
private readonly config : EntityTableConfig < RuleChain > = new EntityTableConfig < RuleChain > ( ) ;
private edgeId : string ;
private edge : Edge ;
private edge : Edge ;
constructor ( private ruleChainService : RuleChainService ,
constructor ( private ruleChainService : RuleChainService ,
@ -75,11 +74,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
new EntityTableColumn < RuleChain > ( 'name' , 'rulechain.name' , '100%' ) ,
new EntityTableColumn < RuleChain > ( 'name' , 'rulechain.name' , '100%' ) ,
new EntityTableColumn < RuleChain > ( 'root' , 'rulechain.root' , '60px' ,
new EntityTableColumn < RuleChain > ( 'root' , 'rulechain.root' , '60px' ,
entity = > {
entity = > {
if ( isDefined ( this . edgeId ) && this . edgeId != null ) {
if ( isDefined ( this . config . componentsData . edgeId ) ) {
return checkBoxCell ( ( this . edge . rootRuleChainId . id == entity . id . id ) ) ;
return checkBoxCell ( ( this . config . componentsData . edge . rootRuleChainId . id == entity . id . id ) ) ;
} else {
} else {
return checkBoxCell ( entity . root ) ;
return checkBoxCell ( entity . root ) ;
}
}
} )
} )
) ;
) ;
this . config . deleteEntityTitle = ruleChain = > this . translate . instant ( 'rulechain.delete-rulechain-title' ,
this . config . deleteEntityTitle = ruleChain = > this . translate . instant ( 'rulechain.delete-rulechain-title' ,
@ -91,23 +90,26 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this . config . saveEntity = ruleChain = > this . saveRuleChain ( ruleChain ) ;
this . config . saveEntity = ruleChain = > this . saveRuleChain ( ruleChain ) ;
this . config . deleteEntity = id = > this . ruleChainService . deleteRuleChain ( id . id ) ;
this . config . deleteEntity = id = > this . ruleChainService . deleteRuleChain ( id . id ) ;
this . config . onEntityAction = action = > this . onRuleChainAction ( action ) ;
this . config . onEntityAction = action = > this . onRuleChainAction ( action ) ;
this . config . deleteEnabled = ( ruleChain ) = > ruleChain && ! ruleChain . root && ! this . edgeId ;
this . config . entitySelectionEnabled = ( ruleChain ) = > {
if ( isDefined ( this . edgeId ) && this . edgeId != null ) {
return this . edge . rootRuleChainId . id != ruleChain . id . id ;
} else {
return ruleChain && ! ruleChain . root ;
}
}
}
}
resolve ( route : ActivatedRouteSnapshot ) : EntityTableConfig < RuleChain > {
resolve ( route : ActivatedRouteSnapshot ) : EntityTableConfig < RuleChain > {
const routeParams = route . params ;
const routeParams = route . params ;
this . config . componentsData = {
this . config . componentsData = {
ruleChainScope : route.data.ruleChainSco pe ,
ruleChainScope : route.data.ruleChainsType ,
type : route . data . type
edgeId : routeParams.edgeId
} ;
} ;
this . edgeId = routeParams . edgeId ;
if ( this . config . componentsData . edgeId ) {
this . config . entitySelectionEnabled = ruleChain = > this . config . componentsData . edge . rootRuleChainId . id != ruleChain . id . id ;
this . config . deleteEnabled = ( ) = > false ;
this . edgeService . getEdge ( this . config . componentsData . edgeId ) . subscribe ( edge = > {
this . config . componentsData . edge = edge ;
this . config . tableTitle = edge . name + ': ' + this . translate . instant ( 'rulechain.edge-rulechains' ) ;
} ) ;
}
else {
this . config . entitySelectionEnabled = ruleChain = > ruleChain && ! ruleChain . root ;
this . config . deleteEnabled = ( ruleChain ) = > ruleChain && ! ruleChain . root ;
}
this . configureEntityFunctions ( this . config . componentsData . ruleChainScope ) ;
this . configureEntityFunctions ( this . config . componentsData . ruleChainScope ) ;
this . config . groupActionDescriptors = this . configureGroupActions ( this . config . componentsData . ruleChainScope ) ;
this . config . groupActionDescriptors = this . configureGroupActions ( this . config . componentsData . ruleChainScope ) ;
this . config . addActionDescriptors = this . configureAddActions ( this . config . componentsData . ruleChainScope ) ;
this . config . addActionDescriptors = this . configureAddActions ( this . config . componentsData . ruleChainScope ) ;
@ -154,14 +156,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this . config . tableTitle = this . translate . instant ( 'rulechain.edge-rulechains' ) ;
this . config . tableTitle = this . translate . instant ( 'rulechain.edge-rulechains' ) ;
this . config . entitiesFetchFunction = pageLink = > this . fetchEdgeRuleChains ( pageLink ) ;
this . config . entitiesFetchFunction = pageLink = > this . fetchEdgeRuleChains ( pageLink ) ;
} else if ( ruleChainScope === 'edge' ) {
} else if ( ruleChainScope === 'edge' ) {
if ( isDefined ( this . edgeId ) && this . edgeId != null ) {
this . config . entitiesFetchFunction = pageLink = > this . ruleChainService . getEdgeRuleChains ( this . config . componentsData . edgeId , pageLink ) ;
this . edgeService . getEdge ( this . edgeId )
. pipe ( map ( edge = > {
this . edge = edge ;
this . config . tableTitle = edge . name + ': ' + this . translate . instant ( 'rulechain.edge-rulechains' )
} ) ) . subscribe ( ) ;
}
this . config . entitiesFetchFunction = pageLink = > this . ruleChainService . getEdgeRuleChains ( this . edgeId , pageLink ) ;
}
}
}
}
@ -241,7 +236,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
{
{
name : this.translate.instant ( 'edge.unassign-from-edge' ) ,
name : this.translate.instant ( 'edge.unassign-from-edge' ) ,
icon : 'portable_wifi_off' ,
icon : 'portable_wifi_off' ,
isEnabled : ( entity ) = > entity . id . id != this . edge . rootRuleChainId . id ,
isEnabled : ( entity ) = > entity . id . id != this . config . componentsData . edge . rootRuleChainId . id ,
onAction : ( $event , entity ) = > this . unassignFromEdge ( $event , entity )
onAction : ( $event , entity ) = > this . unassignFromEdge ( $event , entity )
}
}
)
)
@ -298,10 +293,10 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
true
true
) . subscribe ( ( res ) = > {
) . subscribe ( ( res ) = > {
if ( res ) {
if ( res ) {
if ( isDefined ( this . edgeId ) && this . edgeId != null ) {
if ( this . config . componentsData . edgeId ) {
this . edgeService . setRootRuleChain ( this . edgeId , ruleChain . id . id ) . subscribe (
this . edgeService . setRootRuleChain ( this . config . componentsData . edgeId , ruleChain . id . id ) . subscribe (
( edge ) = > {
( edge ) = > {
this . edge = edge ;
this . config . componentsData . edge = edge ;
this . config . table . updateData ( ) ;
this . config . table . updateData ( ) ;
}
}
)
)
@ -363,7 +358,7 @@ export class RuleChainsTableConfigResolver 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.RULE_CHAIN
entityType : EntityType.RULE_CHAIN
}
}
} ) . afterClosed ( )
} ) . afterClosed ( )
@ -387,7 +382,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
true
true
) . subscribe ( ( res ) = > {
) . subscribe ( ( res ) = > {
if ( res ) {
if ( res ) {
this . ruleChainService . unassignRuleChainFromEdge ( this . edgeId , ruleChain . id . id ) . subscribe (
this . ruleChainService . unassignRuleChainFromEdge ( this . config . componentsData . edgeId , ruleChain . id . id ) . subscribe (
( ) = > {
( ) = > {
this . config . table . updateData ( ) ;
this . config . table . updateData ( ) ;
}
}
@ -470,8 +465,8 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
}
}
isNonRootRuleChain ( ruleChain : RuleChain ) {
isNonRootRuleChain ( ruleChain : RuleChain ) {
if ( isDefined ( this . edgeId ) && this . edgeId != null ) {
if ( this . config . componentsData . edgeId ) {
return ( isDefined ( this . edge . rootRuleChainId ) && this . edge . rootRuleChainId != null && this . edge . rootRuleChainId . id != ruleChain . id . id ) ;
return ( isDefined ( this . config . componentsData . edge . rootRuleChainId ) && this . config . componentsData . edge . rootRuleChainId != null && this . config . componentsData . edge . rootRuleChainId . id != ruleChain . id . id ) ;
}
}
return ( isDefined ( ruleChain ) ) && ! ruleChain . root ;
return ( isDefined ( ruleChain ) ) && ! ruleChain . root ;
}
}
@ -490,21 +485,16 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
fetchEdgeRuleChains ( pageLink : PageLink ) {
fetchEdgeRuleChains ( pageLink : PageLink ) {
let defaultEdgeRuleChainIds : Array < string > = [ ] ;
let defaultEdgeRuleChainIds : Array < string > = [ ] ;
this . ruleChainService . getDefaultEdgeRuleChains ( ) . pipe (
this . ruleChainService . getDefaultEdgeRuleChains ( ) . subscribe ( ruleChains = > {
map ( ruleChains = >
ruleChains . map ( ruleChain = > defaultEdgeRuleChainIds . push ( ruleChain . id . id ) )
ruleChains . map ( ruleChain = >
} ) ;
defaultEdgeRuleChainIds . push ( ruleChain . id . id )
)
)
) . subscribe ( ) ;
return this . ruleChainService . getRuleChains ( pageLink , ruleChainType . edge ) . pipe (
return this . ruleChainService . getRuleChains ( pageLink , ruleChainType . edge ) . pipe (
map ( ( response ) = > {
map ( response = > {
response . data . map ( ruleChain = >
response . data . map ( ruleChain = >
ruleChain . isDefault = defaultEdgeRuleChainIds . some ( id = > ruleChain . id . id . includes ( id ) )
ruleChain . isDefault = defaultEdgeRuleChainIds . some ( id = > ruleChain . id . id . includes ( id ) )
) ;
) ;
return response ;
return response ;
} )
} )
) ;
) ;
}
}
}
}