mirror of https://github.com/openspug/spug
parent
00797fa29e
commit
6f2c22acdd
|
@ -6,6 +6,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Modal, Collapse, Icon } from 'antd';
|
import { Modal, Collapse, Icon } from 'antd';
|
||||||
|
import OutView from './OutView';
|
||||||
import styles from './index.module.css';
|
import styles from './index.module.css';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ class ExecConsole extends React.Component {
|
||||||
this.socket.onopen = () => {
|
this.socket.onopen = () => {
|
||||||
this.socket.send('ok');
|
this.socket.send('ok');
|
||||||
for (let item of Object.values(store.outputs)) {
|
for (let item of Object.values(store.outputs)) {
|
||||||
item['system'] += '### Waiting for schedule\n'
|
item['system'].push('### Waiting for schedule\n')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.socket.onmessage = e => {
|
this.socket.onmessage = e => {
|
||||||
|
@ -38,11 +39,7 @@ class ExecConsole extends React.Component {
|
||||||
if (status !== undefined) {
|
if (status !== undefined) {
|
||||||
store.outputs[key]['status'] = status
|
store.outputs[key]['status'] = status
|
||||||
} else if (data) {
|
} else if (data) {
|
||||||
store.outputs[key][type] += data;
|
store.outputs[key][type].push(data);
|
||||||
store.outputs[key]['latest'] = data;
|
|
||||||
if (this.elements[key]) {
|
|
||||||
this.elements[key].scrollIntoView({behavior: 'smooth'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,15 +49,21 @@ class ExecConsole extends React.Component {
|
||||||
this.socket.close()
|
this.socket.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
genExtra = (key) => {
|
genExtra = (outputs) => {
|
||||||
const item = store.outputs[key];
|
let latest, icon;
|
||||||
|
if (outputs['status'] === -2) {
|
||||||
|
return <Icon type="loading" style={{fontSize: 20, color: '#108ee9'}}/>
|
||||||
|
} else if (outputs['status'] === 0) {
|
||||||
|
latest = outputs['info'][outputs['info'].length - 1];
|
||||||
|
icon = <Icon type="check-circle" style={{fontSize: 20}} theme="twoTone" twoToneColor="#52c41a"/>
|
||||||
|
} else {
|
||||||
|
latest = outputs['error'][outputs['error'].length - 1]
|
||||||
|
icon = <Icon type="warning" style={{fontSize: 20}} theme="twoTone" twoToneColor="red"/>
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div style={{display: 'flex', alignItems: 'center'}}>
|
<div style={{display: 'flex', alignItems: 'center'}}>
|
||||||
<pre className={styles.header}>{item['latest']}</pre>
|
<pre className={styles.header}>{latest}</pre>
|
||||||
{item['status'] === -2 ? <Icon type="loading" style={{fontSize: 20, color: '#108ee9'}}/> :
|
{icon}
|
||||||
item['status'] === 0 ?
|
|
||||||
<Icon type="check-circle" style={{fontSize: 20}} theme="twoTone" twoToneColor="#52c41a"/> :
|
|
||||||
<Icon type="warning" style={{fontSize: 20}} theme="twoTone" twoToneColor="red"/>}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -84,12 +87,8 @@ class ExecConsole extends React.Component {
|
||||||
<Collapse.Panel
|
<Collapse.Panel
|
||||||
key={index}
|
key={index}
|
||||||
header={<b>{item['title']}</b>}
|
header={<b>{item['title']}</b>}
|
||||||
extra={this.genExtra(key)}>
|
extra={this.genExtra(item)}>
|
||||||
<pre className={styles.console}>
|
<OutView outputs={item}/>
|
||||||
<pre style={{color: '#91d5ff'}}>{item['system']}</pre>
|
|
||||||
{item['info']}
|
|
||||||
<pre ref={ref => this.elements[key] = ref} style={{color: '#ffa39e'}}>{item['error']}</pre>
|
|
||||||
</pre>
|
|
||||||
</Collapse.Panel>
|
</Collapse.Panel>
|
||||||
))}
|
))}
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) OpenSpug Organization. https://github.com/openspug/spug
|
||||||
|
* Copyright (c) <spug.dev@gmail.com>
|
||||||
|
* Released under the AGPL-3.0 License.
|
||||||
|
*/
|
||||||
|
import React from 'react';
|
||||||
|
import { toJS } from 'mobx';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import styles from './index.module.css';
|
||||||
|
|
||||||
|
@observer
|
||||||
|
class OutView extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.el = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||||
|
setTimeout(() => this.el.scrollTop = this.el.scrollHeight, 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const outputs = toJS(this.props.outputs);
|
||||||
|
return (
|
||||||
|
<div ref={ref => this.el = ref} className={styles.console}>
|
||||||
|
<pre style={{color: '#91d5ff'}}>{outputs['system']}</pre>
|
||||||
|
<pre>{outputs['info']}</pre>
|
||||||
|
<pre style={{color: '#ffa39e'}}>{outputs['error']}</pre>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default OutView
|
|
@ -5,6 +5,7 @@
|
||||||
.console {
|
.console {
|
||||||
max-height: 300px;
|
max-height: 300px;
|
||||||
padding: 10px 15px;
|
padding: 10px 15px;
|
||||||
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
|
|
|
@ -30,10 +30,9 @@ class Store {
|
||||||
const key = `${item.hostname}:${item.port}`;
|
const key = `${item.hostname}:${item.port}`;
|
||||||
this.outputs[key] = {
|
this.outputs[key] = {
|
||||||
title: `${item.name}(${key})`,
|
title: `${item.name}(${key})`,
|
||||||
system: '### Establishing communication\n',
|
system: ['### Establishing communication\n'],
|
||||||
info: '',
|
info: [],
|
||||||
error: '',
|
error: [],
|
||||||
latest: '',
|
|
||||||
status: -2
|
status: -2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue