mirror of https://github.com/openspug/spug
update
parent
e58e6d2666
commit
ae55a617d0
|
@ -7,4 +7,5 @@ from .views import *
|
|||
|
||||
urlpatterns = [
|
||||
path('', RepositoryView.as_view()),
|
||||
path('request/', get_requests),
|
||||
]
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.views.generic import View
|
|||
from django.db.models import F
|
||||
from libs import json_response, JsonParser, Argument
|
||||
from apps.repository.models import Repository
|
||||
from apps.deploy.models import DeployRequest
|
||||
from apps.repository.utils import dispatch
|
||||
from apps.app.models import Deploy
|
||||
from threading import Thread
|
||||
|
@ -66,5 +67,21 @@ class RepositoryView(View):
|
|||
repository = Repository.objects.filter(pk=form.id).first()
|
||||
if not repository:
|
||||
return json_response(error='未找到指定构建记录')
|
||||
|
||||
if repository.deployrequest_set.exists():
|
||||
return json_response(error='已关联发布申请无法删除')
|
||||
repository.delete()
|
||||
return json_response(error=error)
|
||||
|
||||
|
||||
def get_requests(request):
|
||||
form, error = JsonParser(
|
||||
Argument('repository_id', type=int, help='参数错误')
|
||||
).parse(request.GET)
|
||||
if error is None:
|
||||
requests = []
|
||||
for item in DeployRequest.objects.filter(repository_id=form.repository_id):
|
||||
data = item.to_dict(selects=('id', 'name', 'created_at'))
|
||||
data['host_ids'] = json.loads(item.host_ids)
|
||||
data['status_alias'] = item.get_status_display()
|
||||
requests.append(data)
|
||||
return json_response(requests)
|
||||
|
|
|
@ -1,44 +1,45 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import { observer } from 'mobx-react';
|
||||
import { Drawer, Descriptions, Table } from 'antd';
|
||||
import { Drawer, Descriptions, Table, Button } from 'antd';
|
||||
import { http } from 'libs';
|
||||
import store from './store';
|
||||
import styles from './index.module.less';
|
||||
|
||||
export default observer(function (props) {
|
||||
const [fetching, setFetching] = useState(true);
|
||||
const [order, setOrder] = useState({});
|
||||
const [requests, setRequests] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (store.record.id && props.visible) {
|
||||
|
||||
http.get('/api/repository/request/', {params: {repository_id: store.record.id}})
|
||||
.then(res => setRequests(res))
|
||||
.finally(() => setFetching(false))
|
||||
}
|
||||
}, [props.visible])
|
||||
|
||||
const columns = [{
|
||||
title: '应用名称',
|
||||
key: 'name',
|
||||
}, {
|
||||
title: '商品主图',
|
||||
dataIndex: 'pic',
|
||||
}, {
|
||||
title: '单价',
|
||||
dataIndex: 'price',
|
||||
align: 'right',
|
||||
}, {
|
||||
title: '数量',
|
||||
key: 'number',
|
||||
align: 'right',
|
||||
}, {
|
||||
title: '金额',
|
||||
key: 'money',
|
||||
align: 'right',
|
||||
}]
|
||||
function handleDelete() {
|
||||
setLoading(true);
|
||||
http.delete('/api/repository/', {params: {id: store.record.id}})
|
||||
.then(() => {
|
||||
store.fetchRecords();
|
||||
store.detailVisible = false
|
||||
})
|
||||
.finally(() => setLoading(false))
|
||||
}
|
||||
|
||||
const record = store.record;
|
||||
const [extra1, extra2, extra3] = record.extra || [];
|
||||
return (
|
||||
<Drawer width={550} visible={props.visible} onClose={() => store.detailVisible = false}>
|
||||
<Drawer
|
||||
width={600}
|
||||
visible={props.visible}
|
||||
onClose={() => store.detailVisible = false}
|
||||
footer={(
|
||||
<div style={{display: 'flex', justifyContent: 'flex-end', alignItems: 'flex-end'}}>
|
||||
<span style={{color: '#999', fontSize: 12}}>Tips: 已关联发布申请的构建版本无法删除。</span>
|
||||
<Button danger loading={loading} disabled={requests.length > 0} onClick={handleDelete}>删除</Button>
|
||||
</div>
|
||||
)}>
|
||||
<Descriptions column={1} title={<span style={{fontSize: 22}}>基本信息</span>}>
|
||||
<Descriptions.Item label="应用">{record.app_name}</Descriptions.Item>
|
||||
<Descriptions.Item label="环境">{record.env_name}</Descriptions.Item>
|
||||
|
@ -55,7 +56,12 @@ export default observer(function (props) {
|
|||
<Descriptions.Item label="构建人">{record.created_by_user}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<Descriptions title={<span style={{fontSize: 22}}>发布记录</span>} style={{marginTop: 24}}/>
|
||||
<Table rowKey="id" loading={fetching} columns={columns} dataSource={[]} pagination={false}/>
|
||||
<Table rowKey="id" loading={fetching} dataSource={requests} pagination={false}>
|
||||
<Table.Column title="发布申请" dataIndex="name"/>
|
||||
<Table.Column title="主机数量" dataIndex="host_ids" render={v => `${v.length}台`}/>
|
||||
<Table.Column title="状态" dataIndex="status_alias"/>
|
||||
<Table.Column title="申请时间" dataIndex="created_at"/>
|
||||
</Table>
|
||||
</Drawer>
|
||||
)
|
||||
})
|
|
@ -14,20 +14,6 @@ import store from './store';
|
|||
function ComTable() {
|
||||
const [loading, setLoading] = useState();
|
||||
|
||||
function handleDelete(info) {
|
||||
Modal.confirm({
|
||||
title: '删除确认',
|
||||
content: `确定要删除【${info['name']}】?`,
|
||||
onOk: () => {
|
||||
return http.delete('/api/config/environment/', {params: {id: info.id}})
|
||||
.then(() => {
|
||||
message.success('删除成功');
|
||||
store.fetchRecords()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleRebuild(info) {
|
||||
if (info.status === '5') {
|
||||
Modal.confirm({
|
||||
|
@ -71,10 +57,10 @@ function ComTable() {
|
|||
showTotal: total => `共 ${total} 条`,
|
||||
pageSizeOptions: ['10', '20', '50', '100']
|
||||
}}>
|
||||
<Table.Column ellipsis title="应用" dataIndex="app_name"/>
|
||||
<Table.Column title="应用" dataIndex="app_name"/>
|
||||
<Table.Column title="环境" dataIndex="env_name"/>
|
||||
<Table.Column title="版本" dataIndex="version"/>
|
||||
<Table.Column ellipsis title="备注" dataIndex="remarks"/>
|
||||
<Table.Column title="备注" dataIndex="remarks"/>
|
||||
<Table.Column hide title="构建时间" dataIndex="created_at"/>
|
||||
<Table.Column hide title="构建人" dataIndex="created_by_user"/>
|
||||
<Table.Column width={100} title="状态"
|
||||
|
|
Loading…
Reference in New Issue