From 083452dd9028ece35432c059c379f4acdf6dfaab Mon Sep 17 00:00:00 2001 From: vapao Date: Fri, 20 Aug 2021 00:29:33 +0800 Subject: [PATCH] fix issue --- spug_web/src/pages/deploy/do/Ext1Index.js | 182 ----------------- spug_web/src/pages/deploy/do/Ext2Index.js | 188 ------------------ spug_web/src/pages/deploy/do/OutView.js | 36 ---- spug_web/src/pages/deploy/do/index.module.css | 49 ----- spug_web/src/pages/deploy/do/store.js | 17 -- spug_web/src/routes.js | 6 - 6 files changed, 478 deletions(-) delete mode 100644 spug_web/src/pages/deploy/do/Ext1Index.js delete mode 100644 spug_web/src/pages/deploy/do/Ext2Index.js delete mode 100644 spug_web/src/pages/deploy/do/OutView.js delete mode 100644 spug_web/src/pages/deploy/do/index.module.css delete mode 100644 spug_web/src/pages/deploy/do/store.js diff --git a/spug_web/src/pages/deploy/do/Ext1Index.js b/spug_web/src/pages/deploy/do/Ext1Index.js deleted file mode 100644 index 2ba051b..0000000 --- a/spug_web/src/pages/deploy/do/Ext1Index.js +++ /dev/null @@ -1,182 +0,0 @@ -/** - * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug - * Copyright (c) - * Released under the AGPL-3.0 License. - */ -import React from 'react'; -import { observer } from 'mobx-react'; -import { CaretRightOutlined, LoadingOutlined, PlayCircleOutlined, SyncOutlined } from '@ant-design/icons'; -import { Steps, Collapse, PageHeader, Spin, Tag, Button } from 'antd'; -import { http, history, X_TOKEN } from 'libs'; -import { AuthDiv } from 'components'; -import OutView from './OutView'; -import styles from './index.module.css'; -import store from './store'; -import lds from 'lodash'; - -@observer -class Ext1Index extends React.Component { - constructor(props) { - super(props); - this.timer = null; - this.id = props.match.params.id; - this.log = props.match.params.log; - this.state = { - fetching: true, - loading: false, - } - } - - componentDidMount() { - this.fetch() - } - - componentWillUnmount() { - if (this.socket) this.socket.close(); - if (this.timer) clearTimeout(this.timer); - store.request = {targets: [], host_actions: [], server_actions: []}; - store.outputs = {}; - } - - fetch = () => { - if (!this.timer) this.setState({fetching: true}); - http.get(`/api/deploy/request/${this.id}/`, {params: {log: this.log}}) - .then(res => { - store.request = res; - const outputs = {} - while (res.outputs.length) { - const msg = JSON.parse(res.outputs.pop()); - if (!outputs.hasOwnProperty(msg.key)) { - const data = msg.key === 'local' ? ['读取数据... '] : []; - outputs[msg.key] = {data} - } - this._parse_message(msg, outputs) - } - store.outputs = outputs; - if (store.request.status === '2') { - this.timer = setTimeout(this.fetch, 2000) - } else { - this.timer = null - } - }) - .finally(() => this.setState({fetching: false})) - }; - - _parse_message = (message, outputs) => { - outputs = outputs || store.outputs; - const {key, data, step, status} = message; - if (data !== undefined) { - outputs[key]['data'].push(data); - } - if (step !== undefined) outputs[key]['step'] = step; - if (status !== undefined) outputs[key]['status'] = status; - }; - - handleDeploy = () => { - this.setState({loading: true}); - http.post(`/api/deploy/request/${this.id}/`) - .then(({token, outputs}) => { - store.request.status = '2'; - store.outputs = outputs; - const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - this.socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/exec/${token}/?x-token=${X_TOKEN}`); - this.socket.onopen = () => { - this.socket.send('ok'); - }; - this.socket.onmessage = e => { - if (e.data === 'pong') { - this.socket.send('ping') - } else { - this._parse_message(JSON.parse(e.data)) - } - } - }) - .finally(() => this.setState({loading: false})) - }; - - getStatus = (key, n) => { - const step = lds.get(store.outputs, `${key}.step`, -1); - const isError = lds.get(store.outputs, `${key}.status`) === 'error'; - const icon = ; - if (n > step) { - return {key: n, status: 'wait'} - } else if (n === step) { - return isError ? {key: n, status: 'error'} : {key: n, status: 'process', icon} - } else { - return {key: n, status: 'finish'} - } - }; - - getStatusAlias = () => { - if (Object.keys(store.outputs).length !== 0) { - for (let item of [{id: 'local'}, ...store.request.targets]) { - if (lds.get(store.outputs, `${item.id}.status`) === 'error') { - return 发布异常 - } else if (lds.get(store.outputs, `${item.id}.step`, -1) < 5) { - return 发布中 - } - } - return 发布成功 - } else { - return {store.request['status_alias'] || '...'} - } - }; - - render() { - const {app_name, env_name, status} = store.request; - return ( - - - } type="primary" onClick={this.fetch}>刷新 - ) : ( - - )} - onBack={() => history.goBack()}/> - - - - - - - - - }> - - - - - }> - {store.request.targets.map((item, index) => ( - - {item.title} - - - - - - - }> - - - ))} - - - - ) - } -} - -export default Ext1Index diff --git a/spug_web/src/pages/deploy/do/Ext2Index.js b/spug_web/src/pages/deploy/do/Ext2Index.js deleted file mode 100644 index 481d634..0000000 --- a/spug_web/src/pages/deploy/do/Ext2Index.js +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug - * Copyright (c) - * Released under the AGPL-3.0 License. - */ -import React from 'react'; -import { observer } from 'mobx-react'; -import { CaretRightOutlined, LoadingOutlined, PlayCircleOutlined, SyncOutlined } from '@ant-design/icons'; -import { Steps, Collapse, PageHeader, Spin, Tag, Button } from 'antd'; -import { http, history, X_TOKEN } from 'libs'; -import { AuthDiv } from 'components'; -import OutView from './OutView'; -import styles from './index.module.css'; -import store from './store'; -import lds from 'lodash'; - -@observer -class Ext1Index extends React.Component { - constructor(props) { - super(props); - this.timer = null; - this.id = props.match.params.id; - this.log = props.match.params.log; - this.state = { - fetching: true, - loading: false, - } - } - - componentDidMount() { - this.fetch() - } - - componentWillUnmount() { - if (this.socket) this.socket.close(); - if (this.timer) clearTimeout(this.timer); - store.request = {targets: [], server_actions: [], host_actions: []}; - store.outputs = {}; - } - - - fetch = () => { - if (!this.timer) this.setState({fetching: true}); - http.get(`/api/deploy/request/${this.id}/`, {params: {log: this.log}}) - .then(res => { - store.request = res; - const outputs = {}; - while (res.outputs.length) { - const msg = JSON.parse(res.outputs.pop()); - if (!outputs.hasOwnProperty(msg.key)) { - const data = msg.key === 'local' ? ['读取数据... '] : []; - outputs[msg.key] = {data} - } - this._parse_message(msg, outputs) - } - store.outputs = outputs; - if (store.request.status === '2') { - this.timer = setTimeout(this.fetch, 2000) - } else { - this.timer = null - } - }) - .finally(() => this.setState({fetching: false})) - }; - - _parse_message = (message, outputs) => { - outputs = outputs || store.outputs; - const {key, data, step, status} = message; - if (data !== undefined) { - outputs[key]['data'].push(data); - } - if (step !== undefined) outputs[key]['step'] = step; - if (status !== undefined) outputs[key]['status'] = status; - }; - - handleDeploy = () => { - this.setState({loading: true}); - http.post(`/api/deploy/request/${this.id}/`) - .then(({token, outputs}) => { - store.request.status = '2'; - store.outputs = outputs; - const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - this.socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/exec/${token}/?x-token=${X_TOKEN}`); - this.socket.onopen = () => { - this.socket.send('ok'); - }; - this.socket.onmessage = e => { - if (e.data === 'pong') { - this.socket.send('ping') - } else { - this._parse_message(JSON.parse(e.data)) - } - } - }) - .finally(() => this.setState({loading: false})) - }; - - getStatus = (key, n) => { - const step = lds.get(store.outputs, `${key}.step`, -1); - const isError = lds.get(store.outputs, `${key}.status`) === 'error'; - const icon = ; - if (n > step) { - return {key: n, status: 'wait'} - } else if (n === step) { - return isError ? {key: n, status: 'error'} : {key: n, status: 'process', icon} - } else { - return {key: n, status: 'finish'} - } - }; - - getStatusAlias = () => { - if (Object.keys(store.outputs).length !== 0) { - const {targets, host_actions} = store.request; - for (let item of [{id: 'local'}, ...(host_actions.length > 0 ? targets : [])]) { - if (lds.get(store.outputs, `${item.id}.status`) === 'error') { - return 发布异常 - } else if (lds.get(store.outputs, `${item.id}.step`, -1) < 100) { - return 发布中 - } - } - return 发布成功 - } else { - return {store.request['status_alias'] || '...'} - } - }; - - render() { - const {app_name, env_name, status, server_actions, host_actions} = store.request; - return ( - - - } type="primary" onClick={this.fetch}>刷新 - ) : ( - - )} - onBack={() => history.goBack()}/> - - - - - {server_actions.map((item, index) => ( - - ))} - }> - - - - - {host_actions.length > 0 && ( - }> - {store.request.targets.map((item, index) => ( - - {item.title} - - - {host_actions.map((action, index) => ( - - ))} - - }> - - - ))} - - )} - {host_actions.length === 0 && this.state.fetching === false && ( -
无目标主机动作
- )} -
-
- ) - } -} - -export default Ext1Index diff --git a/spug_web/src/pages/deploy/do/OutView.js b/spug_web/src/pages/deploy/do/OutView.js deleted file mode 100644 index d977bc0..0000000 --- a/spug_web/src/pages/deploy/do/OutView.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug - * Copyright (c) - * 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'; -import store from './store'; -import lds from 'lodash'; - -@observer -class OutView extends React.Component { - constructor(props) { - super(props); - this.el = null; - } - - componentDidUpdate(prevProps, prevState, snapshot) { - setTimeout(() => { - if (this.el) this.el.scrollTop = this.el.scrollHeight - }, 100) - } - - render() { - const outputs = lds.get(store.outputs, `${this.props.id}.data`, []); - return ( -
 this.el = el} className={styles.ext1Console}>
