Commit 0f0a7db4 authored by Matthieu Lamalle's avatar Matthieu Lamalle Committed by Lionel Morin
Browse files

display selections of a server

parent 081306ff
......@@ -7,6 +7,7 @@ export const serverActions = {
create,
updateLocalFilter,
update,
selectionlist,
delete: _delete,
getPeeringConf,
getAll: () => ({type: 'GETALL_NOOP'}),
......@@ -168,3 +169,26 @@ function getPeeringConf(serverId) {
function success(result) { return { type: SERVER_PEERING_CONF_GET_SUCCESS, result }; }
function failure(error) { return { type: SERVER_PEERING_CONF_GET_FAILURE, error }; }
}
export const SERVER_SERVERSELECTION_LIST_REQUEST = 'SERVER_SERVERSELECTION_LIST_REQUEST';
export const SERVER_SERVERSELECTION_LIST_SUCCESS = 'SERVER_SERVERSELECTION_LIST_SUCCESS';
export const SERVER_SERVERSELECTION_LIST_FAILURE = 'SERVER_SERVERSELECTION_LIST_FAILURE';
function selectionlist(serverId) {
return dispatch => {
dispatch(request());
return Zephir.v1.server.serverselection.list({ serverid: serverId })
.then(({response}) => {
dispatch(success(response));
return response;
})
.catch(error => {
dispatch(failure(error));
dispatch(alertActions.error(error.message));
throw error;
});
};
function request(serverId) { return { type: SERVER_SERVERSELECTION_LIST_REQUEST }; }
function success(selections) { return { type: SERVER_SERVERSELECTION_LIST_SUCCESS, selections }; }
function failure(error) { return { type: SERVER_SERVERSELECTION_LIST_FAILURE, error }; }
}
......@@ -94,7 +94,7 @@ class ServerSelectionForm extends React.Component {
requete: ''
};
history.listen((location, action) => {
this.setState({ dismount: true })
this.setState({ dismount: true })
});
return (
......
......@@ -17,12 +17,14 @@ import {
withMobileDialog,
Typography,
GridList,
GridListTile
GridListTile,
Chip
} from '@material-ui/core';
import {
Edit as EditIcon,
Delete as DeleteIcon,
ViewModule as ServerSelectionIcon
} from '@material-ui/icons';
import {
selectServerById,
......@@ -70,12 +72,14 @@ class ServerDetail extends React.Component {
.then(() => this.props.history.push(`/servers`));
});
}
handleNone(){}
render(){
const { classes, theme, fullScreen, inner, sm, availableApps, isLoading, server, servermodel } = this.props;
const prevServerSelection = this.props.location.serverselection;
console.log(classes)
const back = (prevServerSelection && "/serverselections/"+prevServerSelection) || `/servers`
console.log(server)
return (
<Page
title={server && server.servername}
......@@ -124,7 +128,22 @@ class ServerDetail extends React.Component {
<ListItemText primary="Modèle" secondary={servermodel && `${servermodel.model.servermodelname} ${servermodel.model.subreleasename}`} />
</Button>
</ListItem>
</List>
<Typography variant="subtitle1">
Sélections :
</Typography>
{server.selections.map((selection) =>
<Chip
variant="outlined"
className={classes.chip}
key={`${selection.serverselectionid}`}
component={Link}
onClick={this.handleNone}
to={`/serverselections/${selection.serverselectionid}`}
label={`${selection.serverselectionname}`}
/>
)}
</GridListTile>
<GridListTile>
<Typography variant="subtitle1">
......@@ -196,7 +215,10 @@ const styles = theme => ({
},
listSubheader: {
backgroundColor: theme.palette.background.paper
}
},
chip: {
margin: '5px'
},
});
ServerDetail.propTypes = {
......@@ -205,15 +227,17 @@ ServerDetail.propTypes = {
fullScreen: PropTypes.bool.isRequired,
};
function mapStateToProps({ apps, servers, servermodels }, { match }) {
function mapStateToProps({ apps, servers, servermodels}, { match }) {
const serverId = parseInt(match.params.id, 10);
const server = selectServerById(servers.byId, serverId);
let servermodel;
if (server) {
servermodel = selectServermodelById(
servermodels.byId,
server.servermodelid
);
server.selections = servers.selections
}
return {
availableApps: apps.available,
......
......@@ -119,8 +119,9 @@ class ServersPage extends React.Component {
const serverPromise = server && server.serverenvironment ?
Promise.resolve(server) :
dispatch(serverActions.describe(serverId))
;
dispatch(serverActions.describe(serverId));
dispatch(serverActions.selectionlist(serverId));
return serverPromise.then(server => {
// On s'assure que le modèle associé au serveur est également bien chargé
const servermodel = selectServermodelById(
......
......@@ -10,6 +10,9 @@ import {
SERVER_UPDATE_SUCCESS,
SERVER_UPDATE_FAILURE,
SERVER_UPDATE_LOCAL_FILTER,
SERVER_SERVERSELECTION_LIST_REQUEST,
SERVER_SERVERSELECTION_LIST_SUCCESS,
SERVER_SERVERSELECTION_LIST_FAILURE,
} from '../actions/server.actions';
const initialState = {
......@@ -26,6 +29,7 @@ export default function servers(state = initialState, action) {
case SERVER_CREATE_REQUEST:
case SERVER_LIST_REQUEST:
case SERVER_UPDATE_REQUEST:
case SERVER_SERVERSELECTION_LIST_REQUEST:
return updateLoadingFlag(state, true);
// Mise à jour du flag "isLoading" à false pour
......@@ -33,6 +37,7 @@ export default function servers(state = initialState, action) {
case SERVER_CREATE_FAILURE:
case SERVER_UPDATE_FAILURE:
case SERVER_LIST_FAILURE:
case SERVER_SERVERSELECTION_LIST_FAILURE:
return updateLoadingFlag(state, false);
case SERVER_CREATE_SUCCESS:
......@@ -42,6 +47,9 @@ export default function servers(state = initialState, action) {
case SERVER_LIST_SUCCESS:
return updateLoadingFlag(handleServerListSuccess(state, action), false);
case SERVER_SERVERSELECTION_LIST_SUCCESS:
return updateLoadingFlag(handleServerSelectionsListSuccess(state, action), false);
case SERVER_DESCRIBE_SUCCESS:
return updateLoadingFlag(handleServerDescribeSuccess(state, action), false);
......@@ -69,6 +77,14 @@ function handleServerListSuccess(state, action) {
}, {...state.serversById})
};
}
function handleServerSelectionsListSuccess(state, action) {
return {
...state,
selections: action.selections
}
};
function handleServerDescribeSuccess(state, action) {
return {
......
......@@ -30,6 +30,11 @@ const api = {
'create',
'update',
'delete',
{
'serverselection': [
'list'
]
}
],
servermodel: [
'list',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment