diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-08-25 17:48:12 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:44 +0200 |
| commit | c47a27b826f7d76410308a4151611a366f9eaf46 (patch) | |
| tree | c1ca374204714cedabcacb8620848b903a0bf8d6 /src/api/sagas | |
| parent | 1ddbbd3563af77a218020021ea50a8832900b4db (diff) | |
Fetch and display datacenter topology
Diffstat (limited to 'src/api/sagas')
| -rw-r--r-- | src/api/sagas/index.js | 15 | ||||
| -rw-r--r-- | src/api/sagas/objects.js | 24 | ||||
| -rw-r--r-- | src/api/sagas/profile.js | 12 | ||||
| -rw-r--r-- | src/api/sagas/simulations.js | 30 | ||||
| -rw-r--r-- | src/api/sagas/users.js | 46 |
5 files changed, 0 insertions, 127 deletions
diff --git a/src/api/sagas/index.js b/src/api/sagas/index.js deleted file mode 100644 index 7fe57453..00000000 --- a/src/api/sagas/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import {takeEvery} from "redux-saga/effects"; -import {LOG_IN} from "../../actions/auth"; -import {ADD_SIMULATION, DELETE_SIMULATION} from "../../actions/simulations"; -import {DELETE_CURRENT_USER, FETCH_AUTHORIZATIONS_OF_CURRENT_USER} from "../../actions/users"; -import {onDeleteCurrentUser} from "./profile"; -import {onSimulationAdd, onSimulationDelete} from "./simulations"; -import {onFetchAuthorizationsOfCurrentUser, onFetchLoggedInUser} from "./users"; - -export default function* rootSaga() { - yield takeEvery(LOG_IN, onFetchLoggedInUser); - yield takeEvery(FETCH_AUTHORIZATIONS_OF_CURRENT_USER, onFetchAuthorizationsOfCurrentUser); - yield takeEvery(ADD_SIMULATION, onSimulationAdd); - yield takeEvery(DELETE_SIMULATION, onSimulationDelete); - yield takeEvery(DELETE_CURRENT_USER, onDeleteCurrentUser); -} diff --git a/src/api/sagas/objects.js b/src/api/sagas/objects.js deleted file mode 100644 index 98c766ec..00000000 --- a/src/api/sagas/objects.js +++ /dev/null @@ -1,24 +0,0 @@ -import {call, put, select} from "redux-saga/effects"; -import {addToStore} from "../../actions/objects"; -import {getSimulation} from "../routes/simulations"; -import {getUser} from "../routes/users"; - -const selectors = { - simulation: state => state.objects.simulation, - user: state => state.objects.user, - authorization: state => state.objects.authorization, -}; - -function* fetchAndStoreObject(objectType, id, apiCall) { - const objectStore = yield select(selectors[objectType]); - if (!objectStore[id]) { - const object = yield apiCall; - yield put(addToStore(objectType, object)); - } -} - -export const fetchAndStoreSimulation = (id) => - fetchAndStoreObject("simulation", id, call(getSimulation, id)); - -export const fetchAndStoreUser = (id) => - fetchAndStoreObject("user", id, call(getUser, id),); diff --git a/src/api/sagas/profile.js b/src/api/sagas/profile.js deleted file mode 100644 index 3c4e1825..00000000 --- a/src/api/sagas/profile.js +++ /dev/null @@ -1,12 +0,0 @@ -import {call, put} from "redux-saga/effects"; -import {deleteCurrentUserSucceeded} from "../../actions/users"; -import {deleteUser} from "../routes/users"; - -export function* onDeleteCurrentUser(action) { - try { - yield call(deleteUser, action.userId); - yield put(deleteCurrentUserSucceeded()); - } catch (error) { - console.log(error); - } -} diff --git a/src/api/sagas/simulations.js b/src/api/sagas/simulations.js deleted file mode 100644 index 6b7471c0..00000000 --- a/src/api/sagas/simulations.js +++ /dev/null @@ -1,30 +0,0 @@ -import {call, put} from "redux-saga/effects"; -import {addToStore} from "../../actions/objects"; -import {addSimulationSucceeded, deleteSimulationSucceeded} from "../../actions/simulations"; -import {addSimulation, deleteSimulation} from "../routes/simulations"; - -export function* onSimulationAdd(action) { - try { - const simulation = yield call(addSimulation, {name: action.name}); - yield put(addToStore("simulation", simulation)); - - const authorization = { - simulationId: simulation.id, - userId: action.userId, - authorizationLevel: "OWN" - }; - yield put(addToStore("authorization", authorization)); - yield put(addSimulationSucceeded([authorization.userId, authorization.simulationId])); - } catch (error) { - console.log(error); - } -} - -export function* onSimulationDelete(action) { - try { - yield call(deleteSimulation, action.id); - yield put(deleteSimulationSucceeded(action.id)); - } catch (error) { - console.log(error); - } -} diff --git a/src/api/sagas/users.js b/src/api/sagas/users.js deleted file mode 100644 index d3bc3f5f..00000000 --- a/src/api/sagas/users.js +++ /dev/null @@ -1,46 +0,0 @@ -import {call, put} from "redux-saga/effects"; -import {logInSucceeded} from "../../actions/auth"; -import {addToAuthorizationStore} from "../../actions/objects"; -import {fetchAuthorizationsOfCurrentUserSucceeded} from "../../actions/users"; -import {saveAuthLocalStorage} from "../../auth/index"; -import {performTokenSignIn} from "../routes/token-signin"; -import {addUser, getAuthorizationsByUser} from "../routes/users"; -import {fetchAndStoreSimulation, fetchAndStoreUser} from "./objects"; - -export function* onFetchLoggedInUser(action) { - try { - const tokenResponse = yield call(performTokenSignIn, action.payload.authToken); - let userId = tokenResponse.userId; - - if (tokenResponse.isNewUser) { - saveAuthLocalStorage({authToken: action.payload.authToken}); - const newUser = yield call(addUser, action.payload); - userId = newUser.id; - } - - yield put(logInSucceeded(Object.assign({userId}, action.payload))); - } catch (error) { - console.log(error); - } -} - -export function* onFetchAuthorizationsOfCurrentUser(action) { - try { - const authorizations = yield call(getAuthorizationsByUser, action.userId); - - for (const authorization of authorizations) { - yield put(addToAuthorizationStore(authorization)); - - yield fetchAndStoreSimulation(authorization.simulationId); - yield fetchAndStoreUser(authorization.userId); - } - - const authorizationIds = authorizations.map(authorization => ( - [authorization.userId, authorization.simulationId] - )); - - yield put(fetchAuthorizationsOfCurrentUserSucceeded(authorizationIds)); - } catch (error) { - console.log(error); - } -} |
