aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/storeUtil/utils/relatedVnfMember/relatedVnfMember.reducers.ts
blob: 250f934be9121869161ac394083738b6e98c2aa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {Action} from "redux";
import * as _ from "lodash";
import {ServiceState} from "../main.reducer";
import {ServiceInstanceActions} from "../../../models/serviceInstanceActions";
import {
  CreateRelatedVnfMemeberInstanceAction,
  DeleteActionRelatedVnfMemeberInstanceAction, DeleteRelatedVnfMemebrInstanceAction,
  RelatedVnfActions,
  UndoDeleteActionRelatedVnfMemeberInstanceAction
} from "./relatedVnfMember.actions";

export function relatedVnfMemeberReducer(state: ServiceState, action: Action): ServiceState {
  switch (action.type) {

    case RelatedVnfActions.DELETE_ACTION_RELATED_VNF_MEMBER_INSTANCE : {
      let newState = _.cloneDeep(state);
      let relatedVnfMember = newState.serviceInstance[(<DeleteActionRelatedVnfMemeberInstanceAction>action).serviceId].vnfGroups[(<DeleteActionRelatedVnfMemeberInstanceAction>action).vnfGroupStoreKey]['vnfs'][(<DeleteActionRelatedVnfMemeberInstanceAction>action).relatedVnfMemeberStoreKey];
      let oldAction = relatedVnfMember.action;
      if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState;
      newState.serviceInstance[(<DeleteActionRelatedVnfMemeberInstanceAction>action).serviceId].vnfGroups[(<DeleteActionRelatedVnfMemeberInstanceAction>action).vnfGroupStoreKey]['vnfs'][(<DeleteActionRelatedVnfMemeberInstanceAction>action).relatedVnfMemeberStoreKey].action = (oldAction + '_Delete') as ServiceInstanceActions;
      return newState;
    }

    case RelatedVnfActions.UNDO_DELETE_ACTION_RELATED_VNF_MEMBER_INSTANCE : {
      let newState = _.cloneDeep(state);
      let relatedVnfMember = newState.serviceInstance[(<UndoDeleteActionRelatedVnfMemeberInstanceAction>action).serviceId].vnfGroups[(<UndoDeleteActionRelatedVnfMemeberInstanceAction>action).vnfGroupStoreKey]['vnfs'][(<UndoDeleteActionRelatedVnfMemeberInstanceAction>action).relatedVnfMemeberStoreKey];
      let oldState = relatedVnfMember.action;
      newState.serviceInstance[(<DeleteActionRelatedVnfMemeberInstanceAction>action).serviceId].vnfGroups[(<DeleteActionRelatedVnfMemeberInstanceAction>action).vnfGroupStoreKey]['vnfs'][(<DeleteActionRelatedVnfMemeberInstanceAction>action).relatedVnfMemeberStoreKey].action = (oldState.split('_')[0]) as ServiceInstanceActions;
      return newState;
    }

    case RelatedVnfActions.REMOVE_RELATED_VNF_MEMBER_INSTANCE : {
      let newState = _.cloneDeep(state);
      delete newState.serviceInstance[(<DeleteRelatedVnfMemebrInstanceAction>action).serviceId].vnfGroups[(<DeleteRelatedVnfMemebrInstanceAction>action).vnfGroupStoreKey]['vnfs'][(<DeleteRelatedVnfMemebrInstanceAction>action).relatedVnfMemeberStoreKey];
      return newState;
    }

    case RelatedVnfActions.CREATE_RELATED_VNF_MEMBER_INSTANCE : {
      let newState = _.cloneDeep(state);
      let relatedVnfMember = (<CreateRelatedVnfMemeberInstanceAction>action).relatedVnfMember;
      relatedVnfMember['action'] = 'Create';
      relatedVnfMember['vnfStoreKey'] = relatedVnfMember.instanceId;
      relatedVnfMember['trackById'] = relatedVnfMember.instanceId;
      relatedVnfMember['instanceName'] = relatedVnfMember.instanceName;
      if(_.isNil(newState.serviceInstance[(<CreateRelatedVnfMemeberInstanceAction>action).serviceId].vnfGroups[(<CreateRelatedVnfMemeberInstanceAction>action).vnfGroupStoreKey]['vnfs'])){
        newState.serviceInstance[(<CreateRelatedVnfMemeberInstanceAction>action).serviceId].vnfGroups[(<CreateRelatedVnfMemeberInstanceAction>action).vnfGroupStoreKey]['vnfs'] = {};
      }
      newState.serviceInstance[(<CreateRelatedVnfMemeberInstanceAction>action).serviceId].vnfGroups[(<CreateRelatedVnfMemeberInstanceAction>action).vnfGroupStoreKey]['vnfs'][(<CreateRelatedVnfMemeberInstanceAction>action).relatedVnfMember['instanceId']] = relatedVnfMember;
      newState.serviceInstance[(<CreateRelatedVnfMemeberInstanceAction>action).serviceId].isDirty = true;
      return newState;
    }
  }
}