1 import { Action } from '../../../../framework/src/flux/action';
2 import { Dispatch } from '../../../../framework/src/flux/store';
4 import { Ltp } from '../models/availableLtps';
5 import { PerformanceHistoryService } from '../services/performanceHistoryService';
8 * Represents the base action.
10 export class BaseAction extends Action { }
13 * Represents an action causing the store to load available ltps.
15 export class LoadAllAvailableLtpsAction extends BaseAction { }
18 * Represents an action causing the store to update available ltps.
20 export class AllAvailableLtpsLoadedAction extends BaseAction {
22 * Initialize this instance.
23 * @param availableLtps The available ltps which are returned from the database.
25 constructor(public availableLtps: Ltp[] | null, public error?: string) {
32 * Represents an asynchronous thunk action to load available distinctLtps by networkElement from the database and set the returned first Ltp as default.
33 * @param networkElement The network element sent to database to get its available distinct Ltps.
34 * @param selectedTimePeriod The time period selected sent to database to get the distinct Ltps of the selected network element.
35 * @param selectedLtp The Ltp which is selected in the dropdown.
36 * @param selectFirstLtp The function to get the first ltp returned from the database to be selected as default on selection upon network element.
37 * @param resetLtp The function to verify if the selected ltp is also available in the selected time period database else reset the Ltp dropdown to select.
39 export const loadDistinctLtpsbyNetworkElementAsync = (networkElement: string, selectedTimePeriod: string, selectedLtp: string, selectFirstLtp?: Function, resetLtp?: Function) => (dispatch: Dispatch) => {
40 if (selectedTimePeriod == "15min") {
41 dispatch(new LoadAllAvailableLtpsAction());
42 PerformanceHistoryService.getDistinctLtpsFrom15minDatabase(networkElement).then(distinctLtps => {
44 let ltpNotSelected: boolean = true;
45 selectFirstLtp && selectFirstLtp(distinctLtps[0].key);
46 distinctLtps.forEach((value: Ltp) => {
47 if(value.key === selectedLtp) {
48 ltpNotSelected = false;
51 resetLtp && resetLtp(ltpNotSelected);
52 dispatch(new AllAvailableLtpsLoadedAction(distinctLtps))
55 dispatch(new AllAvailableLtpsLoadedAction(null, error));
58 dispatch(new LoadAllAvailableLtpsAction());
59 PerformanceHistoryService.getDistinctLtpsFrom24hoursDatabase(networkElement).then(distinctLtps => {
61 let ltpNotSelected: boolean = true;
62 selectFirstLtp && selectFirstLtp(distinctLtps[0].key);
63 distinctLtps.forEach((value: Ltp) => {
64 if(value.key === selectedLtp) {
65 ltpNotSelected = false;
68 resetLtp && resetLtp(ltpNotSelected);
69 dispatch(new AllAvailableLtpsLoadedAction(distinctLtps))
72 dispatch(new AllAvailableLtpsLoadedAction(null, error));