-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hosts api; Add hosts table view for react theme; Change-Id: I07efe8a5ac052ddc750249224efdd5c00c72e436 Signed-off-by: Haitao Yue <hightall@me.com>
- Loading branch information
Showing
9 changed files
with
178 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Created by yuehaitao on 2017/2/7. | ||
*/ | ||
import React, { PropTypes } from 'react' | ||
import { Badge, Tag, Button, Table, Popconfirm, Pagination } from 'antd' | ||
import styles from './list.less' | ||
|
||
function list({loadingList, dataSource, onDeleteItem, onSelectItem, onSelectTagItem}) { | ||
const columns = [ | ||
{ | ||
title: 'Name', | ||
dataIndex: 'name', | ||
key: 'name', | ||
render: (text, record) => ( | ||
<a onClick={() => onSelectItem(record.id)}>{text}</a> | ||
) | ||
}, | ||
{ | ||
title: 'Status', | ||
dataIndex: 'status', | ||
key: 'status', | ||
render: (text) => ( | ||
<span>{text == "active" ? <Badge status="success" text={text}/> : <Badge status="warning" text={text} />}</span> | ||
) | ||
}, | ||
{ | ||
title: 'Create Time', | ||
dataIndex: 'create_ts', | ||
key: 'create_ts' | ||
}, | ||
{ | ||
title: 'Log Level', | ||
dataIndex: 'log_level', | ||
key: 'log_level' | ||
}, | ||
{ | ||
title: 'Type', | ||
dataIndex: 'type', | ||
key: 'type' | ||
}, | ||
{ | ||
title: 'Log Type', | ||
dataIndex: 'log_type', | ||
key: 'log_type' | ||
}, | ||
{ | ||
title: 'Operation', | ||
key: 'operation', | ||
width: 100, | ||
render: (text, record) => ( | ||
<p> | ||
<Popconfirm title="Confirm to Delete?" onConfirm={() => onDeleteItem(record.id, record.name)}> | ||
<a style={{color: "red"}}>Delete</a> | ||
</Popconfirm> | ||
</p> | ||
) | ||
} | ||
] | ||
|
||
return ( | ||
<div> | ||
<Table | ||
className={styles.table} | ||
columns={columns} | ||
dataSource={dataSource} | ||
loading={loadingList} | ||
size="small" | ||
rowKey={record => record.id} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
list.propTypes = { | ||
loadingList: PropTypes.any, | ||
dataSource: PropTypes.array, | ||
pagination: PropTypes.any, | ||
onPageChange: PropTypes.func, | ||
onDeleteItem: PropTypes.func, | ||
onSelectItem: PropTypes.func, | ||
onSelectTagItem: PropTypes.func | ||
} | ||
|
||
export default list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.avatar{ | ||
line-height: 1; | ||
img{ | ||
border-radius: 50%; | ||
} | ||
} | ||
.table{ | ||
td{ | ||
height: 38px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,52 @@ | ||
/** | ||
* Created by yuehaitao on 2017/1/18. | ||
*/ | ||
import {getHosts} from '../services/hosts' | ||
import {message} from 'antd' | ||
|
||
export default { | ||
namespace: 'host', | ||
state: { | ||
loadingHosts: false, | ||
hosts: [] | ||
}, | ||
subscriptions: { | ||
setup({dispatch, history}) { | ||
history.listen(location => { | ||
if (location.pathname == '/hosts') { | ||
dispatch({type: 'queryHostList'}) | ||
dispatch({type: 'getHosts'}) | ||
} | ||
}) | ||
} | ||
}, | ||
effects: { | ||
*queryHostList({ | ||
payload | ||
}, {call, put}) { | ||
console.log("query host list") | ||
*getHosts({payload}, {call, put}) { | ||
yield put({type: 'showLoadingHosts'}) | ||
try { | ||
const data = yield call(getHosts) | ||
if (data && data.status == "OK") { | ||
yield put({type: 'getHostsSuccess', payload: { | ||
hosts: data.data | ||
}}) | ||
} else { | ||
message.error("get hosts list failed") | ||
yield put({type: 'hideLoadingHosts'}) | ||
} | ||
} catch (e) { | ||
message.error("get hosts list failed") | ||
yield put({type: 'hideLoadingHosts'}) | ||
} | ||
} | ||
}, | ||
reducers: { | ||
showLoadingHosts(state) { | ||
return {...state, loadingHosts: true} | ||
}, | ||
hideLoadingHosts(state) { | ||
return {...state, loadingHosts: false} | ||
}, | ||
getHostsSuccess(state, action) { | ||
return {...state, ...action.payload, loadingHosts: false} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import React from 'react' | ||
import HostsList from '../components/hosts/list' | ||
import { connect } from 'dva' | ||
|
||
const Hosts = () => <div className='content-inner'> | ||
<div> | ||
<h1>Hosts</h1> | ||
</div> | ||
</div> | ||
class Hosts extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
} | ||
render() { | ||
const {host: {loadingHosts, hosts}} = this.props; | ||
const hostsListProps = { | ||
dataSource: hosts, | ||
loadingList: loadingHosts | ||
} | ||
return ( | ||
<div className="content-inner"> | ||
<HostsList {...hostsListProps} /> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default Hosts | ||
export default connect(({host}) => ({host}))(Hosts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Created by yuehaitao on 2017/1/18. | ||
*/ | ||
import { request } from '../utils' | ||
import { config } from '../utils' | ||
|
||
export async function getHosts(params) { | ||
return request(config.urls.hosts, { | ||
method: 'get', | ||
data: params | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const apiBase = '/api' | ||
module.exports = { | ||
name: 'Cello Dashboard', | ||
prefix: 'cello', | ||
footerText: 'Cello Dashboard', | ||
logoText: 'Cello', | ||
urls: { | ||
queryStat: '/api/stat' | ||
queryStat: apiBase + '/stat', | ||
hosts: apiBase + '/hosts' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters