From dd8c7c62e0f090ad128b9aa49067e7c8cdd883cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Sat, 28 Dec 2019 20:06:52 +0800 Subject: [PATCH] A web update --- spug_web/src/pages/config/service/Form.js | 4 +- spug_web/src/pages/deploy/app/AddSelect.js | 4 +- spug_web/src/pages/deploy/app/Ext1Form.js | 2 +- spug_web/src/pages/deploy/app/Ext1Setup1.js | 13 +-- spug_web/src/pages/deploy/app/Ext1Setup2.js | 4 +- spug_web/src/pages/deploy/app/Ext1Setup3.js | 9 ++- spug_web/src/pages/deploy/app/Ext2Form.js | 2 +- spug_web/src/pages/deploy/app/Ext2Setup1.js | 7 +- spug_web/src/pages/deploy/app/Ext2Setup2.js | 2 +- spug_web/src/pages/deploy/app/Ext2Setup3.js | 13 +-- spug_web/src/pages/deploy/app/Form.js | 62 ++++++++++++++ spug_web/src/pages/deploy/app/Table.js | 90 +++++++++++++++++---- spug_web/src/pages/deploy/app/index.js | 2 + spug_web/src/pages/deploy/app/store.js | 32 ++++++-- 14 files changed, 189 insertions(+), 57 deletions(-) create mode 100644 spug_web/src/pages/deploy/app/Form.js diff --git a/spug_web/src/pages/config/service/Form.js b/spug_web/src/pages/config/service/Form.js index 3ba6f47..ec6dc15 100644 --- a/spug_web/src/pages/config/service/Form.js +++ b/spug_web/src/pages/config/service/Form.js @@ -40,12 +40,12 @@ class ComForm extends React.Component {
{getFieldDecorator('name', {initialValue: info['name']})( - + )} {getFieldDecorator('key', {initialValue: info['key']})( - + )} diff --git a/spug_web/src/pages/deploy/app/AddSelect.js b/spug_web/src/pages/deploy/app/AddSelect.js index 3233860..3fce3c9 100644 --- a/spug_web/src/pages/deploy/app/AddSelect.js +++ b/spug_web/src/pages/deploy/app/AddSelect.js @@ -9,7 +9,7 @@ class AddSelect extends React.Component { switchExt1 = () => { store.addVisible = false; store.ext1Visible = true; - store.record = { + store.deploy = { git_type: 'branch', is_audit: false, versions: 10, @@ -21,7 +21,7 @@ class AddSelect extends React.Component { switchExt2 = () => { store.addVisible = false; store.ext2Visible = true; - store.record = { + store.deploy = { is_audit: false, host_ids: [undefined], host_actions: [], diff --git a/spug_web/src/pages/deploy/app/Ext1Form.js b/spug_web/src/pages/deploy/app/Ext1Form.js index bd1b41e..8be42bd 100644 --- a/spug_web/src/pages/deploy/app/Ext1Form.js +++ b/spug_web/src/pages/deploy/app/Ext1Form.js @@ -13,7 +13,7 @@ export default observer(function Ext1From() { visible width={800} maskClosable={false} - title={store.record.id ? '编辑常规发布' : '新建常规发布'} + title={store.deploy.id ? '编辑常规发布' : '新建常规发布'} onCancel={() => store.ext1Visible = false} footer={null}> diff --git a/spug_web/src/pages/deploy/app/Ext1Setup1.js b/spug_web/src/pages/deploy/app/Ext1Setup1.js index 4ebe5be..4d98a5f 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup1.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup1.js @@ -6,12 +6,9 @@ import envStore from 'pages/config/environment/store'; import store from './store'; export default observer(function Ext2Setup1() { - const info = store.record; + const info = store.deploy; return ( - - info.name = e.target.value} placeholder="请输入应用名称"/> - info['git_repo'] = e.target.value} placeholder="请输入Git仓库地址"/> - - - diff --git a/spug_web/src/pages/deploy/app/Ext1Setup2.js b/spug_web/src/pages/deploy/app/Ext1Setup2.js index c824541..5c5f28b 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup2.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup2.js @@ -14,12 +14,12 @@ class Ext1Setup2 extends React.Component { } checkStatus = () => { - const info = store.record; + const info = store.deploy; return info['dst_dir'] && info['dst_repo'] && info['versions'] && info['host_ids'].filter(x => x).length > 0 }; render() { - const info = store.record; + const info = store.deploy; return (
diff --git a/spug_web/src/pages/deploy/app/Ext1Setup3.js b/spug_web/src/pages/deploy/app/Ext1Setup3.js index df61eea..6d632b7 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup3.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup3.js @@ -20,13 +20,14 @@ class Ext1Setup3 extends React.Component { handleSubmit = () => { this.setState({loading: true}); - const info = store.record; + const info = store.deploy; + info['app_id'] = store.app_id; info['extend'] = '1'; info['host_ids'] = info['host_ids'].filter(x => x); - http.post('/api/app/', info) + http.post('/api/app/deploy/', info) .then(() => { message.success('保存成功'); - store.fetchRecords(); + store.loadDeploys(store.app_id); store.ext1Visible = false }, () => this.setState({loading: false})) }; @@ -45,7 +46,7 @@ class Ext1Setup3 extends React.Component { ); render() { - const info = store.record; + const info = store.deploy; return ( diff --git a/spug_web/src/pages/deploy/app/Ext2Form.js b/spug_web/src/pages/deploy/app/Ext2Form.js index da60f78..5a2744c 100644 --- a/spug_web/src/pages/deploy/app/Ext2Form.js +++ b/spug_web/src/pages/deploy/app/Ext2Form.js @@ -13,7 +13,7 @@ export default observer(function Ext2From() { visible width={800} maskClosable={false} - title={store.record.id ? '编辑自定义发布' : '新建自定义发布'} + title={store.deploy.id ? '编辑自定义发布' : '新建自定义发布'} onCancel={() => store.ext2Visible = false} footer={null}> diff --git a/spug_web/src/pages/deploy/app/Ext2Setup1.js b/spug_web/src/pages/deploy/app/Ext2Setup1.js index 96ec0b1..6f37753 100644 --- a/spug_web/src/pages/deploy/app/Ext2Setup1.js +++ b/spug_web/src/pages/deploy/app/Ext2Setup1.js @@ -6,12 +6,9 @@ import envStore from 'pages/config/environment/store'; import store from './store'; export default observer(function Ext2Setup1() { - const info = store.record; + const info = store.deploy; return ( - - info.name = e.target.value} placeholder="请输入应用名称"/> - + )} + + + {getFieldDecorator('key', {initialValue: info['key']})( + + )} + + + {getFieldDecorator('desc', {initialValue: info['desc']})( + + )} + + + + ) + } +} + +export default Form.create()(ComForm) \ No newline at end of file diff --git a/spug_web/src/pages/deploy/app/Table.js b/spug_web/src/pages/deploy/app/Table.js index 0a7251d..cc4e8cc 100644 --- a/spug_web/src/pages/deploy/app/Table.js +++ b/spug_web/src/pages/deploy/app/Table.js @@ -1,4 +1,5 @@ import React from 'react'; +import { toJS } from 'mobx'; import { observer } from 'mobx-react'; import { Table, Divider, Modal, Tag, Icon, message } from 'antd'; import http from 'libs/http'; @@ -25,22 +26,18 @@ class ComTable extends React.Component { title: '应用名称', dataIndex: 'name', }, { - title: '模式', - dataIndex: 'extend', - render: value => value === '1' ? : - + title: '标识符', + dataIndex: 'key' }, { - title: '发布环境', - dataIndex: 'env_id', - render: value => lds.get(envStore.idMap, `${value}.name`) - }, { - title: '发布审核', - dataIndex: 'is_audit', - render: value => value ? 开启 : 关闭 + title: '描述信息', + dataIndex: 'desc', + ellipsis: true }, { title: '操作', render: info => ( + store.showExtForm(info.id)}>新建发布 + store.showForm(info)}>编辑 this.handleDelete(info)}>删除 @@ -51,9 +48,9 @@ class ComTable extends React.Component { handleDelete = (text) => { Modal.confirm({ title: '删除确认', - content: `确定要删除【${text['name']}】?`, + content: `确定要删除应用【${text['name']}】?`, onOk: () => { - return http.delete('/api/exec/template/', {params: {id: text.id}}) + return http.delete('/api/app/', {params: {id: text.id}}) .then(() => { message.success('删除成功'); store.fetchRecords() @@ -62,14 +59,75 @@ class ComTable extends React.Component { }) }; + handleDeployDelete = (text) => { + Modal.confirm({ + title: '删除确认', + content: `确定要删除【${lds.get(envStore.idMap, `${text.env_id}.name`)}】的发布配置?`, + onOk: () => { + return http.delete('/api/app/deploy/', {params: {id: text.id}}) + .then(() => { + message.success('删除成功'); + store.loadDeploys(text.app_id) + }) + } + }) + }; + + expandedRowRender = (record) => { + const columns = [{ + title: '模式', + dataIndex: 'extend', + render: value => value === '1' ? : + , + width: 80 + }, { + title: '发布环境', + dataIndex: 'env_id', + render: value => lds.get(envStore.idMap, `${value}.name`) + }, { + title: '关联主机', + dataIndex: 'host_ids', + render: value => `${value.length} 台` + }, { + title: '发布审核', + dataIndex: 'is_audit', + render: value => value ? 开启 : 关闭 + }, { + title: '操作', + render: info => ( + + store.showExtForm(record.id, info)}>编辑 + + this.handleDeployDelete(info)}>删除 + + ) + }]; + + if (record['deploys'] === undefined) { + store.loadDeploys(record.id) + } + + return + }; + render() { - console.debug(JSON.stringify(envStore.idMap)); - let data = store.records; + let data = Object.values(toJS(store.records)); if (store.f_name) { data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase())) } + return ( -
+
) } } diff --git a/spug_web/src/pages/deploy/app/index.js b/spug_web/src/pages/deploy/app/index.js index 36332e9..e11dbbd 100644 --- a/spug_web/src/pages/deploy/app/index.js +++ b/spug_web/src/pages/deploy/app/index.js @@ -3,6 +3,7 @@ import { observer } from 'mobx-react'; import { Card, Input, Button } from 'antd'; import { SearchForm } from 'components'; import ComTable from './Table'; +import ComForm from './Form'; import Ext1Form from './Ext1Form'; import Ext2Form from './Ext2Form'; import AddSelect from './AddSelect'; @@ -23,6 +24,7 @@ export default observer(function () { + {store.formVisible && } {store.addVisible && } {store.ext1Visible && } {store.ext2Visible && } diff --git a/spug_web/src/pages/deploy/app/store.js b/spug_web/src/pages/deploy/app/store.js index 1afb180..bbbd2a8 100644 --- a/spug_web/src/pages/deploy/app/store.js +++ b/spug_web/src/pages/deploy/app/store.js @@ -2,10 +2,13 @@ import { observable } from "mobx"; import http from 'libs/http'; class Store { - @observable records = []; + @observable records = {}; @observable record = {}; + @observable deploy = {}; @observable page = 0; + @observable loading = {}; @observable isFetching = false; + @observable formVisible = false; @observable addVisible = false; @observable ext1Visible = false; @observable ext2Visible = false; @@ -15,34 +18,51 @@ class Store { fetchRecords = () => { this.isFetching = true; http.get('/api/app/') - .then(res => this.records = res) + .then(res => { + const tmp = {}; + for (let item of res) { + tmp[item.id] = item + } + this.records = tmp + }) .finally(() => this.isFetching = false) }; + loadDeploys = (id) => { + http.get('/api/app/deploy/', {params: {id}}) + .then(res => this.records[id]['deploys'] = res) + }; + showForm = (info) => { + this.record = info || {}; + this.formVisible = true; + }; + + showExtForm = (app_id, info) => { this.page = 0; + this.app_id = app_id; if (info) { if (info.extend === '1') { this.ext1Visible = true } else { this.ext2Visible = true } - this.record = info + this.deploy = info } else { this.addVisible = true; } }; addHost = () => { - this.record['host_ids'].push(undefined) + this.deploy['host_ids'].push(undefined) }; editHost = (index, v) => { - this.record['host_ids'][index] = v + this.deploy['host_ids'][index] = v }; delHost = (index) => { - this.record['host_ids'].splice(index, 1) + this.deploy['host_ids'].splice(index, 1) } }