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

144 lines
3.6 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'
2018-10-03 18:10:16 +02:00
export const LOAD_ROUTESERVERS_REQUEST = '@routeservers/LOAD_ROUTESERVERS_REQUEST';
export const LOAD_ROUTESERVERS_SUCCESS = '@routeservers/LOAD_ROUTESERVERS_SUCCESS';
export const LOAD_ROUTESERVERS_ERROR = '@routeservers/LOAD_ROUTESERVERS_ERROR';
2017-05-16 13:34:00 +02:00
2018-10-03 18:10:16 +02:00
export const LOAD_ROUTESERVER_STATUS_REQUEST = '@routeservers/LOAD_ROUTESERVER_STATUS_REQUEST';
export const LOAD_ROUTESERVER_STATUS_SUCCESS = '@routeservers/LOAD_ROUTESERVER_STATUS_SUCCESS';
export const LOAD_ROUTESERVER_STATUS_ERROR = '@routeservers/LOAD_ROUTESERVER_STATUS_ERROR';
2017-05-16 13:34:00 +02:00
2018-10-03 18:10:16 +02:00
export const LOAD_ROUTESERVER_PROTOCOL_REQUEST = '@routeservers/LOAD_ROUTESERVER_PROTOCOL_REQUEST';
export const LOAD_ROUTESERVER_PROTOCOL_SUCCESS = '@routeservers/LOAD_ROUTESERVER_PROTOCOL_SUCCESS';
export const LOAD_ROUTESERVER_PROTOCOL_ERROR = '@routeservers/LOAD_ROUTESERVER_PROTOCOL_ERROR';
2017-05-16 13:34:00 +02:00
// 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())
2018-10-03 18:10:16 +02:00
axios.get('/api/v1/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));
2018-10-03 18:10:16 +02:00
axios.get(`/api/v1/routeservers/${routeserverId}/status`)
2017-05-16 13:34:00 +02:00
.then(({data}) => {
dispatch(loadRouteserverStatusSuccess(routeserverId, data.status));
})
.catch((error) => {
dispatch(apiError(error));
2018-08-05 18:39:11 +02:00
dispatch(loadRouteserverStatusError(routeserverId, error));
2017-05-16 13:34:00 +02:00
});
}
}
export function loadRouteserverProtocolRequest(routeserverId) {
return {
type: LOAD_ROUTESERVER_PROTOCOL_REQUEST,
payload: {
routeserverId: routeserverId,
}
}
}
2018-10-02 10:29:43 +02:00
export function loadRouteserverProtocolSuccess(routeserverId, protocol, api) {
2017-05-16 13:34:00 +02:00
return {
type: LOAD_ROUTESERVER_PROTOCOL_SUCCESS,
payload: {
routeserverId: routeserverId,
2018-10-02 10:29:43 +02:00
protocol: protocol,
api: api
2017-05-16 13:34:00 +02:00
}
}
}
export function loadRouteserverProtocol(routeserverId) {
return (dispatch) => {
dispatch(loadRouteserverProtocolRequest(routeserverId));
2018-10-03 18:16:17 +02:00
axios.get(`/api/v1/routeservers/${routeserverId}/neighbors`)
2017-05-16 13:34:00 +02:00
.then(({data}) => {
2018-10-02 10:29:43 +02:00
dispatch(loadRouteserverProtocolSuccess(
routeserverId,
data.neighbours,
data.api,
));
2017-05-16 13:34:00 +02:00
})
2018-08-05 18:39:11 +02:00
.catch((error) => dispatch(apiError(error)));
2017-05-16 13:34:00 +02:00
}
}