-        {toJS(outputs)}
-      
- ) - } -} - -export default OutView \ No newline at end of file diff --git a/spug_web/src/pages/deploy/do/index.module.css b/spug_web/src/pages/deploy/do/index.module.css deleted file mode 100644 index c96cab9..0000000 --- a/spug_web/src/pages/deploy/do/index.module.css +++ /dev/null @@ -1,49 +0,0 @@ -.header { - display: flex; -} - -.collapse { - margin-top: 16px; -} - -.collapse :global(.ant-collapse-content-box) { - padding: 0; -} - -.ext1Console { - min-height: 40px; - max-height: 300px; - padding: 10px 15px; -} - -.ext2Block { - display: flex; - background-color: #fff; - margin-top: 16px; - border-radius: 4px; - border: 1px solid #d9d9d9; -} - -.ext2Console { - flex: 1; - padding: 30px; -} - -.ext2Step { - padding: 24px; - width: 220px; - border-right: 1px solid #e8e8e8; -} - -.ext2Step :global(.ant-steps-item) { - height: 100px; -} - -.ext2Tips { - color: #888; - margin-top: 30px; -} - -pre { - margin: 0; -} \ No newline at end of file diff --git a/spug_web/src/pages/deploy/do/store.js b/spug_web/src/pages/deploy/do/store.js deleted file mode 100644 index 88954e3..0000000 --- a/spug_web/src/pages/deploy/do/store.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug - * Copyright (c) - * Released under the AGPL-3.0 License. - */ -import { observable } from "mobx"; - -class Store { - @observable outputs = {}; - @observable request = { - targets: [], - host_actions: [], - server_actions: [] - }; -} - -export default new Store() diff --git a/spug_web/src/routes.js b/spug_web/src/routes.js index e0d60ec..23581f0 100644 --- a/spug_web/src/routes.js +++ b/spug_web/src/routes.js @@ -25,8 +25,6 @@ import ExecTemplate from './pages/exec/template'; import DeployApp from './pages/deploy/app'; import DeployRepository from './pages/deploy/repository'; import DeployRequest from './pages/deploy/request'; -import DoExt1Index from './pages/deploy/do/Ext1Index'; -import DoExt2Index from './pages/deploy/do/Ext2Index'; import ScheduleIndex from './pages/schedule'; import ConfigEnvironment from './pages/config/environment'; import ConfigService from './pages/config/service'; @@ -63,10 +61,6 @@ export default [ {title: '应用管理', auth: 'deploy.app.view', path: '/deploy/app', component: DeployApp}, {title: '构建仓库', auth: 'deploy.repository.view', path: '/deploy/repository', component: DeployRepository}, {title: '发布申请', auth: 'deploy.request.view', path: '/deploy/request', component: DeployRequest}, - {path: '/deploy/do/ext1/:id', component: DoExt1Index}, - {path: '/deploy/do/ext2/:id', component: DoExt2Index}, - {path: '/deploy/do/ext1/:id/:log', component: DoExt1Index}, - {path: '/deploy/do/ext2/:id/:log', component: DoExt2Index}, ] }, {