Skip to content

Commit

Permalink
[CE-345] Add chain management page
Browse files Browse the repository at this point in the history
Can create,operate,delete chain in react theme.

Change-Id: Id4adf58a961bac98069fb67dd15fbd2a71c155d7
Signed-off-by: Haitao Yue <hightall@me.com>
  • Loading branch information
hightall committed Apr 29, 2018
1 parent 250d693 commit 21f0696
Show file tree
Hide file tree
Showing 10 changed files with 874 additions and 79 deletions.
23 changes: 14 additions & 9 deletions src/resources/cluster_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,28 @@ def cluster_create():
"""
logger.info("/cluster action=" + r.method)
request_debug(r, logger)
if not r.form["name"] or not r.form["host_id"] or \
not r.form["network_type"]:
if r.content_type.startswith("application/json"):
body = dict(r.get_json(force=True, silent=True))
else:
body = r.form
if not body["name"] or not body["host_id"] or \
not body["network_type"]:
error_msg = "cluster post without enough data"
logger.warning(error_msg)
return make_fail_resp(error=error_msg, data=r.form)
return make_fail_resp(error=error_msg, data=body)

name, host_id, network_type, size = \
r.form['name'], r.form['host_id'],\
r.form['network_type'], int(r.form['size'])
body['name'], body['host_id'],\
body['network_type'], int(body['size'])

if network_type == NETWORK_TYPE_FABRIC_PRE_V1: # TODO: deprecated soon
config = FabricPreNetworkConfig(
consensus_plugin=r.form['consensus_plugin'],
consensus_mode=r.form['consensus_mode'],
consensus_plugin=body['consensus_plugin'],
consensus_mode=body['consensus_mode'],
size=size)
elif network_type == NETWORK_TYPE_FABRIC_V1:
config = FabricV1NetworkConfig(
consensus_plugin=r.form['consensus_plugin'],
consensus_plugin=body['consensus_plugin'],
size=size)
else:
error_msg = "Unknown network_type={}".format(network_type)
Expand Down Expand Up @@ -308,7 +312,8 @@ def cluster_list():
elif r.method == 'POST':
f.update(request_json_body(r))
logger.info(f)
result = cluster_handler.list(filter_data=f)
col_name = f.get("state", "active")
result = cluster_handler.list(filter_data=f, col_name=col_name)
logger.error(result)
return make_ok_resp(data=result)

Expand Down
7 changes: 6 additions & 1 deletion src/themes/react/static/dashboard/src/common/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ export const getRouterData = app => {
component: dynamicWrapper(app, ['host'], () => import('../routes/Host/CreateHost')),
},
'/chain': {
component: dynamicWrapper(app, [], () => import('../routes/Chain')),
component: dynamicWrapper(app, ['chain'], () => import('../routes/Chain')),
},
'/create-chain': {
component: dynamicWrapper(app, ['host', 'chain'], () =>
import('../routes/Chain/CreateChain')
),
},
'/user-management': {
component: dynamicWrapper(app, [], () => import('../routes/UserManagement')),
Expand Down
25 changes: 24 additions & 1 deletion src/themes/react/static/dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,28 @@
"Host.Create.Validate.Label.Schedulable": "Schedulable",
"Host.Create.Validate.Label.Filled": "Auto Filled",
"Host.Create.Button.Submit": "Submit",
"Host.Create.Button.Cancel": "Cancel"
"Host.Create.Button.Cancel": "Cancel",
"Chain.Messages.Operate.Success.Restart": "Restart chain {name} successfully.",
"Chain.Messages.Operate.Success.Start": "Start chain {name} successfully.",
"Chain.Messages.Operate.Success.Stop": "Stop chain {name} successfully.",
"Chain.Messages.Operate.Success.Release": "Release chain successfully",
"Chain.Messages.Confirm.DeleteChain": "Do you want to delete chain {name}?",
"Chain.Title": "Chains",
"Chain.Button.Restart": "Restart",
"Chain.Button.Start": "Start",
"Chain.Button.Stop": "Stop",
"Chain.Button.Release": "Release",
"Chain.Button.More": "More",
"Chain.Button.Delete": "Delete",
"Chain.Button.Add": "Add",
"Chain.Radio.Option.Active": "Active",
"Chain.Radio.Option.Released": "Released",
"Chain.Label.NetworkType": "Network Type",
"Chain.Label.ConsensusPlugin": "Consensus Plugin",
"Chain.Label.Owner": "Owner",
"Chain.Label.CreateTime": "Create Time",
"Chain.Create.Title": "Create New Chain",
"Chain.Create.Validate.Required.Host": "Must select a host",
"Chain.Create.Label.Host": "Host",
"Chain.Create.Label.ChainSize": "Chain Size"
}
25 changes: 24 additions & 1 deletion src/themes/react/static/dashboard/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,28 @@
"Host.Create.Validate.Label.Schedulable": "可调度",
"Host.Create.Validate.Label.Filled": "自动填充",
"Host.Create.Button.Submit": "提交",
"Host.Create.Button.Cancel": "取消"
"Host.Create.Button.Cancel": "取消",
"Chain.Messages.Operate.Success.Restart": "重启链 {name} 成功。",
"Chain.Messages.Operate.Success.Start": "启动链 {name} 成功。",
"Chain.Messages.Operate.Success.Stop": "停止链 {name} 成功。",
"Chain.Messages.Operate.Success.Release": "释放链成功",
"Chain.Messages.Confirm.DeleteChain": "是否确认删除链 {name}?",
"Chain.Title": "",
"Chain.Button.Restart": "重启",
"Chain.Button.Start": "启动",
"Chain.Button.Stop": "停止",
"Chain.Button.Release": "释放",
"Chain.Button.More": "更多",
"Chain.Button.Delete": "删除",
"Chain.Button.Add": "添加",
"Chain.Radio.Option.Active": "激活",
"Chain.Radio.Option.Released": "释放",
"Chain.Label.NetworkType": "网络类型",
"Chain.Label.ConsensusPlugin": "共识",
"Chain.Label.Owner": "使用者",
"Chain.Label.CreateTime": "创建时间",
"Chain.Create.Title": "创建新的链",
"Chain.Create.Validate.Required.Host": "必须选择一个主机",
"Chain.Create.Label.Host": "主机",
"Chain.Create.Label.ChainSize": "链大小"
}
96 changes: 96 additions & 0 deletions src/themes/react/static/dashboard/src/models/chain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
SPDX-License-Identifier: Apache-2.0
*/
import { routerRedux } from 'dva/router';
import { IntlProvider, defineMessages } from 'react-intl';
import { message } from 'antd';
import { queryChains, operateChain, deleteChain, createChain } from '../services/chain';
import { getLocale } from '../utils/utils';

const currentLocale = getLocale();
const intlProvider = new IntlProvider(
{ locale: currentLocale.locale, messages: currentLocale.messages },
{}
);
const { intl } = intlProvider.getChildContext();

const messages = defineMessages({
operate: {
success: {
restart: {
id: 'Chain.Messages.Operate.Success.Restart',
defaultMessage: '重启链 {name} 成功。',
},
start: {
id: 'Chain.Messages.Operate.Success.Start',
defaultMessage: '启动链 {name} 成功。',
},
stop: {
id: 'Chain.Messages.Operate.Success.Stop',
defaultMessage: '停止链 {name} 成功。',
},
release: {
id: 'Chain.Messages.Operate.Success.Release',
defaultMessage: '释放链成功。',
},
},
},
});

export default {
namespace: 'chain',

state: {
chains: [],
},

effects: {
*fetchChains({ payload }, { call, put }) {
const response = yield call(queryChains, payload);
yield put({
type: 'setChains',
payload: response.data,
});
},
*operateChain({ payload }, { call, put }) {
const response = yield call(operateChain, payload);
yield put({
type: 'fetchChains',
});
if (response.code === 200) {
const values = { name: payload.name };
message.success(intl.formatMessage(messages.operate.success[payload.action], values));
}
},
*deleteChain({ payload }, { call, put }) {
const response = yield call(deleteChain, payload);
if (response.code === 200) {
message.success(`Delete Chain ${payload.name} successfully`);
}
yield put({
type: 'fetchChains',
});
},
*createChain({ payload }, { call, put }) {
const response = yield call(createChain, payload);
if (response.code === 201) {
message.success('Create Chain successfully');
yield put(
routerRedux.push({
pathname: '/chain',
})
);
}
yield call(payload.callback);
},
},

reducers: {
setChains(state, action) {
return {
...state,
chains: action.payload,
};
},
},
};
Loading

0 comments on commit 21f0696

Please sign in to comment.