mirror of https://github.com/openspug/spug
A web update
parent
c5e68f7f13
commit
d5b609cd12
|
@ -10,24 +10,28 @@ import lds from 'lodash';
|
||||||
class Ext1Form extends React.Component {
|
class Ext1Form extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.isReady = false;
|
||||||
this.state = {
|
this.state = {
|
||||||
loading: false,
|
loading: false,
|
||||||
fetching: true,
|
fetching: true,
|
||||||
git_type: 'branch',
|
git_type: lds.get(store.record, 'extra.0', 'branch'),
|
||||||
extra1: undefined,
|
extra1: lds.get(store.record, 'extra.1'),
|
||||||
extra2: undefined,
|
extra2: lds.get(store.record, 'extra.2'),
|
||||||
versions: {},
|
versions: {},
|
||||||
host_ids: store.record['host_ids'].concat()
|
host_ids: store.record['host_ids'].concat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.fetchVersions()
|
this.fetchVersions();
|
||||||
|
if (hostStore.records.length === 0) {
|
||||||
|
hostStore.fetchRecords()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchVersions = () => {
|
fetchVersions = () => {
|
||||||
this.setState({fetching: true});
|
this.setState({fetching: true});
|
||||||
http.get(`/api/app/${store.record.id}/versions/`)
|
http.get(`/api/app/${store.record.app_id}/versions/`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({versions: res}, this._initExtra1);
|
this.setState({versions: res}, this._initExtra1);
|
||||||
})
|
})
|
||||||
|
@ -35,19 +39,23 @@ class Ext1Form extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
_initExtra1 = () => {
|
_initExtra1 = () => {
|
||||||
const {git_type, versions: {branches, tags}} = this.state;
|
if (this.isReady === true || this.state.extra1 === undefined) {
|
||||||
let [extra1, extra2] = [undefined, undefined];
|
const {git_type, versions: {branches, tags}} = this.state;
|
||||||
if (git_type === 'branch') {
|
let [extra1, extra2] = [undefined, undefined];
|
||||||
if (branches) {
|
if (git_type === 'branch') {
|
||||||
extra1 = lds.get(Object.keys(branches), 0);
|
if (branches) {
|
||||||
extra2 = lds.get(branches[extra1], '0.id')
|
extra1 = lds.get(Object.keys(branches), 0);
|
||||||
|
extra2 = lds.get(branches[extra1], '0.id')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (tags) {
|
||||||
|
extra1 = lds.get(Object.keys(tags), 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this.setState({extra1, extra2})
|
||||||
} else {
|
} else {
|
||||||
if (tags) {
|
this.isReady = true
|
||||||
extra1 = lds.get(Object.keys(tags), 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.setState({extra1, extra2})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
switchType = (v) => {
|
switchType = (v) => {
|
||||||
|
@ -67,13 +75,16 @@ class Ext1Form extends React.Component {
|
||||||
return message.error('请至少选择一个要发布的目标主机')
|
return message.error('请至少选择一个要发布的目标主机')
|
||||||
}
|
}
|
||||||
this.setState({loading: true});
|
this.setState({loading: true});
|
||||||
|
const {git_type, extra1, extra2} = this.state;
|
||||||
const formData = this.props.form.getFieldsValue();
|
const formData = this.props.form.getFieldsValue();
|
||||||
formData['id'] = store.record.id;
|
formData['id'] = store.record.id;
|
||||||
formData['body'] = this.state.body;
|
formData['app_id'] = store.record.app_id;
|
||||||
http.post('/api/exec/template/', formData)
|
formData['host_ids'] = this.state.host_ids;
|
||||||
|
formData['extra'] = [git_type, extra1, extra2];
|
||||||
|
http.post('/api/deploy/request/', formData)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
message.success('操作成功');
|
message.success('操作成功');
|
||||||
store.formVisible = false;
|
store.ext1Visible = false;
|
||||||
store.fetchRecords()
|
store.fetchRecords()
|
||||||
}, () => this.setState({loading: false}))
|
}, () => this.setState({loading: false}))
|
||||||
};
|
};
|
||||||
|
@ -135,7 +146,7 @@ class Ext1Form extends React.Component {
|
||||||
{git_type === 'branch' && (
|
{git_type === 'branch' && (
|
||||||
<Form.Item required label="选择Commit ID">
|
<Form.Item required label="选择Commit ID">
|
||||||
<Select value={extra2} placeholder="请选择" onChange={v => this.setState({extra2: v})}>
|
<Select value={extra2} placeholder="请选择" onChange={v => this.setState({extra2: v})}>
|
||||||
{extra1 ? branches[extra1].map(item => (
|
{extra1 && branches ? branches[extra1].map(item => (
|
||||||
<Select.Option
|
<Select.Option
|
||||||
key={item.id}>{item.id.substr(0, 6)} {item['date']} {item['author']} {item['message']}</Select.Option>
|
key={item.id}>{item.id.substr(0, 6)} {item['date']} {item['author']} {item['message']}</Select.Option>
|
||||||
)) : null}
|
)) : null}
|
||||||
|
@ -148,7 +159,7 @@ class Ext1Form extends React.Component {
|
||||||
)}
|
)}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item required label="发布目标主机">
|
<Form.Item required label="发布目标主机">
|
||||||
{info['host_ids'].map(id => (
|
{info['app_host_ids'].map(id => (
|
||||||
<Tag.CheckableTag key={id} checked={host_ids.includes(id)} onChange={() => this.handleChange(id)}>
|
<Tag.CheckableTag key={id} checked={host_ids.includes(id)} onChange={() => this.handleChange(id)}>
|
||||||
{lds.get(hostStore.idMap, `${id}.name`)}({lds.get(hostStore.idMap, `${id}.hostname`)}:{lds.get(hostStore.idMap, `${id}.port`)})
|
{lds.get(hostStore.idMap, `${id}.name`)}({lds.get(hostStore.idMap, `${id}.hostname`)}:{lds.get(hostStore.idMap, `${id}.port`)})
|
||||||
</Tag.CheckableTag>
|
</Tag.CheckableTag>
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { Modal, Button, Menu, Icon } from 'antd';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
import styles from './index.module.css';
|
import styles from './index.module.css';
|
||||||
import envStore from 'pages/config/environment/store';
|
import envStore from 'pages/config/environment/store';
|
||||||
import hostStore from 'pages/host/store';
|
|
||||||
import appStore from '../app/store';
|
import appStore from '../app/store';
|
||||||
import lds from 'lodash';
|
import lds from 'lodash';
|
||||||
|
|
||||||
|
@ -26,9 +25,6 @@ class SelectApp extends React.Component {
|
||||||
if (appStore.records.length === 0) {
|
if (appStore.records.length === 0) {
|
||||||
appStore.fetchRecords()
|
appStore.fetchRecords()
|
||||||
}
|
}
|
||||||
if (hostStore.records.length === 0) {
|
|
||||||
hostStore.fetchRecords()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_initEnv = () => {
|
_initEnv = () => {
|
||||||
|
@ -38,7 +34,7 @@ class SelectApp extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
handleClick = (app) => {
|
handleClick = (app) => {
|
||||||
store.record = app;
|
store.record = {app_id: app.id, app_host_ids: app.host_ids};
|
||||||
if (app.extend === '1') {
|
if (app.extend === '1') {
|
||||||
store.ext1Visible = true
|
store.ext1Visible = true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Table, Divider, Modal, message } from 'antd';
|
import { Table, Divider, Modal, Icon, message } from 'antd';
|
||||||
import http from 'libs/http';
|
import http from 'libs/http';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
import { LinkButton } from "components";
|
import { LinkButton } from "components";
|
||||||
|
@ -12,24 +12,43 @@ class ComTable extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
columns = [{
|
columns = [{
|
||||||
title: '序号',
|
title: '申请标题',
|
||||||
key: 'series',
|
|
||||||
render: (_, __, index) => index + 1,
|
|
||||||
width: 80,
|
|
||||||
}, {
|
|
||||||
title: '模版名称',
|
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
}, {
|
}, {
|
||||||
title: '模版类型',
|
title: '应用',
|
||||||
dataIndex: 'type',
|
dataIndex: 'app_name',
|
||||||
}, {
|
}, {
|
||||||
title: '模版内容',
|
title: '发布环境',
|
||||||
render: text => text.body,
|
dataIndex: 'env_name',
|
||||||
ellipsis: true
|
|
||||||
}, {
|
}, {
|
||||||
title: '描述信息',
|
title: '版本',
|
||||||
dataIndex: 'desc',
|
render: info => {
|
||||||
ellipsis: true
|
if (info['app_extend'] === '1') {
|
||||||
|
const [type, ext1, ext2] = info.extra;
|
||||||
|
if (type === 'branch') {
|
||||||
|
return <React.Fragment>
|
||||||
|
<Icon type="branches"/> {ext1}#{ext2.substr(0, 6)}
|
||||||
|
</React.Fragment>
|
||||||
|
} else {
|
||||||
|
return <React.Fragment>
|
||||||
|
<Icon type="tag"/> {ext1}
|
||||||
|
</React.Fragment>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return <React.Fragment>
|
||||||
|
<Icon type="build"/> xxx
|
||||||
|
</React.Fragment>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status_alias'
|
||||||
|
}, {
|
||||||
|
title: '申请人',
|
||||||
|
dataIndex: 'created_by_user',
|
||||||
|
}, {
|
||||||
|
title: '申请时间',
|
||||||
|
dataIndex: 'created_at'
|
||||||
}, {
|
}, {
|
||||||
title: '操作',
|
title: '操作',
|
||||||
render: info => (
|
render: info => (
|
||||||
|
@ -60,8 +79,8 @@ class ComTable extends React.Component {
|
||||||
if (store.f_name) {
|
if (store.f_name) {
|
||||||
data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase()))
|
data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase()))
|
||||||
}
|
}
|
||||||
if (store.f_type) {
|
if (store.f_app_name) {
|
||||||
data = data.filter(item => item['type'].toLowerCase().includes(store.f_type.toLowerCase()))
|
data = data.filter(item => item['app_name'].toLowerCase().includes(store.f_app_name.toLowerCase()))
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Table rowKey="id" loading={store.isFetching} dataSource={data} columns={this.columns}/>
|
<Table rowKey="id" loading={store.isFetching} dataSource={data} columns={this.columns}/>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Card, Input, Select, Button } from 'antd';
|
import { Card, Input, Button } from 'antd';
|
||||||
import { SearchForm } from 'components';
|
import { SearchForm } from 'components';
|
||||||
import SelectApp from './SelectApp';
|
import SelectApp from './SelectApp';
|
||||||
import Ext1Form from './Ext1Form';
|
import Ext1Form from './Ext1Form';
|
||||||
|
@ -13,13 +13,9 @@ export default observer(function () {
|
||||||
<Card>
|
<Card>
|
||||||
<SearchForm>
|
<SearchForm>
|
||||||
<SearchForm.Item span={8} title="应用名称">
|
<SearchForm.Item span={8} title="应用名称">
|
||||||
<Select allowClear onChange={v => store.f_type = v} placeholder="请选择">
|
<Input allowClear onChange={e => store.f_app_name = e.target.value} placeholder="请输入"/>
|
||||||
{store.types.map(item => (
|
|
||||||
<Select.Option value={item} key={item}>{item}</Select.Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</SearchForm.Item>
|
</SearchForm.Item>
|
||||||
<SearchForm.Item span={8} title="模版名称">
|
<SearchForm.Item span={8} title="申请标题">
|
||||||
<Input allowClear onChange={e => store.f_name = e.target.value} placeholder="请输入"/>
|
<Input allowClear onChange={e => store.f_name = e.target.value} placeholder="请输入"/>
|
||||||
</SearchForm.Item>
|
</SearchForm.Item>
|
||||||
<SearchForm.Item span={8}>
|
<SearchForm.Item span={8}>
|
||||||
|
|
|
@ -11,14 +11,23 @@ class Store {
|
||||||
@observable ext2Visible = false;
|
@observable ext2Visible = false;
|
||||||
|
|
||||||
@observable f_name;
|
@observable f_name;
|
||||||
@observable f_type;
|
@observable f_app_name;
|
||||||
|
|
||||||
fetchRecords = () => {
|
fetchRecords = () => {
|
||||||
this.isFetching = true;
|
this.isFetching = true;
|
||||||
http.get('/api/app/')
|
http.get('/api/deploy/request/')
|
||||||
.then(res => this.records = res)
|
.then(res => this.records = res)
|
||||||
.finally(() => this.isFetching = false)
|
.finally(() => this.isFetching = false)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
showForm = (info) => {
|
||||||
|
this.record = info;
|
||||||
|
if (info['app_extend'] === '1') {
|
||||||
|
this.ext1Visible = true
|
||||||
|
} else {
|
||||||
|
this.ext2Visible = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new Store()
|
export default new Store()
|
Loading…
Reference in New Issue