Skip to content

Commit

Permalink
Refactor displayTabsForNode
Browse files Browse the repository at this point in the history
  • Loading branch information
wkramer committed Nov 8, 2024
1 parent 9200d78 commit 3699afd
Showing 1 changed file with 84 additions and 96 deletions.
180 changes: 84 additions & 96 deletions src/lib/topology/displayTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,109 +2,97 @@ import { TopologyNode } from '@deltares/fews-pi-requests'
import { RouteLocationNamedRaw } from 'vue-router'

export interface DisplayTab {
type:
| 'charts'
| 'map'
| 'reports'
| 'schematic-status-display'
type: 'charts' | 'map' | 'reports' | 'schematic-status-display'
id: string
title: string
href?: string
target?: string
to: RouteLocationNamedRaw
icon: string
active: boolean
}

export function displayTabsForNode(leafNode: TopologyNode, parentNodeId?: string) {
const activeNodeId = leafNode.id
const timeseriesTabId = `${activeNodeId}-timeseries`
const reportsTabId = `${activeNodeId}-reports`
const spatialTabId = `${activeNodeId}-spatial`
const ssdTabId = `${activeNodeId}-ssd`
const _displayTabs: DisplayTab[] = []
if (
leafNode.gridDisplaySelection !== undefined ||
leafNode.filterIds !== undefined
) {
_displayTabs.push({
type: 'map',
id: spatialTabId,
title: 'Map',
to: {
name: 'TopologySpatialDisplay',
params: {
nodeId: parentNodeId ? [parentNodeId, leafNode.id] : leafNode.id,
layerName: leafNode.gridDisplaySelection?.plotId,
},
},
icon: 'mdi-map',
})
}
if (
leafNode.displayGroups !== undefined ||
leafNode.displayId !== undefined ||
(leafNode.plotId != undefined && leafNode.locationIds != undefined)
) {
_displayTabs.push({
type: 'charts',
id: timeseriesTabId,
title: 'Charts',
to: {
name: 'TopologyTimeSeries',
params: {
nodeId: parentNodeId ? [parentNodeId, leafNode.id] : leafNode.id,
},
},
icon: 'mdi-chart-multiple',
})
}
if (
leafNode.filterIds !== undefined &&
leafNode.filterIds.length == 1 &&
leafNode.dataDownloadDisplay !== undefined
) {
_displayTabs.push({
type: 'charts',
id: timeseriesTabId,
title: 'Download',
to: {
name: 'TopologyDataDownload',
params: {
nodeId: parentNodeId ? [parentNodeId, leafNode.id] : leafNode.id,
},
},
icon: 'mdi-download',
})
}
if (leafNode.reportDisplay?.reports.length) {
_displayTabs.push({
type: 'reports',
id: reportsTabId,
title: 'Reports',
to: {
name: 'TopologyReports',
params: {
nodeId: parentNodeId ? [parentNodeId, leafNode.id] : leafNode.id,
},
},
icon: 'mdi-file-document',
})
}
if (leafNode.scadaPanelId !== undefined) {
_displayTabs.push({
type: 'schematic-status-display',
id: ssdTabId,
title: 'Schematic',
to: {
name: 'TopologySchematicStatusDisplay',
params: {
nodeId: parentNodeId ? [parentNodeId, leafNode.id] : leafNode.id,
panelId: leafNode.scadaPanelId,
},
},
icon: 'mdi-view-dashboard',
})
}
return _displayTabs
const displayTabs: DisplayTab[] = [
{
type: 'charts',
id: 'timeseries',
title: 'Charts',
to: { name: 'TopologyTimeSeries' },
icon: 'mdi-chart-multiple',
active: false,
},
{
type: 'map',
id: 'spatial',
title: 'Map',
to: { name: 'TopologySpatialDisplay' },
icon: 'mdi-map',
active: false,
},
{
type: 'reports',
id: 'reports',
title: 'Reports',
to: { name: 'TopologyReports' },
icon: 'mdi-file-document',
active: false,
},
{
type: 'schematic-status-display',
id: 'ssd',
title: 'Schematic',
to: { name: 'TopologySchematicStatusDisplay' },
icon: 'mdi-view-dashboard',
active: false,
},
]



function nodeHasMap(node: TopologyNode) {
return node.gridDisplaySelection !== undefined || node.filterIds !== undefined
}

function nodeHasCharts(node: TopologyNode) {
return (
node.displayGroups !== undefined ||
node.displayId !== undefined ||
(node.plotId != undefined && node.locationIds != undefined)
)
}

function nodeHasReports(node: TopologyNode) {
return node.reportDisplay?.reports !== undefined
}

function nodeHasSchematicStatusDisplay(node: TopologyNode) {
return node.scadaPanelId !== undefined
}

export function displayTabsForNode(node: TopologyNode, parentNodeId?: string) {
for (const tab of displayTabs) {
const params = {
nodeId: parentNodeId ? [parentNodeId, node.id] : node.id,
}
switch (tab.type) {
case 'map':
tab.active = nodeHasMap(node)
tab.to.params = { ...params, LayerName: node.gridDisplaySelection?.plotId,
}
break
case 'charts':
tab.active = nodeHasCharts(node)
tab.to.params = { ...params }
break
case 'reports':
tab.active = nodeHasReports(node)
tab.to.params = { ...params }
break
case 'schematic-status-display':
tab.active = nodeHasSchematicStatusDisplay(node)
tab.to.params = { ...params, panelId: node.scadaPanelId }
break
}
}
return displayTabs.filter((tab) => tab.active)
}

0 comments on commit 3699afd

Please sign in to comment.