Last active
June 22, 2024 04:25
-
-
Save JenHsuan/d5c02755baebe40533c4dc07d8ef069e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as _ from 'lodash'; | |
import { TopologyAssistantType, TopologyContollerType, TopologyController, TopologyStatusType, topologyControllerAssistantItemsTemplate, topologyControllerGroupingItemsTemplate } from "../topology-controlbar/service/topology-controller.domain"; | |
import { TopologyNodeType } from './topology.domain'; | |
export class TopologyCommand implements TopologyICommand { | |
receiver: TopologyCommandReceiver; | |
statusType: TopologyStatusType; | |
configurationItems = _.cloneDeep( | |
[ | |
...topologyControllerAssistantItemsTemplate | |
]); | |
constructor(receiver: TopologyCommandReceiver, statusType: TopologyStatusType) { | |
this.receiver = receiver; | |
this.statusType = statusType; | |
} | |
get currentConfigurationItem(): TopologyController | undefined { | |
return this.configurationItems.find(item => item.statusType === this.statusType); | |
} | |
get type(): TopologyContollerType | undefined { | |
return this.currentConfigurationItem?.type; | |
} | |
execute() { | |
if (!_.isNil(this.currentConfigurationItem)) { | |
const func = commandMap.get(this.currentConfigurationItem.statusType!); | |
if (!_.isNil(func)) { | |
func(this.currentConfigurationItem, this.receiver); | |
} | |
} | |
} | |
} | |
export interface TopologyCommandReceiver { | |
renderAssistantItems(topologyLegendItem: TopologyController); | |
} | |
export interface TopologyCommandInvoker { | |
setCommandStack(commandStack: TopologyCommand[]); | |
setMakeCommand(makeCommand: (statusType: TopologyStatusType) => TopologyCommand); | |
registerCommand(command: TopologyCommand); | |
removeLatestCommand(); | |
} | |
export interface TopologyICommand { | |
execute(); | |
} | |
export const commandMap = new Map<TopologyStatusType, (topologyLegendItem: TopologyController, receiver: TopologyCommandReceiver) => void>([ | |
[TopologyNodeType.Agggregated, (topologyLegendItem, receiver) => receiver.groupNodes(topologyLegendItem)], | |
[TopologyNodeType.Individual, (topologyLegendItem, receiver) => receiver.groupNodes(topologyLegendItem)] | |
]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment