aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/performanceHistoryApp/src/actions/connectedNetworkElementsActions.ts
blob: 0906584b73ec9dab6833f59b75ea6fff004d8926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Action } from '../../../../framework/src/flux/action';
import { Dispatch } from '../../../../framework/src/flux/store';

import { ConnectedNetworkElements } from '../models/connectedNetworkElements';
import { PerformanceHistoryService } from '../services/performanceHistoryService';

/** 
 * Represents the base action. 
 */
export class BaseAction extends Action { }

/** 
 * Represents an action causing the store to load all connected network elements. 
 */
export class LoadAllConnectedNetworkElementsAction extends BaseAction { }

/** 
 * Represents an action causing the store to update all connected network elements. 
 */
export class AllConnectedNetworkElementsLoadedAction extends BaseAction {  
  /**
   * Initialize this instance.
   * 
   * @param connectedNetworkElements The network elements which are returned from the restconf.
   */
  constructor(public connectedNetworkElements: ConnectedNetworkElements[] | null, public error?: string) {
    super();
  }
}

/** 
 * Represents an asynchronous thunk  action to load all connected network elements from the restconf. 
 */
export const loadAllConnectedNetworkElementsAsync = (dispatch: Dispatch) => {
  dispatch(new LoadAllConnectedNetworkElementsAction());
  PerformanceHistoryService.getConnectedNetworkElementsList().then(networkElements => {
    networkElements && dispatch(new AllConnectedNetworkElementsLoadedAction(networkElements));
  }).catch(error => {
    dispatch(new AllConnectedNetworkElementsLoadedAction(null, error));
  });
};