From 6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Wed, 29 Aug 2018 17:01:32 +0300 Subject: merge from ecomp a88f0072 - Modern UI Issue-ID: VID-378 Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6 Signed-off-by: Ittay Stern --- .../storeUtil/utils/general/general.reducers.ts | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts') diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts new file mode 100644 index 000000000..8ee47331f --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts @@ -0,0 +1,147 @@ +import {Action} from "redux"; +import { + ChangeInstanceCounterAction, RemoveInstanceAction, DuplicateBulkInstancesAction, + GeneralActions, + UpdateAicZonesAction, UpdateCategoryParametersAction, + UpdateLcpRegionsAndTenantsAction, UpdateNetworkCollectionFunction, + UpdateProductFamiliesAction, UpdateServiceTypesAction, + UpdateSubscribersAction, UpdateUserIdAction +} from "./general.actions"; +import {TypeNodeInformation} from "../../../../drawingBoard/service-planning/typeNodeInformation.model"; +import * as _ from "lodash"; +import {ITreeNode} from "angular-tree-component/dist/defs/api"; +import {ServiceInstance} from "../../../models/serviceInstance"; +import {ServiceState} from "../main.reducer"; + +export function generalReducer(state: ServiceState, action: Action) : ServiceState { + switch (action.type) { + case GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS: { + Object.assign(state, (action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_SUBSCRIBERS: { + Object.assign(state, (action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_AIC_ZONES: { + Object.assign(state, (action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_PRODUCT_FAMILIES: { + Object.assign(state, (action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_NETWORK_FUNCTION: { + const networkFunctionReduxObj = state['networkFunctions'] == undefined ? {} : state['networkFunctions']; + networkFunctionReduxObj[(action).network_function] = (action).networksAccordingToNetworkCollection; + Object.assign(state, {'networkFunctions': networkFunctionReduxObj}); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_SERVICE_TYPES: { + state.serviceTypes[(action).subscriberId] = (action).serviceTypes; + return Object.assign({}, state); + } + case GeneralActions.UPDATE_CATEGORY_PARAMETERS: { + Object.assign(state, (action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_USER_ID: { + const updateUserId: UpdateUserIdAction = action; + let newState = _.cloneDeep(state); + newState['userId'] = updateUserId.userId; + return newState; + } + case GeneralActions.REMOVE_INSTANCE: { + const actionData = (action); + if (state.serviceInstance[actionData.serviceModelId]) { + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(actionData.node); + updateIsMissingDataOnDelete(state, actionData.serviceModelId, actionData.storeKey, actionData.node); + updateUniqueNames(state.serviceInstance[actionData.serviceModelId][typeNodeInformation.hierarchyName][actionData.storeKey].instanceName, null, state.serviceInstance[actionData.serviceModelId]); + if(actionData.node.data.type === 'VF'){ + _.forOwn(state.serviceInstance[actionData.serviceModelId][typeNodeInformation.hierarchyName][actionData.storeKey].vfModules, (vfModuleMap) => { + _.forOwn(vfModuleMap, (vfModuleInstance) => { + updateUniqueNames(vfModuleInstance.instanceName, null, state.serviceInstance[actionData.serviceModelId]); + }) + }); + } + delete state.serviceInstance[actionData.serviceModelId][typeNodeInformation.hierarchyName][actionData.storeKey]; + } + return Object.assign({}, state); + } + + case GeneralActions.CHANGE_INSTANCE_COUNTER : { + const changeInstanceCounterAction = action; + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(changeInstanceCounterAction.node); + let newState = _.cloneDeep(state); + + let existing: number = getExistingCounter(newState, changeInstanceCounterAction.serviceUUID, changeInstanceCounterAction.UUID, typeNodeInformation); + newState.serviceInstance[changeInstanceCounterAction.serviceUUID][typeNodeInformation.existingMappingCounterName][changeInstanceCounterAction.UUID] = existing ? existing + changeInstanceCounterAction.changeBy : changeInstanceCounterAction.changeBy; + return newState; + } + + case GeneralActions.DUPLICATE_BULK_INSTANCES : { + const createInstanceAction = action; + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(createInstanceAction.node); + const serviceId = createInstanceAction.serviceId; + const objects = createInstanceAction.objects; + + let newState = _.cloneDeep(state); + newState.serviceInstance[serviceId].existingNames = createInstanceAction.existingNames; + newState.serviceInstance[serviceId][typeNodeInformation.hierarchyName] = Object.assign({}, newState.serviceInstance[serviceId][typeNodeInformation.hierarchyName], objects); + return newState; + } + } +} + +const getExistingCounter = (state: any, serviceModelId: string, modelId: string, typeNodeInformation : TypeNodeInformation ) : number => { + const serviceExistingCounterMap = state.serviceInstance[serviceModelId][typeNodeInformation.existingMappingCounterName]; + if(serviceExistingCounterMap && !_.isNil(serviceExistingCounterMap[modelId])){ + return serviceExistingCounterMap[modelId]; + }else { + return null; + } +}; + +const updateIsMissingDataOnDelete = (state: any, serviceModelId: string, storeKey: string, node: ITreeNode): void => { + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(node); + let vnf = state.serviceInstance[serviceModelId][typeNodeInformation.hierarchyName][storeKey]; + if(node.children){ + _.forOwn(vnf.vfModules, (vfModules, vfModulesKey) => { + updateIsMissingDataOnDeleteVFModule(state, serviceModelId, storeKey, vfModulesKey); + }); + } + + + let isMissingData: boolean = state.serviceInstance[serviceModelId][typeNodeInformation.hierarchyName][storeKey].isMissingData; + updateServiceValidationCounter(state, isMissingData, false, serviceModelId); +}; + +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()] = ""; + } +}; + +const updateIsMissingDataOnDeleteVFModule = (state: any, serviceModelId: string, vnfStoreKey: string, vfModuleName): void => { + const vfModules = state.serviceInstance[serviceModelId].vnfs[vnfStoreKey].vfModules[vfModuleName]; + + _.forOwn(vfModules, (vfModuleInstance) => { + let isMissingData: boolean = vfModuleInstance.isMissingData; + updateServiceValidationCounter(state, isMissingData, false, serviceModelId); + }); +}; + +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++; + } +}; + + + -- cgit 1.2.3-korg