summaryrefslogtreecommitdiff
path: root/frontend/src/sagas
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-07-21 15:33:37 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:16 +0200
commit912e1b96bfa7d6c022d854fa744f719b49ca98d0 (patch)
tree49cdaf109aa08b0149c34174ce0f00c7056221ea /frontend/src/sagas
parent791b5d1e443f97adc756264878c3aae41ca0f748 (diff)
Add first plotting attempts for portfolios
Diffstat (limited to 'frontend/src/sagas')
-rw-r--r--frontend/src/sagas/index.js13
-rw-r--r--frontend/src/sagas/objects.js32
-rw-r--r--frontend/src/sagas/portfolios.js12
-rw-r--r--frontend/src/sagas/scenarios.js16
-rw-r--r--frontend/src/sagas/topology.js14
5 files changed, 33 insertions, 54 deletions
diff --git a/frontend/src/sagas/index.js b/frontend/src/sagas/index.js
index daae8d8c..9f6c4809 100644
--- a/frontend/src/sagas/index.js
+++ b/frontend/src/sagas/index.js
@@ -1,10 +1,6 @@
import { takeEvery } from 'redux-saga/effects'
import { LOG_IN } from '../actions/auth'
-import {
- ADD_PORTFOLIO,
- DELETE_PORTFOLIO,
- OPEN_PORTFOLIO_SUCCEEDED, UPDATE_PORTFOLIO,
-} from '../actions/portfolios'
+import { ADD_PORTFOLIO, DELETE_PORTFOLIO, OPEN_PORTFOLIO_SUCCEEDED, UPDATE_PORTFOLIO } from '../actions/portfolios'
import { ADD_PROJECT, DELETE_PROJECT, OPEN_PROJECT_SUCCEEDED } from '../actions/projects'
import {
ADD_TILE,
@@ -16,12 +12,7 @@ import { ADD_UNIT, DELETE_MACHINE, DELETE_UNIT } from '../actions/topology/machi
import { ADD_MACHINE, DELETE_RACK, EDIT_RACK_NAME } from '../actions/topology/rack'
import { ADD_RACK_TO_TILE, DELETE_ROOM, EDIT_ROOM_NAME } from '../actions/topology/room'
import { DELETE_CURRENT_USER, FETCH_AUTHORIZATIONS_OF_CURRENT_USER } from '../actions/users'
-import {
- onAddPortfolio,
- onDeletePortfolio,
- onOpenPortfolioSucceeded,
- onUpdatePortfolio,
-} from './portfolios'
+import { onAddPortfolio, onDeletePortfolio, onOpenPortfolioSucceeded, onUpdatePortfolio } from './portfolios'
import { onDeleteCurrentUser } from './profile'
import { onOpenProjectSucceeded, onProjectAdd, onProjectDelete } from './projects'
import {
diff --git a/frontend/src/sagas/objects.js b/frontend/src/sagas/objects.js
index 17b28d02..1dbc7903 100644
--- a/frontend/src/sagas/objects.js
+++ b/frontend/src/sagas/objects.js
@@ -96,7 +96,7 @@ export const fetchAndStoreTopology = function* (id) {
const filledSlots = new Array(fullRack.capacity).fill(null)
fullRack.machines.forEach(
- (machine) => (filledSlots[machine.position - 1] = machine._id),
+ (machine) => (filledSlots[machine.position - 1] = machine._id)
)
let rack = (({ _id, name, capacity, powerCapacityW }) => ({
_id,
@@ -165,21 +165,21 @@ export const updateTopologyOnServer = function* (id) {
rack: !tileStore[tileId].rackId
? undefined
: {
- _id: rackStore[tileStore[tileId].rackId]._id,
- name: rackStore[tileStore[tileId].rackId].name,
- capacity: rackStore[tileStore[tileId].rackId].capacity,
- powerCapacityW: rackStore[tileStore[tileId].rackId].powerCapacityW,
- machines: rackStore[tileStore[tileId].rackId].machineIds
- .filter((m) => m !== null)
- .map((machineId) => ({
- _id: machineId,
- position: machineStore[machineId].position,
- cpus: machineStore[machineId].cpuIds.map((id) => cpuStore[id]),
- gpus: machineStore[machineId].gpuIds.map((id) => gpuStore[id]),
- memories: machineStore[machineId].memoryIds.map((id) => memoryStore[id]),
- storages: machineStore[machineId].storageIds.map((id) => storageStore[id]),
- })),
- },
+ _id: rackStore[tileStore[tileId].rackId]._id,
+ name: rackStore[tileStore[tileId].rackId].name,
+ capacity: rackStore[tileStore[tileId].rackId].capacity,
+ powerCapacityW: rackStore[tileStore[tileId].rackId].powerCapacityW,
+ machines: rackStore[tileStore[tileId].rackId].machineIds
+ .filter((m) => m !== null)
+ .map((machineId) => ({
+ _id: machineId,
+ position: machineStore[machineId].position,
+ cpus: machineStore[machineId].cpuIds.map((id) => cpuStore[id]),
+ gpus: machineStore[machineId].gpuIds.map((id) => gpuStore[id]),
+ memories: machineStore[machineId].memoryIds.map((id) => memoryStore[id]),
+ storages: machineStore[machineId].storageIds.map((id) => storageStore[id]),
+ })),
+ },
})),
})),
}
diff --git a/frontend/src/sagas/portfolios.js b/frontend/src/sagas/portfolios.js
index cda1be9b..3c004282 100644
--- a/frontend/src/sagas/portfolios.js
+++ b/frontend/src/sagas/portfolios.js
@@ -62,7 +62,7 @@ export function* onAddPortfolio(action) {
Object.assign({}, action.portfolio, {
projectId: currentProjectId,
scenarioIds: [],
- }),
+ })
)
yield put(addToStore('portfolio', portfolio))
@@ -70,7 +70,7 @@ export function* onAddPortfolio(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
portfolioIds: portfolioIds.concat([portfolio._id]),
- }),
+ })
)
} catch (error) {
console.error(error)
@@ -79,11 +79,7 @@ export function* onAddPortfolio(action) {
export function* onUpdatePortfolio(action) {
try {
- const portfolio = yield call(
- updatePortfolio,
- action.portfolio._id,
- action.portfolio,
- )
+ const portfolio = yield call(updatePortfolio, action.portfolio._id, action.portfolio)
yield put(addToStore('portfolio', portfolio))
} catch (error) {
console.error(error)
@@ -100,7 +96,7 @@ export function* onDeletePortfolio(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
portfolioIds: portfolioIds.filter((id) => id !== action.id),
- }),
+ })
)
} catch (error) {
console.error(error)
diff --git a/frontend/src/sagas/scenarios.js b/frontend/src/sagas/scenarios.js
index 48b1e9be..3ecc3fc4 100644
--- a/frontend/src/sagas/scenarios.js
+++ b/frontend/src/sagas/scenarios.js
@@ -23,18 +23,14 @@ export function* onOpenScenarioSucceeded(action) {
export function* onAddScenario(action) {
try {
- const scenario = yield call(
- addScenario,
- action.scenario.portfolioId,
- action.scenario,
- )
+ const scenario = yield call(addScenario, action.scenario.portfolioId, action.scenario)
yield put(addToStore('scenario', scenario))
const scenarioIds = yield select((state) => state.objects.portfolio[action.scenario.portfolioId].scenarioIds)
yield put(
addPropToStoreObject('portfolio', action.scenario.portfolioId, {
scenarioIds: scenarioIds.concat([scenario._id]),
- }),
+ })
)
} catch (error) {
console.error(error)
@@ -43,11 +39,7 @@ export function* onAddScenario(action) {
export function* onUpdateScenario(action) {
try {
- const scenario = yield call(
- updateScenario,
- action.scenario._id,
- action.scenario,
- )
+ const scenario = yield call(updateScenario, action.scenario._id, action.scenario)
yield put(addToStore('scenario', scenario))
} catch (error) {
console.error(error)
@@ -64,7 +56,7 @@ export function* onDeleteScenario(action) {
yield put(
addPropToStoreObject('scenario', currentPortfolioId, {
scenarioIds: scenarioIds.filter((id) => id !== action.id),
- }),
+ })
)
} catch (error) {
console.error(error)
diff --git a/frontend/src/sagas/topology.js b/frontend/src/sagas/topology.js
index e915f9ff..14c1ed2d 100644
--- a/frontend/src/sagas/topology.js
+++ b/frontend/src/sagas/topology.js
@@ -44,7 +44,7 @@ export function* onAddTopology(action) {
addTopology,
Object.assign({}, action.topology, {
projectId: currentProjectId,
- }),
+ })
)
yield fetchAndStoreTopology(topology._id)
@@ -52,7 +52,7 @@ export function* onAddTopology(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.concat([topology._id]),
- }),
+ })
)
yield put(setCurrentTopology(topology._id))
} catch (error) {
@@ -74,7 +74,7 @@ export function* onDeleteTopology(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.filter((id) => id !== action.id),
- }),
+ })
)
} catch (error) {
console.error(error)
@@ -258,7 +258,7 @@ export function* onAddUnit(action) {
const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
(state) =>
- state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]],
+ state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
)
if (machine[action.unitType + 'Ids'].length >= MAX_NUM_UNITS_PER_MACHINE) {
@@ -269,7 +269,7 @@ export function* onAddUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: units,
- }),
+ })
)
yield updateTopologyOnServer(topologyId)
} catch (error) {
@@ -284,7 +284,7 @@ export function* onDeleteUnit(action) {
const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
(state) =>
- state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]],
+ state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
)
const unitIds = machine[action.unitType + 'Ids'].slice()
unitIds.splice(action.index, 1)
@@ -292,7 +292,7 @@ export function* onDeleteUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: unitIds,
- }),
+ })
)
yield updateTopologyOnServer(topologyId)
} catch (error) {