Add dashboard to odlux
[ccsdk/features.git] / sdnr / wt / odlux / apps / connectApp / src / actions / connectionStatusCountActions.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 import { getConnectionStatusCountStateFromDatabase } from '../services/connectionStatusCountService';
19 import { Dispatch } from '../../../../framework/src/flux/store';
20
21 import { Action } from '../../../../framework/src/flux/action';
22
23
24 export class ConnectionStatusCountBaseAction extends Action { }
25
26
27 export class SetConnectionStatusCountAction extends ConnectionStatusCountBaseAction {
28   constructor(public ConnectedCount: number, public ConnectingCount: number, public DisconnectedCount: number,
29     public MountedCount: number, public UnableToConnectCount: number, public UndefinedCount: number, public UnmountedCount: number, public totalCount: number) {
30     super();
31   }
32 }
33
34
35 export const refreshConnectionStatusCountAsyncAction = async (dispatch: Dispatch) => {
36   const result = await getConnectionStatusCountStateFromDatabase().catch(_ => null);
37   if (result) {
38     const statusAction = new SetConnectionStatusCountAction(
39       result["Connected"] || 0,
40       result["Connecting"] || 0,
41       result["Disconnected"] || 0,
42       result["Mounted"] || 0,
43       result["UnableToConnect"] || 0,
44       result["Undefined"] || 0,
45       result["Unmounted"] || 0,
46       result["total"] || 0
47     );
48     dispatch(statusAction);
49     return;
50   }
51   dispatch(new SetConnectionStatusCountAction(0, 0, 0, 0, 0, 0, 0, 0));
52 }