Skip to content

Commit

Permalink
Add host operation fillup/clean/reset
Browse files Browse the repository at this point in the history
Related to #CE-9

https://jira.hyperledger.org/browse/CE-9

Change-Id: I69233678cf52fa6aed3f190509bed0fd12e58fd2
Signed-off-by: Haitao Yue <[email protected]>
  • Loading branch information
hightall committed Apr 4, 2017
1 parent 453389c commit b3d4986
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 10 deletions.
26 changes: 25 additions & 1 deletion src/themes/react/static/js/models/host.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Created by yuehaitao on 2017/1/18.
*/
import {getHosts, createHost, deleteHost, updateHost} from '../services/host'
import {getHosts, createHost, deleteHost, updateHost, opHost} from '../services/host'
import {message} from 'antd'

export default {
Expand Down Expand Up @@ -84,6 +84,30 @@ export default {
})
message.error("Update host failed")
}
},
*opHost({payload}, {select, call, put}) {
const host = yield select(state => state.host)
let {hosts} = host
hosts.map((host, i) => {
if (host.id === payload.id) {
host.status = "operating"
}
})
yield put({
type: 'getHostsSuccess',
payload: {
hosts
}
})
const data = yield call(opHost, payload)
if (data && data.status === "OK") {
message.success("Operation host successful")
yield put({
type: 'getHosts'
})
} else {
message.error("Operation host failed")
}
}
},
reducers: {
Expand Down
52 changes: 44 additions & 8 deletions src/themes/react/static/js/routes/host/HostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,67 @@ import { DropOption } from '../../components'

const confirm = Modal.confirm

function list({loadingList, dataSource, onDelete, onEdit, onSelectTagItem}) {
function list({loadingList, dataSource, onDelete, onEdit, onOperation}) {
const handleMenuClick = (record, e, index) => {
if (e.key === 'edit') {
onEdit(record)
}else if (e.key === 'delete') {
} else if (e.key === 'delete') {
confirm({
title: 'Confirm to delete?',
onOk () {
onDelete(record, index)
},
})
} else {
if (e.key === 'reset') {
confirm({
title: 'Want to reset?',
content: <div><p>you are about to <span style={{color: 'red'}}>reset</span> the host node1, this procedure is irreversible.</p></div>,
okText: 'Confirm',
cancelText: 'Cancel',
onOk () {
onOperation(record, e.key)
},
})
} else {
onOperation(record, e.key)
}
}
}
const loadingText = ["operating"]
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
render: (text, record) => (
<a onClick={() => onSelectItem(record.id)}>{text}</a>
)
key: 'name'
},
{
title: 'Status',
dataIndex: 'status',
key: 'status',
render: (text) => {
let status = "success"
if (loadingText.indexOf(text) >= 0) {
status = "processing"
} else if (text !== "active") {
status = "warning"
}
return (
<span><Badge status={status} text={text} /></span>
)
}
},
{
title: 'Capacity',
dataIndex: 'capacity',
key: 'capacity'
},
{
title: 'Chains',
dataIndex: 'clusters',
key: 'clusters',
render: (text) => (
<span>{text === "active" ? <Badge status="success" text={text}/> : <Badge status="warning" text={text} />}</span>
<span>{text.length}</span>
)
},
{
Expand Down Expand Up @@ -65,7 +98,10 @@ function list({loadingList, dataSource, onDelete, onEdit, onSelectTagItem}) {
render: (text, record, index) => {
const menuOptions = [
{key: 'edit', name: 'Edit'},
{key: 'delete', name: 'Delete'}
{key: 'delete', name: 'Delete'},
{key: 'fillup', name: 'Fill Up'},
{key: 'clean', name: 'Clean'},
{key: 'reset', name: 'Reset'}
]
return <DropOption onMenuClick={e => handleMenuClick(record, e, index)} menuOptions={menuOptions} />
}
Expand Down
9 changes: 9 additions & 0 deletions src/themes/react/static/js/routes/host/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ class Hosts extends React.Component {
currentHost: record
}
})
},
onOperation(record, operation) {
dispatch({
type: 'host/opHost',
payload: {
id: record.id,
action: operation
}
})
}
}
const modalProps = {
Expand Down
8 changes: 8 additions & 0 deletions src/themes/react/static/js/services/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ export async function updateHost(params) {
data: params
})
}

export async function opHost(params) {
return request({
url: config.urls.host.operation,
method: 'post',
data: params
})
}
3 changes: 2 additions & 1 deletion src/themes/react/static/js/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
list: apiBase + '/hosts',
create: apiBase + '/host',
delete: apiBase + '/host',
update: apiBase + '/host'
update: apiBase + '/host',
operation: apiBase + '/host_op'
}
}
}

0 comments on commit b3d4986

Please sign in to comment.