diff options
Diffstat (limited to 'sdnr/wt/odlux/apps/performanceHistoryApp/src/actions')
-rw-r--r-- | sdnr/wt/odlux/apps/performanceHistoryApp/src/actions/deviceListActions.ts (renamed from sdnr/wt/odlux/apps/performanceHistoryApp/src/actions/connectedNetworkElementsActions.ts) | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/sdnr/wt/odlux/apps/performanceHistoryApp/src/actions/connectedNetworkElementsActions.ts b/sdnr/wt/odlux/apps/performanceHistoryApp/src/actions/deviceListActions.ts index 97d531608..9637fec81 100644 --- a/sdnr/wt/odlux/apps/performanceHistoryApp/src/actions/connectedNetworkElementsActions.ts +++ b/sdnr/wt/odlux/apps/performanceHistoryApp/src/actions/deviceListActions.ts @@ -19,7 +19,8 @@ import { Action } from '../../../../framework/src/flux/action'; import { Dispatch } from '../../../../framework/src/flux/store'; import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore'; -import { ConnectedNetworkElementIds } from '../models/connectedNetworkElements'; +import { DeviceListType } from '../models/deviceListType'; +import { PerformanceHistoryService } from '../services/performanceHistoryService'; /** * Represents the base action. @@ -27,52 +28,44 @@ import { ConnectedNetworkElementIds } from '../models/connectedNetworkElements'; export class BaseAction extends Action { } /** - * Represents an action causing the store to load all connected network element Ids. + * Represents an action causing the store to load all devices. */ -export class LoadAllConnectedNetworkElementsAction extends BaseAction { } +export class LoadAllDeviceListAction extends BaseAction { } /** - * Represents an action causing the store to update all connected network element Ids. + * Represents an action causing the store to update all devices. */ -export class AllConnectedNetworkElementsLoadedAction extends BaseAction { +export class AllDeviceListLoadedAction extends BaseAction { /** * Initialize this instance. * - * @param connectedNetworkElements The connected network element Ids which are loaded from the state of connectApp. + * @param deviceList All the distinct devices from the performance history database. */ - constructor(public connectedNetworkElementIds: ConnectedNetworkElementIds[] | null, public error?: string) { + constructor(public deviceList: DeviceListType[] | null, public error?: string) { super(); } } /** - * Represents an asynchronous thunk action to load all connected network element Ids. + * Represents an asynchronous thunk action to load all devices. */ -export const loadAllConnectedNetworkElementsAsync = (dispatch: Dispatch, getState: () => IApplicationStoreState) => { - window.setTimeout(() => { - dispatch(new LoadAllConnectedNetworkElementsAction()); - const connectedNetworkElementsIds = getState().connect.mountedNetworkElements; - let mountIdList: ConnectedNetworkElementIds[] = []; - connectedNetworkElementsIds.elements.forEach(element => { - const connectedNetworkElement = { - mountId: element.mountId - } - mountIdList.push(connectedNetworkElement); - }); - mountIdList.sort((a, b) => { - if (a.mountId < b.mountId) return -1; - if (a.mountId > b.mountId) return 1; - return 0; - }); - dispatch(new AllConnectedNetworkElementsLoadedAction(mountIdList)); - }, 500); +export const loadAllDeviceListAsync = async (dispatch: Dispatch) => { + dispatch(new LoadAllDeviceListAction()); + const deviceListFromPerfHistory: DeviceListType[] = await PerformanceHistoryService.getDeviceListfromPerf15minHistory().then(ne => (ne)) || []; + const deviceListFromPerf24History: DeviceListType[] = await PerformanceHistoryService.getDeviceListfromPerf24hHistory().then(ne => (ne)) || []; + deviceListFromPerf24History.forEach(deviceList24h => { + if (deviceListFromPerfHistory.findIndex(deviceList15min => deviceList15min.nodeId === deviceList24h.nodeId) < 0) { + deviceListFromPerfHistory.push(deviceList24h); + }; + }); + return deviceListFromPerfHistory && dispatch(new AllDeviceListLoadedAction(deviceListFromPerfHistory)); }; /** * Represents an action causing the store to update mountId. */ export class UpdateMountId extends BaseAction { - constructor (public nodeId?: string) { + constructor(public nodeId?: string) { super(); } } @@ -80,6 +73,6 @@ export class UpdateMountId extends BaseAction { /** * Represents an asynchronous thunk action to load updated mountId. */ -export const updateMountIdActionCreator = (nodeId: string ) => async (dispatch: Dispatch) => { +export const updateMountIdActionCreator = (nodeId: string) => async (dispatch: Dispatch) => { return dispatch(new UpdateMountId(nodeId)); } |