Merge "Refactoring data-provider:provider generateDTOs"
[ccsdk/features.git] / sdnr / wt / odlux / apps / performanceHistoryApp / src / handlers / performanceHistoryRootHandler.ts
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 // main state handler
19
20 import { combineActionHandler } from '../../../../framework/src/flux/middleware';
21
22 // ** do not remove **
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
24 import { IActionHandler } from '../../../../framework/src/flux/action';
25
26 import { IConnectAppStoreState } from '../../../connectApp/src/handlers/connectAppRootHandler';
27 import { IPerformanceDataState, performanceDataActionHandler } from './performanceDataHandler';
28 import { IReceiveLevelState, receiveLevelActionHandler } from './receiveLevelHandler';
29 import { ITransmissionPowerState, transmissionPowerActionHandler } from './transmissionPowerHandler';
30 import { IAdaptiveModulationState, adaptiveModulationActionHandler } from './adaptiveModulationHandler';
31 import { ITemperatureState, temperatureActionHandler } from './temperatureHandler';
32 import { ISignalToInterferenceState, signalToInterferenceActionHandler } from './signalToInterferenceHandler';
33 import { ICrossPolarDiscriminationState, crossPolarDiscriminationActionHandler } from './crossPolarDiscriminationHandler';
34 import { SetPanelAction } from '../actions/panelChangeActions';
35 import { IDeviceListState, deviceListActionHandler } from './deviceListActionHandler';
36 import { IAvailableLtpsState, availableLtpsActionHandler } from './availableLtpsActionHandler';
37 import { PmDataInterval } from '../models/performanceDataType';
38 import { TimeChangeAction } from '../actions/timeChangeAction';
39 import { UpdateMountId } from '../actions/deviceListActions';
40 import { SetSubViewAction, ResetAllSubViewsAction, SetFilterVisibility } from '../actions/toggleActions';
41 import { SubTabType, currentViewType } from '../models/toggleDataType';
42
43 export interface IPerformanceHistoryStoreState {
44   nodeId: string;
45   networkElements: IDeviceListState;
46   ltps: IAvailableLtpsState;
47   performanceData: IPerformanceDataState;
48   receiveLevel: IReceiveLevelState;
49   transmissionPower: ITransmissionPowerState;
50   adaptiveModulation: IAdaptiveModulationState;
51   temperature: ITemperatureState;
52   signalToInterference: ISignalToInterferenceState;
53   crossPolarDiscrimination: ICrossPolarDiscriminationState;
54   currentOpenPanel: string | null;
55   pmDataIntervalType: PmDataInterval;
56   subViews: toggleViewDataType;
57 }
58
59 const mountIdHandler: IActionHandler<string> = (state = "", action) => {
60   if (action instanceof UpdateMountId) {
61     state = "";
62     if (action.nodeId) {
63       state = action.nodeId;
64     }
65   }
66   return state;
67 }
68
69
70 const currentOpenPanelHandler: IActionHandler<string | null> = (state = null, action) => {
71   if (action instanceof SetPanelAction) {
72     state = action.panelId;
73   }
74   return state;
75 }
76
77 const currentPMDataIntervalHandler: IActionHandler<PmDataInterval> = (state = PmDataInterval.pmInterval15Min, action) => {
78   if (action instanceof TimeChangeAction) {
79     state = action.time;
80   }
81   return state;
82 }
83
84 type filterableSubview = { subView: SubTabType, isFilterVisible: boolean };
85 type toggleViewDataType = { currentSubView: currentViewType, performanceData: filterableSubview, receiveLevel: filterableSubview, transmissionPower: filterableSubview, adaptiveModulation: filterableSubview, temperatur: filterableSubview, SINR: filterableSubview, CPD: filterableSubview };
86
87
88 const toogleViewDataHandler: IActionHandler<toggleViewDataType> = (state = { currentSubView: "performanceData", performanceData: { subView: "chart", isFilterVisible: true }, receiveLevel: { subView: "chart", isFilterVisible: true }, adaptiveModulation: { subView: "chart", isFilterVisible: true }, transmissionPower: { subView: "chart", isFilterVisible: true }, temperatur: { subView: "chart", isFilterVisible: true }, SINR: { subView: "chart", isFilterVisible: true }, CPD: { subView: "chart", isFilterVisible: true } }, action) => {
89
90   if (action instanceof SetSubViewAction) {
91     switch (action.currentView) {
92       case "performanceData": state = { ...state, performanceData: { ...state.performanceData, subView: action.selectedTab } }; break;
93       case "adaptiveModulation": state = { ...state, adaptiveModulation: { ...state.adaptiveModulation, subView: action.selectedTab } }; break;
94       case "receiveLevel": state = { ...state, receiveLevel: { ...state.receiveLevel, subView: action.selectedTab } }; break;
95       case "transmissionPower": state = { ...state, transmissionPower: { ...state.transmissionPower, subView: action.selectedTab } }; break;
96       case "Temp": state = { ...state, temperatur: { ...state.temperatur, subView: action.selectedTab } }; break;
97       case "SINR": state = { ...state, SINR: { ...state.SINR, subView: action.selectedTab } }; break;
98       case "CPD": state = { ...state, CPD: { ...state.CPD, subView: action.selectedTab } }; break;
99     }
100   }
101   else if (action instanceof SetFilterVisibility) {
102     switch (action.currentView) {
103       case "performanceData": state = {
104         ...state, performanceData: { ...state.performanceData, isFilterVisible: action.isVisible }
105       }; break;
106       case "adaptiveModulation": state = { ...state, adaptiveModulation: { ...state.performanceData, isFilterVisible: action.isVisible } }; break;
107       case "receiveLevel": state = { ...state, receiveLevel: { ...state.receiveLevel, isFilterVisible: action.isVisible } }; break;
108       case "transmissionPower": state = { ...state, transmissionPower: { ...state.transmissionPower, isFilterVisible: action.isVisible } }; break;
109       case "Temp": state = { ...state, temperatur: { ...state.temperatur, isFilterVisible: action.isVisible } }; break;
110       case "SINR": state = { ...state, SINR: { ...state.SINR, isFilterVisible: action.isVisible } }; break;
111       case "CPD": state = { ...state, CPD: { ...state.CPD, isFilterVisible: action.isVisible } }; break;
112     }
113
114   } else if (action instanceof ResetAllSubViewsAction) {
115     state = {
116       ...state, performanceData: { ...state.performanceData, subView: "chart" },
117       adaptiveModulation: { ...state.adaptiveModulation, subView: "chart" },
118       receiveLevel: { ...state.receiveLevel, subView: "chart" },
119       transmissionPower: { ...state.transmissionPower, subView: "chart" },
120       temperatur: { ...state.temperatur, subView: "chart" },
121       SINR: { ...state.SINR, subView: "chart" },
122       CPD: { ...state.CPD, subView: "chart" }
123     }
124   }
125
126   return state;
127 }
128
129 declare module '../../../../framework/src/store/applicationStore' {
130   interface IApplicationStoreState {
131     performanceHistory: IPerformanceHistoryStoreState;
132     connect: IConnectAppStoreState;
133   }
134 }
135
136 const actionHandlers = {
137   nodeId: mountIdHandler,
138   networkElements: deviceListActionHandler,
139   ltps: availableLtpsActionHandler,
140   performanceData: performanceDataActionHandler,
141   receiveLevel: receiveLevelActionHandler,
142   transmissionPower: transmissionPowerActionHandler,
143   adaptiveModulation: adaptiveModulationActionHandler,
144   temperature: temperatureActionHandler,
145   signalToInterference: signalToInterferenceActionHandler,
146   crossPolarDiscrimination: crossPolarDiscriminationActionHandler,
147   currentOpenPanel: currentOpenPanelHandler,
148   pmDataIntervalType: currentPMDataIntervalHandler,
149   subViews: toogleViewDataHandler
150 };
151
152 const performanceHistoryRootHandler = combineActionHandler<IPerformanceHistoryStoreState>(actionHandlers);
153 export default performanceHistoryRootHandler;
154