diff options
author | 2018-08-29 17:01:32 +0300 | |
---|---|---|
committer | 2019-02-18 18:35:30 +0200 | |
commit | 6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch) | |
tree | 936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts | |
parent | 67d99f816cc583643c35193197594cf78d8ce60a (diff) |
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378
Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts')
-rw-r--r-- | vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts new file mode 100644 index 000000000..2923c09b2 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts @@ -0,0 +1,108 @@ +import {Action} from "redux"; +import {VnfGroupInstance} from "../../../models/vnfGroupInstance"; +import * as _ from "lodash"; +import {ServiceInstance} from "../../../models/serviceInstance"; +import {ServiceState} from "../main.reducer"; +import { + CreateVnfGroupInstanceAction, + DeleteActionVnfGroupInstanceAction, SetOptionalMembersVnfGroupInstanceAction, + UpdateVnfGroupInstanceAction, + VnfGroupActions +} from "./vnfGroup.actions"; +import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; + +export function vnfGroupReducer(state: ServiceState, action: Action): ServiceState { + switch (action.type) { + case VnfGroupActions.CREATE_VNF_GROUP_INSTANCE: { + const updateVnfGroupInstanceAction = <CreateVnfGroupInstanceAction>action; + const serviceUuid = updateVnfGroupInstanceAction.serviceUuid; + let vnfGroupModelName = updateVnfGroupInstanceAction.vnfGroupModelName; + let newState = _.cloneDeep(state); + + updateVnfGroupInstanceAction.vnfGroupInstance.originalName = vnfGroupModelName; + updateVnfGroupInstanceAction.vnfGroupModelName = calculateNextUniqueModelName(vnfGroupModelName, serviceUuid, newState, 'vnfGroups'); + + let vnfGroupInstance: VnfGroupInstance = newState.serviceInstance[serviceUuid].vnfGroups[vnfGroupModelName]; + vnfGroupInstance = new VnfGroupInstance(); + updateVnfGroupInstanceAction.vnfGroupInstance.vnfGroupStoreKey = updateVnfGroupInstanceAction.vnfGroupModelName; + updateVnfGroupInstanceAction.vnfGroupInstance.originalName = vnfGroupModelName; + vnfGroupInstance.originalName = updateVnfGroupInstanceAction.vnfGroupInstance.originalName; + vnfGroupInstance.vnfGroupStoreKey = updateVnfGroupInstanceAction.vnfGroupInstance.vnfGroupStoreKey; + updateServiceValidationCounter(newState, vnfGroupInstance['isMissingData'], updateVnfGroupInstanceAction.vnfGroupInstance['isMissingData'], serviceUuid); + + newState.serviceInstance[serviceUuid].vnfGroups[updateVnfGroupInstanceAction.vnfGroupModelName] = Object.assign(vnfGroupInstance, updateVnfGroupInstanceAction.vnfGroupInstance); + return newState; + } + case VnfGroupActions.UPDATE_VNF_GROUP_INSTANCE: { + const updateVnfInstanceAction = <UpdateVnfGroupInstanceAction>action; + const serviceUuid = updateVnfInstanceAction.serviceUuid; + let vnfGroupStoreKey = updateVnfInstanceAction.vnfGroupStoreKey; + + + let newState = _.cloneDeep(state); + let vnfGroupInstance: VnfGroupInstance = newState.serviceInstance[serviceUuid].vnfGroups[vnfGroupStoreKey]; + updateUniqueNames(vnfGroupInstance ? vnfGroupInstance.instanceName : null, updateVnfInstanceAction.vnfGroupInstance.instanceName, newState.serviceInstance[serviceUuid]); + + vnfGroupInstance = vnfGroupInstance || new VnfGroupInstance(); + updateServiceValidationCounter(newState, vnfGroupInstance['isMissingData'], updateVnfInstanceAction.vnfGroupInstance['isMissingData'], serviceUuid); + + newState.serviceInstance[serviceUuid].vnfGroups[vnfGroupStoreKey] = Object.assign(vnfGroupInstance, updateVnfInstanceAction.vnfGroupInstance); + return newState; + } + case VnfGroupActions.DELETE_ACTION_VNF_GROUP_INSTANCE : { + let newState = _.cloneDeep(state); + let oldAction = newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action; + if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState; + newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action = (oldAction + '_Delete') as ServiceInstanceActions; + return newState; + } + case VnfGroupActions.UNDO_DELETE_ACTION_VNF_GROUP_INSTANCE : { + let newState = _.cloneDeep(state); + let oldState = newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action; + newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action = (oldState.split('_')[0]) as ServiceInstanceActions; + return newState; + } + case VnfGroupActions.SET_OPTIONAL_MEMBERS_VNF_GROUP_INSTANCE:{ + let newState = _.cloneDeep(state); + newState.serviceInstance[(<SetOptionalMembersVnfGroupInstanceAction>action).serviceId].optionalGroupMembersMap[(<SetOptionalMembersVnfGroupInstanceAction>action).path] = (<SetOptionalMembersVnfGroupInstanceAction>action).vnfMembers; + return newState; + } + } +} + +const updateServiceValidationCounter = (newState: any, oldValidationState: boolean, newValidationState: boolean, serviceUuid: string) => { + if (oldValidationState && !newValidationState) { + newState.serviceInstance[serviceUuid].validationCounter--; + } else if (!oldValidationState && newValidationState) { + newState.serviceInstance[serviceUuid].validationCounter++; + } +}; + + +const updateUniqueNames = (oldName: string, newName: string, serviceInstance: ServiceInstance): void => { + let existingNames = serviceInstance.existingNames; + if (!_.isNil(oldName) && oldName.toLowerCase() in existingNames) { + delete existingNames[oldName.toLowerCase()]; + } + if (!_.isNil(newName)) { + existingNames[newName.toLowerCase()] = ""; + } +}; + + +export const calculateNextUniqueModelName = (vnfGroupModelName: string, serviceId: string, state: any, levelName: string): string => { + let counter: number = null; + while (true) { + let pattern = !_.isNil(counter) ? ("_" + counter) : ""; + if (!_.isNil(state.serviceInstance[serviceId][levelName][vnfGroupModelName + pattern])) { + counter = counter ? (counter + 1) : 1; + } else { + return vnfGroupModelName + pattern; + } + } +}; + + + + + |