Commit 610b2387 authored by Matthieu Lamalle's avatar Matthieu Lamalle Committed by Lionel Morin
Browse files

integrate servermodel config editor

parent 72f1dbaa
......@@ -9,26 +9,37 @@ export const CONFIG_START_SESSION_REQUEST = 'CONFIG_START_SESSION_REQUEST';
export const CONFIG_START_SESSION_SUCCESS = 'CONFIG_START_SESSION_SUCCESS';
export const CONFIG_START_SESSION_FAILURE = 'CONFIG_START_SESSION_FAILURE';
export function startSession(serverId) {
export function startSession(id, type) {
return dispatch => {
dispatch(request(serverId));
return Zephir.v1.config.session.server.start({
id: serverId
}).then(({response}) => {
dispatch(success(response));
return response;
}).catch(err => {
dispatch(failure(err));
throw err;
});
dispatch(request(id));
if (type === 'server'){
return Zephir.v1.config.session.server.start({
id: id
}).then(({response}) => {
dispatch(success(response));
return response;
}).catch(err => {
dispatch(failure(err));
throw err;
});
}
if (type === 'servermodel'){
return Zephir.v1.config.session.servermodel.start({
id: id
}).then(({response}) => {
dispatch(success(response));
return response;
}).catch(err => {
dispatch(failure(err));
throw err;
});
}
};
function request(serverId) { return { type: CONFIG_START_SESSION_REQUEST, serverId }; }
function request(id) { return { type: CONFIG_START_SESSION_REQUEST, id }; }
function success(response) { return { type: CONFIG_START_SESSION_SUCCESS, ...response }; }
function failure(error, serverId) { return { type: CONFIG_START_SESSION_FAILURE, serverId, error }; }
function failure(error, id) { return { type: CONFIG_START_SESSION_FAILURE, id, error }; }
}
......@@ -36,20 +47,32 @@ export const CONFIG_STOP_SESSION_REQUEST = 'CONFIG_STOP_SESSION_REQUEST';
export const CONFIG_STOP_SESSION_SUCCESS = 'CONFIG_STOP_SESSION_SUCCESS';
export const CONFIG_STOP_SESSION_FAILURE = 'CONFIG_STOP_SESSION_FAILURE';
export function stopSession(sessionId) {
export function stopSession(sessionId, type) {
return dispatch => {
dispatch(request(sessionId));
return Zephir.v1.config.session.server.stop({
sessionid: sessionId.toString()
}).then(({response}) => {
dispatch(success(response));
return response;
}).catch(err => {
dispatch(failure(err, sessionId));
throw err;
});
if (type==='server'){
return Zephir.v1.config.session.server.stop({
sessionid: sessionId.toString()
}).then(({response}) => {
dispatch(success(response));
return response;
}).catch(err => {
dispatch(failure(err, sessionId));
throw err;
});
}
if (type==='servermodel'){
return Zephir.v1.config.session.servermodel.stop({
sessionid: sessionId.toString()
}).then(({response}) => {
dispatch(success(response));
return response;
}).catch(err => {
dispatch(failure(err, sessionId));
throw err;
});
}
};
......
......@@ -18,27 +18,43 @@ class ConfigEditor extends React.Component {
static getInstanceLabel(instance) {
const { server } = instance.opts || {};
const { servermodel } = instance.opts || {};
let name = ''
if (server) {name = server.servername}
if (servermodel) {name = servermodel.servermodelname}
const { label } = ConfigEditor.getAppMetadata();
return `${server.servername} - ${label}`;
return `${name} - ${label}`;
}
static open(instance, opened) {
const { server } = instance.opts || {};
if (!server) return Promise.reject('Un serveur doit être spécifié.');
const { servermodel } = instance.opts || {};
if (!server && ! servermodel) return Promise.reject('Un serveur ou un modèle doit être spécifié.');
const serverId = parseInt(server.serverid, 10);
let id = 0;
if (server) id = parseInt(server.serverid, 10);
if (servermodel) id = parseInt(servermodel.servermodelid, 10);
// L'édition de la configuration est en mode "singleton"
// on doit donc rechercher si une instance est déjà ouverte pour le serveur
for(let openedInstance, i = 0; (openedInstance = opened[i]); ++i) {
if (openedInstance.appName !== instance.appName) continue;
if (openedInstance.opts.server.serverid === server.serverid) {
if (server && openedInstance.opts.server.serverid === id) {
return Promise.resolve(openedInstance);
}
if (servermodel && openedInstance.opts.servermodel.servermodelid === id) {
return Promise.resolve(openedInstance);
}
}
let type = '';
if (server) type = 'server';
if (servermodel) type = 'servermodel';
return store.dispatch(configActions.startSession(serverId))
return store.dispatch(configActions.startSession(id, type))
.then(res => {
instance.opts.configSession = {id: res.sessionid, url: `/config/${res.sessionid}/`};
return instance;
......@@ -69,9 +85,14 @@ class ConfigEditor extends React.Component {
static close(instance) {
const { configSession } = instance.opts || {};
const { server } = instance.opts || {};
const { servermodel } = instance.opts || {};
let type = "";
if (server) type = "server"
if (servermodel) type = "servermodel"
if (!configSession) return Promise.reject('Aucune session d\'édition de configuration n\'est associée à l\'application.');
document.cookie = "X-Userinfo=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
return store.dispatch(configActions.stopSession(configSession.id))
return store.dispatch(configActions.stopSession(configSession.id, type))
.catch(err => {
store.dispatch(alertActions.error(err.message));
});
......@@ -96,10 +117,6 @@ ConfigEditor.propTypes = {
instance: PropTypes.object.isRequired
};
ConfigEditor.instanceOptsPropTypes = {
server: PropTypes.object.isRequired
};
const styles = theme => {
return {
frame: {
......
......@@ -17,6 +17,12 @@ class AppDetail extends React.Component {
render() {
const { classes, instance, onClose } = this.props;
const title = getInstanceLabel(instance);
console.log(this.props)
let id = '';
let type = '';
if (instance.opts.server) {id = instance.opts.server.serverid ; type = 'servers'}
if (instance.opts.servermodel) {id = instance.opts.servermodel.servermodelid; type = 'servermodels'}
console.log(type)
return (
<Page title={title}
className={`${classes.root} ${classes.appBar}`} navLeft={
......@@ -24,7 +30,7 @@ class AppDetail extends React.Component {
<AppIcon icon={instance.icon} />
</div>
} navRight={
<IconButton onClick={() => onClose(instance.id, instance.opts.server.serverid)} color="inherit">
<IconButton onClick={() => onClose(instance.id, id, type)} color="inherit">
<CloseIcon />
</IconButton>
}>
......
......@@ -19,10 +19,10 @@ class AppsPage extends React.Component {
this.renderApps = this.renderApps.bind(this);
}
closeApp(id,serverid) {
this.props.dispatch(appActions.closeApp(id,serverid));
closeApp(id,srcid,type) {
this.props.dispatch(appActions.closeApp(id,srcid));
//history.goBack();
history.push("/servers/"+serverid);
history.push("/"+type+"/"+srcid);
}
render() {
......
......@@ -14,6 +14,10 @@ import {
GridList,
GridListTile,
} from '@material-ui/core';
import {
Settings as SettingsIcon,
} from '@material-ui/icons';
import { appActions } from '../../actions';
import {
Page,
......@@ -27,6 +31,7 @@ class ServerModelDetail extends React.Component {
this.state = {
isLoading: false,
};
this.onAppClick = this.onAppClick.bind(this);
}
render(){
......@@ -56,7 +61,15 @@ class ServerModelDetail extends React.Component {
<ListItem divider >
<ListItemText primary="Description" secondary={servermodel.model.servermodeldescription} />
</ListItem>
<ListItem divider
button
onClick={this.onAppClick}
>
<ListItemText primary="Configuration" secondary="Editer la configuration du modèle de serveur" />
<SettingsIcon />
</ListItem>
</List>
</GridListTile>
}
right={
......@@ -77,6 +90,13 @@ class ServerModelDetail extends React.Component {
);
}
onAppClick(app) {
const { servermodel } = this.props;
this.props.dispatch(appActions.openApp('ConfigEditor', {servermodel: servermodel.model}))
.then(instance => this.props.history.push(`/apps/${instance.id}`));
}
showServices = (servermodel) => {
const service = servermodel.services.map(el =>
<ListItem key={el.id} divider>
......
......@@ -9,7 +9,7 @@ import { withStyles } from '@material-ui/core/styles';
import { AppIcon } from '../../components';
class ServerApps extends React.Component {
render() {
render() {
return (
<List>
{ this.renderApps() }
......
......@@ -19,6 +19,7 @@ import {
GridList,
GridListTile
} from '@material-ui/core';
import {
Edit as EditIcon,
Delete as DeleteIcon,
......
......@@ -63,6 +63,11 @@ const api = {
'start',
'stop',
'list'
],
servermodel: [
'start',
'stop',
'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