From 3d202a04b99f0e61b6ccf8b7a5610e1a15ca58e7 Mon Sep 17 00:00:00 2001 From: Herbert Eiselt Date: Mon, 11 Feb 2019 14:54:12 +0100 Subject: Add sdnr wt odlux Add complete sdnr wireless transport app odlux core and apps Change-Id: I5dcbfb8f3b790e3bda7c8df67bd69d81958f65e5 Issue-ID: SDNC-576 Signed-off-by: Herbert Eiselt --- .../faultApp/src/actions/notificationActions.ts | 16 +++ .../faultApp/src/actions/panelChangeActions.ts | 9 ++ .../src/handlers/alarmLogEntriesHandler.ts | 24 +++++ .../src/handlers/currentProblemsHandler.ts | 24 +++++ .../faultApp/src/handlers/faultAppRootHandler.ts | 42 ++++++++ .../faultApp/src/handlers/notificationsHandler.ts | 30 ++++++ sdnr/wt/odlux/apps/faultApp/src/index.html | 25 +++++ sdnr/wt/odlux/apps/faultApp/src/models/fault.ts | 14 +++ sdnr/wt/odlux/apps/faultApp/src/models/panelId.ts | 1 + sdnr/wt/odlux/apps/faultApp/src/plugin.tsx | 78 ++++++++++++++ .../apps/faultApp/src/views/faultApplication.tsx | 114 +++++++++++++++++++++ 11 files changed, 377 insertions(+) create mode 100644 sdnr/wt/odlux/apps/faultApp/src/actions/notificationActions.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/actions/panelChangeActions.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/handlers/alarmLogEntriesHandler.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/handlers/currentProblemsHandler.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/handlers/faultAppRootHandler.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/handlers/notificationsHandler.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/index.html create mode 100644 sdnr/wt/odlux/apps/faultApp/src/models/fault.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/models/panelId.ts create mode 100644 sdnr/wt/odlux/apps/faultApp/src/plugin.tsx create mode 100644 sdnr/wt/odlux/apps/faultApp/src/views/faultApplication.tsx (limited to 'sdnr/wt/odlux/apps/faultApp/src') diff --git a/sdnr/wt/odlux/apps/faultApp/src/actions/notificationActions.ts b/sdnr/wt/odlux/apps/faultApp/src/actions/notificationActions.ts new file mode 100644 index 000000000..be4908530 --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/actions/notificationActions.ts @@ -0,0 +1,16 @@ +import { Action } from '../../../../framework/src/flux/action'; + +import { Fault } from '../models/fault'; + +export class FaultApplicationBaseAction extends Action { } + + +export class AddFaultNotificationAction extends FaultApplicationBaseAction { + constructor(public fault:Fault) { + super(); + } +} + +export class ResetFaultNotificationsAction extends FaultApplicationBaseAction { + +} diff --git a/sdnr/wt/odlux/apps/faultApp/src/actions/panelChangeActions.ts b/sdnr/wt/odlux/apps/faultApp/src/actions/panelChangeActions.ts new file mode 100644 index 000000000..dea07a0b0 --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/actions/panelChangeActions.ts @@ -0,0 +1,9 @@ +import { Action } from '../../../../framework/src/flux/action'; +import { PanelId } from '../models/panelId'; + +export class SetPanelAction extends Action { + constructor(public panelId: PanelId) { + super(); + } +} + diff --git a/sdnr/wt/odlux/apps/faultApp/src/handlers/alarmLogEntriesHandler.ts b/sdnr/wt/odlux/apps/faultApp/src/handlers/alarmLogEntriesHandler.ts new file mode 100644 index 000000000..0b974207b --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/handlers/alarmLogEntriesHandler.ts @@ -0,0 +1,24 @@ +import { createExternal,IExternalTableState } from '../../../../framework/src/components/material-table/utilities'; +import { createSearchDataHandler } from '../../../../framework/src/utilities/elasticSearch'; + +import { Fault, FaultLog } from '../models/fault'; + +export interface IAlarmLogEntriesState extends IExternalTableState { } + +// create eleactic search material data fetch handler +const alarmLogEntriesSearchHandler = createSearchDataHandler( + 'sdnevents/faultlog', + null, + (hit) => ({ _id: hit._id, ...hit._source.fault }), + (name) => `fault.${ name }` +); + +export const { + actionHandler: alarmLogEntriesActionHandler, + createActions: createAlarmLogEntriesActions, + createProperties: createAlarmLogEntriesProperties, + reloadAction: alarmLogEntriesReloadAction, + + // set value action, to change a value +} = createExternal(alarmLogEntriesSearchHandler, appState => appState.faultApp.alarmLogEntries); + diff --git a/sdnr/wt/odlux/apps/faultApp/src/handlers/currentProblemsHandler.ts b/sdnr/wt/odlux/apps/faultApp/src/handlers/currentProblemsHandler.ts new file mode 100644 index 000000000..6bbe2976f --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/handlers/currentProblemsHandler.ts @@ -0,0 +1,24 @@ +import { createExternal,IExternalTableState } from '../../../../framework/src/components/material-table/utilities'; +import { createSearchDataHandler } from '../../../../framework/src/utilities/elasticSearch'; + +import { FaultResult, Fault } from '../models/fault'; + +export interface ICurrentProblemsState extends IExternalTableState { } + +// create eleactic search material data fetch handler +const currentProblemsSearchHandler = createSearchDataHandler( + 'sdnevents/faultcurrent', + null, + (hit) => ({ _id: hit._id, ...hit._source.faultCurrent }), + (name) => `faultCurrent.${name}` + ); + +export const { + actionHandler: currentProblemsActionHandler, + createActions: createCurrentProblemsActions, + createProperties: createCurrentProblemsProperties, + reloadAction: currentProblemsReloadAction, + + // set value action, to change a value +} = createExternal(currentProblemsSearchHandler, appState => appState.faultApp.currentProblems); + diff --git a/sdnr/wt/odlux/apps/faultApp/src/handlers/faultAppRootHandler.ts b/sdnr/wt/odlux/apps/faultApp/src/handlers/faultAppRootHandler.ts new file mode 100644 index 000000000..005e3e5a4 --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/handlers/faultAppRootHandler.ts @@ -0,0 +1,42 @@ +// main state handler + +import { combineActionHandler } from '../../../../framework/src/flux/middleware'; + +// ** do not remove ** +import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore'; +import { IActionHandler } from '../../../../framework/src/flux/action'; + +import { IFaultNotifications, faultNotificationsHandler } from './notificationsHandler'; +import { ICurrentProblemsState, currentProblemsActionHandler } from './currentProblemsHandler'; +import { IAlarmLogEntriesState, alarmLogEntriesActionHandler } from './alarmLogEntriesHandler'; +import { SetPanelAction } from '../actions/panelChangeActions'; + +export interface IFaultAppStoreState { + currentProblems: ICurrentProblemsState; + faultNotifications: IFaultNotifications; + alarmLogEntries: IAlarmLogEntriesState; + currentOpenPanel: string|null; +} + +const currentOpenPanelHandler: IActionHandler = (state = null, action) => { + if (action instanceof SetPanelAction) { + state = action.panelId; + } + return state; +} + +declare module '../../../../framework/src/store/applicationStore' { + interface IApplicationStoreState { + faultApp: IFaultAppStoreState; + } +} + +const actionHandlers = { + currentProblems: currentProblemsActionHandler, + faultNotifications: faultNotificationsHandler, + alarmLogEntries: alarmLogEntriesActionHandler, + currentOpenPanel: currentOpenPanelHandler +}; + +export const faultAppRootHandler = combineActionHandler(actionHandlers); +export default faultAppRootHandler; diff --git a/sdnr/wt/odlux/apps/faultApp/src/handlers/notificationsHandler.ts b/sdnr/wt/odlux/apps/faultApp/src/handlers/notificationsHandler.ts new file mode 100644 index 000000000..b73ed14a3 --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/handlers/notificationsHandler.ts @@ -0,0 +1,30 @@ +import { IActionHandler } from '../../../../framework/src/flux/action'; +import { AddFaultNotificationAction, ResetFaultNotificationsAction } from '../actions/notificationActions'; +import { Fault } from '../models/fault'; + +export interface IFaultNotifications { + faults: Fault[]; + since: Date; +} + +const faultNotoficationsInit: IFaultNotifications = { + faults: [], + since: new Date() +}; + +export const faultNotificationsHandler: IActionHandler = (state = faultNotoficationsInit, action) => { + if (action instanceof AddFaultNotificationAction) { + state = { + ...state, + faults: [...state.faults, action.fault] + }; + } else if (action instanceof ResetFaultNotificationsAction){ + state = { + ...state, + faults: [], + since: new Date() + }; + } + + return state; +} \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/faultApp/src/index.html b/sdnr/wt/odlux/apps/faultApp/src/index.html new file mode 100644 index 000000000..5f6794f33 --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/index.html @@ -0,0 +1,25 @@ + + + + + + + + + Minimal App + + + +
+ + + + + + \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/faultApp/src/models/fault.ts b/sdnr/wt/odlux/apps/faultApp/src/models/fault.ts new file mode 100644 index 000000000..ecd0c9993 --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/models/fault.ts @@ -0,0 +1,14 @@ +export type FaultType = { + nodeName: string; + counter: string; + timeStamp: string; + objectId: string; + problem: string; + severity: null | 'Warning' | 'Minor' | 'Major' | 'Critical' ; + type: string; +} +export type FaultResult = { faultCurrent: FaultType }; + +export type FaultLog = { fault: FaultType }; + +export type Fault = FaultType & { _id: string }; diff --git a/sdnr/wt/odlux/apps/faultApp/src/models/panelId.ts b/sdnr/wt/odlux/apps/faultApp/src/models/panelId.ts new file mode 100644 index 000000000..56f117ad3 --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/models/panelId.ts @@ -0,0 +1 @@ +export type PanelId = null | "CurrentProblem" | "AlarmNotifications" | "AlarmLog"; \ No newline at end of file diff --git a/sdnr/wt/odlux/apps/faultApp/src/plugin.tsx b/sdnr/wt/odlux/apps/faultApp/src/plugin.tsx new file mode 100644 index 000000000..6f83e74dc --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/plugin.tsx @@ -0,0 +1,78 @@ +// app configuration and main entry point for the app + + +import * as React from "react"; +import { withRouter, RouteComponentProps, Route, Switch, Redirect } from 'react-router-dom'; + +import connect, { Connect, IDispatcher } from '../../../framework/src/flux/connect'; + +import { faBell } from '@fortawesome/free-solid-svg-icons'; // select app icon +import applicationManager from '../../../framework/src/services/applicationManager'; +import { subscribe, IFormatedMessage } from '../../../framework/src/services/notificationService'; +import { IApplicationStoreState } from "../../../framework/src/store/applicationStore"; + +import { faultAppRootHandler } from './handlers/faultAppRootHandler'; +import { FaultApplication } from "./views/faultApplication"; + +import { Fault } from "./models/fault"; +import { PanelId } from "./models/panelId"; + +import { SetPanelAction } from "./actions/panelChangeActions"; +import { AddFaultNotificationAction } from "./actions/notificationActions"; + +import { createCurrentProblemsProperties, createCurrentProblemsActions } from "./handlers/currentProblemsHandler"; + +let currentMountId: string | undefined = undefined; + +const mapProps = (state: IApplicationStoreState) => ({ + currentProblemsProperties: createCurrentProblemsProperties(state), +}); + +const mapDisp = (dispatcher: IDispatcher) => ({ + currentProblemsActions: createCurrentProblemsActions(dispatcher.dispatch, true), + setCurrentPanel: (panelId: PanelId) => dispatcher.dispatch(new SetPanelAction(panelId)) +}); + +const FaultApplicationRouteAdapter = connect(mapProps, mapDisp)((props: RouteComponentProps<{ mountId?: string }> & Connect) => { + if (currentMountId !== props.match.params.mountId) { + // route parameter has changed + currentMountId = props.match.params.mountId || undefined; + // Hint: This timeout is need, since it is not recommended to change the state while rendering is in progress ! + window.setTimeout(() => { + if (currentMountId) { + props.setCurrentPanel("CurrentProblem"); + props.currentProblemsActions.onFilterChanged("objectId", currentMountId); + props.currentProblemsProperties.showFilter || (props.currentProblemsActions.onToggleFilter()); + props.currentProblemsActions.onRefresh(); + } + }); + } + return ( + + ) +}); + +const App = withRouter((props: RouteComponentProps) => ( + + + + +)); + +export function register() { + const applicationApi = applicationManager.registerApplication({ + name: "faultApp", + icon: faBell, + rootComponent: App, + rootActionHandler: faultAppRootHandler, + menuEntry: "Fault" + }); + + // subscribe to the websocket notifications + subscribe("ProblemNotification", (fault => { + const store = applicationApi && applicationApi.applicationStore; + if (fault && store) { + store.dispatch(new AddFaultNotificationAction(fault)); + } + })); +} diff --git a/sdnr/wt/odlux/apps/faultApp/src/views/faultApplication.tsx b/sdnr/wt/odlux/apps/faultApp/src/views/faultApplication.tsx new file mode 100644 index 000000000..9eb3a00ff --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/views/faultApplication.tsx @@ -0,0 +1,114 @@ +import * as React from 'react'; + +import { withRouter, RouteComponentProps } from 'react-router-dom'; + +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'; + +import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table'; +import { Panel } from '../../../../framework/src/components/material-ui'; + +import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore'; +import connect, { Connect, IDispatcher } from '../../../../framework/src/flux/connect'; + +import { Fault } from '../models/fault'; +import { PanelId } from '../models/panelId'; + +import { createCurrentProblemsProperties, createCurrentProblemsActions, currentProblemsReloadAction } from '../handlers/currentProblemsHandler'; +import { createAlarmLogEntriesProperties, createAlarmLogEntriesActions, alarmLogEntriesReloadAction } from '../handlers/alarmLogEntriesHandler'; +import { SetPanelAction } from '../actions/panelChangeActions'; + +const mapProps = (state: IApplicationStoreState) => ({ + activePanel: state.faultApp.currentOpenPanel, + currentProblemsProperties: createCurrentProblemsProperties(state), + faultNotifications: state.faultApp.faultNotifications, + alarmLogEntriesProperties: createAlarmLogEntriesProperties(state) +}); + +const mapDisp = (dispatcher: IDispatcher) => ({ + currentProblemsActions: createCurrentProblemsActions(dispatcher.dispatch), + alarmLogEntriesActions: createAlarmLogEntriesActions(dispatcher.dispatch), + reloadCurrentProblems: () => dispatcher.dispatch(currentProblemsReloadAction), + reloadAlarmLogEntries: () => dispatcher.dispatch(alarmLogEntriesReloadAction), + setCurrentPanel: (panelId: PanelId) => dispatcher.dispatch(new SetPanelAction(panelId)) +}); + +type FaultApplicationComponentProps = RouteComponentProps & Connect; + + +const FaultTable = MaterialTable as MaterialTableCtorType; + +class FaultApplicationComponent extends React.Component{ + + render(): JSX.Element { + + const { activePanel } = this.props; + + const onTogglePanel = (panelId: PanelId) => { + const nextActivePanel = panelId === this.props.activePanel ? null : panelId; + this.props.setCurrentPanel(nextActivePanel); + + switch (nextActivePanel) { + case 'CurrentProblem': + this.props.reloadCurrentProblems(); + break; + case 'AlarmLog': + this.props.reloadAlarmLogEntries(); + break; + case 'AlarmNotifications': + case null: + default: + // nothing to do + break; + } + }; + + return ( + <> + + + + + + + + + + + ); + }; + + private renderIcon = (props: { rowData: Fault }) => { + return ( + + ); + }; + +} + +export const FaultApplication = withRouter(connect(mapProps, mapDisp)(FaultApplicationComponent)); +export default FaultApplication; -- cgit 1.2.3-korg