Update ODLUX
[ccsdk/features.git] / sdnr / wt / odlux / apps / connectApp / src / pluginConnect.tsx
index f711c44..1990cc0 100644 (file)
  * ============LICENSE_END==========================================================================
  */
 
+import * as React from "react";
+import { withRouter, RouteComponentProps, Route, Switch, Redirect } from 'react-router-dom';
 import { faPlug } from '@fortawesome/free-solid-svg-icons';
 
 import applicationManager from '../../../framework/src/services/applicationManager';
 import { subscribe, IFormatedMessage } from '../../../framework/src/services/notificationService';
+import { AddSnackbarNotification } from '../../../framework/src/actions/snackbarActions';
+import { IApplicationStoreState } from "../../../framework/src/store/applicationStore";
+import connect, { Connect, IDispatcher } from '../../../framework/src/flux/connect';
 
+import { findWebUrisForGuiCutThroughAsyncAction, updateCurrentViewAsyncAction, SetPanelAction } from './actions/commonNetworkElementsActions';
+import { refreshConnectionStatusCountAsyncAction } from './actions/connectionStatusCountActions';
+import { createNetworkElementsActions, createNetworkElementsProperties, networkElementsReloadAction } from './handlers/networkElementsHandler';
 import connectAppRootHandler from './handlers/connectAppRootHandler';
 import ConnectApplication from './views/connectView';
+import { PanelId } from "./models/panelId";
+import { NetworkElementsList } from './components/networkElements'
+
+let currentStatus: string | undefined = undefined;
+
+const mapProps = (state: IApplicationStoreState) => ({
+  currentProblemsProperties: createNetworkElementsProperties(state),
+});
+
+const mapDisp = (dispatcher: IDispatcher) => ({
+  currentProblemsActions: createNetworkElementsActions(dispatcher.dispatch, true),
+  setCurrentPanel: (panelId: PanelId) => dispatcher.dispatch(new SetPanelAction(panelId)),
+});
+
+const ConnectApplicationRouteAdapter = connect(mapProps, mapDisp)((props: RouteComponentProps<{ status?: string }> & Connect<typeof mapProps, typeof mapDisp>) => {
+  if (currentStatus !== props.match.params.status) {
+    currentStatus = props.match.params.status || undefined;
+    window.setTimeout(() => {
+      if (currentStatus) {
+        props.setCurrentPanel("NetworkElements");
+        props.currentProblemsActions.onFilterChanged("status", currentStatus);
+        if (!props.currentProblemsProperties.showFilter) {
+          props.currentProblemsActions.onToggleFilter(false);
+          props.currentProblemsActions.onRefresh();
+        }
+        else
+          props.currentProblemsActions.onRefresh();
+      }
+    });
+  }
+  return (
+    <NetworkElementsList />
+  )
+});
 
-import { AddSnackbarNotification } from '../../../framework/src/actions/snackbarActions';
-import { updateCurrentViewAsyncAction } from './actions/commonNetworkElementsActions';
 
-type ObjectNotification = {
-  counter: string;
-  nodeName: string;
-  objectId: string;
-  timeStamp: string;
-}
+const App = withRouter((props: RouteComponentProps) => (
+  <Switch>
+    <Route path={`${props.match.path}/connectionStatus/:status?`} component={ConnectApplicationRouteAdapter} />
+    <Route path={`${props.match.path}`} component={ConnectApplication} />
+    <Redirect to={`${props.match.path}`} />
+  </Switch>
+));
 
 export function register() {
   const applicationApi = applicationManager.registerApplication({
     name: "connect",
     icon: faPlug,
-    rootComponent: ConnectApplication,
+    rootComponent: App,
     rootActionHandler: connectAppRootHandler,
     menuEntry: "Connect"
   });
 
   // subscribe to the websocket notifications
-  subscribe<ObjectNotification & IFormatedMessage>(["ObjectCreationNotification", "ObjectDeletionNotification", "AttributeValueChangedNotification"], (msg => {
+  subscribe<IFormatedMessage>(["object-creation-notification", "object-deletion-notification", "attribute-value-changed-notification"], (msg => {
     const store = applicationApi.applicationStore;
-    if (msg && msg.notifType === "ObjectCreationNotification" && store) {
-      store.dispatch(new AddSnackbarNotification({ message: `Adding network element [${msg.objectId}]`, options: { variant: 'info' } }));
-    } else if (msg && (msg.notifType === "ObjectDeletionNotification" || msg.notifType === "AttributeValueChangedNotification") && store) {
-      store.dispatch(new AddSnackbarNotification({ message: `Updating network element [${msg.objectId}]`, options: { variant: 'info' } }));
+    if (msg && msg.type.type === "object-creation-notification" && store) {
+      store.dispatch(new AddSnackbarNotification({ message: `Adding network element [${msg.data['object-id-ref']}]`, options: { variant: 'info' } }));
+    } else if (msg && (msg.type.type === "object-deletion-notification" || msg.type.type === "attribute-value-changed-notification") && store) {
+      store.dispatch(new AddSnackbarNotification({ message: `Updating network element [${msg.data['object-id-ref']}]`, options: { variant: 'info' } }));
+    }
+    if (store) {
+      store.dispatch(updateCurrentViewAsyncAction() as any).then(() => {
+        if (msg['node-id']) {
+          store.dispatch(findWebUrisForGuiCutThroughAsyncAction([msg['node-id']]));
+        }
+      });
     }
-    store && store.dispatch(updateCurrentViewAsyncAction());
   }));
+
+  applicationApi.applicationStoreInitialized.then(store => {
+    store.dispatch(networkElementsReloadAction);
+  });
+
+  applicationApi.applicationStoreInitialized.then(store => {
+    store.dispatch(refreshConnectionStatusCountAsyncAction);
+  });
+  window.setInterval(() => {
+    applicationApi.applicationStoreInitialized.then(store => {
+      store.dispatch(refreshConnectionStatusCountAsyncAction);
+    });
+  }, 15000);
 }
\ No newline at end of file