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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 // app configuration and main entry point for the app
20 import React from 'react';
21 import { Redirect, Route, RouteComponentProps, Switch, withRouter } from 'react-router-dom';
23 import { connect, Connect, IDispatcher } from '../../../framework/src/flux/connect';
24 import applicationManager from '../../../framework/src/services/applicationManager';
25 import { IFormatedMessage, subscribe } from '../../../framework/src/services/notificationService';
26 import { IApplicationStoreState } from '../../../framework/src/store/applicationStore';
28 import { AddFaultNotificationAction } from './actions/notificationActions';
29 import { SetPanelAction } from './actions/panelChangeActions';
30 import { refreshFaultStatusAsyncAction, SetFaultStatusAction } from './actions/statusActions';
31 import DashboardHome from './components/dashboardHome';
32 import { FaultStatus } from './components/faultStatus';
33 import { createCurrentAlarmsActions, createCurrentAlarmsProperties, currentAlarmsReloadAction } from './handlers/currentAlarmsHandler';
34 import { faultAppRootHandler } from './handlers/faultAppRootHandler';
35 import { FaultAlarmNotificationWS } from './models/fault';
36 import { PanelId } from './models/panelId';
37 import { FaultApplication } from './views/faultApplication';
39 const appIcon = require('./assets/icons/faultAppIcon.svg'); // select app icon
41 let currentMountId: string | undefined = undefined;
42 let currentSeverity: string | undefined = undefined;
43 let refreshInterval: ReturnType<typeof window.setInterval> | null = null;
45 const mapProps = (state: IApplicationStoreState) => ({
46 currentAlarmsProperties: createCurrentAlarmsProperties(state),
49 const mapDispatch = (dispatcher: IDispatcher) => ({
50 currentAlarmsActions: createCurrentAlarmsActions(dispatcher.dispatch, true),
51 setCurrentPanel: (panelId: PanelId) => dispatcher.dispatch(new SetPanelAction(panelId)),
54 const FaultApplicationRouteAdapter = connect(mapProps, mapDispatch)((props: RouteComponentProps<{ mountId?: string }> & Connect<typeof mapProps, typeof mapDispatch>) => {
55 if (currentMountId !== props.match.params.mountId) {
56 // route parameter has changed
57 currentMountId = props.match.params.mountId || undefined;
58 // Hint: This timeout is need, since it is not recommended to change the state while rendering is in progress !
59 window.setTimeout(() => {
61 props.setCurrentPanel('CurrentAlarms');
62 props.currentAlarmsActions.onFilterChanged('nodeId', currentMountId);
63 if (!props.currentAlarmsProperties.showFilter) {
64 props.currentAlarmsActions.onToggleFilter(false);
65 props.currentAlarmsActions.onRefresh();
67 props.currentAlarmsActions.onRefresh();
76 const FaultApplicationAlarmStatusRouteAdapter = connect(mapProps, mapDispatch)((props: RouteComponentProps<{ severity?: string }> & Connect<typeof mapProps, typeof mapDispatch>) => {
77 if (currentSeverity !== props.match.params.severity) {
78 currentSeverity = props.match.params.severity || undefined;
79 window.setTimeout(() => {
80 if (currentSeverity) {
81 props.setCurrentPanel('CurrentAlarms');
82 props.currentAlarmsActions.onFilterChanged('severity', currentSeverity);
83 if (!props.currentAlarmsProperties.showFilter) {
84 props.currentAlarmsActions.onToggleFilter(false);
85 props.currentAlarmsActions.onRefresh();
87 props.currentAlarmsActions.onRefresh();
96 const App = withRouter((props: RouteComponentProps) => (
98 <Route path={`${props.match.path}/alarmStatus/:severity?`} component={FaultApplicationAlarmStatusRouteAdapter} />
99 <Route path={`${props.match.path}/:mountId?`} component={FaultApplicationRouteAdapter} />
100 <Redirect to={`${props.match.path}`} />
104 export function register() {
105 const applicationApi = applicationManager.registerApplication({
109 rootActionHandler: faultAppRootHandler,
110 statusBarElement: FaultStatus,
111 dashbaordElement: DashboardHome,
116 // subscribe to the websocket notifications
117 subscribe<FaultAlarmNotificationWS & IFormatedMessage>('problem-notification', (fault => {
118 const store = applicationApi && applicationApi.applicationStore;
119 if (fault && store) {
121 store.dispatch(new AddFaultNotificationAction({
122 id: String(counter++),
123 nodeName: fault['node-id'],
124 counter: +fault.data.counter,
125 objectId: fault.data['object-id-ref'],
126 problem: fault.data.problem,
127 severity: fault.data.severity || '',
128 timeStamp: fault.data['time-stamp'],
133 applicationApi.applicationStoreInitialized.then(store => {
134 store.dispatch(currentAlarmsReloadAction);
137 applicationApi.applicationStoreInitialized.then(store => {
138 store.dispatch(refreshFaultStatusAsyncAction);
141 applicationApi.logoutEvent.addHandler(()=>{
143 applicationApi.applicationStoreInitialized.then(store => {
144 store.dispatch(new SetFaultStatusAction(0, 0, 0, 0, false, 0, 0, 0, 0, 0, 0, 0, 0, false));
145 clearInterval(refreshInterval!);
149 function startRefreshInterval() {
150 const refreshFaultStatus = window.setInterval(() => {
151 applicationApi.applicationStoreInitialized.then(store => {
153 store.dispatch(refreshFaultStatusAsyncAction);
157 return refreshFaultStatus;
160 applicationApi.loginEvent.addHandler(()=>{
161 if (refreshInterval) {
162 clearInterval(refreshInterval);
164 refreshInterval = startRefreshInterval() as any;
167 applicationApi.logoutEvent.addHandler(()=>{
168 refreshInterval && window.clearInterval(refreshInterval);
169 refreshInterval = null;