@ -40,11 +40,6 @@ export interface MenuReference {
pages? : Array < MenuReference > ;
}
export interface HomeSectionReference {
name : string ;
places : Array < MenuId > ;
}
export interface HomeSection {
name : string ;
places : Array < MenuSection > ;
@ -1064,107 +1059,14 @@ const defaultUserMenuMap = new Map<Authority, MenuReference[]>([
]
] ) ;
const defaultHomeSectionMap = new Map < Authority , HomeSectionReference [ ] > ( [
[
Authority . SYS_ADMIN ,
[
{
name : 'tenant.management' ,
places : [ MenuId . tenants , MenuId . tenant_profiles ]
} ,
{
name : 'widget.management' ,
places : [ MenuId . widget_library ]
} ,
{
name : 'admin.system-settings' ,
places : [ MenuId . general , MenuId . mail_server ,
MenuId . notification_settings , MenuId . security_settings , MenuId . oauth2 , MenuId . domains ,
MenuId . clients , MenuId . two_fa , MenuId . resources_library , MenuId . queues ]
}
]
] ,
[
Authority . TENANT_ADMIN ,
[
{
name : 'rulechain.management' ,
places : [ MenuId . rule_chains ]
} ,
{
name : 'customer.management' ,
places : [ MenuId . customers ]
} ,
{
name : 'asset.management' ,
places : [ MenuId . assets , MenuId . asset_profiles ]
} ,
{
name : 'device.management' ,
places : [ MenuId . devices , MenuId . device_profiles , MenuId . otaUpdates ]
} ,
{
name : 'entity-view.management' ,
places : [ MenuId . entity_views ]
} ,
{
name : 'edge.management' ,
places : [ MenuId . edges , MenuId . rulechain_templates ]
} ,
{
name : 'dashboard.management' ,
places : [ MenuId . widget_library , MenuId . dashboards ]
} ,
{
name : 'version-control.management' ,
places : [ MenuId . version_control ]
} ,
{
name : 'audit-log.audit' ,
places : [ MenuId . audit_log , MenuId . api_usage ]
} ,
{
name : 'admin.system-settings' ,
places : [ MenuId . home_settings , MenuId . resources_library , MenuId . repository_settings , MenuId . auto_commit_settings , MenuId . trendz_settings ]
}
]
] ,
[
Authority . CUSTOMER_USER ,
[
{
name : 'asset.view-assets' ,
places : [ MenuId . assets ]
} ,
{
name : 'device.view-devices' ,
places : [ MenuId . devices ]
} ,
{
name : 'entity-view.management' ,
places : [ MenuId . entity_views ]
} ,
{
name : 'edge.management' ,
places : [ MenuId . edge_instances ]
} ,
{
name : 'dashboard.view-dashboards' ,
places : [ MenuId . dashboards ]
}
]
]
] ) ;
export const buildUserMenu = ( authState : AuthState ) : Array < MenuSection > = > {
const references = defaultUserMenuMap . get ( authState . authUser . authority ) ;
return ( references || [ ] ) . map ( ref = > referenceToMenuSection ( authState , ref ) ) . filter ( section = > ! ! section ) ;
} ;
export const buildUserHome = ( authState : AuthState , availableMenuSections : MenuSection [ ] ) : Array < HomeSection > = > {
const references = defaultHomeSectionMap . get ( authState . authUser . authority ) ;
return ( references || [ ] ) . map ( ref = >
homeReferenceToHomeSection ( availableMenuSections , ref ) ) . filter ( section = > ! ! section ) ;
export const buildUserHome = ( currentMenuSections : MenuSection [ ] ) : Array < HomeSection > = > {
return ( currentMenuSections || [ ] ) . map ( section = >
menuSectionToHomeSection ( section ) ) . filter ( section = > ! ! section ) ;
} ;
const referenceToMenuSection = ( authState : AuthState , reference : MenuReference ) : MenuSection | undefined = > {
@ -1202,14 +1104,18 @@ const filterMenuReference = (authState: AuthState, reference: MenuReference): bo
}
} ;
const homeReferenceToHomeSection = ( availableMenuSections : MenuSection [ ] , reference : HomeSectionReference ) : HomeSection | undefined = > {
const places = reference . places . map ( id = > availableMenuSections . find ( m = > m . id === id ) ) . filter ( p = > ! ! p ) ;
if ( places . length ) {
return {
name : reference.name ,
places
} ;
} else {
return undefined ;
const menuSectionToHomeSection = ( section : MenuSection ) : HomeSection = > {
if ( section . id !== MenuId . home ) {
if ( section . type === 'link' ) {
return {
name : section.name ,
places : [ section ]
}
} else if ( section . type === 'toggle' && section . pages ? . length ) {
return {
name : section.name ,
places : section.pages
} ;
}
}
} ;
}