1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

250 lines
6.3 KiB
React
Raw Normal View History

2017-05-16 13:34:00 +02:00
/**
* Routeservers Actions
*/
import axios from 'axios'
import {apiError} from 'components/errors/actions'
export const LOAD_ROUTESERVERS_REQUEST = '@birdseye/LOAD_ROUTESERVERS_REQUEST';
export const LOAD_ROUTESERVERS_SUCCESS = '@birdseye/LOAD_ROUTESERVERS_SUCCESS';
export const LOAD_ROUTESERVERS_ERROR = '@birdseye/LOAD_ROUTESERVERS_ERROR';
export const LOAD_ROUTESERVER_STATUS_REQUEST = '@birdseye/LOAD_ROUTESERVER_STATUS_REQUEST';
export const LOAD_ROUTESERVER_STATUS_SUCCESS = '@birdseye/LOAD_ROUTESERVER_STATUS_SUCCESS';
export const LOAD_ROUTESERVER_STATUS_ERROR = '@birdseye/LOAD_ROUTESERVER_STATUS_ERROR';
export const LOAD_ROUTESERVER_PROTOCOL_REQUEST = '@birdseye/LOAD_ROUTESERVER_PROTOCOL_REQUEST';
export const LOAD_ROUTESERVER_PROTOCOL_SUCCESS = '@birdseye/LOAD_ROUTESERVER_PROTOCOL_SUCCESS';
export const LOAD_ROUTESERVER_PROTOCOL_ERROR = '@birdseye/LOAD_ROUTESERVER_PROTOCOL_ERROR';
export const LOAD_ROUTESERVER_ROUTES_REQUEST = '@birdseye/LOAD_ROUTESERVER_ROUTES_REQUEST';
export const LOAD_ROUTESERVER_ROUTES_SUCCESS = '@birdseye/LOAD_ROUTESERVER_ROUTES_SUCCESS';
export const LOAD_ROUTESERVER_ROUTES_ERROR = '@birdseye/LOAD_ROUTESERVER_ROUTES_ERROR';
2017-05-16 13:34:00 +02:00
export const LOAD_ROUTESERVER_ROUTES_FILTERED_SUCCESS = '@birdseye/LOAD_ROUTESERVER_ROUTES_FILTERED_SUCCESS';
export const LOAD_ROUTESERVER_ROUTES_NOEXPORT_SUCCESS = '@birdseye/LOAD_ROUTESERVER_ROUTES_NOEXPORT_SUCCESS';
2017-05-16 13:34:00 +02:00
export const SET_PROTOCOLS_FILTER_VALUE = '@birdseye/SET_PROTOCOLS_FILTER_VALUE';
export const SET_PROTOCOLS_FILTER = '@birdseye/SET_PROTOCOLS_FILTER';
2017-05-16 13:34:00 +02:00
export const SET_ROUTES_FILTER_VALUE = '@birdseye/SET_ROUTES_FILTER_VALUE';
// Action Creators
export function loadRouteserversRequest() {
return {
type: LOAD_ROUTESERVERS_REQUEST
}
}
export function loadRouteserversSuccess(routeservers) {
return {
type: LOAD_ROUTESERVERS_SUCCESS,
payload: {
routeservers: routeservers
}
}
}
export function loadRouteserversError(error) {
return {
type: LOAD_ROUTESERVERS_ERROR,
payload: {
error: error
}
}
}
export function loadRouteservers() {
return (dispatch) => {
dispatch(loadRouteserversRequest())
2017-05-22 15:22:25 +02:00
axios.get('/api/routeservers')
2017-05-16 13:34:00 +02:00
.then(({data}) => {
dispatch(loadRouteserversSuccess(data["routeservers"]));
})
.catch((error) => {
dispatch(apiError(error));
dispatch(loadRouteserversError(error.data));
});
}
}
export function loadRouteserverStatusRequest(routeserverId) {
return {
type: LOAD_ROUTESERVER_STATUS_REQUEST,
payload: {
routeserverId: routeserverId
}
}
}
export function loadRouteserverStatusSuccess(routeserverId, status) {
return {
type: LOAD_ROUTESERVER_STATUS_SUCCESS,
payload: {
status: status,
routeserverId: routeserverId
}
}
}
export function loadRouteserverStatusError(routeserverId, error) {
return {
type: LOAD_ROUTESERVER_STATUS_ERROR,
payload: {
error: error,
routeserverId: routeserverId
}
}
}
export function loadRouteserverStatus(routeserverId) {
return (dispatch) => {
dispatch(loadRouteserverStatusRequest(routeserverId));
2017-05-22 15:22:25 +02:00
axios.get(`/api/routeservers/${routeserverId}/status`)
2017-05-16 13:34:00 +02:00
.then(({data}) => {
dispatch(loadRouteserverStatusSuccess(routeserverId, data.status));
})
.catch((error) => {
dispatch(apiError(error));
dispatch(loadRouteserverStatusError(routeserverId, error.data));
});
}
}
export function loadRouteserverProtocolRequest(routeserverId) {
return {
type: LOAD_ROUTESERVER_PROTOCOL_REQUEST,
payload: {
routeserverId: routeserverId,
}
}
}
export function loadRouteserverProtocolSuccess(routeserverId, protocol) {
return {
type: LOAD_ROUTESERVER_PROTOCOL_SUCCESS,
payload: {
routeserverId: routeserverId,
protocol: protocol
}
}
}
export function loadRouteserverProtocol(routeserverId) {
return (dispatch) => {
dispatch(loadRouteserverProtocolRequest(routeserverId));
2017-05-22 15:22:25 +02:00
axios.get(`/api/routeservers/${routeserverId}/neighbours`)
2017-05-16 13:34:00 +02:00
.then(({data}) => {
dispatch(setProtocolsFilterValue(""));
2017-05-22 15:22:25 +02:00
dispatch(loadRouteserverProtocolSuccess(routeserverId, data.neighbours));
2017-05-16 13:34:00 +02:00
})
.catch(error => dispatch(apiError(error)));
}
}
export function loadRouteserverRoutesRequest(routeserverId, protocolId) {
return {
type: LOAD_ROUTESERVER_ROUTES_REQUEST,
payload: {
routeserverId: routeserverId,
protocolId: protocolId,
}
}
}
export function loadRouteserverRoutesSuccess(routeserverId, protocolId, routes) {
return {
type: LOAD_ROUTESERVER_ROUTES_SUCCESS,
payload: {
routeserverId: routeserverId,
protocolId: protocolId,
routes: routes
}
}
}
export function loadRouteserverRoutes(routeserverId, protocolId) {
return (dispatch) => {
dispatch(loadRouteserverRoutesRequest(routeserverId, protocolId))
2017-05-22 16:37:30 +02:00
axios.get(`/api/routeservers/${routeserverId}/neighbours/${protocolId}/routes`)
2017-05-16 13:34:00 +02:00
.then(({data}) => {
dispatch(
2017-05-23 15:25:15 +02:00
loadRouteserverRoutesSuccess(routeserverId, protocolId, data.imported)
2017-05-22 15:22:25 +02:00
);
dispatch(
loadRouteserverRoutesFilteredSuccess(routeserverId, protocolId, data.filtered)
2017-05-16 13:34:00 +02:00
);
dispatch(
loadRouteserverRoutesNoexportSuccess(routeserverId, protocolId, data.not_exported)
);
2017-05-16 13:34:00 +02:00
dispatch(setRoutesFilterValue(""));
})
.catch(error => dispatch(apiError(error)));
}
}
export function loadRouteserverRoutesFilteredSuccess(routeserverId, protocolId, routes) {
2017-05-16 13:34:00 +02:00
return {
type: LOAD_ROUTESERVER_ROUTES_FILTERED_SUCCESS,
2017-05-16 13:34:00 +02:00
payload: {
routeserverId: routeserverId,
protocolId: protocolId,
routes: routes
2017-05-16 13:34:00 +02:00
}
}
}
export function loadRouteserverRoutesNoexportSuccess(routeserverId, protocolId, routes) {
2017-05-16 13:34:00 +02:00
return {
type: LOAD_ROUTESERVER_ROUTES_NOEXPORT_SUCCESS,
2017-05-16 13:34:00 +02:00
payload: {
routeserverId: routeserverId,
protocolId: protocolId,
routes: routes
}
}
}
2017-05-16 13:34:00 +02:00
export function setProtocolsFilterValue(value) {
return {
type: SET_PROTOCOLS_FILTER_VALUE,
payload: {
value: value
}
}
}
export function setProtocolsFilter(value) {
return {
type: SET_PROTOCOLS_FILTER,
payload: {
value: value,
2017-05-16 13:34:00 +02:00
}
}
}
export function setRoutesFilterValue(value) {
return {
type: SET_ROUTES_FILTER_VALUE,
payload: {
routesFilterValue: value
}
}
}